7474WAITING_DOT_NUMBER = 10
7575MAX_ITEMS = 100
7676PAGE_SIZE = 10
77+ _MAX_BUFFER_SIZE = 100 * 1024 * 1024 # 100 MB - Maximum buffer size for streaming iterators
78+
79+ _SENSITIVE_SYSTEM_PATHS = [
80+ abspath (os .path .expanduser ("~/.aws" )),
81+ abspath (os .path .expanduser ("~/.ssh" )),
82+ abspath (os .path .expanduser ("~/.kube" )),
83+ abspath (os .path .expanduser ("~/.docker" )),
84+ abspath (os .path .expanduser ("~/.config" )),
85+ abspath (os .path .expanduser ("~/.credentials" )),
86+ "/etc" ,
87+ "/root" ,
88+ "/home" ,
89+ "/var/lib" ,
90+ "/opt/ml/metadata" ,
91+ ]
7792
7893logger = logging .getLogger (__name__ )
7994
@@ -622,35 +637,17 @@ def _validate_source_directory(source_directory):
622637 # S3 paths and None are safe
623638 return
624639
625- abs_source = abspath (source_directory )
626-
627- # Blocklist of sensitive directories that should not be accessible
628- sensitive_paths = [
629- abspath (os .path .expanduser ("~/.aws" )),
630- abspath (os .path .expanduser ("~/.ssh" )),
631- abspath (os .path .expanduser ("~/.kube" )),
632- abspath (os .path .expanduser ("~/.docker" )),
633- abspath (os .path .expanduser ("~/.config" )),
634- abspath (os .path .expanduser ("~/.credentials" )),
635- "/etc" ,
636- "/root" ,
637- "/home" ,
638- "/var/lib" ,
639- "/opt/ml/metadata" ,
640- ]
640+ # Resolve symlinks to get the actual path
641+ abs_source = abspath (realpath (source_directory ))
641642
642643 # Check if the source path is under any sensitive directory
643- for sensitive_path in sensitive_paths :
644+ for sensitive_path in _SENSITIVE_SYSTEM_PATHS :
644645 if abs_source .startswith (sensitive_path ):
645646 raise ValueError (
646647 f"source_directory cannot access sensitive system paths. "
647648 f"Got: { source_directory } (resolved to { abs_source } )"
648649 )
649650
650- # Check for symlinks to prevent symlink-based escapes
651- if os .path .islink (abs_source ):
652- raise ValueError (f"source_directory cannot be a symlink: { source_directory } " )
653-
654651
655652def _validate_dependency_path (dependency ):
656653 """Validate that a dependency path is safe to use.
@@ -666,35 +663,17 @@ def _validate_dependency_path(dependency):
666663 if not dependency :
667664 return
668665
669- abs_dependency = abspath (dependency )
670-
671- # Blocklist of sensitive directories that should not be accessible
672- sensitive_paths = [
673- abspath (os .path .expanduser ("~/.aws" )),
674- abspath (os .path .expanduser ("~/.ssh" )),
675- abspath (os .path .expanduser ("~/.kube" )),
676- abspath (os .path .expanduser ("~/.docker" )),
677- abspath (os .path .expanduser ("~/.config" )),
678- abspath (os .path .expanduser ("~/.credentials" )),
679- "/etc" ,
680- "/root" ,
681- "/home" ,
682- "/var/lib" ,
683- "/opt/ml/metadata" ,
684- ]
666+ # Resolve symlinks to get the actual path
667+ abs_dependency = abspath (realpath (dependency ))
685668
686669 # Check if the dependency path is under any sensitive directory
687- for sensitive_path in sensitive_paths :
670+ for sensitive_path in _SENSITIVE_SYSTEM_PATHS :
688671 if abs_dependency .startswith (sensitive_path ):
689672 raise ValueError (
690673 f"dependency path cannot access sensitive system paths. "
691674 f"Got: { dependency } (resolved to { abs_dependency } )"
692675 )
693676
694- # Check for symlinks to prevent symlink-based escapes
695- if os .path .islink (abs_dependency ):
696- raise ValueError (f"dependency path cannot be a symlink: { dependency } " )
697-
698677
699678def _create_or_update_code_dir (
700679 model_dir , inference_script , source_directory , dependencies , sagemaker_session , tmp
0 commit comments