Sub topic 4
Reading the token claims: iss, aud, and sub
This chapter assumes you know basic IAM roles and policies, can read JSON, and have written a GitHub Actions workflow. A claim is a named fact inside the OIDC token, such as who issued it or who it is for. AWS makes its access decision from three of them: iss, aud, and sub.
The three claims AWS checks
The token is a JSON Web Token (JWT). It has three parts: a header, a payload of claims, and a signature. AWS verifies the signature against GitHub's published keys. It then compares the claims with your IAM configuration.
| Claim | Meaning | Example value | Where AWS checks it |
|---|---|---|---|
| `iss` | Issuer: who created the token | `https://token.actions.githubusercontent.com` | Matched to the IAM OIDC provider URL |
| `aud` | Audience: who the token is meant for | `sts.amazonaws.com` | Matched to the provider's client ID list and your trust policy |
| `sub` | Subject: which workflow run is asking | `repo:my-org/my-repo:ref:refs/heads/main` | Matched by your trust policy condition |
The iss claim picks the provider. If no IAM provider has that URL, the call fails before any role is considered.
The aud claim stops a token meant for another service from being replayed against AWS. The configure-aws-credentials action requests sts.amazonaws.com by default.
The sub claim is the one you write most conditions against, because it identifies the repository and the trigger.
How sub is built
GitHub builds sub from the context of the run. The common shapes are:
- Branch push:
repo:OWNER/REPO:ref:refs/heads/BRANCH - Tag push:
repo:OWNER/REPO:ref:refs/tags/TAG - Job using an environment:
repo:OWNER/REPO:environment:NAME - Pull request:
repo:OWNER/REPO:pull_request
A job that uses an environment gets the environment form of sub. The branch name is not in it. A role locked to ref:refs/heads/main will therefore reject that job.
Seeing the claims in a run
You can decode a token's payload to inspect it. This step is for learning only. Do not print real tokens in shared logs.
name: inspect-claims
on: workflow_dispatch
permissions:
id-token: write
contents: read
jobs:
inspect:
runs-on: ubuntu-latest
steps:
- name: Print 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 "$TOKEN" | cut -d. -f2 | tr '_-' '/+' | base64 -d 2>/dev/null | jq '{iss, aud, sub}'Run it from main and you should see sub set to repo:<owner>/<repo>:ref:refs/heads/main.
Matching claims in the trust policy
Trust policy condition keys are the provider URL without https://, a colon, and the claim name. For example, token.actions.githubusercontent.com:sub. Use StringEquals for an exact match. Use StringLike when you need a * wildcard.
Exercise
A job declares environment: production in the repository my-org/my-repo. What sub value does its token carry, and would a trust policy that requires repo:my-org/my-repo:ref:refs/heads/main accept it?
Show answer
The sub is repo:my-org/my-repo:environment:production. The policy would reject it, because jobs that use an environment get the environment form of sub and it contains no branch reference.