A company requires a team of data analysts to execute analytical queries against a BigQuery dataset in the analytics-prod project from their local workstations. To strictly align with GCP security best practices, long-lived service account keys must not be created or downloaded. The analysts must perform operations using the identity of a dedicated service account, [email protected], which already possesses the necessary BigQuery permissions. Which configuration properly enables the analysts to impersonate this service account while following the principle of least privilege?
- Grant the data analysts group the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the sa-bq-executor service account resource, and instruct analysts to run CLI commands with the --impersonate-service-account flag.Answer
- BCreate and export a JSON service account key for sa-bq-executor, then distribute the key file to the analysts to set their GOOGLE_APPLICATION_CREDENTIALS environment variable.
- CGrant the data analysts group the Service Account User role (roles/iam.serviceAccountUser) on the target service account and instruct them to authenticate directly via gcloud config set account.
- DGrant the data analysts group the Project Editor role (roles/editor) at the project level to automatically grant permission to act as any service account in the project.
Answer
Granting the data analysts group the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the specific target service account allows them to generate short-lived tokens and use the --impersonate-service-account flag, adhering to keyless security best practices and least privilege.
To impersonate a service account for local CLI operations without exporting long-lived service account keys, principals must be granted the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) directly on the target service account resource. They can then specify the target identity using flags such as --impersonate-service-account in gcloud commands.
Step-by-Step Solution
Key Concept
Service Account Impersonation via IAM Token Creator Role