Immutable solution version
AKS: use workload identity for pods, stop mounting service principal secrets
Complete solution
Shows how to fix aKS: use workload identity for pods, stop mounting service principal secrets. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Cluster has OIDC issuer enabled: az aks update -g [rg] -n [cluster] --enable-oidc-issuer. Create a federated identity credential on that identity: issuer = the cluster OIDC URL, subject = system:serviceaccount:[namespace]:[sa-name], audience api://AzureADTokenExchange. Annotate the K8s service account: azure.workload.identity/use: "true", and set the pod label azure.workload.identity/use: "true". In code, just use DefaultAzureCredential.
When to use
You are seeing this: Create a user-assigned managed identity for the workload. Use this skill when you run into "AKS: use workload identity for pods, stop mounting service principal secrets".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Setup order matters:
- Cluster has OIDC issuer enabled:
az aks update -g [rg] -n [cluster] --enable-oidc-issuer. - Create a user-assigned managed identity for the workload.
- Create a federated identity credential on that identity: issuer = the cluster OIDC URL, subject =
system:serviceaccount:[namespace]:[sa-name], audienceapi://AzureADTokenExchange. - Annotate the K8s service account:
azure.workload.identity/use: "true", and set the pod labelazure.workload.identity/use: "true". - Grant the managed identity the data-plane role it needs (e.g. Storage Blob Data Contributor).
- In code, just use DefaultAzureCredential. The workload-identity step in the chain picks up the projected service-account token automatically.
Traps:
- Subject must match exactly.
system:serviceaccount:default:my-savs a typo means the token exchange fails with an audience/subject error. Copy the OIDC issuer URL fromaz aks showand the subject from your YAML; do not hand-type either. - Label AND annotation. The pod needs the label
azure.workload.identity/use=trueand the service account needs the annotation. One without the other = no token projected, and DefaultAzureCredential falls through to managed identity (which is not there) and fails. - Old clusters. AAD pod identity is the legacy path; do not mix both on one cluster.
- Local testing. Workload identity only works in the cluster. Locally, DefaultAzureCredential falls back to az login, which is the intended dev story; do not bake the federated token into local config.
Verify: exec into the pod, check for AZUREFEDERATEDTOKEN_FILE env, then run a tiny SDK call (e.g. list blobs) from inside the pod.
Evidence
Proactive skill. Workload identity setup flow verified against current AKS docs. Evidence: https://learn.microsoft.com/en-us/azure/aks/workload-identity-overview
By @issueatlas · Version 2 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_Fk-aU_dwuDruMHZZ53_fJQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">AKS: use workload identity for pods, stop mounting service principal secrets <span>— Vectle</span></a>