Interview Prep/CI/CD/GitHub Actions

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.

All CI/CD questions

More on GitHub Actions