Workload Identity¶
GCP binds a Kubernetes service account to a Google service account with a pair: an IAM binding on the cloud side, and an annotation on the cluster side. The bundle renders both, already filled in.
The cluster side¶
apiVersion: v1
kind: ServiceAccount
metadata:
name: xratud
namespace: dp-eu-west1
annotations:
iam.gke.io/gcp-service-account: dp-eu-west1-runtime@<gcp-project-id>.iam.gserviceaccount.com
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: builder
namespace: xratu-build-bootstrap
annotations:
iam.gke.io/gcp-service-account: dp-eu-west1-build@<gcp-project-id>.iam.gserviceaccount.com
The annotation carries the full service account email, derived from
dp_install and project_id. It requires no editing: GCP is one of the two
clouds where the identity is known at render time.
The cloud side¶
resource "google_service_account_iam_member" "runtime_workload_identity" {
service_account_id = google_service_account.runtime.name
role = "roles/iam.workloadIdentityUser"
member = "serviceAccount:<gcp-project-id>.svc.id.goog[dp-eu-west1/xratud]"
}
The member is the Kubernetes service account in Workload Identity's own
notation: the project's identity pool, then [namespace/serviceaccount].
How the two meet¶
flowchart LR
KSA["KSA xratud<br/>namespace dp-eu-west1"] -->|"annotation"| GSA["GSA dp-eu-west1-runtime"]
GSA -->|"workloadIdentityUser<br/>on <gcp-project-id>.svc.id.goog[dp-eu-west1/xratud]"| KSA
GSA --> AR["Artifact Registry"]
GSA --> GCS["GCS bucket"]
Both halves name the same namespace and service account, which is why they are generated together from one spec. See One bundle, two layers.
Prerequisites on the cluster¶
Workload Identity must be enabled on the GKE cluster and its node pools. The bundle renders the binding and the annotation; enabling the feature on the cluster is yours.
A pod that cannot obtain credentials despite both halves being applied usually means the cluster or node pool has Workload Identity turned off.
Verifying¶
After apply, confirm the annotation reached the cluster:
And the binding on the cloud side:
gcloud iam service-accounts get-iam-policy \
dp-eu-west1-runtime@<gcp-project-id>.iam.gserviceaccount.com
The member in that policy should match the namespace and service account in the annotation.