Repository navigation
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
Activity
bgavrilMS commentedon Jun 12, 2024
Possible P1 as it blocks a fairly big scenario on Kubernetes.
jennyf19 commentedon Jun 13, 2024
For AKS, partners need to use
TokenExchangeUrlis needed in the sovereign cloud scenarios, is that correct Jean-Marc Prieur (@jmprieur) ?jmprieur commentedon Jun 13, 2024
yes, this is right. for
"SourceType":"SignedAssertionFromManagedIdentity",TokenExchangeUrlis needed in the sovereign cloud scenarios, jennyf19bgavrilMS commentedon Jun 13, 2024
The problem is not
TokenExchangeUrl, the problem is WorkloadIdentityCredentialLet me try to explain again.
Expected
api://azureADTokenExchangefrom some "assertion provider" like MSI or K8Actual
api://azureADTokenExchangeusing Azure.Identity'sDefaultAzureCredentialWorkloadIdentityCredentialfirst. And since the app is hosted on K8, this triggers. So what it internally does is:api://azureADTokenExchangewhich is wrong! This is where the error occurs.Today, you cannot use
WorkloadIdentityCredentialat all to provide the K8 FIC functionality in Id.Web. There is no SDK out there that exposes only step1 of WorkloadIdenitity + FIC.Fix for #2893 - do not attempt WorkloadIdentityCredential for MSI FIC
jmprieur commentedon Jun 13, 2024
Bogdan Gavril (@bgavrilMS) : why do people try to use
SignedAssertionFromManagedIdentityon AKS and notSignedAssertionFileDiskPath?This sounds the problem?
Fix for #2893 - do not attempt WorkloadIdentityCredential for MSI FIC
Fix for #2893 - do not attempt WorkloadIdentityCredential for MSI FIC
Fix for #2893 - do not attempt WorkloadIdentityCredential for MSI FIC…