Sub topic 3
What GitHub issues to a running job
This chapter assumes you know basic GitHub Actions workflows (jobs, steps, triggers) and basic AWS IAM concepts (users, roles, policies). You should also be comfortable reading JSON and YAML.
The token is created on request
When a job starts, GitHub does not hand it an AWS credential. It does not hand it a token either. The job has to ask for one.
A job can ask only if the workflow allows it. You grant that permission with id-token: write. Without it, GitHub's OIDC provider will not issue a token to the job.
An OIDC token is a JSON Web Token (JWT). A JWT is a signed string with three parts separated by dots: a header, a payload of claims, and a signature. A claim is a single fact about the job, such as which repository it belongs to.
GitHub signs each token with its private key. AWS checks the signature against GitHub's public keys. AWS does not need to contact your repository to trust the token.
How the job gets the token
GitHub places two values in the runner's environment when id-token: write is set:
ACTIONS_ID_TOKEN_REQUEST_URL, the address of GitHub's token endpoint.ACTIONS_ID_TOKEN_REQUEST_TOKEN, a bearer token that authorizes the request.
A step calls the URL with that bearer token and an optional audience query parameter. The response is JSON with a value field that holds the JWT. The aws-actions/configure-aws-credentials action does this for you. You will meet it in a later chapter. The step below shows the raw call so you can see what happens.
name: inspect-token
on: workflow_dispatch
permissions:
id-token: write
contents: read
jobs:
inspect:
runs-on: ubuntu-latest
steps:
- name: Request an OIDC token and print its 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 .The step splits the JWT on dots, takes the payload, and decodes it. Base64url encoding can omit padding, so base64 -d may print a warning about trailing input. The 2>/dev/null hides that warning, and the JSON still prints.
Short-lived and per job
The token is valid for a short time, on the order of minutes. It belongs to one job run. A new job gets a new token, and the token cannot be reused later as a standing credential.
Treat the token as sensitive anyway. Do not print it to logs in real workflows. Anyone who has a valid token can present it to AWS until it expires.
What the decoded payload shows
The payload contains claims such as iss, aud, sub, repository, ref, and workflow. The next chapter explains the key three, iss, aud, and sub, and how AWS uses them.
Exercise
A job runs the token request from the example but receives an error, and the environment has no ACTIONSIDTOKENREQUESTURL variable. What is the most likely cause, and how do you fix it?
Show answer
The workflow or job does not grant the id-token: write permission, so GitHub never sets the request variables. Add permissions: id-token: write (plus contents: read if the job also checks out code) at the workflow or job level.