{Packaging} harden launcher against cwd module loading - #33780
{Packaging} harden launcher against cwd module loading#33780Naga Nandyala (naga-nandyala) wants to merge 2 commits into
Conversation
Replace python -m re-exec with runpy invocation and explicitly prepend the launcher src path to sys.path before module execution. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 08ab13f2-06ce-4fb7-bc01-ad4510b2f6bb
|
Hi Naga Nandyala (@naga-nandyala), |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
There was a problem hiding this comment.
Pull request overview
This PR hardens the az Python launcher against importing azure modules from an untrusted current working directory by avoiding python -m azure.cli re-exec and instead executing the CLI module in-process.
Changes:
- Replaces
os.execl(..., '-m', 'azure.cli', ...)withrunpy.run_module(...)to avoid-msemantics that put the current working directory first onsys.path. - Prepends a launcher-derived path to
sys.pathbefore executing the CLI module.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use azure.cli.__main__ as runpy target and resolve launcher path robustly by falling back to launcher directory when ./src is absent. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 08ab13f2-06ce-4fb7-bc01-ad4510b2f6bb
Live test skipped⏭️ Skipping the live test for this revision because no new test file was added ( The live-test pipeline runs only the test files a PR changes, so there is nothing to execute for this commit. This is informational — a regression test is encouraged where it makes sense, but not required. If a test file is added in a later commit, the live test will run automatically. |
There was a problem hiding this comment.
CI Review Summary
Automated CI check for this PR shows failures that need attention before merge:
| Check | Result |
|---|---|
Azure.azure-cli (Build) |
❌ Failed — Build #20260724.3 failed |
Azure.azure-cli (Test Homebrew Formula) |
❌ Failed — Test Homebrew Formula failed |
93/95 checks passed overall. Please review the failing checks below and push a fix:
- Build: https://github.com/Azure/azure-cli/runs/89389219399
- Homebrew Formula test: https://github.com/Azure/azure-cli/runs/89377866534
No live-test was applicable for this PR (no runnable test file changes detected), so this summary reflects upstream CI only.
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
🤖 PR Validation — ❌ Action needed
❌AzureCLI-BreakingChangeTest
Please submit your Breaking Change Pre-announcement ASAP if you haven't already. Please note:
Description
python -madds the current working directory to the start ofsys.path, so runningazfrom an untrusted directory can load a localazure.pybefore the real package.This change hardens the launcher in
src/azure-cli/azto avoid that cwd import path.Changes
os.execl(sys.executable, sys.executable, '-m', 'azure.cli', *sys.argv[1:])withrunpy.run_module(...).srcdirectory tosys.pathbefore module execution to preserve local launcher import behavior.run_name='__main__'andalter_sys=Truefor closer-msemantics while avoiding-mcwd import behavior.Security context
This addresses the cwd import vector described in Debian bug #1005251 while keeping launcher behavior stable.
Related