An application deployed on Cloud Run in Project-A needs to publish messages securely to a Cloud Pub/Sub topic located in Project-B. Enterprise security policy strictly forbids generating or downloading service account keys. A dedicated target service account with Pub/Sub Publisher privileges has already been created in Project-B. Which IAM configuration correctly enables the Cloud Run service account in Project-A to generate short-lived credentials for the target service account following Google Cloud best practices?
- Grant the Cloud Run service account the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the target service account in Project-B.Cevap
- BGenerate a JSON service account key for the target service account in Project-B, store it in Secret Manager, and grant Secret Accessor rights to Project-A.
- CGrant the Cloud Run service account the Service Account User role (roles/iam.serviceAccountUser) on the target service account in Project-B.
- DGrant the Cloud Run service account the Project Editor role (roles/editor) at the Project-B resource hierarchy level.
Cevap
Grant the Cloud Run service account the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) on the target service account in Project-B.
To impersonate a service account and request short-lived credentials (such as OAuth 2.0 access tokens), the calling identity must be assigned the Service Account Token Creator role (`roles/iam.serviceAccountTokenCreator`) on the target service account. This allows keyless cross-project authentication adhering to the principle of least privilege.
Adım Adım Çözüm
Anahtar Kavram
Configuring Service Account Impersonation using the Service Account Token Creator role