{Packaging} Harden cross-platform launchers against CWD imports#33781
{Packaging} Harden cross-platform launchers against CWD imports#33781naga-nandyala wants to merge 1 commit into
Conversation
|
Hi @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). |
There was a problem hiding this comment.
Pull request overview
This PR hardens Azure CLI “production” launcher paths against current-working-directory (CWD) module shadowing (e.g., attacker-controlled azure.py in the launch directory), by avoiding python -m azure.cli and/or removing CWD from sys.path before dispatch.
Changes:
- Updated macOS and RPM launchers to execute the trusted
azure/cli/__main__.pydirectly. - Updated Windows batch/PowerShell and curl-based dispatch to remove CWD from
sys.pathbeforerunpyexecution, and preserved PowerShell exit codes. - Added targeted regression tests to ensure launcher paths do not use unsafe
-m azure.cli-style entry.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/azure-cli/azure/cli/command_modules/cognitiveservices/custom.py | Switches nested ACR login invocation to the trusted azure/cli/__main__.py entry file. |
| src/azure-cli/azps.ps1 | Removes CWD from sys.path prior to module execution and preserves exit codes; adjusts PYTHONPATH for source vs installed layouts. |
| src/azure-cli/az.bat | Removes CWD from sys.path prior to module execution; adjusts PYTHONPATH for source vs installed layouts. |
| scripts/release/tests/test_launcher_security.py | Adds hostile-CWD regression coverage and a launcher invariant. |
| scripts/release/rpm/azure-cli.spec | Hardens RPM launcher by executing trusted entry file via -s and explicit script path. |
| scripts/release/macos/templates/az_launcher.sh.in | Hardens macOS launcher by executing trusted entry file via -s and explicit script path. |
| scripts/curl_install_pypi/install.py | Hardens curl-install dispatch by removing CWD from sys.path before runpy execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ) | ||
| python_wrapper.chmod(0o755) | ||
|
|
||
| dispatch_template = runpy.run_path(str(CURL_INSTALLER))['AZ_DISPATCH_TEMPLATE'] |
| contents = launcher_path.read_text(encoding='utf-8') | ||
| self.assertNotIn('-m azure.cli', contents) | ||
| self.assertNotIn("'-m', 'azure.cli'", contents) |
|
Hi Naga, Could we preserve the trusted source/install path while removing the implicit CWD entries? A regression test where CWD matches a legitimate module path would help cover this case. |
Related command
azDescription
Follow up on #33780 by hardening the remaining production Azure CLI launch paths against current-working-directory module shadowing.
python -m azure.cliprepends the current directory tosys.path, which can execute an attacker-controlledazure.pyorazurepackage when Azure CLI is launched from an untrusted directory. This PR:azure/cli/__main__.pydirectly from the macOS and RPM launchers;sys.pathbeforerunpyexecution in the curl, Windows batch, and Windows PowerShell launchers while retaining Python 3.10 and source-layout compatibility;Related security context: #21261 and #33780.
Merge prerequisite:
src/azure-cli/azps.ps1contains an embedded Authenticode signature. Because this source change invalidates the existing signature, the file must be re-signed by the Azure CLI release/signing process before merge or packaging.Testing Guide
The regression suite renders and runs the macOS and curl launchers from a temporary hostile directory, verifies arguments and exit codes, and asserts that malicious CWD modules are not executed.
Additional local validation:
History Notes
None.
🤖 PR Validation — ️✔️ All clear