Fix Azure Arc errors returned before authentication challenge - #962
Merged
Merged
Conversation
Preserve Azure Arc endpoint errors returned before the managed identity Basic authentication challenge instead of replacing them with a misleading WWW-Authenticate exception. Add coverage for an identity selector rejected on the initial request. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2a68a512-5f7b-487b-956e-dfc6aee127c2
Gladwin Johnson VR (gladjohn)
requested a review
from a team
as a code owner
September 16, 2026 13:17
Copilot started reviewing on behalf of
Gladwin Johnson VR (gladjohn)
September 16, 2026 13:17
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The reviewed changes are covered by regression tests and have no identified blocking issues.
Pull request overview
Fixes Azure Arc pre-challenge errors by surfacing actionable response bodies instead of masking them as authentication-header errors.
Changes:
- Normalize non-401 Arc responses into managed identity errors.
- Preserve fail-closed identity selection.
- Add regression coverage for rejected selectors and caching.
File summaries
| File | Description |
|---|---|
tests/test_mi.py |
Adds regression tests for pre-challenge errors and cache behavior. |
msal/managed_identity.py |
Handles and surfaces Arc errors before authentication challenges. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Nilesh Choudhary (4gust)
approved these changes
Sep 16, 2026
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.
Summary
Azure Arc can reject an identity selector on the initial request with an HTTP error response before returning the Basic authentication challenge. MSAL currently discards that response body and raises
ManagedIdentityError: Unrecognizable WWW-Authenticate header, hiding the actionable error returned by Arc.This change:
erroranderror_description) when the initial response is not the expected HTTP 401 challengeclient_idrejected on the initial requestRegression context
This path became reachable after #944 began forwarding Azure Arc user-assigned identity selectors. Before #944, Arc selectors were ignored, so supplying a system-assigned identity's client ID appeared to work because Arc returned the system-assigned token. After #944, any supplied
client_idis correctly treated as a user-assigned identity selector, and Arc can reject a system-assigned client ID before issuing the Basic challenge.The correct system-assigned usage is to omit the selector. This PR does not restore the old silent fallback; it only preserves and surfaces Arc's actual error response.
Before
After
{ "error": "invalid_request", "error_description": "<Azure Arc response body>", }Tests
python -m pytest tests/test_mi.py -qpython -m pytest -q— 409 passed, 104 skipped