Skip to content

fix(train): validate symlinks stay within source root when staging to S3 - #6569

Closed
mufaddal-rohawala wants to merge 1 commit into
aws:masterfrom
mufaddal-rohawala:fix/model-trainer-symlink-staging-V2444867084
Closed

mufaddal-rohawala wants to merge 1 commit into
aws:masterfrom
mufaddal-rohawala:fix/model-trainer-symlink-staging-V2444867084

Conversation

@mufaddal-rohawala

Copy link
Copy Markdown
Member

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.

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).

This branch was successfully deployed

1 active deployment
auto-approve — bddc6c3d Deployed Nov 6, 2026 by mufaddal-rohawala via wait-for-approval #1913
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants