Added bucket-ownership checks for Amazon S3#18542
Conversation
|
@kingroryg Thank you for the contribution! Could you fix the following issue(s)? ⚠ DCO checkThe DCO check failed. Please sign off your commit(s) by following the instructions here. See https://github.com/mlflow/mlflow/blob/master/CONTRIBUTING.md#sign-your-work for more details. |
eb360f5 to
c5a9ba6
Compare
serena-ruan
left a comment
There was a problem hiding this comment.
Thanks for this fix, looks solid! Could you address comments?
c5a9ba6 to
cf1d489
Compare
|
@serena-ruan The requested changes have been pushed. Thanks for the prompt review! |
cf1d489 to
b0a265d
Compare
b0a265d to
6be5126
Compare
|
@serena-ruan Pushed the requested changes. Apologies for being remiss about the imports. Thanks. |
serena-ruan
left a comment
There was a problem hiding this comment.
LGTM! Thanks for the contribution!! Let's fix the doc format (https://github.com/mlflow/mlflow/actions/runs/18916054315/job/54040568892?pr=18542) and we're good to go!
6be5126 to
2b0b35c
Compare
|
Done, thx! @serena-ruan |
|
/review |
|
Documentation preview for 5c5b2bb is available at: Changed Pages (1)More info
|
2b0b35c to
8b80f0e
Compare
|
Thanks @harupy. I've pushed all the changes except this: #18542 (comment) |
Signed-off-by: Sarthak Munshi <smunshii@amazon.com>
8b80f0e to
77c6cc5
Compare
Replace _add_bucket_owner_if_present with _get_bucket_owner_params to return bucket owner parameters as a dict instead of mutating kwargs in place. This improves code clarity by making the return value explicit and eliminates side effects. Also adds type hints and uses modern Python patterns including the walrus operator for cleaner conditional assignments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Replace _get_bucket_owner_params() method with _bucket_owner_params instance variable computed once during initialization. This eliminates redundant dict creation on every S3 operation and simplifies the code by removing the method and the separate _bucket_owner variable. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Update test assertions to check _bucket_owner_params dict instead of the removed _bucket_owner attribute. Tests now verify the dict structure matches expected values. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Replace unnecessary file writing with file_path.touch() in bucket owner tests. The tests only need files to exist, not specific content. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds S3 bucket ownership verification to protect against bucket takeover attacks. It introduces a new environment variable MLFLOW_S3_EXPECTED_BUCKET_OWNER that, when set, includes the ExpectedBucketOwner parameter in all S3 API calls to verify that the bucket is owned by the expected AWS account.
Key changes:
- Added
MLFLOW_S3_EXPECTED_BUCKET_OWNERenvironment variable - Updated S3 artifact repository classes to include bucket owner verification in all S3 operations
- Added comprehensive test coverage for the bucket ownership verification feature
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| mlflow/environment_variables.py | Defines the new MLFLOW_S3_EXPECTED_BUCKET_OWNER environment variable |
| mlflow/store/artifact/s3_artifact_repo.py | Implements bucket owner verification in S3ArtifactRepository by adding _bucket_owner_params to all S3 API calls |
| mlflow/store/artifact/optimized_s3_artifact_repo.py | Implements bucket owner verification in OptimizedS3ArtifactRepository by adding _bucket_owner_params to all S3 API calls |
| tests/store/artifact/test_s3_artifact_repo.py | Adds comprehensive tests for bucket ownership verification including upload, download, list, delete, and multipart upload operations |
| docs/docs/self-hosting/architecture/artifact-store.mdx | Documents the new bucket ownership verification feature with usage examples and security context |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
Fix #18541
What changes are proposed in this pull request?
mlflow/environment_variables.py)Added
MLFLOW_S3_BUCKET_OWNERenvironment variable to specify the expected AWS account ID that owns the S3 bucket. This is optional and backward compatible - when not set, the system behaves as before.mlflow/store/artifact/s3_artifact_repo.py)_bucket_ownerattribute initialized from the environment variableExpectedBucketOwnerparameter when configured:upload_file(single file uploads)download_file(file downloads)list_objects_v2(listing artifacts)delete_objects(deleting artifacts)create_multipart_upload(multipart upload initiation)complete_multipart_upload(multipart upload completion)abort_multipart_upload(multipart upload abortion)generate_presigned_url(presigned URL generation)mlflow/store/artifact/optimized_s3_artifact_repo.py)tests/store/artifact/test_s3_artifact_repo.py)How is this PR tested?
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.