Interview Prep/Real-World Interview/Multi-env and multi-account

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 →

  1. CI authenticates to the tools account via OIDC (GitHub Actions to IAM), getting short-lived credentials.
  2. Each target account has a deployer role whose trust policy allows only the CI role, and for prod, only from the main branch'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"
    }
  }
}
  1. Alternatively, trust OIDC directly in each account with the sub claim scoped per environment; this avoids role chaining.
  2. 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.

All Real-World Interview questions Roadmap: Interview readiness

More on Multi-env and multi-account