Course contentsShow
← Security
Lesson 1725 of 3,05235. Cloud Security - IAMFree lesson

GCP Service Account Impersonation

Learn service account impersonation, short-lived token generation, and workload identity for Kubernetes in GCP.

GCP Service Account Impersonation

What you'll learn: How to securely grant users temporary permissions by impersonating service accounts instead of creating long-lived keys.

The Core Idea

Service account impersonation in Google Cloud Platform allows a user or another service account to act as a service account without needing its private key. Instead of downloading and storing permanent credentials (which can leak), you request short-lived access tokens on-the-fly.

Think of it like borrowing someone's security badge temporarily instead of making a permanent copy. When you're done, the badge expires automatically.

How It Works

You grant a principal (user, group, or service account) the roles/iam.serviceAccountTokenCreator role on a target service account. That principal can then:

  1. Generate short-lived OAuth 2.0 tokens (valid for 1 hour by default)
  2. Create ID tokens for authenticating to specific services
  3. Sign blobs using the service account's identity

Instead of storing credentials in your code, you make API calls that say "act as service-account-X@project.iam.gserviceaccount.com" when needed.

Workload Identity for Kubernetes

Workload Identity extends this pattern to Kubernetes pods. Instead of mounting service account keys as secrets, you bind Kubernetes service accounts to GCP service accounts. Pods automatically receive short-lived tokens through the metadata server—no keys to manage or rotate.

This eliminates the most common credential exposure risk in containerized workloads.

Security Benefits

  • No long-lived keys to steal or accidentally commit to Git
  • Automatic expiration limits blast radius of compromised tokens
  • Audit trail shows who impersonated which service account and when
  • Just-in-time access aligns with least privilege principles

Key Takeaway: GCP service account impersonation replaces risky long-lived credentials with short-lived tokens generated on demand, dramatically reducing credential exposure in both human and workload scenarios.