Repository navigation
[Core] Fix #34227: az login: Prevent local redis directory from shadowing dependencies - #34256
Open
Aditya Pujara (a0x1ab) wants to merge 4 commits into
Open
Aditya Pujara (a0x1ab) wants to merge 4 commits into
Aditya Pujara (a0x1ab) wants to merge 4 commits into
Conversation
…m shadowing dependencies Root cause: src/azure-cli/azure/cli/__main__.py imported core with Python's implicit working-directory sys.path entry intact. _profile._create_identity_instance lazily imports auth.identity and auth.persistence, whose msal_extensions dependency imports portalocker. With the source-pinned portalocker 3.2.0, an empty local redis directory becomes a namespace package lacking client and crashes authentication. This is dependency shadowing at CLI startup, not account or cache configuration. Change: Remove only the interpreter-prepended unsafe sys.path entry at shared CLI entry-point execution, before timeit or CLI dependencies. Skip removal under safe-path or isolated mode, using getattr for Python 3.10 compatibility. Retain explicit PYTHONPATH entries, including duplicate current-directory entries, and normal extension loading. Add credential-free real CLI subprocess regressions for default/device login, the owned launcher, cached-account group list, control-directory equivalence, account show, help/version, explicit PYTHONPATH extensions and safe-path execution. Owned PIP, batch, PowerShell and curl module … Alternatives considered: - Launcher-only -P or PYTHONSAFEPATH misses direct module invocation and does not support Python 3.10. - Using -I everywhere discards explicit PYTHONPATH imports. Verified: - Trusted validation passed (1 command). - New or changed tests fail on the base revision and pass with the change: `src/azure-cli-core/azure/cli/core/tests/test_main.py::TestCliMain::test_default_login_from_redis_directory`, `src/azure-cli-core/azure/cli/core/tests/test_main.py::TestCliMain::test_group_list_from_redis_directory`, `src/azure-cli-core/azure/cli/core/tests/test_main.py::TestCliMain::test_login_equivalent_with_and_without_redis`. - Unit tests: 8 executed, 0 skipped. - flake8 and pylint passed. - Pre-publication gates passed: release-artifact, generated-ownership, command-help, lint, regression-test, independent-review. - Repository CI and live tests run on this PR. Fixes Azure#34227
Contributor
Member
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
microsoft-github-policy-service
Bot
requested review from
Yu Chen (jsntcy) and
Yong Zhang (yonzhan)
October 21, 2026 15:39
Member
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
Contributor
There was a problem hiding this comment.
Aditya Pujara (@a0x1ab) Ready for human review. See the X Engineering Agent Report.
Member
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
Member
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The Windows batch launcher still adds the working directory through an empty PYTHONPATH component, leaving the reported failure possible.
1 open issue
What changed in this PR
This PR addresses #34227 by removing Python’s implicit import path at Azure CLI startup, preventing a local redis directory from shadowing authentication dependencies.
Changes:
- Remove the implicit path before loading CLI dependencies, while preserving explicit
PYTHONPATHentries and safe-path behavior. - Add subprocess regressions for authentication, cached-account commands, help/version, launcher execution, and extension imports.
| File | Description |
|---|---|
| src/azure-cli/azure/cli/__main__.py | Remove the implicit import path during CLI startup. |
| src/azure-cli-core/azure/cli/core/tests/test_main.py | Add startup and dependency-shadowing regression tests. |
Review effort: Balanced
Comment on lines
+10
to
+11
| # Remove Python's implicit import path, but retain explicit PYTHONPATH entries. | ||
| sys.path.pop(0) |
Collaborator
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

🤖 PR Validation — ️✔️ All clear
Related command
az loginDescription
Fixes #34227.
Prevent local redis directory from shadowing dependencies.
Root cause: src/azure-cli/azure/cli/main.py imported core with Python's implicit working-directory sys.path entry intact. _profile._create_identity_instance lazily imports auth.identity and auth.persistence, whose msal_extensions dependency imports portalocker. With the source-pinned portalocker 3.2.0, an empty local redis directory becomes a namespace package lacking client and crashes authentication. This is dependency shadowing at CLI startup, not account or cache configuration.
Fix: Remove only the interpreter-prepended unsafe sys.path entry at shared CLI entry-point execution, before timeit or CLI dependencies. Skip removal under safe-path or isolated mode, using getattr for Python 3.10 compatibility. Retain explicit PYTHONPATH entries, including duplicate current-directory entries, and normal extension loading. Add credential-free real CLI subprocess regressions for default/device login, the owned launcher, cached-account group list, control-directory equivalence, account show, help/version, explicit PYTHONPATH extensions and safe-path execution. Owned PIP, batch, PowerShell and curl module …
Risks and limitations (from the job report):
Testing Guide
src/azure-cli-core/azure/cli/core/tests/test_main.py::TestCliMain::test_default_login_from_redis_directory,src/azure-cli-core/azure/cli/core/tests/test_main.py::TestCliMain::test_group_list_from_redis_directory,src/azure-cli-core/azure/cli/core/tests/test_main.py::TestCliMain::test_login_equivalent_with_and_without_redis.Reproduction run: https://github.com/Azure/issue-sentinel/actions/runs/39347404670
History Notes
[Core]
az login: Prevent local redis directory from shadowing dependenciesThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.
Independent review: an independent reviewer checked this change against 8 acceptance criteria derived from the issue (6 required). The sandbox could not check 3 of them, so the Agent re-ran the live reproduction of the issue on this PR head and it no longer fails.