OpsCanary
Back to daily brief
gcpgkePractitioner

Securing Google Cloud API Access in GKE with Workload Identity Federation

5 min read Google Cloud DocsApr 23, 2026
PractitionerHands-on experience recommended

In today's cloud-native environments, securing API access is paramount. Workload Identity Federation for GKE addresses this need by enabling workloads running in Google Kubernetes Engine to authenticate with Google Cloud APIs securely. This mechanism not only enhances security but also simplifies the management of IAM roles by linking them directly to Kubernetes ServiceAccounts.

To implement Workload Identity Federation, you must first enable it at the cluster level. This can be done using the gcloud CLI or the Google Cloud console. Once enabled, workloads can authenticate to Google Cloud APIs using IAM policies that correspond to Kubernetes ServiceAccounts. Key parameters include the --workload-pool, which specifies the identity pool for the cluster, and --workload-metadata, which configures the node pool to use the GKE metadata server. For example, you can update your cluster with the command: gcloud container clusters update CLUSTER_NAME --location=LOCATION --workload-pool=PROJECT_ID.svc.id.goog.

In production, be aware of the limitations of Workload Identity Federation. All new node pools default to using this federation if enabled on the cluster, so ensure you include the necessary flags to avoid surprises. Also, confirm that the Google Cloud APIs you intend to access are supported by this mechanism. If not, consider linking Kubernetes ServiceAccounts to IAM as an alternative.

Key takeaways

  • Enable Workload Identity Federation at the cluster level using gcloud commands.
  • Link Kubernetes ServiceAccounts to IAM policies for secure API access.
  • Use the --workload-pool flag to specify the identity pool for your cluster.
  • Configure node pools with --workload-metadata to utilize GKE metadata server.
  • Check API support for Workload Identity Federation before implementation.

Why it matters

Implementing Workload Identity Federation can significantly reduce the risk of credential leaks and streamline permissions management, leading to a more secure and efficient cloud environment.

Code examples

Bash
gcloud container clusters update CLUSTER_NAME --location=LOCATION --workload-pool=PROJECT_ID.svc.id.goog
Bash
gcloud container node-pools create NODEPOOL_NAME --cluster=CLUSTER_NAME --location=CONTROL_PLANE_LOCATION --workload-metadata=GKE_METADATA
Bash
gcloud projects add-iam-policy-binding projects/PROJECT_ID --role=roles/container.clusterViewer --member=principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/NAMESPACE/sa/KSA_NAME --condition=None

When NOT to use this

If the API isn't supported or if your use case is blocked by the limitations of Workload Identity Federation for that service, consider linking Kubernetes ServiceAccounts to IAM instead.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.