Fix GCP GKE Workload Identity Errors
When working with GCP GKE, you may encounter a configuration error that prevents your deployment from working. This guide explains the most common mistake with workload identity and shows the exact fix.
A Common Mistake
Using the default compute service account with excessive permissions instead of Workload Identity to provide fine-grained per-pod IAM permissions.
The incorrect command:
# Pod uses default SA
gcloud container clusters create my-cluster --region=us-central1
Error output:
Cluster created.
Pods run as the default compute SA which has roles/editor on the project. Any compromised pod has full project edit access. A malicious container can delete Cloud Storage buckets, modify IAM policies, and create expensive resources.
The Correct Approach
The right way to configure workload identity in GCP GKE:
gcloud container clusters create my-cluster --region=us-central1 --workload-pool=my-project.svc.id.goog && gcloud iam service-accounts create my-workload-sa && gcloud iam service-accounts add-iam-policy-binding my-workload-sa --role=roles/iam.workloadIdentityUser --member=serviceAccount:my-project.svc.id.goog[default/my-ksa] && gcloud projects add-iam-policy-binding my-project --member=serviceAccount:my-workload-sa@my-project.iam.gserviceaccount.com --role=roles/storage.objectViewer
Successful result:
Workload Identity enabled.
KSA my-ksa can now impersonate GCP SA my-workload-sa with storage read-only access.
Blast radius: compromised pods can only read storage objects.
How to Prevent This
Enable Workload Identity on all GKE clusters. Create one GCP SA per application with minimal permissions. Annotate KSA with the GCP SA email. This eliminates the need for service account keys. Audit with gcloud iam service-accounts get-iam-policy. Use Workload Identity Federation for external clusters.
FAQ
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Secure your cloud with DodaTech.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro