Repository navigation
fix(train): validate symlinks stay within source root when staging to S3 - #6569
Closed
mufaddal-rohawala wants to merge 1 commit into
Closed
mufaddal-rohawala wants to merge 1 commit into
mufaddal-rohawala wants to merge 1 commit into
Conversation
ModelTrainer.create_input_data_channel stages a local source_dir or input path to S3 so the training container can download it. The upload path copies/archives the directory (shutil.copytree, Session.upload_data), which follows nested symlinks: a symlink under the directory that points elsewhere on the file system gets packaged as a regular file, pulling in unrelated content. Reuse the existing _validate_symlinks_within_root() helper from sagemaker.core.common_utils (added in aws#6545 for ModelBuilder packaging) and invoke it before staging a local directory. Nested symlinks that resolve inside the directory, relative or absolute, are still supported; a symlink that resolves outside the directory now raises ValueError. S3 and tar.gz inputs are unaffected. Adds unit tests covering an in-root symlink (staged normally) and an out-of-root symlink (rejected before upload).
aviruthen
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.
ModelTrainer.create_input_data_channel stages a local source_dir or input path to S3 so the training container can download it. The upload path copies/archives the directory (shutil.copytree, Session.upload_data), which follows nested symlinks: a symlink under the directory that points elsewhere on the file system gets packaged as a regular file, pulling in unrelated content.
Reuse the existing _validate_symlinks_within_root() helper from sagemaker.core.common_utils (added in #6545 for ModelBuilder packaging) and invoke it before staging a local directory. Nested symlinks that resolve inside the directory, relative or absolute, are still supported; a symlink that resolves outside the directory now raises ValueError. S3 and tar.gz inputs are unaffected.
Adds unit tests covering an in-root symlink (staged normally) and an out-of-root symlink (rejected before upload).
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.