Sub topic 3
What GitHub issues to a running job
This chapter assumes you can read a GitHub Actions workflow (jobs, steps, triggers), know what an AWS IAM role is, and can read JSON and decode base64. The previous chapters explained why OIDC replaces stored access keys. This chapter covers what GitHub gives a job at run time and how the job asks for it.
A token, not a credential
GitHub does not hand a job AWS credentials. It gives the job the ability to request an OIDC token. This is a JSON Web Token (JWT): three base64url-encoded parts separated by dots (header, payload, signature). GitHub signs it with a private key. AWS later checks the signature against GitHub's public keys.
The token proves one thing: "GitHub vouches that this specific workflow run, in this repository, on this ref, is asking." It grants no access by itself. AWS decides what to do with that proof, based on the trust policy you write in later chapters.
How a job gets its token
When a job has permission to request tokens, the runner sets two environment variables for its steps:
| Variable | Purpose |
|---|---|
| `ACTIONS_ID_TOKEN_REQUEST_URL` | The endpoint of GitHub's token service for this run. It already contains a query string. |
| `ACTIONS_ID_TOKEN_REQUEST_TOKEN` | A bearer token that authorizes the request to that endpoint. |
The job sends an HTTP GET to the URL with the header Authorization: bearer <request token>. The response is JSON with a value field that holds the JWT. You can add an audience query parameter to choose the token's aud claim. If you omit it, the audience defaults to the URL of the repository owner, such as https://github.com/my-org. AWS will reject that default, because the identity provider expects sts.amazonaws.com.
In practice you rarely make this call yourself. aws-actions/configure-aws-credentials makes it for you, using the toolkit function core.getIDToken(audience). Doing it by hand once is still useful, because it shows exactly what AWS will receive.
The permission that switches it on
The environment variables only exist when the workflow grants the id-token: write permission. Without it, the variables are absent and any request fails.
permissions:
id-token: write
contents: readTwo details trip people up:
- Setting
permissionsat the workflow or job level replaces the defaults. If you addid-token: writeand nothing else,contentsbecomesnone, andactions/checkoutfails on a private repository. Listcontents: readexplicitly. id-token: writedoes not let the job write to your repository or to GitHub in any other way. It only allows requesting OIDC tokens.
Inspecting a real token
This workflow requests a token with the AWS audience and prints its non-secret claims. It needs no AWS account. You can run it from the Actions tab with workflow_dispatch.
name: inspect-token
on:
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
inspect:
runs-on: ubuntu-latest
steps:
- name: Request and decode an OIDC token
run: |
set -euo pipefail
RESPONSE=$(curl -sS \
-H "Authorization: bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=sts.amazonaws.com")
TOKEN=$(echo "$RESPONSE" | jq -r '.value')
echo "::add-mask::${TOKEN}"
PAYLOAD=$(echo "$TOKEN" | cut -d. -f2 | tr '_-' '/+')
while [ $(( ${#PAYLOAD} % 4 )) -ne 0 ]; do PAYLOAD="${PAYLOAD}="; done
echo "$PAYLOAD" | base64 -d | jq '{iss, aud, sub, repository, ref, environment, job_workflow_ref}'The step does three things beyond the request:
::add-mask::tells the runner to hide the token in logs. Treat the whole JWT as a secret, even though it expires quickly.tr '_-' '/+'converts base64url to standard base64, whichbase64 -dexpects.- The
whileloop restores the=padding that base64url omits.
For a push to main in my-org/my-repo, the output 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"
}The next chapter goes through these claims one by one. For now, notice that iss is the provider URL you register in IAM, aud is the value you requested, and sub is built from the repository and the ref. environment is null because the job did not declare an environment. If it had, sub would change to the repo:my-org/my-repo:environment:<name> form.
Properties worth knowing
- Tokens are minted per request. Each call returns a new JWT. A job can request several, for example one per audience.
- Tokens are short-lived. The JWT is meant to be exchanged right away. AWS checks its expiry when you call STS, so you cannot save one for later.
- Scope is one job. The request token is tied to the running job. Another job needs its own
id-token: writepermission and makes its own request. - The claims come from GitHub, not from your workflow file. A step cannot edit the
suborrepositoryvalues. This is why trust policies can rely on them. - Signing keys rotate. AWS fetches GitHub's keys from the issuer's published discovery document, so you do not upload keys yourself.
When no token is available
Other situations that leave a job without a token:
- The workflow or job does not set
id-token: write. The environment variables are missing, andconfigure-aws-credentialsreports that it could not get an ID token. - The job runs in a reusable workflow whose caller did not grant the permission. A called workflow cannot have more permissions than its caller gives it.
- A self-hosted runner cannot reach the token service endpoint, for example because of a proxy rule.
Common mistakes
- Requesting a token without
audience, then wondering why AWS says the audience does not match. - Printing the full JWT to a log without masking it.
- Putting
id-token: writeat the top level of a workflow where only one job needs it. Granting it per job follows least privilege better. - Expecting
aws sts get-caller-identityto work right after the token request. The token is only the proof. You still have to exchange it with STS for credentials.
Exercise
A workflow sets permissions: id-token: write at the top level and nothing else. The first step, actions/checkout, fails on a private repository. Why, and what is the fix?
Show answer
Declaring permissions replaces the default set, so every scope you do not list becomes none. contents is now none, and checkout cannot read the repository. Add contents: read next to id-token: write.
Exercise
You run the inspection workflow on a pull request from a fork, and the step fails because ACTIONS_ID_TOKEN_REQUEST_URL is empty. Is this a bug in the workflow? Explain.
Show answer
No. For pull requests from forks, GitHub does not grant id-token: write, so the runner never sets the request variables. This prevents untrusted code from obtaining a token that AWS could trust. Run the workflow on a branch in the same repository instead.