Sub topic 2
OpenID Connect and JWTs in a Nutshell
This chapter assumes you can read basic GitHub Actions workflow syntax, know what a cloud IAM role is, and are comfortable with HTTP and JSON. It covers the two building blocks behind everything that follows: OpenID Connect (OIDC) and JSON Web Tokens (JWTs).
What OIDC is
OIDC is an identity layer built on top of OAuth 2.0. OAuth 2.0 answers "what may this client do?". OIDC adds "who is this?". It does this with an ID token, a signed statement from an identity provider (IdP) about an identity.
Three roles appear in every OIDC exchange:
- The identity provider issues and signs tokens. In this tutorial, GitHub is the IdP.
- The subject is the thing being identified. Here it is a workflow run, not a person.
- The relying party receives the token and decides whether to trust it. Here it is a cloud provider such as AWS.
The relying party never sees a password or a long-lived key. It sees a signed token and checks it.
What a JWT looks like
An ID token is usually a JWT. A JWT is three Base64URL-encoded parts joined by dots:
<header>.<payload>.<signature>- The header names the signing algorithm (
alg) and the key ID (kid) used to sign. - The payload holds claims, which are key-value statements such as who issued the token and who it is for.
- The signature is computed over the header and payload with the IdP's private key.
Base64URL is an encoding, not encryption. Anyone who holds a JWT can read its payload. The signature only prevents tampering.
You can decode a payload locally to inspect it:
echo '{"iss":"https://token.actions.githubusercontent.com","aud":"sts.amazonaws.com"}' \
| base64 | tr '+/' '-_' | tr -d '=' > payload.txt
cat payload.txt
# Decode it back (restore padding if your tool requires it):
python3 -c "import base64,sys; s=open('payload.txt').read().strip(); print(base64.urlsafe_b64decode(s + '=' * (-len(s) % 4)).decode())"Because the payload is readable, treat a real token as a secret until it expires, even though it holds no password. Do not print it in logs.
Standard claims
OIDC defines a few claims that every verifier relies on:
| Claim | Meaning |
|---|---|
| `iss` | Issuer: the URL of the IdP that signed the token |
| `aud` | Audience: the party the token is meant for |
| `sub` | Subject: the identity the token describes |
| `iat` | Issued-at time |
| `nbf` | Not-before time |
| `exp` | Expiry time |
IdPs add their own claims on top. GitHub adds claims about the repository, branch, and workflow, which later chapters cover.
How trust works without shared secrets
The relying party and the IdP never exchange a secret. Instead, the IdP publishes its public keys at a well-known address, and the relying party fetches them.
- The relying party is configured once to trust a specific issuer URL.
- It discovers the issuer's public signing keys from a standard metadata location.
- For each token, it uses the
kidin the header to pick the matching public key. - It verifies the signature, then checks
iss,aud, and the time claims.
Only the IdP holds the private key, so only the IdP can produce a valid signature. That is why a token can stand in for a stored credential.
Common mistakes
- Trusting a token without checking
aud. A token issued for another service could otherwise be replayed against yours. - Assuming a JWT is encrypted. Its payload is readable by anyone who holds it.
- Ignoring
exp. Short lifetimes limit the damage of a leaked token, so verifiers must enforce them.
Exercise
A teammate says, "The token's signature is valid, so we can grant access." Name two other checks the relying party must make, and say what each prevents.
Show answer
It must check aud, which prevents a token issued for a different service from being replayed against this one. It must also check exp (and nbf), which prevents an old or leaked token from being used after its validity window. Checking iss against the trusted issuer, and checking sub or other subject claims, are also correct answers.