Configuring access and security · Topic 3 of 3
Impersonation, Short-Lived Credentials and Workload Identity
Service account impersonation, short-lived credentials, Workload Identity Federation for GKE, and Workload Identity Federation for workloads outside Google Cloud.
- 5 min
- Impersonation needs
roles/iam.serviceAccountTokenCreator; use--impersonate-service-account. - Short-lived credentials: access tokens, ID tokens, signed JWTs, from the Service Account Credentials API.
- Workload Identity Federation for GKE: KSA mapped to IAM;
roles/iam.workloadIdentityUserwhen linking to a service account.
What it is
The safest credentials are the ones that expire quickly and are never downloaded. Service account impersonation lets a user or another service account act as a service account temporarily. Short-lived credentials (access tokens, ID tokens, signed JWTs) replace long-lived keys. Workload Identity Federation for GKE lets Kubernetes workloads use IAM identities, and Workload Identity Federation lets workloads outside Google Cloud (AWS, Azure, on premises, CI/CD systems) access Google Cloud without keys.
How it works
Service account impersonation
A principal with Service Account Token Creator (roles/iam.serviceAccountTokenCreator) on a service account can obtain short-lived tokens for it and act as it.
# grant a group permission to impersonate the deploy service account
gcloud iam service-accounts add-iam-policy-binding \
deployer@shop-prod-1234.iam.gserviceaccount.com \
--member="group:release-managers@example.com" \
--role="roles/iam.serviceAccountTokenCreator"
# run one command as the service account
gcloud storage ls gs://releases-1234 \
--impersonate-service-account=deployer@shop-prod-1234.iam.gserviceaccount.com
Benefits: users keep minimal personal permissions, privileged access is used only when needed, and audit logs record both the caller and the impersonated service account.
"Engineers need temporary elevated access for deployments without keys" is impersonation with Service Account Token Creator.
Short-lived credentials
The IAM Service Account Credentials API issues credentials that expire, by default within an hour for OAuth access tokens:
| Credential | Use |
|---|---|
| OAuth 2.0 access token | Call Google Cloud APIs as the service account |
| OpenID Connect ID token | Authenticate to services that accept ID tokens, such as a private Cloud Run service |
| Self-signed JWT or signed blob | Sign data or tokens without exporting a private key |
gcloud auth print-access-token --impersonate-service-account=deployer@shop-prod-1234.iam.gserviceaccount.com
Short-lived credentials limit the damage of a leak because they expire quickly and can be issued only to authorized callers.
Service accounts for GKE applications
Workload Identity Federation for GKE maps Kubernetes identities to IAM, so Pods call Google Cloud APIs without node-wide permissions or keys.
| Step | What you do |
|---|---|
| 1 | Enable Workload Identity Federation for GKE on the cluster (enabled by default on Autopilot) |
| 2 | Create a Kubernetes service account (KSA) for the workload |
| 3 | Grant IAM roles directly to the KSA principal, or link it to an IAM service account by granting roles/iam.workloadIdentityUser and annotating the KSA |
| 4 | Run the Pods with that KSA |
For a direct grant, the principal is principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/NAMESPACE/sa/KSA_NAME. The IAM member for a KSA in the second approach looks like serviceAccount:PROJECT_ID.svc.id.goog[NAMESPACE/KSA_NAME]. Each workload gets only its own permissions, unlike sharing the node's service account.
Workload Identity Federation
Workload Identity Federation lets external workloads exchange their own credentials for short-lived Google tokens.
| Step | What you do |
|---|---|
| 1 | Create a workload identity pool in a project |
| 2 | Add a provider that trusts the external identity source: AWS, Azure, an OIDC provider (such as GitHub Actions or GitLab) or SAML 2.0 |
| 3 | Map and optionally restrict attributes (for example only one repository) |
| 4 | Grant access: directly to federated principals, or let them impersonate a service account |
| 5 | The workload uses a credential configuration file (not a key) to exchange tokens through the Security Token Service |
| Need | Choose |
|---|---|
| Pods on GKE call Google APIs | Workload Identity Federation for GKE |
| CI/CD pipeline in GitHub Actions deploys to Google Cloud | Workload Identity Federation with an OIDC provider |
| App on AWS reads a Cloud Storage bucket | Workload Identity Federation with an AWS provider |
| Employees sign in with an external IdP | Workforce Identity Federation (people, not workloads) |
A worked scenario
A company removes all service account keys. Release managers impersonate a deployer service account when needed. GKE Pods use Workload Identity Federation for GKE, each with its own Kubernetes service account and minimal roles. The GitHub Actions pipeline authenticates through Workload Identity Federation with an OIDC provider restricted to the company's repository. An app on AWS reads a bucket through an AWS provider. The organization policy disabling key creation is then enforced.
How the exam asks about this
- "Act as a service account temporarily without a key." Impersonation, with Service Account Token Creator.
- "Pods need access to Cloud Storage with least privilege." Workload Identity Federation for GKE with a dedicated Kubernetes service account.
- "GitHub Actions must deploy to Google Cloud without stored keys." Workload Identity Federation with an OIDC provider.
- "Access a private Cloud Run service from a script." An ID token.
What to remember for the exam
- Impersonation needs
roles/iam.serviceAccountTokenCreator; use--impersonate-service-account. - Short-lived credentials: access tokens, ID tokens, signed JWTs, from the Service Account Credentials API.
- Workload Identity Federation for GKE: KSA mapped to IAM;
roles/iam.workloadIdentityUserwhen linking to a service account. - Workload Identity Federation: pools and providers for AWS, Azure, OIDC and SAML workloads; no keys.
- Workforce Identity Federation is for people; Workload Identity Federation is for workloads.
Service Account Token Creator is powerful. Anyone with it can act with all of that service account's permissions.
Common mistakes
Downloading a key for a CI/CD pipeline. Use Workload Identity Federation.
Giving the GKE node service account broad roles for all Pods. Use Workload Identity Federation for GKE per workload.
Confusing Service Account User with Token Creator. User attaches the account to resources; Token Creator impersonates it directly.
Check yourself
Which role allows a principal to impersonate a service account?
Service Account Token Creator,
roles/iam.serviceAccountTokenCreator.How should a GitHub Actions pipeline authenticate to Google Cloud without keys?
Through Workload Identity Federation with an OIDC provider.
What does Workload Identity Federation for GKE provide?
Kubernetes workloads use IAM identities to call Google Cloud APIs without keys or node-wide permissions.
Topic 3 of 3 in Configuring access and security
Test yourself on Configuring access and security
The full Google Cloud Associate Cloud Engineer question bank has 661 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Google Cloud. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.