Sub topic 2
OpenID Connect and JWTs in a Nutshell
This chapter explains the two building blocks behind GitHub's OIDC support: OpenID Connect (OIDC) and JSON Web Tokens (JWTs). It assumes you know basic GitHub Actions syntax, have a general idea of cloud IAM roles and policies, and can read HTTP and JSON. Later chapters build on the vocabulary introduced here.
Why a standard is needed
The previous chapter showed the problem with long-lived credentials stored as secrets. They can leak, they rarely rotate, and anyone who holds them can use them from anywhere. The alternative is for the workflow to prove who it is each time it runs, and for the cloud provider to hand back short-lived access.
For that to work, the two sides need a shared way to say "this is who I am" and a shared way to check it. OIDC provides that agreement. It is a standard that lets one system (the identity provider) vouch for the identity of a caller to another system (the relying party). In this tutorial, GitHub is the identity provider. The cloud (AWS, Azure, Google Cloud, or Vault) is the relying party.
OpenID Connect in one paragraph
OpenID Connect is an identity layer built on top of OAuth 2.0. OAuth 2.0 answers "what may this caller do?" by issuing access tokens. OIDC adds "who is this caller?" by defining an ID token, a signed statement about an identity. The key terms are:
- Identity provider (IdP): the service that authenticates a subject and issues ID tokens. GitHub plays this role for workflow runs.
- Relying party (RP): the service that receives an ID token and decides whether to trust it. Your cloud provider plays this role.
- ID token: a signed JWT that carries claims about the subject.
- Claim: a single piece of information in the token, such as who issued it or which repository it came from.
- Issuer: the URL that identifies the IdP. It appears in the token as
iss. - Audience: the party the token is meant for. It appears as
aud.
Browser login with "Sign in with Google" uses the full OIDC flow, with redirects and a human in the loop. GitHub Actions uses a much shorter path. A running job asks GitHub for a token over HTTP, and no user interaction is involved. The pieces that matter are the same: a signed token, an issuer, an audience, and a verifier.
What a JWT looks like
A JSON Web Token (JWT) is a compact string that carries JSON claims and a signature. It has three parts, each encoded with base64url and separated by dots:
<header>.<payload>.<signature>| Part | Contents | Example fields |
|---|---|---|
| Header | How the token was signed | `alg`, `kid`, `typ` |
| Payload | The claims | `iss`, `aud`, `sub`, `exp` |
| Signature | A cryptographic signature over the header and payload | binary data, base64url-encoded |
Base64url is an encoding. It is not encryption. Anyone who holds a JWT can read the header and payload. The signature does not hide the contents. It proves that the contents have not been changed and that they were produced by the holder of the signing key.
You can inspect the payload of any JWT with a short script. This one reads a token from standard input and prints the header and payload:
import base64
import json
import sys
def decode_part(part: str) -> dict:
# base64url omits padding, so add it back before decoding.
padded = part + "=" * (-len(part) % 4)
return json.loads(base64.urlsafe_b64decode(padded))
token = sys.stdin.read().strip()
header, payload, _signature = token.split(".")
print("header:", json.dumps(decode_part(header), indent=2))
print("payload:", json.dumps(decode_part(payload), indent=2))Decoding is not validating. This script does not check the signature, so it tells you nothing about whether the token is genuine. Use it for debugging only, and never make a trust decision from a payload you have only decoded.
The header
The header tells a verifier how to check the signature. A typical header for a GitHub token looks like this:
{
"alg": "RS256",
"kid": "38826b17-6a30-5f9b-b169-8beb8202f723",
"typ": "JWT"
}algis the signing algorithm.RS256means RSA with SHA-256.kidis the key ID. The issuer publishes several keys, andkidsays which one signed this token. This lets the issuer rotate keys without breaking verification.typsays the token is a JWT.
The kid value above is an example. Real values differ and change over time.
The payload
The payload holds the claims. Some are standard names defined by the JWT and OIDC specifications. Others are specific to the issuer. GitHub adds many of its own, such as repository and job_workflow_ref, which later chapters cover in detail. The standard claims you need now are:
| Claim | Meaning |
|---|---|
| `iss` | The issuer. The URL of the party that created the token. |
| `aud` | The audience. Who the token is intended for. |
| `sub` | The subject. Who or what the token describes. |
| `iat` | Issued at. The time the token was created, in seconds since the Unix epoch. |
| `nbf` | Not before. The token is invalid earlier than this time. |
| `exp` | Expiry. The token is invalid after this time. |
All three time claims are numeric timestamps. A short expiry is what makes the token safe to hand to a build job. Even if it leaks, it stops working soon afterward.
How a verifier checks a token
A relying party does not call GitHub each time it sees a token. It uses public-key cryptography, so it can check the token by itself. The process rests on discovery documents that the issuer publishes at well-known URLs.
- The issuer signs each token with a private key that never leaves its systems.
- The issuer publishes the matching public keys as a JSON Web Key Set (JWKS), at a URL listed in its discovery document.
- The relying party fetches the discovery document from
<issuer>/.well-known/openid-configuration. It reads thejwks_urifield from that document. - The relying party downloads the JWKS, picks the key whose
kidmatches the token header, and verifies the signature. - It then checks the claims:
iss,aud, and the time window.
For GitHub, the issuer is https://token.actions.githubusercontent.com. You can fetch its discovery document yourself:
curl -sS https://token.actions.githubusercontent.com/.well-known/openid-configuration | jq '{issuer, jwks_uri, id_token_signing_alg_values_supported}'The output shows the issuer URL, the location of the public keys, and the supported signing algorithms. Fetching the key set is the same kind of request against the jwks_uri value.
The relying party can cache the keys. This is why verification is fast and why key rotation works through kid: when the issuer adds a new key, the relying party sees an unfamiliar kid and refreshes its copy.
The checks that matter
Each check blocks a different attack. Skipping any of them leaves a gap.
| Check | What it prevents |
|---|---|
| Signature | Forged tokens or tokens with edited claims |
| `iss` | Tokens from an unrelated provider that signs with its own keys |
| `aud` | A token issued for service A being replayed against service B |
| `exp` and `nbf` | Reuse of old or not-yet-valid tokens |
The audience check deserves attention. A token minted for one cloud is useless at another only if the second cloud insists on its own audience value. If a verifier accepts any audience, a token that leaked to one service can be replayed against others.
Common mistakes
- Treating a JWT as encrypted. The payload is readable by anyone. Do not put secrets in claims, and do not assume a token is safe to paste into logs or chat. A live token can still be replayed until it expires.
- Trusting a decoded payload. Reading claims is not verifying them. Only a verifier that has checked the signature may act on them.
- Ignoring
aud. A valid signature from the right issuer is not enough. The token must also be meant for the service that receives it. - Confusing
subwith a username. The subject identifies what the token describes. For GitHub it describes a workflow context, such as a repository and branch, not a person. - Assuming tokens last long. The expiry is short by design. Request the token close to the point where you use it.
Where GitHub fits
Everything above is generic OIDC. GitHub's contribution is specific: each workflow job can ask GitHub's identity provider for a JWT whose claims describe that run, including the repository, the branch or environment, and the workflow. The cloud provider is configured once to trust GitHub's issuer and to accept tokens only when their claims match a rule you write. The next chapters cover how GitHub issues these tokens and which claims it includes.
Exercise
A teammate pastes a JWT into a chat and says, "It's fine, the token is encrypted so no one can read it." Is that correct? What can someone do with the token, and what limits the damage?
Show answer
It is not correct. A JWT is signed, not encrypted. The header and payload are only base64url-encoded, so anyone can decode and read the claims. A holder can also present the token to a relying party that trusts the issuer and audience. The damage is limited by the short expiry (exp) and by the audience check (aud), which restricts which service accepts the token. The token should still be treated as sensitive until it expires.
Exercise
A relying party receives a JWT whose signature is valid and whose iss is the expected issuer, but whose aud is a different service. Should it accept the token? List the other checks it must perform.
Show answer
No. The token was issued for a different audience, so accepting it would allow replay of a token meant for another service. The relying party must also check that the token has not expired (exp), that it is not used before nbf, and, for a policy that depends on identity, that the sub and other claims match the conditions in its trust rules.