A database administrator needs to execute local gcloud CLI commands to update Cloud Spanner schema configurations using the dedicated service account [email protected]. Security policy strictly forbids creating or downloading static service account JSON keys. Which IAM role assignment and gcloud configuration allows the administrator to temporarily assume the identity of the service account?
- Grant the administrator the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the target service account, and pass the --impersonate-service-account flag in gcloud commands.Answer
- BGenerate a short-lived service account key file using gcloud iam service-accounts keys create, configure gcloud auth activate-service-account, and delete the key file after execution.
- CGrant the administrator the primitive Owner role (roles/owner) on the project containing the service account so that all CLI calls automatically run with service account authorization.
- DGrant the administrator the Service Account User role (roles/iam.serviceAccountUser) on the project, and explicitly deny token creation permissions on the individual service account.
Answer
Grant the administrator the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the target service account, and pass the --impersonate-service-account flag in gcloud commands.
To impersonate a service account using Google Cloud CLI without static service account keys, the user principal performing the action must be granted the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the target service account. When the user executes gcloud commands with the --impersonate-service-account flag, gcloud requests short-lived credentials for that service account.
Step-by-Step Solution
Key Concept
Service Account Impersonation via gcloud and IAM Token Creator Role