Interview Prep/DevSecOps/Cloud identity: IRSA, Workload Identity and CI OIDC

GitHub OIDC to AWS works on pushes to `main` but fails with `Not authorized to perform sts:AssumeRoleWithWebIdentity` in the deploy job that uses `environment: prod`

IntermediateTroubleshootingCloud identity: IRSA, Workload Identity and CI OIDC
Answer

Likely causes → The sub claim changes format depending on context. On a branch push it is repo:acme/api:ref:refs/heads/main. When the job targets an environment it becomes repo:acme/api:environment:prod. Pull requests use repo:acme/api:pull_request.

Diagnose → Print the claims once in a debug job:

curl -sH "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
  "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=sts.amazonaws.com" | jq -r .value | cut -d. -f2 | base64 -d | jq .sub

Fix → Trust repo:acme/api:environment:prod for the prod role, and protect the prod environment with required reviewers.

Prevent → One role per environment, each trusting exactly one sub value. Use environments as the gate rather than branch names.

All DevSecOps questions Roadmap: Supply chain, secrets & identity

More on Cloud identity: IRSA, Workload Identity and CI OIDC