38
38
EXTRACT_JSON_CMD = "j"
39
39
40
40
# Paths
41
+ CONTAINER_AWS_CONFIG_DIRECTORY = pathlib .Path ("/" ) / ".aws"
41
42
CONTAINER_CLP_HOME = pathlib .Path ("/" ) / "opt" / "clp"
42
43
CONTAINER_INPUT_LOGS_ROOT_DIR = pathlib .Path ("/" ) / "mnt" / "logs"
43
44
CLP_DEFAULT_CONFIG_FILE_RELATIVE_PATH = pathlib .Path ("etc" ) / "clp-config.yml"
@@ -227,23 +228,20 @@ def generate_container_config(
227
228
DockerMountType .BIND , input_logs_dir , container_clp_config .logs_input .directory , True
228
229
)
229
230
230
- container_clp_config .data_directory = CONTAINER_CLP_HOME / "var" / "data"
231
231
if not is_path_already_mounted (
232
232
clp_home , CONTAINER_CLP_HOME , clp_config .data_directory , container_clp_config .data_directory
233
233
):
234
234
docker_mounts .data_dir = DockerMount (
235
235
DockerMountType .BIND , clp_config .data_directory , container_clp_config .data_directory
236
236
)
237
237
238
- container_clp_config .logs_directory = CONTAINER_CLP_HOME / "var" / "log"
239
238
if not is_path_already_mounted (
240
239
clp_home , CONTAINER_CLP_HOME , clp_config .logs_directory , container_clp_config .logs_directory
241
240
):
242
241
docker_mounts .logs_dir = DockerMount (
243
242
DockerMountType .BIND , clp_config .logs_directory , container_clp_config .logs_directory
244
243
)
245
244
246
- container_clp_config .archive_output .set_directory (pathlib .Path ("/" ) / "mnt" / "archive-output" )
247
245
if not is_path_already_mounted (
248
246
clp_home ,
249
247
CONTAINER_CLP_HOME ,
@@ -256,7 +254,6 @@ def generate_container_config(
256
254
container_clp_config .archive_output .get_directory (),
257
255
)
258
256
259
- container_clp_config .stream_output .set_directory (pathlib .Path ("/" ) / "mnt" / "stream-output" )
260
257
if not is_path_already_mounted (
261
258
clp_home ,
262
259
CONTAINER_CLP_HOME ,
@@ -271,7 +268,7 @@ def generate_container_config(
271
268
272
269
# Only create the mount if the directory exists
273
270
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
275
272
docker_mounts .aws_config_dir = DockerMount (
276
273
DockerMountType .BIND ,
277
274
clp_config .aws_config_directory ,
@@ -369,6 +366,9 @@ def load_config_file(
369
366
clp_config .make_config_paths_absolute (clp_home )
370
367
clp_config .load_execution_container_name ()
371
368
369
+ validate_path_for_container_mount (clp_config .data_directory )
370
+ validate_path_for_container_mount (clp_config .logs_directory )
371
+
372
372
# Make data and logs directories node-specific
373
373
hostname = socket .gethostname ()
374
374
clp_config .data_directory /= hostname
@@ -509,6 +509,9 @@ def validate_worker_config(clp_config: CLPConfig):
509
509
clp_config .validate_archive_output_config ()
510
510
clp_config .validate_stream_output_config ()
511
511
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
+
512
515
513
516
def validate_webui_config (
514
517
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:
537
540
clp_config .log_viewer_webui .host ,
538
541
clp_config .log_viewer_webui .port ,
539
542
)
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