fix: apply output KMS key to ModelTrainer source-code S3 uploads (#5956) - #6339
Conversation
…#5956) V2 Estimator encrypted staged user code in S3 with output_kms_key; v3 ModelTrainer uploaded source code and driver files to S3 with no KMS encryption, so it could not be used in environments whose S3 policies enforce SSE-KMS. create_input_data_channel now passes S3 ExtraArgs (ServerSideEncryption=aws:kms, SSEKMSKeyId=...) on local uploads, using an explicit new kms_key argument when given and otherwise falling back to output_data_config.kms_key_id (mirroring V2, where the output KMS key also encrypted staged code). Behavior is unchanged when no KMS key is configured (extra_args stays None).
|
Claude finished @mohamedzeidan2021's task in 1m 28s —— View job Code Review
(The inline-comment tool isn't available in this run, so findings are inline below with file:line references.) Overall this is a clean, correct, well-scoped fix that restores v2 parity for encrypting staged user code. The design is sound: routing all local uploads through I verified the key claims:
Minor observations (non-blocking)
No correctness, security, or performance concerns. The KMS |
Issue
Fixes #5956.
The v2
Estimatorencrypted staged user code in S3 usingoutput_kms_key(see_stage_user_code_in_s3). The v3ModelTraineruploads source code and driver files to S3 (viacreate_input_data_channel→Session.upload_data) with no KMS encryption and no way to configure one. In environments whose S3 bucket policies enforce SSE-KMS, this makesModelTrainerunusable with custom training scripts — a regression from v2.Fix
create_input_data_channelnow encrypts local uploads with a KMS key when one is configured:kms_key: Optional[str] = Noneargument (appended last; keyword-compatible)._resolve_upload_extra_args: uses the explicitkms_keyif given, else falls back tooutput_data_config.kms_key_id— mirroring v2, where the output KMS key also encrypted staged code. It returns S3ExtraArgs{"ServerSideEncryption": "aws:kms", "SSEKMSKeyId": <key>}, orNonewhen no usable string key is set (so aPipelineVariable/Unassigned/Nonekey is ignored).upload_datacalls now passextra_args=.Because the internal
source_code,sm_drivers, andrecipechannels all route throughcreate_input_data_channel, they inherit the configuredoutput_data_config.kms_key_idautomatically. S3-URI /S3DataSource/FileSystemDataSource/ local-container sources don't upload and are unaffected.Validation
test_model_trainer.py): new tests assert the KMSExtraArgsare passed whenoutput_data_config.kms_key_idis set, when an explicitkms_keyoverrides it, and thatextra_argsstaysNoneby default. Fail on master, pass with the fix; full module green (72 passed).upload_data(..., extra_args={"ServerSideEncryption":"aws:kms","SSEKMSKeyId":...})produced an object thathead_objectreports asServerSideEncryption=aws:kmswith a resolved KMS key ARN.Backwards compatibility
Default behavior is byte-identical: with no KMS key configured,
extra_argsisNoneand uploads are unchanged. The new argument is optional and keyword-compatible; no public signature is broken.