What Is Google Cloud Service Account Impersonation? Delegate Access with Short-Lived Credentials
Google Cloud service account impersonation lets an authenticated user or another service account obtain short-lived credentials for a target service account, then call APIs with that account’s permissions. Granting roles to the target service account alone is not enough: the caller must also be allowed to impersonate it. Impersonation can support local development, limited operational tasks, and external workloads without distributing long-lived service account keys, but the impersonation grant is itself a privilege-escalation path, so scope it narrowly.
This article follows Google Cloud IAM documentation checked on November 19, 2026. It focuses on users obtaining short-lived credentials with the Google Cloud CLI or supported client libraries. GKE Workload Identity, detailed external federation setup, and service account key administration are separate topics.
Which two identities take part?
Impersonation involves a caller and a target service account. The caller first proves its identity through a user login or another workload’s credentials. It then asks for short-lived credentials, such as an access token, for the target service account. If allowed, the caller uses those credentials to call Google Cloud APIs, and the target service account’s permissions apply to those calls.
Suppose Mina, a developer, runs a deployment tool on her workstation. She authenticates as herself and impersonates a deployment-only service account to get a short-lived token. That service account has permission to deploy Cloud Run only in a test project. Mina can test deployments within that scope; impersonation does not give her new access to data in other projects. If the service account has excessive roles, however, a developer allowed to impersonate it can use those privileges.
Two checks are therefore needed:
**The caller’s impersonation permission:** Can the caller create short-lived credentials for this service account?
**The target account’s resource permissions:** What can that service account do on the target resources?
You can configure these separately: the caller does not need a broad project-wide role if it only needs permission to impersonate one service account, and the target account should receive only the resource roles it needs. Still, the Service Account Token Creator role includes permissions beyond access-token creation, such as signing and delegation capabilities, so grant it only to necessary users and workloads.
How is impersonation different from a key or an attached account?
A service account key is a long-lived private key that lets its holder authenticate directly as the service account. If a key file is copied or exposed, there is no separate caller-authentication step, and logs based only on key use may not identify the original person or workload. With impersonation, an already authenticated caller requests short-lived credentials; most relevant audit logs can show both the caller and the impersonated service account. The credentials expire and are not automatically refreshed, so obtaining new ones requires repeating the caller authentication and issuance flow.
Do not confuse impersonation with the Service Account User role. That role primarily allows attaching a service account to a resource, such as a Compute Engine instance, through iam.serviceAccounts.actAs. To use the CLI’s --impersonate-service-account flag or create short-lived credentials, the caller generally needs iam.serviceAccounts.getAccessToken, included in Service Account Token Creator (roles/iam.serviceAccountTokenCreator) on the target service account. The names are similar, but the permitted actions differ.
| Method | How it works | Good fit | Main caution |
|---|---|---|---|
| Service account impersonation | Authenticate an existing identity, then issue short-lived credentials | Local development, scoped operations, federated external workloads | Impersonation lets the caller borrow the target account’s permissions |
| Service account key | Authenticate directly as the service account with a long-lived private key | Limited cases where keyless options are unavailable | A leaked key can be misused until disabled or deleted; attribution is harder |
| Attach a service account to a resource | A VM, Cloud Run service, or other resource runs as its attached account | Long-running workloads inside Google Cloud | People who can run code on the resource might use that account’s permissions |
The Google Cloud console does not let you enter resource pages as an impersonated service account; console actions use your user credentials. Keep this separate from testing service account permissions through CLI commands or supported Application Default Credentials (ADC).
When is impersonation useful?
Use impersonation when someone needs to use a service account’s permissions temporarily without changing their own IAM roles. Examples include lending limited deployment access during incident response, checking whether a service account with a specific role can run a command, or developing locally an application that requires service-account credentials.
An application running outside Google Cloud can first authenticate its external identity with Workload Identity Federation, then use a credential configuration file to impersonate a target service account. The external identity still needs permission to impersonate that account, and the target account needs its own resource permissions. Google recommends avoiding long-lived service account keys for external applications when possible because of their exposure risk.
For a VM or Cloud Run job that continuously runs with service-account permissions inside Google Cloud, attaching a service account to the resource may be a better fit than having a user impersonate it through the CLI each time. GKE has workload identity mechanisms such as Workload Identity; follow the documentation for that environment.
A safe basic flow with the gcloud CLI
The example below assumes a local user authenticates and runs one command as a deployment service account. Replace the project ID and service account email with values from your own environment.
Limit the target service account first. Grant it only the roles needed on the target project or resources. A test deployment should not also require database administrator or organization administrator access.
Allow the caller to impersonate only the intended account. On the target service account’s IAM policy, grant the user or caller service account
roles/iam.serviceAccountTokenCreatorwhen needed. Prefer granting it on the service account resource rather than broadly across a project.Confirm that the Service Account Credentials API is enabled. If it is disabled, an administrator with API-enablement permission must enable it. That permission is separate from permission to impersonate the service account.
Sign in to the CLI as the user. Use the Google Cloud CLI user authentication approved by your organization. This user is the caller and is distinct from the target service account.
Run a single, scoped command. For example:
gcloud run services list \ --project=PROJECT_ID \ --impersonate-service-account=DEPLOYER_SA_EMAILThis is an illustrative list command; results depend on the command and the target account’s permissions. You can also set
gcloud config set auth/impersonate_service_account ...to use impersonation by default, but review the consequences first: every later command may unexpectedly run as a different identity.Verify both success and denial. In a non-production environment, confirm that the intended list or deployment action succeeds and that ungranted projects or actions are denied. If it fails, check the active caller, exact service account email, Token Creator permission, target account’s resource roles, and API enablement in that order.
Remove temporary access and review logs. After the task, remove temporary impersonation grants and any temporary resource roles on the target account. Check Cloud Audit Logs for credential issuance and API calls. Because logging varies by service, confirm whether the required IAM and Security Token Service Data Access logs are enabled and which identities the relevant service records.
Successfully obtaining a token does not prove that the target resource can be accessed. Issuance checks the caller’s impersonation permission; the API request must also pass the target service account’s resource roles and any service-specific conditions. Conversely, an overly privileged target account can turn a convenient one-line CLI command into a broad privilege-escalation path.
Permission and audit risks to watch
Impersonation permission means “can act as this target service account.” If that account has organization-wide administrator access or broad storage permissions, callers allowed to impersonate it can use those privileges through short-lived credentials. The predefined Token Creator role includes access tokens, ID tokens, JWT and blob signing, and delegation-chain capabilities. If you only need OIDC ID tokens, consider whether the narrower roles/iam.serviceAccountOpenIdTokenCreator role is sufficient.
Audit logs improve traceability, but services do not all record the same details. Google says most logs include the caller and impersonated account, while noting that some services omit impersonation information. IAM Data Access logs might be needed to record issuance of short-lived credentials; for external federation, review Security Token Service logging as well. Do not assume a log field exists—check the actual service and API you use.
Impersonation can reduce risks compared with service account keys, but it does not remove the underlying privileges. Give the target account only necessary roles, grant impersonation narrowly on specific accounts, and plan temporary access expiry, removal, and log collection. For external workloads, prefer evaluating Workload Identity Federation over key files; for continuously running workloads, consider the platform’s attached service account mechanism.
References
[Google Cloud service account impersonation: overview and behavior](https://cloud.google.com/iam/docs/service-account-impersonation)
[Roles and permissions for service account authentication](https://cloud.google.com/iam/docs/service-account-permissions)
[Use service account impersonation: prerequisites and gcloud example](https://cloud.google.com/docs/authentication/use-service-account-impersonation)
[Service account security best practices and audit-log setup](https://cloud.google.com/iam/docs/best-practices-service-accounts)
[Short-lived service account credentials and audit-log examples](https://cloud.google.com/iam/docs/audit-logging/examples-service-accounts)