Bitzu

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

Single choice

Which role, granted on a service account, lets a user generate short-lived credentials for it?

  1. roles/iam.serviceAccountViewer
  2. roles/iam.serviceAccountKeyAdmin
  3. roles/iam.serviceAccountTokenCreator
  4. 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.

Select all that apply

Which are advantages of impersonating a service account instead of using a downloaded key?

  1. No long-lived secret file has to be stored or rotated
  2. Access can be withdrawn by removing the IAM binding
  3. Audit logs generally record the caller as well as the service account
  4. The issued tokens never expire
  5. 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

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.

Download on the App StoreGet it on Google Play

More Associate Cloud Engineer topics in this module