3838EXTRACT_JSON_CMD = "j"
3939
4040# Paths
41+ CONTAINER_AWS_CONFIG_DIRECTORY = pathlib .Path ("/" ) / ".aws"
4142CONTAINER_CLP_HOME = pathlib .Path ("/" ) / "opt" / "clp"
4243CONTAINER_INPUT_LOGS_ROOT_DIR = pathlib .Path ("/" ) / "mnt" / "logs"
4344CLP_DEFAULT_CONFIG_FILE_RELATIVE_PATH = pathlib .Path ("etc" ) / "clp-config.yml"
@@ -227,23 +228,20 @@ def generate_container_config(
227228 DockerMountType .BIND , input_logs_dir , container_clp_config .logs_input .directory , True
228229 )
229230
230- container_clp_config .data_directory = CONTAINER_CLP_HOME / "var" / "data"
231231 if not is_path_already_mounted (
232232 clp_home , CONTAINER_CLP_HOME , clp_config .data_directory , container_clp_config .data_directory
233233 ):
234234 docker_mounts .data_dir = DockerMount (
235235 DockerMountType .BIND , clp_config .data_directory , container_clp_config .data_directory
236236 )
237237
238- container_clp_config .logs_directory = CONTAINER_CLP_HOME / "var" / "log"
239238 if not is_path_already_mounted (
240239 clp_home , CONTAINER_CLP_HOME , clp_config .logs_directory , container_clp_config .logs_directory
241240 ):
242241 docker_mounts .logs_dir = DockerMount (
243242 DockerMountType .BIND , clp_config .logs_directory , container_clp_config .logs_directory
244243 )
245244
246- container_clp_config .archive_output .set_directory (pathlib .Path ("/" ) / "mnt" / "archive-output" )
247245 if not is_path_already_mounted (
248246 clp_home ,
249247 CONTAINER_CLP_HOME ,
@@ -256,7 +254,6 @@ def generate_container_config(
256254 container_clp_config .archive_output .get_directory (),
257255 )
258256
259- container_clp_config .stream_output .set_directory (pathlib .Path ("/" ) / "mnt" / "stream-output" )
260257 if not is_path_already_mounted (
261258 clp_home ,
262259 CONTAINER_CLP_HOME ,
@@ -271,7 +268,7 @@ def generate_container_config(
271268
272269 # Only create the mount if the directory exists
273270 if clp_config .aws_config_directory is not None :
274- container_clp_config .aws_config_directory = pathlib . Path ( "/" ) / ".aws"
271+ container_clp_config .aws_config_directory = CONTAINER_AWS_CONFIG_DIRECTORY
275272 docker_mounts .aws_config_dir = DockerMount (
276273 DockerMountType .BIND ,
277274 clp_config .aws_config_directory ,
@@ -369,6 +366,9 @@ def load_config_file(
369366 clp_config .make_config_paths_absolute (clp_home )
370367 clp_config .load_execution_container_name ()
371368
369+ validate_path_for_container_mount (clp_config .data_directory )
370+ validate_path_for_container_mount (clp_config .logs_directory )
371+
372372 # Make data and logs directories node-specific
373373 hostname = socket .gethostname ()
374374 clp_config .data_directory /= hostname
@@ -509,6 +509,9 @@ def validate_worker_config(clp_config: CLPConfig):
509509 clp_config .validate_archive_output_config ()
510510 clp_config .validate_stream_output_config ()
511511
512+ validate_path_for_container_mount (clp_config .archive_output .get_directory ())
513+ validate_path_for_container_mount (clp_config .stream_output .get_directory ())
514+
512515
513516def validate_webui_config (
514517 clp_config : CLPConfig , logs_dir : pathlib .Path , settings_json_path : pathlib .Path
@@ -537,3 +540,37 @@ def validate_log_viewer_webui_config(clp_config: CLPConfig, settings_json_path:
537540 clp_config .log_viewer_webui .host ,
538541 clp_config .log_viewer_webui .port ,
539542 )
543+
544+
545+ def validate_path_for_container_mount (path : pathlib .Path ) -> None :
546+ RESTRICTED_PREFIXES : List [pathlib .Path ] = [
547+ CONTAINER_AWS_CONFIG_DIRECTORY ,
548+ CONTAINER_CLP_HOME ,
549+ CONTAINER_INPUT_LOGS_ROOT_DIR ,
550+ pathlib .Path ("/bin" ),
551+ pathlib .Path ("/boot" ),
552+ pathlib .Path ("/dev" ),
553+ pathlib .Path ("/etc" ),
554+ pathlib .Path ("/lib" ),
555+ pathlib .Path ("/lib32" ),
556+ pathlib .Path ("/lib64" ),
557+ pathlib .Path ("/libx32" ),
558+ pathlib .Path ("/proc" ),
559+ pathlib .Path ("/root" ),
560+ pathlib .Path ("/run" ),
561+ pathlib .Path ("/sbin" ),
562+ pathlib .Path ("/srv" ),
563+ pathlib .Path ("/sys" ),
564+ pathlib .Path ("/usr" ),
565+ pathlib .Path ("/var" ),
566+ ]
567+
568+ if not path .is_absolute ():
569+ raise ValueError (f"Path: `{ path } ` must be absolute:" )
570+
571+ for prefix in RESTRICTED_PREFIXES :
572+ if path .is_relative_to (prefix ):
573+ raise ValueError (
574+ f"Invalid path: `{ path } ` cannot be under '{ prefix } ' which may overlap with a path"
575+ f" in the container."
576+ )
0 commit comments