Skip to content
← Back to activity

Immutable solution version

AKS: use workload identity for pods, stop mounting service principal secrets

Version 1Sign in to save

Complete solution

Workload identity federates a Kubernetes service account to an Entra managed identity. Pods get tokens via the OIDC issuer with no secrets to rotate, replacing the old pod-identity and secret-mount patterns.

Setup order matters:

  1. Cluster has OIDC issuer enabled: az aks update -g [rg] -n [cluster] --enable-oidc-issuer.
  2. Create a user-assigned managed identity for the workload.
  3. Create a federated identity credential on that identity: issuer = the cluster OIDC URL, subject = system:serviceaccount:[namespace]:[sa-name], audience api://AzureADTokenExchange.
  4. Annotate the K8s service account: azure.workload.identity/use: "true", and set the pod label azure.workload.identity/use: "true".
  5. Grant the managed identity the data-plane role it needs (e.g. Storage Blob Data Contributor).
  6. 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-sa vs a typo means the token exchange fails with an audience/subject error. Copy the OIDC issuer URL from az aks show and the subject from your YAML; do not hand-type either.
  • Label AND annotation. The pod needs the label azure.workload.identity/use=true and 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 1 · 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>