Sub topic 12
Troubleshooting common failures
This chapter assumes you can read a workflow file, you know the claims in a GitHub OIDC token (sub, aud, iss), and you have seen an IAM role trust policy. The failures below mostly come from one of three places: the workflow never gets a token, the token has the wrong values, or the cloud trust policy rejects the values it receives.
Find the stage that failed
The OIDC exchange has three stages. Each stage fails in a different way, so first work out which one broke.
- The job asks GitHub for a token. This needs the
id-token: writepermission. - The cloud provider validates the token: signature, issuer, audience, and expiry.
- The provider evaluates the trust policy conditions, then the role's permission policies.
A useful rule: if aws sts get-caller-identity succeeds, authentication worked. Any later failure is an authorization problem in the role's permission policy, not an OIDC problem.
Failure 1: the job cannot get a token
Symptom. The credentials step fails before it contacts AWS. The exact wording depends on the action version. Typical messages mention ACTIONS_ID_TOKEN_REQUEST_URL or say that credentials could not be loaded from any providers.
Cause. The runner only sets ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN when the job has id-token: write. Without those variables, nothing can request a token.
Fix. Add the permission at the workflow or job level:
permissions:
id-token: write
contents: readTwo details trip people up:
- Setting any
permissionskey resets every permission you do not list tonone. If you addid-token: writeand dropcontents: read,actions/checkoutfails on a private repository. - A job-level
permissionsblock replaces the workflow-level one. It does not merge with it.
Some events never receive OIDC tokens with write access. Workflows triggered by pull_request from a fork run with a read-only token, and Dependabot-triggered runs are similarly restricted. If the job works on push but fails on a fork pull request, this is expected behavior, not a bug. Do not work around it by switching to pull_request_target with untrusted code checked out. That combination is a well-known way to leak access.
Failure 2: the OIDC provider does not exist in the cloud account
Symptom. AWS returns an error such as No OpenIDConnect provider found in your account for https://token.actions.githubusercontent.com.
Cause. The trust policy names a federated principal, but the account has no IAM OIDC identity provider for GitHub. The provider is created once per AWS account, and the role's Principal.Federated ARN must match it.
Fix. Create the provider with URL https://token.actions.githubusercontent.com and audience sts.amazonaws.com. Then check that the account ID in the Principal ARN is the account that contains the provider. A role in account A cannot use a provider that exists only in account B.
Failure 3: "Not authorized to perform sts:AssumeRoleWithWebIdentity"
This is the most common error, and it is also the least specific. AWS returns the same message for a wrong audience, a wrong subject, a wrong action in the policy, and a wrong principal. Do not guess. Look at the actual token claims and compare them with the trust policy line by line.
Print the claims safely
An ID token is a bearer credential until it expires. Never print the whole token. Decode it and print only the claims that matter:
- name: Show token claims
run: |
TOKEN=$(curl -sS \
-H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=sts.amazonaws.com" \
| jq -r '.value')
echo "::add-mask::$TOKEN"
TOKEN="$TOKEN" python3 - <<'PY'
import base64, json, os
payload = os.environ["TOKEN"].split(".")[1]
payload += "=" * (-len(payload) % 4)
claims = json.loads(base64.urlsafe_b64decode(payload))
for key in ("iss", "aud", "sub", "repository", "ref",
"environment", "job_workflow_ref"):
print(key, "=", claims.get(key))
PYThe ::add-mask:: line tells the runner to hide the token if it appears in logs. Remove this debugging step once you have the answer.
Compare each claim with the policy
| Claim in the token | Trust policy condition key | Typical mismatch |
|---|---|---|
| `aud` | `token.actions.githubusercontent.com:aud` | The workflow requested a custom audience, but the policy expects `sts.amazonaws.com`. |
| `sub` | `token.actions.githubusercontent.com:sub` | The policy expects a branch, but the job runs under an environment, tag, or pull request. |
| `iss` | The provider URL itself | The provider was created with a typo or a trailing path. |
Subject mismatches in detail
The sub value changes shape depending on how the job runs. These are the default formats:
repo:octo-org/octo-repo:ref:refs/heads/mainfor a branch.repo:octo-org/octo-repo:ref:refs/tags/v1.0.0for a tag.repo:octo-org/octo-repo:pull_requestfor a pull request event.repo:octo-org/octo-repo:environment:productionfor a job that declaresenvironment: production.
The environment case causes the most confusion. When a job uses an environment, the subject contains the environment name and does not contain the branch. A trust policy that requires ref:refs/heads/main will reject that job, even though it runs on main. Update the policy to match the form the job actually produces.
Other subject problems:
StringEqualsis case-sensitive.Octo-Org/octo-repodoes not matchocto-org/octo-repo.- A wildcard needs
StringLike. UsingStringEqualswithrepo:octo-org/*matches nothing, becauseStringEqualstreats*as a literal character. - If your organization or repository customizes the subject claim, the default formats above no longer apply. Print the real
suband write the policy against that value.
Audience mismatches in detail
aws-actions/configure-aws-credentials requests the audience sts.amazonaws.com by default. If you request a token yourself with a different audience value, the aud condition fails. Either change the request or change the policy, but make them agree. Also check that the audience is registered in the IAM OIDC provider's client ID list.
Policy structure mistakes
- The
Actionmust bests:AssumeRoleWithWebIdentity. Writingsts:AssumeRoleis a common error, because that action is for a different trust flow. - The
Principalmust useFederated, notAWS. - The
role-to-assumeARN in the workflow must exactly match the role. A wrong account ID or a misspelled role name can also produce an authorization error.
Failure 4: token or session expiry
Symptom. Authentication works at the start of a long job but later calls fail with an expired-credentials error. Or a hand-rolled script that requests a token early fails when it uses the token minutes later.
Cause. The GitHub ID token is short-lived and is meant to be exchanged right away. The AWS session credentials last only for the role session duration, one hour by default.
Fix. Request the token immediately before you exchange it. For long deployments, raise role-duration-seconds in the action, but only up to the role's maximum session duration. The role's maximum must allow the value you ask for. Alternatively, split the work into jobs that each authenticate again.
Failure 5: authentication works, but calls are denied
Symptom. aws sts get-caller-identity shows the assumed role, then a command such as aws s3 sync fails with AccessDenied.
Cause. The trust policy controls who can assume the role. The role's permission policies control what the role can do. The first is working, and the second is missing a permission.
Fix. Read the denied action and resource in the error message, then add that permission to the role. Check for permission boundaries or service control policies if the permission already exists and the call is still denied.
Quick reference
| Symptom | Most likely cause | First check |
|---|---|---|
| Cannot find the token request URL | Missing `id-token: write` | The `permissions` block at job and workflow level |
| Checkout fails after adding permissions | `contents: read` was dropped | Unlisted permissions become `none` |
| No OpenIDConnect provider found | Provider missing in this account | IAM identity providers list |
| Not authorized to assume the role | Audience or subject mismatch | Decoded `aud` and `sub` |
| Works on `main`, fails with an environment | Subject has `environment:` form | Printed `sub` value |
| Fails only on fork pull requests | No write token for forks | Event type and trigger |
| Fails mid-job with expired credentials | Session duration reached | `role-duration-seconds` |
| `AccessDenied` after `get-caller-identity` works | Permission policy gap | The denied action in the error |
Exercise
A deploy job declares environment: production and runs on main. The role's trust policy requires sub to equal repo:octo-org/octo-repo:ref:refs/heads/main. The job fails with "Not authorized to perform sts:AssumeRoleWithWebIdentity". What is the cause, and how do you confirm it?
Show answer
When a job declares an environment, the default sub claim is repo:octo-org/octo-repo:environment:production. It does not contain the branch. The StringEquals condition therefore fails. Confirm it by decoding the token in a debug step and printing sub. Then change the trust policy to accept the environment form, for example repo:octo-org/octo-repo:environment:production.
Exercise
A workflow sets permissions: id-token: write at the top. The actions/checkout step now fails on a private repository, although the OIDC step worked. Why, and what is the fix?
Show answer
Setting any permissions key makes every unlisted permission none, including contents: read, which checkout needs. Add contents: read next to id-token: write.
Exercise
aws sts get-caller-identity prints the assumed role, but the next aws s3 cp step fails with AccessDenied. Should you edit the trust policy?
Show answer
No. The assume-role step succeeded, so the trust policy is working. The role's permission policy lacks the needed S3 action or resource. Add the permission there, and check permission boundaries or service control policies if it already exists.