Sub topic 2
What is inside the OIDC token
This chapter assumes you know what a JSON Web Token (JWT) is, can read GitHub Actions workflow YAML, and have a basic grasp of IAM roles. You will look at the token a workflow receives and learn which parts of it a trust policy can check.
Structure of the token
A JWT has three base64url-encoded parts separated by dots: a header, a payload, and a signature. The header names the signing key. The payload holds the claims. The signature lets the cloud provider verify that GitHub issued the token and that nobody changed it.
The cloud provider never trusts a claim on its own. It trusts a claim only after the signature check passes. Your trust policy then decides which claim values are acceptable.
Reading the claims
You can decode the payload of a token inside a job to see exactly what GitHub sends. The job needs the id-token: write permission, which later chapters cover in detail.
name: inspect-token
on: workflow_dispatch
permissions:
id-token: write
contents: read
jobs:
inspect:
runs-on: ubuntu-latest
steps:
- name: Print 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)
payload=$(echo "$TOKEN" | cut -d. -f2 | tr '_-' '/+')
while [ $(( ${#payload} % 4 )) -ne 0 ]; do payload="$payload="; done
echo "$payload" | base64 -d | jq .The step prints only the payload. Never print the whole token, because anyone holding it can present it until it expires.
A payload for a push to main looks like this. The values are examples.
{
"iss": "https://token.actions.githubusercontent.com",
"aud": "sts.amazonaws.com",
"sub": "repo:example-org/example-repo:ref:refs/heads/main",
"repository": "example-org/example-repo",
"repository_owner": "example-org",
"ref": "refs/heads/main",
"sha": "0123456789abcdef0123456789abcdef01234567",
"event_name": "push",
"workflow": "deploy",
"job_workflow_ref": "example-org/example-repo/.github/workflows/deploy.yml@refs/heads/main",
"actor": "octocat",
"iat": 1764865642,
"exp": 1764866542
}The claims that matter for trust
| Claim | Meaning | Use in a trust policy |
|---|---|---|
| `iss` | The issuer, `https://token.actions.githubusercontent.com` | Identifies the OIDC provider you registered in IAM |
| `aud` | The audience the token was minted for | Pin it to `sts.amazonaws.com` so tokens made for other services are rejected |
| `sub` | The subject, which encodes the repository and the branch, tag, pull request, or environment | The main condition for restricting access |
| `repository`, `ref`, `environment` | The same facts as separate fields | Useful for reading and auditing |
| `job_workflow_ref` | The workflow file and ref that ran the job | Lets you trust a specific workflow file |
| `iat`, `exp` | Issue and expiry times | Checked by the provider, not by you |
The sub claim is the main focus of this tutorial. It packs the repository and the run context into one string, so a single condition can say "this repository, this branch". The next chapters cover its formats.
What the token does not prove
- The token proves where the job ran. It does not prove the code was reviewed.
- Any workflow in a repository you allow can request a token. Branch protection and environment rules decide who can run what.
- Claims such as
actorname the person who triggered the run. They are rarely a good basis for trust.
Exercise
A trust policy checks only the aud claim and requires sts.amazonaws.com. A job in an unrelated repository on GitHub receives a token with that audience. Can it assume your role, and why?
Show answer
Yes. Any GitHub Actions job can get a token with that audience, and the signature is valid because GitHub signed it. The policy never checks sub, which says which repository and branch the job ran from. Adding a sub condition is what restricts the role to your repository.