Skip to content

Fix Azure Arc errors returned before authentication challenge - #962

Merged
Gladwin Johnson VR (gladjohn) merged 1 commit into
devfrom
fix/arc-pre-challenge-error
Sep 16, 2026
Merged

Gladwin Johnson VR (gladjohn) merged 1 commit into
devfrom
fix/arc-pre-challenge-error

Conversation

@gladjohn

@gladjohn Gladwin Johnson VR (gladjohn) commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

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:

  • returns the Arc response body through the standard MSAL token-error dictionary (error and error_description) when the initial response is not the expected HTTP 401 challenge
  • preserves fail-closed behavior for explicit identity selectors; MSAL does not retry without the selector or return a token for another identity
  • adds regression coverage for a client_id rejected on the initial request

Regression 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_id is 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

ManagedIdentityError: Unrecognizable WWW-Authenticate header: {...}

After

{
    "error": "invalid_request",
    "error_description": "<Azure Arc response body>",
}

Tests

  • python -m pytest tests/test_mi.py -q
  • python -m pytest -q — 409 passed, 104 skipped

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
Copilot AI lite review requested due to automatic review settings September 16, 2026 13:17

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.

🟢 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.

@gladjohn
Gladwin Johnson VR (gladjohn) merged commit f15f912 into dev Sep 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants