Repository: microsoft/MLOS

Issue:
Make all parameters visible as `$vars` in paths and other applications that does not involve the OS shell
When constructing paths for file share upload and download, we require that all `$vars` in such paths should be explicitly exposed via `shell_env_params`. This makes sense for local and remote shell commands, as it prevents the leakage of (potentially sensitive) parameters to the shell but is redundant and too restrictive for the path names. We should allow using all parameters in such paths without any explicit declarations.


Discussion:

Resolving patch:
diff --git a/mlos_bench/mlos_bench/environments/local/local_fileshare_env.py b/mlos_bench/mlos_bench/environments/local/local_fileshare_env.py
--- a/mlos_bench/mlos_bench/environments/local/local_fileshare_env.py
+++ b/mlos_bench/mlos_bench/environments/local/local_fileshare_env.py
@@ -118,7 +118,7 @@ def setup(self, tunables: TunableGroups, global_config: Optional[dict] = None) -
         self._is_ready = super().setup(tunables, global_config)
         if self._is_ready:
             assert self._temp_dir is not None
-            params = self._get_env_params()
+            params = self._get_env_params(restrict=False)
             params["PWD"] = self._temp_dir
             for (path_from, path_to) in self._expand(self._upload, params):
                 self._file_share_service.upload(self._params, self._config_loader_service.resolve_path(
@@ -136,7 +136,7 @@ def _download_files(self, ignore_missing: bool = False) -> None:
             If False, proceed with downloading other files and log a warning.
         """
         assert self._temp_dir is not None
-        params = self._get_env_params()
+        params = self._get_env_params(restrict=False)
         params["PWD"] = self._temp_dir
         for (path_from, path_to) in self._expand(self._download, params):
             try:
diff --git a/mlos_bench/mlos_bench/environments/script_env.py b/mlos_bench/mlos_bench/environments/script_env.py
--- a/mlos_bench/mlos_bench/environments/script_env.py
+++ b/mlos_bench/mlos_bench/environments/script_env.py
@@ -78,17 +78,25 @@ def __init__(self,
         self._results_stdout_pattern: Optional[re.Pattern[str]] = \
             re.compile(results_stdout_pattern) if results_stdout_pattern else None
 
-    def _get_env_params(self) -> Dict[str, str]:
+    def _get_env_params(self, restrict: bool = True) -> Dict[str, str]:
         """
         Get the *shell* environment parameters to be passed to the script.
 
+        Parameters
+        ----------
+        restrict : bool
+            If True, only return the parameters that are in the `_shell_env_params`
+            list. If False, return all parameters in `_params` with some possible
+            conversions.
+
         Returns
         -------
         env_params : Dict[str, str]
             Parameters to pass as *shell* environment variables into the script.
             This is usually a subset of `_params` with some possible conversions.
         """
-        rename = {self._RE_INVALID.sub("_", key): key for key in self._shell_env_params}
+        input_params = self._shell_env_params if restrict else self._params.keys()
+        rename = {self._RE_INVALID.sub("_", key): key for key in input_params}
         rename.update(self._shell_env_params_rename)
         return {key_sub: str(self._params[key]) for (key_sub, key) in rename.items()}
 


Test patch: