fix: improve logging around packages_to_install#269
fix: improve logging around packages_to_install#269briangallagher wants to merge 2 commits intokubeflow:mainfrom
Conversation
Signed-off-by: Brian Gallagher <briangal@gmail.com>
ed465a1 to
363a68f
Compare
kramaranya
left a comment
There was a problem hiding this comment.
Thanks @briangallagher, left a few comments.
/assign @andreyvelich @astefanutti
| echo "ERROR: Failed to install Python packages: $PACKAGES" >&2 | ||
| cat "$LOG_FILE" >&2 |
There was a problem hiding this comment.
shall we have exit 1 here?
There was a problem hiding this comment.
I think we should, updated.
| if PIP_DISABLE_PIP_VERSION_CHECK=1 python -m pip install --quiet \\ | ||
| --no-warn-script-location $PIP_OPTS --user $PACKAGES >"$LOG_FILE" 2>&1; then | ||
| echo "Successfully installed Python packages: $PACKAGES" | ||
| elif PIP_DISABLE_PIP_VERSION_CHECK=1 python -m pip install --quiet \\ | ||
| --no-warn-script-location $PIP_OPTS $PACKAGES >"$LOG_FILE" 2>&1; then | ||
| echo "Successfully installed Python packages: $PACKAGES" | ||
| else | ||
| echo "ERROR: Failed to install Python packages: $PACKAGES" >&2 | ||
| cat "$LOG_FILE" >&2 |
There was a problem hiding this comment.
Looks like we overwrite the first attempt's output with the second. Can we append the second output?
There was a problem hiding this comment.
Good catch, updated now
Signed-off-by: Brian Gallagher <briangal@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Pull Request Test Coverage Report for Build 22133084545Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
There was a problem hiding this comment.
Pull request overview
This PR improves pip install logging for runtime package installation to address issue #268. The previous implementation ran two pip install attempts with ||, causing confusing error messages when the first attempt failed but the second succeeded. The new implementation uses explicit shell logic with an if-elif-else structure that captures pip output to a log file and only displays errors when both installation attempts fail.
Changes:
- Refactored pip install script to use explicit conditional logic instead of
||operator - Added log file capture (
/tmp/pip_install.log) to store pip output from both installation attempts - Success cases now print concise confirmation messages instead of verbose pip output
- Error cases display captured log content only when both user and system-wide installations fail
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
kubeflow/trainer/backends/kubernetes/utils.py |
Rewrote get_script_for_python_packages to use shell variables and if-elif-else logic for better error handling |
kubeflow/trainer/backends/kubernetes/utils_test.py |
Updated test expectations to match new shell script format with log file handling |
kubeflow/trainer/backends/kubernetes/backend_test.py |
Refactored get_custom_trainer to call utils.get_script_for_python_packages for consistency with production code |
| # first url will be the index-url. | ||
| options = [f"--index-url {pip_index_urls[0]}"] | ||
| options.extend(f"--extra-index-url {extra_index_url}" for extra_index_url in pip_index_urls[1:]) | ||
| options_str = " ".join(options) |
There was a problem hiding this comment.
Command injection vulnerability: pip_index_urls are embedded in shell options without escaping. A malicious URL like 'https://evil.com"; rm -rf / #' could break out of the quotes and execute arbitrary commands. Apply shlex.quote() to each URL when building options: options = [f"--index-url {shlex.quote(pip_index_urls[0])}"] and similarly for extra-index-url.
There was a problem hiding this comment.
Good catch, tho.
@kubeflow/kubeflow-sdk-team @kubeflow/wg-pipeline-leads Do we know if we have the same CVE in KFP Client upstream?
| PACKAGES="{packages_str}" | ||
| PIP_OPTS="{options_str}" |
There was a problem hiding this comment.
Command injection vulnerability: packages_str and options_str are directly interpolated into double-quoted shell strings without escaping. A malicious package name like 'torch"; rm -rf / #' or URL with shell metacharacters could break out of the quotes and execute arbitrary commands. Use shlex.quote() to properly escape each package name and URL before joining them, or use shell arrays for safer variable handling.
|
Thanks @briangallagher! /lgtm |
kramaranya
left a comment
There was a problem hiding this comment.
Thanks @briangallagher!
/lgtm
/assign @andreyvelich @Fiona-Waters
andreyvelich
left a comment
There was a problem hiding this comment.
Sorry for the delay @briangallagher!
Overall, looks good! I left a few thoughts.
| # first url will be the index-url. | ||
| options = [f"--index-url {pip_index_urls[0]}"] | ||
| options.extend(f"--extra-index-url {extra_index_url}" for extra_index_url in pip_index_urls[1:]) | ||
| options_str = " ".join(options) |
There was a problem hiding this comment.
Good catch, tho.
@kubeflow/kubeflow-sdk-team @kubeflow/wg-pipeline-leads Do we know if we have the same CVE in KFP Client upstream?
|
|
||
| if PIP_DISABLE_PIP_VERSION_CHECK=1 python -m pip install --quiet \\ | ||
| --no-warn-script-location $PIP_OPTS --user $PACKAGES >"$LOG_FILE" 2>&1; then | ||
| echo "Successfully installed Python packages: $PACKAGES" |
There was a problem hiding this comment.
Maybe we should say?
| echo "Successfully installed Python packages: $PACKAGES" | |
| echo "Successfully installed the user' Python packages: $PACKAGES" |
| echo "Successfully installed Python packages: $PACKAGES" | ||
| elif PIP_DISABLE_PIP_VERSION_CHECK=1 python -m pip install --quiet \\ | ||
| --no-warn-script-location $PIP_OPTS $PACKAGES >>"$LOG_FILE" 2>&1; then | ||
| echo "Successfully installed Python packages: $PACKAGES" |
There was a problem hiding this comment.
| echo "Successfully installed Python packages: $PACKAGES" | |
| echo "Successfully installed the system's Python packages: $PACKAGES" |
| f""" | ||
| PACKAGES="{packages_str}" | ||
| PIP_OPTS="{options_str}" | ||
| LOG_FILE=/tmp/pip_install.log |
There was a problem hiding this comment.
What if /tmp directory doesn't exist, shall we just use ?
Do we know if KFP client write pip logs to a file?
cc @kubeflow/wg-pipeline-leads
Improve pip install logging for runtime package installation #268
Fixes #268
Checklist: