Interview Prep/GitHub Actions/OIDC & Security Hardening

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.

All GitHub Actions questions Roadmap: GitHub Actions

More on OIDC & Security Hardening