CI runs in a shared tools account and must deploy to dev, staging and prod accounts. How do you set up access?
IntermediateScenarioMulti-env and multi-account
Answer
Situation read → Use role assumption across accounts. No access keys stored anywhere, and each target role allows only what that environment's deploy needs.
What I'd do →
- CI authenticates to the tools account via OIDC (GitHub Actions to IAM), getting short-lived credentials.
- Each target account has a
deployerrole whose trust policy allows only the CI role, and for prod, only from themainbranch's 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/shop:environment:production"
}
}
}
- Alternatively, trust OIDC directly in each account with the
subclaim scoped per environment; this avoids role chaining. - Least privilege per role, and CloudTrail in each account records every deploy.
Why → Scoping trust by the OIDC sub claim means a feature branch can't assume the prod role.
Interview tip → Quote the sub claim condition; it's the detail that makes OIDC actually secure.
More on Multi-env and multi-account
Design the AWS account structure for a 50-engineer startup that's growing fast.IntermediateHow do you promote the same build from dev to staging to prod?BeginnerBugs keep passing staging and appearing in production. How do you make staging closer to prod?IntermediateHow do you structure Terraform for dev, staging and prod? Workspaces, directories or Terragrunt?IntermediateDevelopers want a preview environment for every pull request. How would you build it?AdvancedHelm values files or Kustomize overlays for per-environment config?Beginner