Learning Objectives
- Explain the OpenID Connect handshake between GitHub Actions `id-token: write` and AWS STS `AssumeRoleWithWebIdentity`.
- Scope AWS IAM trust conditions (`sub: repo:org/name:ref:refs/heads/main`) to prevent forked PR credential theft.
Prerequisites
- GitHub repository workflows basics and AWS IAM Roles familiarity
Why Static Cloud Keys in CI Settings Are Risky
Traditional CI tutorials paste permanent AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY credentials into repository secrets. If a token leaks or goes unrotated for months, attackers gain continuous API access across environments.
With OpenID Connect (OIDC), GitHub’s runner requests a short-lived signed JWT claiming exact repository, branch, and environment claims. AWS STS verifies the signature and mints temporary credentials expiring automatically once the job finishes.
Pair keyless CI/CD with Multi-Stage Docker Builds and our AWS Certified DevOps Engineer (DOP-C02) Program.
Practical Programming Examples
Keyless GitHub Actions Test + OIDC Cloud Role Workflow
Verify tests pass first, then request an OIDC token scoped only to main deployments without static cloud keys.
name: ci-deploy
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
verify-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/github-oidc-deploy
aws-region: ap-south-1
- run: aws sts get-caller-identity
STS returns temporary assumed-role ARN (`github-oidc-deploy`) valid only for that job run.
- `permissions: id-token: write` authorizes the runner to mint a scoped OIDC token.
- `configure-aws-credentials@v4` exchanges that JWT via AWS STS without needing `aws-access-key-id` secrets.
Common Mistakes to Avoid
- Leaving trust-policy `sub` condition wildcarded (`repo:my-org/*`) — lets unrelated repos or PR branches assume deploy roles.
Production Best Practices
- Lock IAM trust policy `StringEquals` strictly to `repo:ORG/REPO:ref:refs/heads/main` or dedicated protected environments.
Technical Interview Relevance
Standard DevOps/DOP-C02 security architecture design question.
Practice & Self-Check Questions
Which permission must a GitHub Actions workflow declare to exchange an OIDC token with AWS STS?
It must grant `id-token: write` (alongside `contents: read` for checkout).