Question

Difficulty: MediumConfiguring Service Account Impersonation and Workload Identity

An organization enforces a strict security policy prohibiting the creation and downloading of service account JSON keys. A cloud engineer must run local deployment commands using `gcloud` under the identity of `[email protected]`. The engineer has already been granted the Service Account Token Creator role (`roles/iam.serviceAccountTokenCreator`) on the service account resource. Which method should the engineer use to execute these commands securely?

  1. Pass the `--impersonate-service-account=deployer@proj-prod-app.iam.gserviceaccount.com` flag or set the `auth/impersonate_service_account` property in `gcloud config`.Answer
  2. B
    Create a service account key using `gcloud iam service-accounts keys create` and set `GOOGLE_APPLICATION_CREDENTIALS` for the session.
  3. C
    Grant the engineer the Service Account User role (`roles/iam.serviceAccountUser`) at the project level to automatically inherit the target identity.
  4. D
    Assign the primitive Editor role (`roles/editor`) to the engineer on the service account so `gcloud` automatically assumes its identity.

Answer

Configure `gcloud` to use service account impersonation via the `--impersonate-service-account` flag or by setting `auth/impersonate_service_account` in `gcloud config`.
Service account impersonation allows authenticated principals holding the Service Account Token Creator role (`roles/iam.serviceAccountTokenCreator`) to generate short-lived credentials dynamically. Supplying `--impersonate-service-account` in `gcloud` or setting `auth/impersonate_service_account` configures the SDK to transparently request access tokens for the target service account without storing key files.

Step-by-Step Solution

1
Identify the authentication requirement
The engineer must act as a service account without using long-lived JSON keys.
Security policies strictly forbid service account key downloads.
2
Verify required IAM permissions
The user holds `roles/iam.serviceAccountTokenCreator` on the target service account.
This permission allows minting short-lived OAuth 2.0 access tokens for impersonation.
3
Apply the appropriate gcloud impersonation mechanism
Pass `--impersonate-service-account` with the `gcloud` CLI command or set `gcloud config set auth/impersonate_service_account`.
This instructs `gcloud` to dynamically request short-lived credentials for the target service account.

Key Concept

Service Account Impersonation via gcloud
Rate this question