Repository navigation
fix: validate symlinks stay within source root when staging to S3 - #6570
Open
mufaddal-rohawala wants to merge 1 commit into
Open
mufaddal-rohawala wants to merge 1 commit into
mufaddal-rohawala wants to merge 1 commit into
Conversation
When ModelTrainer stages a local source_dir to S3 for the code channel, it copies/archives the directory (shutil.copytree, Session.upload_data), which follows nested symlinks: a symlink under source_dir that points elsewhere on the file system gets packaged as a regular file, pulling in unrelated content. Validate source_dir before staging the code channel in _create_training_job_args, reusing _validate_source_directory and _validate_symlinks_within_root from sagemaker.core.common_utils (the same guards ModelBuilder uses, added in aws#6545). The check is scoped to source_dir and skipped for LOCAL_CONTAINER (which mounts via EFS and does not upload). User InputData data channels are intentionally not covered, so shared-storage and local Hugging Face snapshot layouts that rely on symlinks keep working, consistent with aws#6545. Nested symlinks that resolve inside source_dir (relative or absolute) are still supported; S3 and .tar.gz inputs are unaffected. Adds unit tests driven through _create_training_job_args(): an in-root symlink is staged, an out-of-root symlink is rejected, and a data channel with an out-of-root symlink still uploads. Behavior change: a symlink under source_dir that resolves outside source_dir now raises ValueError during ModelTrainer.train(). To fix, copy the target into source_dir or point source_dir at a parent directory that contains both.
papriwal
approved these changes
Nov 6, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When ModelTrainer stages a local source_dir to S3 for the code channel, it copies/archives the directory (shutil.copytree, Session.upload_data), which follows nested symlinks: a symlink under source_dir that points elsewhere on the file system gets packaged as a regular file, pulling in unrelated content.
Validate source_dir before staging the code channel in _create_training_job_args, reusing _validate_source_directory and _validate_symlinks_within_root from sagemaker.core.common_utils (the same guards ModelBuilder uses, added in #6545). The check is scoped to source_dir and skipped for LOCAL_CONTAINER (which mounts via EFS and does not upload). User InputData data channels are intentionally not covered, so shared-storage and local Hugging Face snapshot layouts that rely on symlinks keep working, consistent with #6545. Nested symlinks that resolve inside source_dir (relative or absolute) are still supported; S3 and .tar.gz inputs are unaffected.
Adds unit tests driven through _create_training_job_args(): an in-root symlink is staged, an out-of-root symlink is rejected, and a data channel with an out-of-root symlink still uploads.
Behavior change: a symlink under source_dir that resolves outside source_dir now raises ValueError during ModelTrainer.train(). To fix, copy the target into source_dir or point source_dir at a parent directory that contains both.
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.