Switch container build to subprocess for Sagemaker#19277
Switch container build to subprocess for Sagemaker#19277BenWilson2 merged 3 commits intomlflow:masterfrom
Conversation
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
There was a problem hiding this comment.
Pull request overview
This PR enhances security by replacing shell command execution (os.system()) with direct subprocess calls in the SageMaker container build and deployment process. This eliminates potential shell injection attack vectors.
Key Changes:
- Replaced shell command concatenation and
os.system()with individualsubprocess.run()calls inpush_image_to_ecr() - Changed from importing
Popendirectly to usingsubprocess.Popenfor consistency - Removed platform-specific command separator logic (no longer needed with subprocess)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Documentation preview for d2abc1e is available at: More info
|
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
mlflow/sagemaker/__init__.py
Outdated
| subprocess.run( | ||
| ["docker", "login", "--username", "AWS", "--password-stdin", registry], | ||
| input=aws_result.stdout, | ||
| capture_output=True, |
There was a problem hiding this comment.
do we need to capture_output? The original code doesn't.
There was a problem hiding this comment.
The only one we need it for is the first one :) The others are not really super critical and it's best that both stdout and stderr just stream naturally. I'll remove those other ones!
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| capture_output=True, | ||
| check=True, | ||
| ) | ||
| subprocess.run( | ||
| ["docker", "login", "--username", "AWS", "--password-stdin", registry], | ||
| input=aws_result.stdout, | ||
| check=True, |
There was a problem hiding this comment.
For consistency with other subprocess usage in the codebase, consider adding text=True to subprocess.run calls when dealing with text output. While the current implementation works (passing bytes from aws_result.stdout to docker login stdin), using text=True would make the code more readable and consistent with patterns in mlflow/utils/environment.py and mlflow/utils/env_pack.py.
Additionally, the second subprocess.run call (line 154) should capture output with capture_output=True to enable better error diagnostics if the docker login command fails.
| capture_output=True, | |
| check=True, | |
| ) | |
| subprocess.run( | |
| ["docker", "login", "--username", "AWS", "--password-stdin", registry], | |
| input=aws_result.stdout, | |
| check=True, | |
| capture_output=True, | |
| text=True, | |
| check=True, | |
| ) | |
| subprocess.run( | |
| ["docker", "login", "--username", "AWS", "--password-stdin", registry], | |
| input=aws_result.stdout, | |
| check=True, | |
| capture_output=True, | |
| text=True, |
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
Change the container build process for EKS to use subprocess execution to eliminate an attack vector. This is how other similar operations are already done in MLflow.
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.