For years, the easy way to let a pod on GKE call Google Cloud APIs was to download a service account key and mount it as a secret, or to let pods borrow the node's service account. Both are risky. Keys are long-lived credentials that leak through repositories, images, and logs. Node service accounts give every pod on the node the same permissions, so compromising one workload exposes all of them. Workload Identity Federation for GKE replaces both with short-lived credentials bound to a specific Kubernetes service account.
How Workload Identity Federation for GKE works
- PodRuns with a Kubernetes service account (KSA)
- GKE metadata serverIntercepts credential requests on the node
- Workload identity poolPROJECT_ID.svc.id.goog trusts the cluster
- IAM policyGrants roles to the KSA principal directly
- Short-lived tokenGoogle client libraries use it automatically
Why node service accounts and keys are a problem
- The default Compute Engine service account historically had broad project permissions, and every pod on the node could use them.
- Service account keys never expire unless rotated, are hard to inventory, and are a common root cause of cloud breaches.
- Shared identities make audit logs ambiguous—you cannot tell which workload made a call.
- Least privilege is impossible when many workloads share one identity.
1. Enable Workload Identity on the cluster and node pools
Workload Identity is enabled by default on Autopilot clusters. On Standard clusters, enable it on the cluster and make sure node pools use the GKE metadata server, which intercepts requests that would otherwise reach the node's own credentials.
gcloud container clusters update prod-cluster \
--location=us-central1 \
--workload-pool=PROJECT_ID.svc.id.goog
gcloud container node-pools update default-pool \
--cluster=prod-cluster \
--location=us-central1 \
--workload-metadata=GKE_METADATA2. Grant IAM roles to the Kubernetes service account
The current recommended approach grants IAM roles directly to a principal identifier that represents the Kubernetes service account, without creating a Google service account at all. The principal is scoped by project number, workload identity pool, namespace, and service account name, so the grant applies to exactly one workload identity.
kubectl create serviceaccount orders-api --namespace orders
gcloud storage buckets add-iam-policy-binding gs://example-orders-exports \
--role=roles/storage.objectViewer \
--member="principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/orders/sa/orders-api"Grant roles on the specific resource—a bucket, a topic, a secret—rather than at the project level wherever the service supports resource-level IAM. That keeps each workload's permissions to the resources it actually uses.
How does your cloud measure up?
Score your setup across foundation, delivery, reliability, security, and cost in 3 minutes—instant results, no email needed.
3. When you still need a Google service account
A few Google Cloud APIs and some third-party tools do not yet support the direct principal identifiers. In those cases, link the Kubernetes service account to a dedicated Google service account through impersonation: grant the KSA the Workload Identity User role on the Google service account, and annotate the KSA.
gcloud iam service-accounts create orders-api-gsa --project=PROJECT_ID
gcloud iam service-accounts add-iam-policy-binding \
orders-api-gsa@PROJECT_ID.iam.gserviceaccount.com \
--role=roles/iam.workloadIdentityUser \
--member="serviceAccount:PROJECT_ID.svc.id.goog[orders/orders-api]"
kubectl annotate serviceaccount orders-api --namespace orders \
iam.gke.io/gcp-service-account=orders-api-gsa@PROJECT_ID.iam.gserviceaccount.comUse one Google service account per workload, never a shared one, and give it only the roles that workload needs.
4. Use the service account in your workload
apiVersion: apps/v1
kind: Deployment
metadata:
name: orders-api
namespace: orders
spec:
template:
spec:
serviceAccountName: orders-api
containers:
- name: api
image: us-docker.pkg.dev/PROJECT_ID/apps/orders-api@sha256:<digest>Google Cloud client libraries use Application Default Credentials, which automatically obtain tokens from the metadata server. No code changes, environment variables, or mounted keys are needed—and if you find a GOOGLE_APPLICATION_CREDENTIALS variable pointing at a key file, it should be removed.
5. Lock the door behind you
Once workloads use workload identity, prevent keys from coming back. Enforce the iam.disableServiceAccountKeyCreation organisation policy, delete existing user-managed keys after confirming they are unused, and give node pools a minimal custom service account with only logging and monitoring permissions instead of the default Compute Engine service account.
for SA in $(gcloud iam service-accounts list --format="value(email)"); do
gcloud iam service-accounts keys list --iam-account="$SA" \
--managed-by=user --format="table(name.basename(), validAfterTime)"
done6. Cross-project and multi-tenant patterns
The workload identity pool belongs to the cluster's project, but the IAM grant can be made on resources in any project—so a workload in a shared platform cluster can read a bucket owned by an application project without that project creating keys. In multi-tenant clusters, namespaces map naturally to tenants: grant each tenant's service accounts only that tenant's resources. Remember that anyone who can create pods with a given service account in a namespace inherits its permissions, so Kubernetes RBAC on namespaces and service accounts is part of your IAM model.
7. Verify and audit
- Run a short-lived pod with the service account and call the API to confirm access works and nothing broader does.
- Check Cloud Audit Logs: calls now show the workload identity principal, so you can attribute every request to a namespace and service account.
- Use Policy Analyzer to answer which principals can access a sensitive resource, including workload identities.
- Review grants quarterly and remove roles the workload no longer uses, guided by IAM recommender.
Common pitfalls
- Enabling workload identity on the cluster but not switching node pools to the GKE metadata server.
- Using the same Kubernetes service account name across namespaces and assuming it is the same identity—the namespace is part of the principal.
- Pods running with hostNetwork, which bypass the metadata server interception.
- Granting project-wide roles when a resource-level role would do.
- Leaving old keys active after migration because nobody checked who used them.
Beyond GKE: the same idea everywhere
Workload identity is a general pattern, not a GKE feature. Cloud Run and Cloud Functions run as a service account without keys. CI systems such as GitHub Actions and GitLab can use Workload Identity Federation with external OIDC providers to call Google Cloud without stored credentials. Workloads in other clouds or on-premises can federate through workload identity pools. Applying the pattern consistently is what lets you enforce the organisation-wide ban on service account keys without exceptions.
Plan the migration service by service: inventory which workloads use keys or node identity, create their Kubernetes service accounts and IAM grants, deploy with workload identity in staging, confirm access in audit logs, then remove the key and repeat.
Keep a short list of any workloads that still need keys, with an owner and a target date, so exceptions shrink rather than settle in.
Checklist
- Workload Identity enabled on all clusters; node pools use GKE_METADATA.
- One Kubernetes service account per workload, granted resource-level IAM roles directly.
- Google service accounts only where an API requires them, one per workload.
- No key files in images, secrets, or environment variables.
- Key creation blocked by organisation policy; legacy keys deleted.
- Minimal custom service accounts for node pools.
- Audit logs and periodic access reviews per workload identity.
Workload identity is one of the highest-value security changes on GKE because it removes a whole class of credential leaks. Our Kubernetes and posture-hardening work includes this migration as a standard step.
Key takeaways
- Prefer Workload Identity over JSON keys on nodes or in secrets.
- Bind Kubernetes service accounts to narrowly scoped Google IAMs.
- Rotate and review bindings when services change ownership.
FAQ
Do we still need Kubernetes RBAC?
Yes. Workload Identity covers Google API access; RBAC still controls what can happen inside the cluster.
What is a common misconfiguration?
Over-broad IAM on the Google service account, or enabling Workload Identity without removing leftover keys that remain valid.