Token Exchange Failure¶
Symptom¶
Pods start, Kubernetes service account configuration looks plausible, but Azure SDK calls fail because Microsoft Entra never returns a usable access token.
Possible Causes¶
- OIDC issuer mismatch.
- Subject or audience mismatch in the federated identity credential.
- The wrong managed identity or app registration is bound to the workload.
- The cluster feature flags for OIDC issuer or workload identity are not enabled.
- The application is not actually using the workload identity authentication path.
Diagnosis Steps¶
flowchart TD
A[Azure SDK call fails] --> B[Confirm workload identity feature flags]
B --> C[Confirm ServiceAccount and pod binding]
C --> D[Compare issuer, subject, and audience with federated credential]
D --> E[Inspect application logs for token exchange errors]
E --> F{Exchange succeeds?}
F -->|No| G[Fix federation mismatch]
F -->|Yes| H[Check downstream authorization such as Key Vault access] -
Confirm the cluster features are enabled.
az aks show \ --resource-group "$RG" \ --name "$CLUSTER_NAME" \ --query "{issuer:oidcIssuerProfile.issuerUrl,workloadIdentity:securityProfile.workloadIdentity}" \ --output yamlCommand Purpose az aks showShow the OIDC issuer and workload identity state. --resource-groupResource group that contains the AKS cluster. --nameName of the AKS cluster. --querySelects the issuer URL and workload identity profile. --outputOutput format for the result. -
Confirm the deployment and pod are bound to the expected service account.
-
Inspect the federated identity credential definition.
az identity federated-credential show \ --resource-group "$RG" \ --identity-name "$USER_ASSIGNED_IDENTITY_NAME" \ --federated-credential-name "$FEDERATED_CREDENTIAL_NAME" \ --output jsonCommand Purpose az identity federated-credential showShow a federated credential on the identity. --resource-groupResource group that contains the identity. --identity-nameManaged identity that owns the credential. --federated-credential-nameName of the federated credential. --outputOutput format for the result. -
Review application logs to confirm whether the failure is token exchange or downstream authorization.
Resolution¶
- Correct the issuer, subject, or audience mismatch on the federated identity credential.
- Verify the workload is using the intended service account and identity target.
- If exchange succeeds after correction, continue with downstream service authorization validation such as Key Vault roles or access policies.
Prevention¶
- Treat workload identity rollout as a four-part contract: cluster issuer, service account subject, audience, and downstream authorization.
- Keep identity changes reversible by adding replacement federated credentials before removing old ones.
- Use a canary deployment to validate fresh token exchange during rotations and cluster migrations.
See Also¶
- Microsoft Entra Workload Identity
- OIDC Issuer Mismatch
- Audience Mismatch
- RBAC Success but Key Vault Still Fails