Interview Prep/GitHub Actions/Secrets, OIDC & Environments

Write the AWS trust policy for a role used only by the prod deploy job of one repo.

IntermediateScenarioSecrets, OIDC & Environments
Answer

Situation read → Pin issuer, audience and subject.

What I'd do →

  1. Trust policy:
    {
      "Version": "2012-10-17",
      "Statement": [{
        "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:devopsshack/shack-api:environment:prod"
          }
        }
      }]
    }
    
  2. Attach a policy allowing only what the deploy needs (for example eks:DescribeCluster).

Why → Only jobs bound to the prod environment, which require approval, can assume it.

Interview tip → Explain that environment protection plus sub pinning chains GitHub approvals to AWS access.

All GitHub Actions questions Roadmap: GitHub Actions

More on Secrets, OIDC & Environments