When teams give AI coding agents access to GCP (gcloud, Terraform, Python SDKs, or Vertex AI), most setups still drop a static service account JSON key or mount a broad developer gcloud config into the workspace. If a prompt injection or transcript leak happens, that key lives until someone notices and rotates it.
Here are the four GCP-specific lessons we hit building keyless agent access with Workload Identity Federation (WIF):
- **Test WIF trust conditions against fabricated identities before saving**
- It's very easy to misconfigure a Workload Identity Pool attribute condition so it trusts too broadly (e.g., another org or another resource from the same OIDC issuer).
- During connection verification, we actively probe Google STS with 3 fabricated identities (another connection in the same org, another org's connection, and an environment subject) and refuse to save the connection unless Google rejects all three. That catches overly broad WIF bindings before a single token is minted.
2. **GCP impersonation tokens don't downscope like AWS STS session policies**
- Unlike AWS AssumeRole (which takes an inline session policy to intersect permissions), GCP service account impersonation tokens inherit *all* roles of the target service account — Credential Access Boundaries only downscope Cloud Storage, not general GCP IAM.
- Our fix: bind multiple narrow, task-specific service accounts (up to 20 per WIF connection) and let org/project access profiles expose only a subset of those accounts to each agent, with 10-60 min token lifetimes.
3. **Two subtle gotchas delivering tokens inside a microVM with zero key files on disk**
- We run a loopback GCE metadata server inside the environment backed by an out-of-band unix socket so the OIDC signing key never enters the VM.
- **Gotcha A (Python SDKs):** Setting only `GCE_METADATA_HOST` isn't enough for Google's Python client libraries — you also need `GCE_METADATA_IP` set, or they skip the loopback server and fail to find credentials.
- **Gotcha B (gcloud multi-account):** `gcloud` only queries a metadata server for the default account's token even when `--account` or `CLOUDSDK_CORE_ACCOUNT` is set. We had to wrap `gcloud` with a lightweight shim that pulls the token for the requested account from the socket directly (plus a wrapper command that spins up a per-command loopback metadata server for Terraform and SDKs acting as a non-default account).
4. **Use keyless Vertex AI WIF to keep ZDR and CMEK intact**
- Routing coding agent inference through Vertex AI via WIF (service account with `roles/aiplatform.user`, zero static API keys) keeps model calls inside your GCP project under your own ZDR, residency, and CMEK controls instead of a tool vendor's org.
Honest caveat: a prompt-injected agent can still do whatever the narrow service account is allowed to do while the token is valid (10-60 min), so narrow SA design and Cloud Audit Logs monitoring still matter.
Disclosure: I'm building kosem (kosem.ai), where we run Kata microVMs on GKE Standard (nested virtualization) and built this GCP WIF + Vertex AI integration. Full 5-layer defense-in-depth write-up here if helpful: https://kosem.ai/blog/defense-in-depth-for-coding-agents
Curious how other GCP shops are isolating coding agents from broad developer gcloud profiles and static SA keys.