Fix credential scope normalization for AzureCLICredential in CI#91
Merged
Merged
Conversation
DefaultAzureCredential falls through to AzureCLICredential after azure/login OIDC. That credential passes the scope string to az account get-access-token as a resource identifier, so a delegated-permission scope like https://graph.microsoft.com/RoleManagement.Read.Directory triggers AADSTS500011 because the CLI treats the full path as the resource appId. Normalize each scope to its resource's .default form before calling GetToken. AzureCLICredential then strips /.default to extract the correct resource URL and the token request succeeds. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Root cause
`DefaultAzureCredential` falls through to `AzureCLICredential` after `azure/login` OIDC (earlier credential types — `EnvironmentCredential`, `WorkloadIdentityCredential`, `ManagedIdentityCredential` — all fail on GitHub-hosted runners without extra env-var plumbing). `AzureCLICredential` calls `az account get-access-token` and passes the scope string as a resource identifier. A delegated-permission scope like `https://graph.microsoft.com/RoleManagement.Read.Directory\` causes `AADSTS500011` because the CLI treats the full path as the resource `appId` — no such resource exists in Entra.
The Phase 1 sanity-check worked because it passed `https://graph.microsoft.com/.default\` directly. Phase 2 passes `collector.GraphRoleManagementReadScope` (`https://graph.microsoft.com/RoleManagement.Read.Directory\`), which breaks the CLI credential path.
Fix
Extract a `normalizeScope` helper and call it in `credAdapter.Token` before passing scopes to `DefaultAzureCredential.GetToken`. The helper converts:
`AzureCLICredential` then strips `/.default` to extract the resource URL (`https://graph.microsoft.com\`) and calls `az account get-access-token --resource https://graph.microsoft.com\`, which succeeds against the `azure/login` session.
Test plan
🤖 Generated with Claude Code