Interview Prep/GitHub Actions/OIDC & Cloud Authentication

`Error: Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity`

AdvancedTroubleshootingOIDC & Cloud Authentication
Answer

Likely causes → Trust policy sub does not match the token's actual sub (most often: the job uses an environment, so sub is repo:ORG/REPO:environment:prod, not the ref: form), wrong aud, wrong repo or org name casing, wrong OIDC provider ARN or account.

Diagnose → Print the claims of the token:

- uses: actions/github-script@v7
  with:
    script: |
      const t = await core.getIDToken('sts.amazonaws.com');
      core.info(Buffer.from(t.split('.')[1], 'base64').toString());

Compare sub and aud with aws iam get-role --role-name gha-deploy-prod --query Role.AssumeRolePolicyDocument.

Fix → Update the trust condition to the real sub.

Prevent → Template trust policies in Terraform with the environment form for environment-bound jobs.

All GitHub Actions questions Roadmap: GitHub Actions

More on OIDC & Cloud Authentication