An organization uses an automated security auditing script running on a centralized admin virtual machine. The script needs temporary credentials to inspect configuration settings across multiple Google Cloud projects by impersonating a target service account named `[email protected]`. The security policy strictly prohibits creating or downloading long-lived service account key files. Which IAM configuration should the cloud engineer apply to enable this setup while adhering to the principle of least privilege?
- Grant the admin VM's identity the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the auditor service account.Answer
- BGenerate a JSON service account key for auditor-sa and store it securely in Secret Manager for the script to download during execution.
- CGrant the admin VM's identity the Service Account User role (roles/iam.serviceAccountUser) on the target service account.
- DGrant the admin VM's identity the Project Editor primitive role (roles/editor) on the project containing the auditor service account.
Answer
Grant the admin VM's identity the Service Account Token Creator role (`roles/iam.serviceAccountTokenCreator`) on the auditor service account.
To impersonate a service account and generate short-lived credentials (like access tokens or ID tokens), a principal must have the Service Account Token Creator role (`roles/iam.serviceAccountTokenCreator`) granted on the target service account. This allows keyless authentication while adhering to least privilege.
Step-by-Step Solution
Key Concept
Service Account Impersonation and Short-Lived Credentials