Skip to content

[Core] Fix #34227: az login: Prevent local redis directory from shadowing dependencies - #34256

Open
Aditya Pujara (a0x1ab) wants to merge 4 commits into
Azure:devfrom
a0x1ab:agent-assist/azure-azure-cli-issue-34227-2df38bbd1afd
Open

Aditya Pujara (a0x1ab) wants to merge 4 commits into
Azure:devfrom
a0x1ab:agent-assist/azure-azure-cli-issue-34227-2df38bbd1afd

Conversation

@a0x1ab

@a0x1ab Aditya Pujara (a0x1ab) commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests
️✔️ None ️✔️ 130/130

Related command

az login

Description

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):

  • Docker and macOS Homebrew Cask installations are unavailable here; container and formula-to-Cask migration verification remain …
  • Valid-credential login and rerunning the original isolated Azure group-list ReproSpec require the Azure live-test lane; …
  • Only Python 3.12 is installed locally; the supported Python version and Windows/macOS matrix remains repository …

Testing Guide

  • 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.
Before After
Reproduced: az group list Not reproduced: PR #34256 @ 468eaba: Not reproduced (exit 0)

Reproduction run: https://github.com/Azure/issue-sentinel/actions/runs/39347404670

History Notes

[Core] az login: Prevent local redis directory from shadowing dependencies


This checklist is used to make sure that common guidelines for a pull request are followed.

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.

…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
@x-engineering-agent x-engineering-agent Bot added Request X Engineering Agent Ask the agent to triage this issue or review this PR X Engineering Agent Generated Agent opened this PR do-not-merge labels Oct 21, 2026
@x-engineering-agent

x-engineering-agent Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

X Engineering Agent Pull request review: Comments

Aditya Pujara (@a0x1ab)

Agent review: no blocking findings

The startup change removes Python's implicit import path before CLI dependencies load, while preserving explicit PYTHONPATH entries and safe-path/isolated execution (src/azure-cli/azure/cli/__main__.py:7-18). The owned launcher reaches this entry point (src/azure-cli/az:19).

The new subprocess tests exercise default/device login, cached-account commands, help/version, and explicit extension imports; authentication retains real persistence imports beneath network mocks (src/azure-cli-core/azure/cli/core/tests/test_main.py:32-38,146-227). No semantic defect was confirmed. Upstream CI: 52/52 passed.

Not verified: Actual Azure sign-in, Docker/Homebrew installations, and the supported OS/Python matrix were not independently exercised. No tests were run in this review.

Test validation
  • Live test: Skipped: PR changes only azure-cli-core unit tests (not runnable by azdev --live)
  • Regression coverage: Not applicable to the changed files.
⚖️ Risk assessment — 0/100 · Low

The Low rating reflects the detected change scope with no elevated security, reliability, customer, operational, dependency, sovereign-cloud, generated-output, or cross-component signal.

  • Change scope: 2 changed files, 239 changed lines (+237 / -2), including 0 production files.
  • Affected components: No production component was identified.
  • Risk drivers: No elevated risk signal was detected.
  • Regression evidence: No production-code regression-test signal applies.
  • Confidence: Low because no production changed-line evidence was available.
  • Required review: No additional owning-squad review signal was detected.

X Engineering Agent · Reviewer · react 👍 / 👎 to train the agent

🧪 Live test — Skipped

Skipping the live test for this revision because the only test file(s) changed are azure-cli-core unit tests, which the live-test pipeline (azdev test --live) does not run — it covers command-module and extension tests only.

These azure-cli-core tests are exercised by upstream CI's unit-test jobs instead. This is informational; no action is required.

X Engineering Agent · Tester · react 👍 / 👎 to train the agent


Ask the Agent

Tick a box to queue an action. Requires write access to this repository.

  • 🔁 Re-review this PR
  • 🧪 Run Agent live tests on this PR

@a0x1ab

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@a0x1ab

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@x-engineering-agent x-engineering-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aditya Pujara (@a0x1ab) Ready for human review. See the X Engineering Agent Report.

@x-engineering-agent x-engineering-agent Bot added X Engineering Agent Reviewed Agent reviewed this PR and removed Request X Engineering Agent Ask the agent to triage this issue or review this PR labels Oct 22, 2026
@a0x1ab

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@a0x1ab

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@x-engineering-agent
x-engineering-agent Bot marked this pull request as ready for review October 23, 2026 07:28
Copilot AI balanced review requested due to automatic review settings October 23, 2026 07:28
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 PYTHONPATH entries 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)
@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: module 'redis' has no attribute 'client'

4 participants