Sub topic 4
Reading the token claims: iss, aud, and sub
This chapter assumes you can read JSON and YAML, know what an IAM role and trust policy are, and have written a basic GitHub Actions workflow. The previous chapters covered why OIDC replaces stored keys and how a job receives a token. Here you will learn to read that token, because the trust policy you write later is built entirely from its claims.
What a claim is
The GitHub OIDC token is a JSON Web Token (JWT). A JWT has three parts separated by dots: a header, a payload, and a signature. The payload is a JSON object. Each key in it is a claim, a statement GitHub makes about the running job. The signature proves GitHub made those statements and that nobody changed them.
AWS checks the signature first. It then compares the claims with the identity provider you registered and with the conditions in the role's trust policy.
The three claims that matter for AWS
iss: who issued the token
iss (issuer) is the URL of the system that signed the token. For GitHub Actions it is always:
https://token.actions.githubusercontent.comAWS uses this value to find the IAM OIDC provider that holds the matching configuration. If you registered the provider with a different URL, such as one with a trailing slash or a typo, there is no match and the call fails. This is also why the trust policy's Principal and its condition keys use token.actions.githubusercontent.com as a prefix. The issuer decides which provider handles the token.
aud: who the token is for
aud (audience) names the service that should accept the token. A token meant for one service should be rejected by any other. If you request a token without specifying an audience, GitHub sets aud to the URL of your organization or user, for example https://github.com/my-org.
AWS expects sts.amazonaws.com. The aws-actions/configure-aws-credentials action requests that audience for you. The IAM provider's client ID list must include the same value, as in the --client-id-list sts.amazonaws.com option you used when creating the provider. The trust policy then repeats the check:
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
}The aud check proves the token was minted for AWS. It does not tell AWS which repository the job belongs to. Many people stop at this check, and that is a mistake. Every GitHub repository on earth can obtain a token with this audience.
sub: who is asking
sub (subject) identifies the workload that requested the token. It is the claim that separates your repository from everyone else's. It is built from the repository and the context of the run:
| Situation | Value of sub |
|---|---|
| Push or manual run on a branch | `repo:my-org/my-repo:ref:refs/heads/main` |
| Run on a tag | `repo:my-org/my-repo:ref:refs/tags/v1.2.0` |
| Job that references an environment | `repo:my-org/my-repo:environment:production` |
| Run triggered by `pull_request` | `repo:my-org/my-repo:pull_request` |
Two details cause most real-world mistakes:
- Environment replaces ref. When a job declares
environment: production, thesubclaim contains the environment name and no branch. A policy that only allowsref:refs/heads/mainwill reject that job, even if it runs onmain. - Pull requests have no branch. For the
pull_requestevent,subends in:pull_request. The branch name is not part of it, so you cannot allow one pull request branch and deny another throughsubalone.
Use StringLike for sub when you need wildcards, such as repo:my-org/my-repo:*. Use StringEquals when you want an exact match. A wildcard on the repository part, such as repo:my-org/*, grants access to every repository in the organization, including ones created later.
Other claims worth knowing
The token carries more than three claims. These are the ones you will meet most often:
| Claim | Meaning | Example |
|---|---|---|
| `repository` | Owner and repository name | `my-org/my-repo` |
| `repository_owner` | Organization or user | `my-org` |
| `ref` | Full Git reference | `refs/heads/main` |
| `sha` | Commit that triggered the run | `9f2c...` |
| `environment` | Environment name, if the job uses one | `production` |
| `job_workflow_ref` | Workflow file the job runs, including reusable workflows | `my-org/shared/.github/workflows/deploy.yml@refs/heads/main` |
| `actor` | User who triggered the run | `octocat` |
AWS can match on aud, sub, and a few others in IAM conditions. Your trust policy decisions, however, will mostly rest on sub. Later chapters return to job_workflow_ref for reusable workflows.
Inspecting a real token
The quickest way to learn the claim values is to read them from a running job. The workflow below requests a token with the AWS audience and prints selected claims. It masks the raw token first so it cannot appear in logs.
name: inspect-claims
on: workflow_dispatch
permissions:
id-token: write
contents: read
jobs:
inspect:
runs-on: ubuntu-latest
steps:
- name: Print selected 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"
echo "$TOKEN" | jq -R '
split(".")[1]
| gsub("-"; "+") | gsub("_"; "/")
| @base64d | fromjson
| {iss, aud, sub, repository, ref, environment, job_workflow_ref}'The environment variables ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN exist only because of id-token: write. Without that permission, the curl call fails. A typical result on main looks like this:
{
"iss": "https://token.actions.githubusercontent.com",
"aud": "sts.amazonaws.com",
"sub": "repo:my-org/my-repo:ref:refs/heads/main",
"repository": "my-org/my-repo",
"ref": "refs/heads/main",
"environment": null,
"job_workflow_ref": "my-org/my-repo/.github/workflows/inspect.yml@refs/heads/main"
}Run it from a branch, from a tag, and from a job with an environment. Compare the sub values with the table above. Copy the exact string you see into your trust policy condition rather than composing it from memory.
How the claims map to the trust policy
Each claim feeds a specific part of the trust policy you wrote earlier:
issselects the provider named inPrincipal.Federated.audappears as the condition keytoken.actions.githubusercontent.com:aud.subappears as the condition keytoken.actions.githubusercontent.com:sub.
If the value you see in the decoded token differs even by one character from the condition value, the role cannot be assumed. Case matters, and so does the exact repository name. The next chapters build on this when they register the provider and restrict access by branch and environment.
Exercise
A job uses environment: staging and runs on the main branch. The role trust policy has "token.actions.githubusercontent.com:sub": "repo:my-org/my-repo:ref:refs/heads/main" under StringLike. Will the job assume the role? If not, what should the condition value be?
Show answer
No. Because the job references an environment, its sub claim is repo:my-org/my-repo:environment:staging, with no branch in it, so the condition does not match and STS denies the call. Change the condition to repo:my-org/my-repo:environment:staging. You can also allow several values by listing them in an array.
Exercise
Why is checking only the aud claim not enough to protect a deployment role?
Show answer
Any GitHub repository can obtain a token with the audience sts.amazonaws.com, so the aud check only proves the token was meant for AWS. The sub claim identifies the repository, branch, or environment, so the trust policy must also restrict sub to your own repository.