Bitzu

Associate Cloud Engineer ยท Impersonation, short-lived credentials and workload identity

Short-lived credentials and avoiding keys

Access tokens, ID tokens and signed JWTs via the IAM Credentials API, token lifetime limits, service account key risks and the org policy that blocks key creation.

Key points

  • The IAM Credentials API issues access tokens (generateAccessToken), ID tokens (generateIdToken) and signed blobs/JWTs.
  • Access tokens last 1 hour by default; via REST the maximum can be raised to 12 hours for service accounts listed in the iam.allowServiceAccountCredentialLifetimeExtension org policy.
  • Service account keys are long-lived secrets, so prefer tokens, and block key creation with the iam.disableServiceAccountKeyCreation constraint.

Source: https://docs.cloud.google.com/iam/docs/create-short-lived-credentials-direct

Practice questions

Single choice

By default, what is the maximum lifetime of an access token generated for a service account?

  1. 15 minutes
  2. 1 hour
  3. 12 hours
  4. 24 hours
Show answer

Answer: B. 1 hour

The default maximum is 1 hour (3,600 seconds). Longer needs an org policy exception and REST, up to 12 hours.

Select all that apply

Which statements about service account tokens are correct?

  1. Access tokens are created with generateAccessToken
  2. ID tokens use the roles/iam.serviceAccountOpenIdTokenCreator role
  3. Lifetimes beyond 1 hour require an org policy allowing the extension
  4. gcloud can set a custom token lifetime with a flag
  5. Impersonated access tokens include a refresh token
Show answer

Answer: A. Access tokens are created with generateAccessToken, B. ID tokens use the roles/iam.serviceAccountOpenIdTokenCreator role, C. Lifetimes beyond 1 hour require an org policy allowing the extension

Access tokens come from generateAccessToken and ID tokens need the OpenID Token Creator role. Extending the lifetime is a REST-only feature gated by org policy. gcloud cannot set the lifetime and impersonated tokens carry no refresh token.

True or false

True or false: an impersonated access token comes with a refresh token, so it renews itself.

Show answer

Answer: False

False. There is no refresh token; after expiry you must perform the impersonation again to get a new token.

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