-
Notifications
You must be signed in to change notification settings - Fork 7
Derive ARM auth scopes from endpoint URL #928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,7 +126,7 @@ export function emitClients(module: rust.ModuleContainer): ClientModules | undef | |
| } | ||
|
|
||
| // if there's a credential param, create the necessary auth policy | ||
| const authPolicy = getAuthPolicy(constructor, use); | ||
| const authPolicy = getAuthPolicy(constructor, use, endpointParamName); | ||
| if (authPolicy) { | ||
| body += `${indent.get()}${authPolicy}\n`; | ||
| } | ||
|
|
@@ -680,11 +680,19 @@ function getHeaderTraitDocComment(indent: helpers.indentation, module: rust.Modu | |
| * @param use the use statement builder currently in scope | ||
| * @returns the auth policy instantiation code or undefined if not required | ||
| */ | ||
| function getAuthPolicy(ctor: rust.Constructor, use: Use): string | undefined { | ||
| function getAuthPolicy(ctor: rust.Constructor, use: Use, endpointParamName: string): string | undefined { | ||
| for (const param of ctor.params) { | ||
| const arcTokenCred = utils.asTypeOf<rust.TokenCredential>(param.type, 'tokenCredential', 'arc'); | ||
| if (arcTokenCred) { | ||
| use.add('azure_core::http::policies', 'auth::BearerTokenAuthorizationPolicy', 'Policy'); | ||
| const hasRelativeScopes = arcTokenCred.scopes.some(s => !s.startsWith('http')); | ||
| if (hasRelativeScopes) { | ||
|
Comment on lines
+688
to
+689
|
||
| // Relative scopes (e.g. "user_impersonation" from ARM specs) must be | ||
| // qualified at runtime using the service endpoint so that sovereign | ||
| // clouds work correctly. The standard Azure SDK pattern is | ||
| // "{endpoint_origin}/.default". | ||
| return `let auth_policy: Arc<dyn Policy> = Arc::new(BearerTokenAuthorizationPolicy::new(credential, vec![format!("{}/.default", ${endpointParamName}.origin().ascii_serialization())]));`; | ||
| } | ||
| const scopes = new Array<string>(); | ||
| for (const scope of arcTokenCred.scopes) { | ||
| scopes.push(`"${scope}"`); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!s.startsWith('http')misclassifies non-HTTP absolute scopes (e.g.,api://{client-id}/.default) as “relative”, which would incorrectly replace them with{endpoint_origin}/.default. Consider detecting “absolute” scopes by checking for a URI scheme (e.g.,s.includes('://')) or using URL parsing where possible, and only treating truly relative bare scopes as relative.