-
Notifications
You must be signed in to change notification settings - Fork 245
Description
Microsoft.Identity.Web Library
Microsoft.Identity.Web
Microsoft.Identity.Web version
2.19.1
Web app
Sign-in users
Web API
Protected web APIs (validating tokens)
Token cache serialization
In-memory caches
Description
Id.Web fails to fetch a token when using FIC+MSI, if the app is deployed to Kubernetes
Reproduction steps
- Configure a FIC + MSI like:
"ClientCredentials":[
{
"SourceType":"SignedAssertionFromManagedIdentity",
"ManagedIdentityClientId":"GUID"
}
]- Deploy app on Kubernetes, where kubelogin is configred
- Use MISE CallApi or Id.Web DownstreamAPI etc.
Actual:
[MsIdWeb] Not using Managed identity for client credentials: ClientAssertionCredential authentication failed: AADSTS1002012: The provided value for scope api://AzureADTokenExchange is not valid. Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI). Trace ID: bb815fb3-3f99-4a0a-8767-e34147a08900 Correlation ID: e8e4bf4d-8461-42ca-bfeb-28224fbda7f6 Timestamp: 2024-06-12 02:51:00Z.
Notice the name of the credential that is failing - ClientAssertionCredential. This is not ManagedIdentityCredential as you'd expect. ClientAssertionCredential is part of WorkloadIdentityCredential
Root cause
This is due to the use of DefaultAzureCredential (DAC) here. DAC will first try WorkloadIdentity and then ManagedIdentity
So what happens is that WorkloadIdentity will kick in, because we're on Kubernetes and kubelogin is configured. WorkloadIdentityCredential read the assertion from a file and then Id.Web incorrectly asks for a token for api://azureAdTokenExchange (the assertion has that audience already, we don't need to ask for it!).
WorkloadIdentityCredential then fails with the above message.
Proposed solution
Workload Identity never worked with Id.Web, so it is safe to remove. We should add as an explicit SourceType. SignedAssertionFromManagedIdentity is not WorkloadIdentity and the TokenExchangeUrl config doesn't even make sense.
Error message
[MsIdWeb] Not using Managed identity for client credentials: ClientAssertionCredential authentication failed: AADSTS1002012: The provided value for scope api://AzureADTokenExchange is not valid. Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI). Trace ID: bb815fb3-3f99-4a0a-8767-e34147a08900 Correlation ID: e8e4bf4d-8461-42ca-bfeb-28224fbda7f6 Timestamp: 2024-06-12 02:51:00Z.
Id Web logs
No response
Relevant code snippets
So many mandatory boxes...Regression
No response
Expected behavior
token