Explain OIDC federation from GitHub Actions to a cloud provider.
AdvancedConceptGitHub Actions
Answer
Instead of storing long-lived cloud keys as secrets, the job requests a short-lived OIDC JWT from GitHub (needs permissions: id-token: write). The token's claims include sub (for example repo:org/app:ref:refs/heads/main or repo:org/app:environment:production), repository, ref, workflow. The cloud (AWS IAM, Azure, GCP Workload Identity Federation) is configured to trust GitHub's issuer https://token.actions.githubusercontent.com and exchanges the JWT for temporary credentials, restricted by a condition on sub.
permissions: { id-token: write, contents: read }
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-deploy
aws-region: ap-south-1
The IAM trust policy must pin token.actions.githubusercontent.com:sub to the exact repo and branch or environment, otherwise any repository could assume the role.
More on GitHub Actions
What are workflows, jobs, steps and actions in GitHub Actions?BeginnerWhat events can trigger a workflow?BeginnerWhat is the difference between `pull_request` and `pull_request_target`?AdvancedWhat is a runner, and how do GitHub-hosted and self-hosted runners differ?BeginnerHow do you pass data between steps and between jobs?IntermediateHow does a build matrix work?Intermediate