How do you design AWS OIDC trust for GitHub Actions so only production deploys can assume the prod role?
IntermediateProductionIdentity, Least Privilege & OIDC for CI
Answer
Restrict the sub claim to an environment, which also lets you put required reviewers on that environment.
{
"Effect": "Allow",
"Principal": { "Federated": "arn:aws:iam::111122223333:oidc-provider/token.actions.githubusercontent.com" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:acme/payments-api:environment:production"
}
}
}
Never use StringLike with repo:acme/* for a prod role; any repo in the org (or a fork workflow) could then assume it.
More on Identity, Least Privilege & OIDC for CI
What are the common mistakes in OIDC trust policies for CI?AdvancedHow do you configure OIDC for GitLab CI to AWS?IntermediateHow do you get from "everyone has AdministratorAccess" to least privilege without breaking things?AdvancedWhat SCP guardrails do you apply across an AWS organisation?IntermediateHow do you implement just-in-time (JIT) privileged access for production?IntermediateHow do you design IAM for a multi-account AWS landing zone?Beginner