How do you design the GitHub Actions OIDC trust policy for AWS safely?
AdvancedProductionGitHub Actions and GitLab CI in Production
Answer
Create the IAM OIDC provider for token.actions.githubusercontent.com, then a role per purpose (plan, deploy-staging, deploy-prod) with a trust policy that pins the audience and a specific sub. For production, bind to a GitHub environment so only approved jobs can assume it.
{
"Effect": "Allow",
"Principal": { "Federated": "arn:aws:iam::123456789012: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/shop-api:environment:production"
}
}
}
Never use wildcards like repo:acme/* for production roles, and give each role least-privilege permissions.
More on GitHub Actions and GitLab CI in Production
How do you organise reusable workflows for an organisation on GitHub?IntermediateHow do you reduce GitHub Actions minutes cost on private repos?IntermediateHow do you secure self-hosted runners?AdvancedHow do you handle approvals and deployments across environments in GitHub Actions?IntermediateHow do you handle required checks when workflows use path filters or matrices?AdvancedHow do you keep GitHub Actions workflow files themselves safe from unauthorised changes?Intermediate