I broke Workload Identity Federation for GKE four ways on a test cluster. The 403 names a different identity each time, gcloud in the pod blames the wrong thing, and a new binding took about 90 seconds to work.

A pod on my test GKE cluster asked its metadata server for a token and got this back:
Unable to generate access token; IAM returned 403 Forbidden: Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist).
This error could be caused by a missing IAM policy binding on the target IAM service account.
The gcloud CLI in the same pod reported a different problem:
ERROR: gcloud crashed (MetadataServerException): The request is rejected. Please check if the metadata server is concealed.
The Kubernetes service account had an annotation pointing at a Google service account, and that Google service account had no roles/iam.workloadIdentityUser binding for it.
I broke the other links on the same test bed too: an Autopilot cluster on GKE 1.36.4 in europe-central2, a bucket with uniform bucket-level access and one file in it, and four Kubernetes service accounts in one namespace. One had no annotation, two pointed at real Google service accounts, and one pointed at my-gas@ where it should have said my-gsa@. Every pod ran the same probe: read its email and a token from the metadata server, list the bucket with curl and that token, then run gcloud storage ls on it.
What each Workload Identity 403 looks like from the pod
- No annotation, no grant anywhere. Token: 200. Listing the bucket: 403 Caller does not have storage.objects.list access to the Google Cloud Storage bucket.
- Annotation, but no workloadIdentityUser binding on the Google service account. Token: 403 Permission 'iam.serviceAccounts.getAccessToken' denied. Listing the bucket: no token to try with.
- Annotation names a service account that doesn’t exist. Token: 404 Gaia id not found for email my-gas@my-project.iam.gserviceaccount.com. Listing the bucket: no token to try with.
- Link works, the Google service account has no role on the bucket. Token: 200. Listing the bucket: 403 my-gsa@my-project.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket.
Both bucket 403s end with the same sentence, Permission 'storage.objects.list' denied on resource '//storage.googleapis.com/projects/_/buckets/my-bucket' (or it may not exist). "Caller" at the start means the pod called as itself, with no Google service account in between. An email means the link to that service account worked and the role on the resource is what's missing.
The 404 came with a hint that’s right for once: This error might be due to a missing IAM service account. Please verify that the service account exists.
The email endpoint won’t tell you which case you’re in. For the account with no annotation it returned the pool name, my-project.svc.id.goog. For the annotated ones it returned whatever the annotation said, typo included, with HTTP 200. The token request shows whether the link works, from any container that has curl:
MD=http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default
curl -s -H 'Metadata-Flavor: Google' $MD/email; echo
curl -s -o /tmp/tok -w '%{http_code}\n' -H 'Metadata-Flavor: Google' $MD/token
If the second command prints anything but 200, cat /tmp/tok shows the error text. On 200 that file holds a live token, so remove it when you're done.
gcloud in the pod is worse at this than curl. For the typo it printed There was a problem refreshing your current auth tokens, then the 404 inside a long Python repr, then:
Please run:
$ gcloud auth login
which is no help inside a pod. In the no-grant case gcloud did name an identity, This command is authenticated as my-project.svc.id.goog, and that's the pool, not your namespace or service account.
Direct grants to the Kubernetes service account
Google’s Workload Identity Federation for GKE how-to page gives this as the best practice: “Use IAM principal identifiers to configure Workload Identity Federation for GKE.” There is no Google service account and no annotation in this setup. You grant the role on the resource to the Kubernetes service account itself:
gcloud storage buckets add-iam-policy-binding gs://my-bucket \
--member=principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/my-project.svc.id.goog/subject/ns/my-namespace/sa/my-ksa \
--role=roles/storage.objectViewer
The member wants the project number, not the project ID: gcloud projects describe my-project –format='value(projectNumber)'.
My next poll, one second after the grant command returned, listed the bucket. The pod didn’t need a new token. The one it had before the grant (expires_in 3586 at the first probe) kept working after it (3174 seven minutes later). gcloud auth list in the pod still showed my-project.svc.id.goog as the active account, and gcloud storage ls worked.
To check the grant, read the bucket’s policy:
gcloud storage buckets get-iam-policy gs://my-bucket --format=json
Look for the member ending in /subject/ns/my-namespace/sa/my-ksa. That command rejects –filter with unrecognized arguments, so read the JSON or pipe it to jq.
Direct grants have limits per API, and the how-to links an IAM page that lists them. For Cloud Storage: “Identity federation with all Cloud Storage APIs is supported only for uniform bucket-level access buckets”, and “identity federation users and workloads cannot generate signed URLs.” My bucket used uniform access, so I didn’t run into either. I’d start a new workload with a direct grant and switch to a Google service account only when it needs something on that list, signed URLs being the one I’d expect to hit first.
Linking a Kubernetes service account to a Google service account
Google lists this one as the alternative: “Both the IAM allow policy and the annotation are required when you use this method.” Check the annotation first:
kubectl get sa -n my-namespace \
-o custom-columns='NAME:.metadata.name,GSA:.metadata.annotations.iam\.gke\.io/gcp-service-account'
Whether the account it names exists:
gcloud iam service-accounts describe my-gsa@my-project.iam.gserviceaccount.com --project=my-project
For the typo this returned NOT_FOUND: Unknown service account. Fix the annotation or create the account. kubectl annotate won't replace an existing value unless you pass –overwrite.
Whether the account lets your Kubernetes service account use it:
gcloud iam service-accounts get-iam-policy my-gsa@my-project.iam.gserviceaccount.com --project=my-project
Before the binding, this returned an etag and no bindings. The fix:
gcloud iam service-accounts add-iam-policy-binding my-gsa@my-project.iam.gserviceaccount.com \
--role=roles/iam.workloadIdentityUser \
--member='serviceAccount:my-project.svc.id.goog[my-namespace/my-ksa]'
The role on the resource comes last. For a bucket that’s the same buckets get-iam-policy as above, looking for serviceAccount:my-gsa@my-project.iam.gserviceaccount.com, and the same buckets add-iam-policy-binding with that member if it's missing.
About 90 seconds after the binding
After the workloadIdentityUser binding returned, the pod kept getting the getAccessToken 403. I polled about every 11 seconds, and the first 200 came about 99 seconds after the binding. I repeated it with a second Google service account and a second Kubernetes service account and got about 87 seconds.
Role grants on the bucket behaved differently. Three times (the direct principal and each of the two Google service accounts) the next poll after the grant returned 200, about a second later.
I don’t know what causes the wait. Google’s propagation page gives a policy change “Typically 2 minutes, potentially 7 minutes or longer”, which fits the binding but not the bucket grants. The concepts page says “To reduce client latency, the GKE metadata server caches the access tokens”, so the metadata server holding on to a refusal is possible too. I didn’t run the test that would tell them apart: asking IAM for the token as the federated identity, outside the metadata server, while the pod still gets 403.
In the same second the bucket role for the first Google service account landed, curl listed the bucket and gcloud storage ls in the same pod still returned the old 403. From 24 seconds later, six reads over about 80 seconds all worked with both. So after a workloadIdentityUser binding I'd give it two minutes before changing anything else.
The cluster side
I didn’t break these. On Standard, the cluster needs a workload pool (gcloud container clusters describe my-cluster –location=LOCATION –project=my-project –format='value(workloadIdentityConfig.workloadPool)' should print my-project.svc.id.goog) and each node pool needs GKE_METADATA in config.workloadMetadataConfig.mode. On Autopilot, gcloud container node-pools list fails with ResponseError: code=400, message=Autopilot node pools cannot be accessed or modified., and Google says "In Autopilot, Workload Identity Federation for GKE is always enabled".
What I built for this
I build Ostgate, a paid Mac app for Google Cloud with GKE support. On a pod, Ostgate checks the Workload Identity chain from the node pool to the roles the Google service account holds, names the first broken link and gives the gcloud command that fixes it, for whoever administers the project. It reads roles granted on projects only. A role on a single resource, like every bucket grant in this post, isn’t read, so for those you still need buckets get-iam-policy. It runs on Apple Silicon with macOS 15 or later, with a 7-day trial: https://ostgate.app/docs/gke
I’m the developer of Ostgate. Not affiliated with Google. Drafted with AI assistance and edited by me.
GKE Workload Identity 403: which link broke, and how long the fix takes was originally published in Google Cloud – Community on Medium, where people are continuing the conversation by highlighting and responding to this story.
Source Credit: https://medium.com/google-cloud/gke-workload-identity-403-f51fa2783882?source=rss—-e52cf94d98af—4
