A security policy limits external credentials to 10 minutes. Each night, a Cloud Build job must hand a third-party CI server an OAuth 2.0 access token for the service account [email protected] so the CI server can publish a few Pub/Sub messages. Long-lived service-account keys are forbidden. How should the build obtain and pass the required short-lived token?
Call the IAM Credentials API generateAccessToken for ci-publisher with a 600-second lifetime; ensure Cloud Build holds roles/iam.serviceAccountTokenCreator on that account.
Execute gcloud auth print-access-token --impersonate-service-account=ci-publisher@proj.iam.gserviceaccount.com and pass the resulting token to the CI server.
Run gcloud iam service-accounts keys create during the build to generate a JSON key for ci-publisher and send the key file to the CI server.
Grant the CI server roles/pubsub.publisher on the project and let it authenticate using Application Default Credentials instead of a key.
The IAM Credentials API's generateAccessToken method lets a caller that has the Service Account Token Creator role on a service account mint a short-lived OAuth 2.0 access token for that account. The build can request a 600-second lifetime and forward the token to the CI server, satisfying the 10-minute policy without creating or storing long-lived key material. Creating JSON keys or using gcloud auth print-access-token would yield longer-lived credentials, while granting the CI server a publisher role would give it permanent access.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the IAM Credentials API?
Open an interactive chat with Bash
What is the roles/iam.serviceAccountTokenCreator role?
Open an interactive chat with Bash
Why would JSON key-based authentication be less secure in this case?
Open an interactive chat with Bash
What is the IAM Credentials API?
Open an interactive chat with Bash
What is the role of a Service Account Token Creator?
Open an interactive chat with Bash
Why are short-lived access tokens preferred over long-lived service account keys?
Open an interactive chat with Bash
GCP Associate Cloud Engineer
Configuring access and security
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99 $11.99
$11.99/mo
Billed monthly, Cancel any time.
$19.99 after promotion ends
3 Month Pass
$44.99 $26.99
$8.99/mo
One time purchase of $26.99, Does not auto-renew.
$44.99 after promotion ends
Save $18!
MOST POPULAR
Annual Pass
$119.99 $71.99
$5.99/mo
One time purchase of $71.99, Does not auto-renew.
$119.99 after promotion ends
Save $48!
BEST DEAL
Lifetime Pass
$189.99 $113.99
One time purchase, Good for life.
Save $76!
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .