`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.
More on OIDC & Cloud Authentication
`Error: Credentials could not be loaded, please check your action inputs: Could not load credentials from any providers`Intermediate`Error: Unable to get ACTIONS_ID_TOKEN_REQUEST_URL env variable`BeginnerOIDC works on `main` but fails on a tag-triggered release workflow.Intermediate`An error occurred (AccessDenied) when calling the AssumeRoleWithWebIdentity operation: Incorrect token audience`Intermediate`No OpenIDConnect provider found in your account for https://token.actions.githubusercontent.com`BeginnerAfter assuming the role, `aws ecr get-login-password` works but push fails: `denied: User: arn:aws:sts::111122223333:assumed-role/gha-ecr-push/gha-123 is not authorized to perform: ecr:InitiateLayerUpload on resource: arn:aws:ecr:ap-south-1:111122223333:repository/shack-api`Intermediate