Skip to content

Commit b11c1a5

Browse files
authored
Relax tenant verification for credentials having optional tenant IDs (Azure#23951)
1 parent e557039 commit b11c1a5

File tree

8 files changed

+359
-255
lines changed

8 files changed

+359
-255
lines changed

sdk/azidentity/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
### Bugs Fixed
1010
* User credential types inconsistently log access token scopes
1111
* `DefaultAzureCredential` skips managed identity in Azure Container Instances
12+
* Credentials having optional tenant IDs such as `AzureCLICredential` and
13+
`InteractiveBrowserCredential` require setting `AdditionallyAllowedTenants`
14+
when used with some clients
1215

1316
### Other Changes
1417
* `ChainedTokenCredential` and `DefaultAzureCredential` continue to their next

sdk/azidentity/azidentity.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,16 @@ func resolveAdditionalTenants(tenants []string) []string {
105105
return cp
106106
}
107107

108-
// resolveTenant returns the correct tenant for a token request
108+
// resolveTenant returns the correct tenant for a token request, or "" when the calling credential doesn't
109+
// have an explicitly configured tenant and the caller didn't specify a tenant for the token request.
110+
//
111+
// - defaultTenant: tenant set when constructing the credential, if any. "" is valid for credentials
112+
// having an optional or implicit tenant such as dev tool and interactive user credentials. Those
113+
// default to the tool's configured tenant or the user's home tenant, respectively.
114+
// - specified: tenant specified for this token request i.e., TokenRequestOptions.TenantID. May be "".
115+
// - credName: name of the calling credential type; for error messages
116+
// - additionalTenants: optional allow list of tenants the credential may acquire tokens from in
117+
// addition to defaultTenant i.e., the credential's AdditionallyAllowedTenants option
109118
func resolveTenant(defaultTenant, specified, credName string, additionalTenants []string) (string, error) {
110119
if specified == "" || specified == defaultTenant {
111120
return defaultTenant, nil
@@ -121,6 +130,17 @@ func resolveTenant(defaultTenant, specified, credName string, additionalTenants
121130
return specified, nil
122131
}
123132
}
133+
if len(additionalTenants) == 0 {
134+
switch defaultTenant {
135+
case "", organizationsTenantID:
136+
// The application didn't specify a tenant or allow list when constructing the credential. Allow the
137+
// tenant specified for this token request because we have nothing to compare it to (i.e., it vacuously
138+
// satisfies the credential's configuration); don't know whether the application is multitenant; and
139+
// don't want to return an error in the common case that the specified tenant matches the credential's
140+
// default tenant determined elsewhere e.g., in some dev tool's configuration.
141+
return specified, nil
142+
}
143+
}
124144
return "", fmt.Errorf(`%s isn't configured to acquire tokens for tenant %q. To enable acquiring tokens for this tenant add it to the AdditionallyAllowedTenants on the credential options, or add "*" to allow acquiring tokens for any tenant`, credName, specified)
125145
}
126146

0 commit comments

Comments
 (0)