Associate Cloud Engineer ยท Impersonation, short-lived credentials and workload identity
Service account impersonation
roles/iam.serviceAccountTokenCreator, --impersonate-service-account, why impersonation beats downloaded keys, audit trail.
Key points
- A principal acts as a service account by minting short-lived credentials for it.
- The caller needs a role such as roles/iam.serviceAccountTokenCreator on that service account (permission iam.serviceAccounts.getAccessToken).
- In gcloud, add --impersonate-service-account=SA_EMAIL.
- No key file is downloaded, and audit logs generally record both the caller and the impersonated service account.
Source: https://docs.cloud.google.com/iam/docs/service-account-impersonation
Practice questions
Which role, granted on a service account, lets a user generate short-lived credentials for it?
- roles/iam.serviceAccountViewer
- roles/iam.serviceAccountKeyAdmin
- roles/iam.serviceAccountTokenCreator
- roles/iam.securityReviewer
Show answer
Answer: C. roles/iam.serviceAccountTokenCreator
Service Account Token Creator carries iam.serviceAccounts.getAccessToken. Viewer and Key Admin do not allow minting tokens; Key Admin manages long-lived keys, which is the opposite approach.
Which are advantages of impersonating a service account instead of using a downloaded key?
- No long-lived secret file has to be stored or rotated
- Access can be withdrawn by removing the IAM binding
- Audit logs generally record the caller as well as the service account
- The issued tokens never expire
- It can be done from the Google Cloud console
Show answer
Answer: A. No long-lived secret file has to be stored or rotated, B. Access can be withdrawn by removing the IAM binding, C. Audit logs generally record the caller as well as the service account
Impersonation produces expiring credentials, access ends when the binding is removed, and logs generally show the caller too. Tokens do expire, and the console cannot impersonate.
True or false: you can impersonate a service account directly in the Google Cloud console.
Show answer
Answer: False
False. The console always uses your own user credentials; impersonation is done through gcloud, client libraries or the Service Account Credentials API.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
