Derive ARM auth scopes from endpoint URL#928
Draft
cataggar wants to merge 1 commit intoAzure:mainfrom
Draft
Conversation
ARM TypeSpec specs declare OAuth2 with relative scopes like
'user_impersonation'. Passing this bare scope to the Azure
identity libraries fails because it resolves to the wrong
resource (Microsoft Graph instead of Azure Management).
When scopes are relative (not absolute URLs), generate code
that derives the scope from the endpoint origin at runtime
using the '{endpoint_origin}/.default' pattern. This is
consistent with other Azure SDK languages (Python, Go) and
correctly handles sovereign clouds.
Absolute scopes (e.g. 'https://vault.azure.net/.default')
are still emitted as static strings.
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.
Problem
ARM TypeSpec specs declare OAuth2 with relative scopes like
user_impersonation. The emitter passes this bare scope verbatim toBearerTokenAuthorizationPolicy::new(). When Azure CLI or other identity libraries try to acquire a token for justuser_impersonation, it resolves to Microsoft Graph (00000003-0000-0000-c000-000000000000) instead of Azure Management, causing authentication failures:Fix
When scopes are relative (not absolute URLs), generate code that derives the scope from the endpoint origin at runtime using the standard Azure SDK pattern:
{endpoint_origin}/.default.Before (broken):
After (fixed):
Absolute scopes (e.g.
https://vault.azure.net/.defaultused by data-plane services) are still emitted as static strings.This is consistent with other Azure SDK languages (Python uses
f"{base_url}/.default", Go usescloud.Services[ResourceManager].Audience + "/.default").Validation