Interview Prep/DevSecOps/Cloud identity: IRSA, Workload Identity and CI OIDC

GKE pod fails with `Unable to generate access token; IAM returned 403 Forbidden: Permission 'iam.serviceAccounts.getAccessToken' denied on resource`

IntermediateTroubleshootingCloud identity: IRSA, Workload Identity and CI OIDC
Answer

Likely causes → The KSA is annotated with iam.gke.io/gcp-service-account, but the GSA lacks the roles/iam.workloadIdentityUser binding for that exact KSA, or the namespace or name in the member string is wrong.

Diagnose →

kubectl get sa api -n prod -o jsonpath='{.metadata.annotations.iam\.gke\.io/gcp-service-account}'
gcloud iam service-accounts get-iam-policy [email protected]

Fix →

gcloud iam service-accounts add-iam-policy-binding [email protected] \
  --role roles/iam.workloadIdentityUser \
  --member "serviceAccount:proj.svc.id.goog[prod/api]"

Expect a few minutes of propagation delay.

Prevent → Manage the KSA, GSA and binding in one Terraform module.

All DevSecOps questions Roadmap: Supply chain, secrets & identity

More on Cloud identity: IRSA, Workload Identity and CI OIDC