Sub topic 15
Troubleshooting workload identity
This chapter assumes you have set up workload identity on at least one provider (EKS, GKE, or AKS). It also assumes you know how projected tokens carry aud (audience) and sub (subject) claims. Most failures come from a mismatch between what the token says and what the cloud trust configuration expects.
A four-step triage
Work from the Pod outward. Stop at the first step that fails.
Step 1: Does the Pod have a token?
Check which ServiceAccount the Pod uses and whether the injected variables exist. On EKS you should see AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE. On AKS you should see AZURE_CLIENT_ID and AZURE_FEDERATED_TOKEN_FILE.
kubectl get pod token-demo -n demo -o jsonpath='{.spec.serviceAccountName}{"\n"}'
kubectl exec -n demo token-demo -- env | grep -E 'AWS_|AZURE_'Webhooks inject these values only when a Pod is created. If you annotated the ServiceAccount after the Pod started, restart the Pod.
Step 2: Do the claims match?
Decode the token payload and compare it with your trust policy.
kubectl exec -n demo token-demo -- cat /var/run/secrets/tokens/cloud-token \
| cut -d. -f2 | tr '_-' '/+' | base64 -d 2>/dev/null; echoLook at three fields. aud must equal the audience in the trust policy, such as sts.amazonaws.com. sub must be system:serviceaccount:<namespace>:<name>. iss must equal the issuer the cloud provider has registered, character for character.
Common failures
| Symptom | Likely cause | Fix |
|---|---|---|
| EKS: `Not authorized to perform sts:AssumeRoleWithWebIdentity` | `sub` or `aud` condition in the trust policy does not match | Compare the decoded token with the `StringEquals` conditions |
| EKS: no `AWS_ROLE_ARN` in the Pod | Missing `eks.amazonaws.com/role-arn` annotation, or Pod created before it | Annotate, then restart the Pod |
| EKS: `No OpenIDConnect provider found` | The provider is not registered in IAM, or its URL differs from the issuer | Register it with the exact issuer URL |
| GKE: 403 when impersonating the Google service account | Missing `roles/iam.workloadIdentityUser` binding, or a wrong member string | Use `PROJECT.svc.id.goog[namespace/name]` exactly |
| AKS: no `AZURE_FEDERATED_TOKEN_FILE` | Pod lacks the `azure.workload.identity/use: "true"` label | Add the label to the Pod template, not only to the Deployment |
| AKS: `AADSTS70021` (no matching federated identity record) | Federated credential issuer, subject, or audience differs from the token | Recreate the credential with the correct values |
| Works for an hour, then fails | Application cached the token and never re-read the file | Upgrade the SDK, or re-read the file on each request |
Step 3: Does the cloud trust the issuer?
Confirm the issuer is reachable and publishes keys. The cloud provider fetches the same documents you can read yourself.
kubectl get --raw /.well-known/openid-configuration
kubectl get --raw /openid/v1/jwksIf the cluster's issuer URL changed, for example after a rebuild, every trust relationship that references the old URL breaks. Providers cache keys, so a key rotation can also cause short failures.
Step 4: Does the role allow the action?
When the credential exchange succeeds but the cloud API call returns access denied, the identity is working. Check the permissions policy on the role or service account instead.
Exercise
A Pod on EKS gets Not authorized to perform sts:AssumeRoleWithWebIdentity. The ServiceAccount is demo/app-reader, and the trust policy sub condition is system:serviceaccount:demo:app_reader. What is wrong, and how do you confirm it?
Show answer
The ServiceAccount name in the trust policy uses an underscore, but the real name is app-reader. Decode the Pod's token with the command in Step 2 and compare its sub claim with the trust policy string. Correct the policy to system:serviceaccount:demo:app-reader.