Configure OIDC to GCP.
AdvancedConceptOIDC & Security Hardening
Answer
Create a Workload Identity Pool and an OIDC provider with an attribute mapping and a condition, then let the GitHub principal impersonate a service account (or grant roles directly to the principal set).
gcloud iam workload-identity-pools providers create-oidc github \
--location=global --workload-identity-pool=github-pool \
--issuer-uri=https://token.actions.githubusercontent.com \
--attribute-mapping="google.subject=assertion.sub,attribute.repository=assertion.repository" \
--attribute-condition="assertion.repository_owner == 'devopsshack'"
- uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/123456/locations/global/workloadIdentityPools/github-pool/providers/github
service_account: [email protected]
The attribute condition is mandatory now; without it any GitHub repo could authenticate to your pool.
More on OIDC & Security Hardening
How does GitHub OIDC work, end to end?IntermediateWhat are the `sub` claim formats, and which do you put in an AWS trust policy?AdvancedConfigure OIDC to AWS: provider, role and workflow.AdvancedConfigure OIDC to Azure.AdvancedWhy pin actions to a full commit SHA, and how do you keep pins updated?IntermediateWhat is script injection, and how do you fix it?Advanced