articles / github-actions-aws-oidc-sub

GitHub Actions and AWS with OIDC: why my AssumeRole was denied

Mounir Guizani · 28 November 2026 · 5 min read

  • aws
  • github-actions
  • oidc
  • terraform

To deploy this portfolio, my GitHub Actions pipelines connect to AWS without any stored key: each repo assumes an IAM role through OIDC. Yet when I set it all up, the very first deployment was denied.

How it works

GitHub issues a signed OIDC token to every job. AWS verifies it, then grants temporary credentials if the role's trust policy allows it. The key condition is on the sub claim, which identifies the repo and the job context:

condition {
  test     = "StringEquals"
  variable = "token.actions.githubusercontent.com:sub"
  values   = ["repo:MounirGuizani91/portfolio-infra:environment:dev"]
}

The symptom

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

The OIDC provider existed, the audience was right, and so were the repo name and the environment. Everything looked correct.

The diagnosis: look at the real token

Rather than guessing, I added a temporary workflow that requests a token and prints its claims (never the token itself):

permissions:
  id-token: write
steps:
  - uses: actions/github-script@v7
    with:
      script: |
        const t = await core.getIDToken('sts.amazonaws.com');
        const p = JSON.parse(Buffer.from(t.split('.')[1], 'base64url').toString());
        core.info(JSON.stringify({ sub: p.sub, aud: p.aud }, null, 2));

Result:

repo:MounirGuizani91@198454566/portfolio-infra@1475569133:environment:dev

The sub claim contained the immutable numeric IDs of the account and the repo. My StringEquals condition expected the old format, without them, so AWS was right to refuse.

The fix

In the Terraform bootstrap, the allowed contexts are generated for each repo, in the new format (and the old one, for compatibility):

values = flatten([
  for prefix in [
    "repo:${var.github_owner}@${var.github_owner_id}/${repo}@${repo_id}",
    "repo:${var.github_owner}/${repo}",
  ] : [for ctx in contexts : "${prefix}:${ctx}"]
])

One terraform apply later, the pipeline went through.

Takeaways

  • Diagnose with real data: printing the token claims takes five minutes and saves hours of guesswork.
  • Keep conditions strict: StringEquals with the exact list of contexts (main branch, dev and prod environments) rather than a repo:* wildcard.
  • The new format is safer: a repo deleted and recreated under the same name gets a different ID, so it cannot assume the role.