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.
More on Cloud identity: IRSA, Workload Identity and CI OIDC
A pod configured for IRSA runs `aws sts get-caller-identity` and gets the node role (`eks-node-group-role`) instead of its own roleBeginner`An error occurred (AccessDenied) when calling the AssumeRoleWithWebIdentity operation: Not authorized to perform sts:AssumeRoleWithWebIdentity` from an IRSA podIntermediate`InvalidIdentityToken: No OpenIDConnect provider found in your account for https://oidc.eks.ap-south-1.amazonaws.com/id/ABC123`BeginnerIRSA env vars are present in the pod, but one legacy service still uses the node roleIntermediatePods without IRSA can still call AWS with the node's permissions through `169.254.169.254`IntermediateWith EKS Pod Identity, the pod gets `Unable to locate credentials` even though a pod identity association existsIntermediate