Sub topic 3
GitHub Actions as an identity provider
This chapter assumes you know basic workflow syntax, what a JWT is from the previous chapter, and what a cloud IAM role is. It explains what it means for GitHub to act as an OpenID Connect (OIDC) identity provider, where the trust comes from, and which parts of the system GitHub runs.
What an identity provider does
In OIDC, an identity provider (IdP) is a service that authenticates a subject and then issues a signed statement about that subject. A relying party, which is the service that consumes the statement, decides what to do with it.
With a person logging in to a web app, Google or Okta is the IdP and the web app is the relying party. In GitHub Actions the roles change:
| Role | Who plays it |
|---|---|
| Identity provider | GitHub's OIDC service for Actions |
| Subject | A single workflow job run |
| Relying party | Your cloud provider, such as AWS, Azure, or Google Cloud |
| Credential | A signed JWT called the ID token |
The subject is not a person. GitHub already knows which repository, branch, workflow, and trigger started the job. The ID token states those facts in a form the cloud can verify without any shared secret.
The three pieces GitHub provides
GitHub's side of the arrangement has three parts.
- A token issuer. During a job, GitHub's service mints a JWT on request. The token is signed with a private key that only GitHub holds.
- A discovery document. This is a public JSON file that tells relying parties where the signing keys are and how tokens are signed.
- A published key set. This is a JWKS (JSON Web Key Set), a public list of the keys that verify GitHub's signatures.
The cloud never calls back into your workflow. It only fetches public documents from GitHub and checks the token's signature against them. That is why no secret needs to be stored in either place.
The issuer URL
Every OIDC token carries an iss (issuer) claim. For GitHub.com the issuer is:
https://token.actions.githubusercontent.comThis URL has two jobs. It is the name that trust policies refer to, and it is the base URL for discovery. By the OIDC discovery convention, a relying party appends /.well-known/openid-configuration to the issuer to find the configuration.
You can fetch it yourself. It is public, and you don't need a token:
curl -sS https://token.actions.githubusercontent.com/.well-known/openid-configuration \
| jq '{issuer, jwks_uri, id_token_signing_alg_values_supported}'The response names the issuer, a jwks_uri pointing at the key set, and the signing algorithms. GitHub signs with RS256, which is RSA with SHA-256. Fetch the jwks_uri value and you get the public keys. Each key has a kid (key ID), and each token header names the kid that signed it. That is how a verifier picks the right key, including while GitHub rotates keys.
Issuer variations
The issuer is not the same everywhere:
- GitHub.com:
https://token.actions.githubusercontent.com. - GitHub Enterprise Cloud: an enterprise can opt in to a custom issuer that includes the enterprise name, in the form
https://token.actions.githubusercontent.com/<enterprise-slug>. This makes the issuer unique to your enterprise. - GitHub Enterprise Server: the issuer is served from your own host, in the form
https://HOSTNAME/_services/token.
The cloud's trust configuration must use the exact issuer string that appears in your tokens. A trust set up for the default issuer will not match tokens from a custom one.
How a job gets a token
The token is not placed in the job's environment up front. A job obtains one on request, in a short exchange:
- The runner starts the job. If the job has the
id-token: writepermission, the runner sets two environment variables:ACTIONS_ID_TOKEN_REQUEST_URLandACTIONS_ID_TOKEN_REQUEST_TOKEN. - A step calls that URL, using the request token as a bearer credential.
- GitHub's service checks the request token, builds a claims set from what it knows about this run, signs it, and returns the JWT.
- The step sends the JWT to the cloud provider, which verifies it and returns temporary credentials.
The request token in step 1 is not the ID token. It only proves to GitHub that the caller is a legitimate step in a running job. It is scoped to that run and is only good for asking GitHub for an ID token. The permission and the request parameters have their own chapters. Here the point is that GitHub issues the claims itself, from its own records of the run. The workflow code cannot write the claims.
Looking at a token header
You can see GitHub's signing details by decoding the header of a real token. This workflow requests a token and prints only the header, never the payload or the whole token. It also masks the token in the logs as a precaution.
name: inspect-header
on: workflow_dispatch
permissions:
id-token: write
contents: read
jobs:
inspect:
runs-on: ubuntu-latest
steps:
- name: Print the JWT header
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" | cut -d. -f1 | jq -R '@base64d | fromjson'The output has an alg of RS256, a typ of JWT, and a kid that matches one entry in the published key set. The kid is the only link between a token and the key that verifies it. If a verifier can't find that kid in the key set, it must reject the token.
What GitHub guarantees, and what it doesn't
The token tells the cloud who GitHub says is asking. It doesn't tell the cloud whether that caller should be allowed in.
GitHub guarantees the following:
- The claims were produced by GitHub's service from the actual run. A workflow author can't forge a different
repositoryorref. - The token is signed. Any change to the payload invalidates the signature.
- The token is short-lived and carries an
exptimestamp.
GitHub does not guarantee the following:
- That the code running in the job is trustworthy. Anyone who can change a workflow file on an allowed branch can run code that requests a token.
- That your cloud trusts the right repositories. That depends on your trust policy, which is the subject of later chapters.
Any repository on GitHub can get a token from the same issuer with the same signing keys. The signature alone therefore proves very little. It proves the token came from GitHub, not that it came from your repository. Your cloud trust policy must check claims such as the subject to narrow acceptance to specific repositories and branches.
Limits worth knowing
- Pull requests from forks. Workflows triggered by pull requests from forks run with reduced permissions, and they don't get
id-token: write. This is a deliberate protection, so an outside contributor can't mint a token that your cloud would trust. - Per-job tokens. Each job requests its own token. A token from one job is not a session for the whole workflow.
- Public discovery. The discovery document and key set are public. Network restrictions on your cloud don't prevent it from fetching them, but they can break verification if the cloud is blocked from reaching GitHub's issuer.
- Short lifetime. Tokens are meant to be used soon after they're requested. Request one just before you need it. Don't store it for later steps.
Exercise
A colleague says, "Our cloud verifies GitHub's signature on the token, so only our repository can get credentials." Why is this reasoning wrong, and what does the trust policy need in addition to signature verification?
Show answer
GitHub signs tokens for every repository on the platform with the same keys under the same issuer, so a valid signature only shows the token came from GitHub. The trust policy must also check claims that identify your repository, most importantly the sub claim (for example repo:octo-org/octo-repo:ref:refs/heads/main), along with the audience.
Exercise
Which two environment variables does the runner set when a job has id-token: write, and why is the value of one of them not itself an ID token?
Show answer
ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN. The request token only authenticates the step to GitHub's OIDC service so it can ask for an ID token. GitHub then mints and signs the actual ID token with the claims for that run.