Sub topic 8
How a cloud provider validates the token
This chapter assumes you know the three-part structure of a JWT (header, payload, signature), what the iss, aud, sub and exp claims mean, and how a workflow gets a token with id-token: write. You should also have a general idea of IAM roles and trust policies.
A GitHub OIDC token is only a string. The cloud provider has no reason to believe it until it checks it. This chapter covers what the provider checks, in what order, and which errors each check produces.
Validation has two stages
Validation happens in two stages, and mixing them up causes most of the confusing errors.
- Token validation answers "Is this token genuine, current, and meant for me?" It covers the signature, issuer, audience, and time claims. It involves no policy decisions.
- Trust policy evaluation answers "Is this genuine workflow allowed to do this?" It compares claims such as
subandrepositoryagainst the conditions you wrote.
A token can pass stage one and fail stage two. That happens when it is a real GitHub token for the wrong repository.
Stage one: verifying the token
Step 1: Read the header and find the key
A JWT header is a small JSON object. For GitHub tokens it looks like this (abbreviated):
{
"alg": "RS256",
"typ": "JWT",
"kid": "38826b17-6a30-5f9b-b169-8beb8202f723"
}alg names the signature algorithm. kid is the key ID, which says which of GitHub's signing keys produced the signature. GitHub rotates keys, so the verifier cannot hard-code one.
The verifier must also decide which algorithms it accepts. A safe verifier accepts only the algorithm it expects for that provider (RS256 here) and never the value the token claims to use. This blocks the classic attack where a forged token sets alg to none or to a symmetric algorithm.
Step 2: Fetch the public keys
The verifier needs the issuer's public keys. It finds them in two requests:
- It takes the
issclaim and appends/.well-known/openid-configuration. This is the discovery document. - The discovery document has a
jwks_urifield. That URL returns a JSON Web Key Set (JWKS), a list of public keys, each with akid.
You can follow this chain yourself:
ISS="https://token.actions.githubusercontent.com"
JWKS_URI=$(curl -sS "$ISS/.well-known/openid-configuration" | jq -r '.jwks_uri')
echo "$JWKS_URI"
curl -sS "$JWKS_URI" | jq -r '.keys[].kid'The first command prints the JWKS URL. The second lists the key IDs currently published. The token's kid must appear in that list.
Providers cache the JWKS so they do not fetch it on every login. When a token arrives with an unknown kid, a well-behaved verifier refetches the set once before rejecting the token. That is how key rotation works without breaking logins.
Step 3: Check the signature
The signature covers the encoded header and payload. The verifier recomputes it with the matching public key and compares. If one character of the payload changed, for example sub edited to name another repository, the signature fails. The public key cannot create signatures, so only GitHub, which holds the private key, can make a token that verifies.
Step 4: Check the issuer
The iss claim must exactly match an identity provider you registered with the cloud account, here https://token.actions.githubusercontent.com. This is why you create an OIDC provider entry in AWS IAM, a workload identity pool provider in Google Cloud, or a federated credential in Azure. It is your list of issuers you trust. A validly signed token from any other issuer is rejected.
Step 5: Check the audience
The aud claim says who the token is for. The provider compares it to the audiences you configured. For AWS this is the provider's client ID list, and the default value used by configure-aws-credentials is sts.amazonaws.com. A token minted for another service fails here. This stops a token sent to one service from being replayed against your cloud account.
Step 6: Check the time claims
The verifier checks three timestamps, which are seconds since the Unix epoch:
exp: the token must not be expired. GitHub tokens are short-lived, so a token captured from an old log is useless.nbf: the token must not be used before this time.iat: when the token was issued. Verifiers use it to reject tokens dated in the future.
Verifiers usually allow a small clock skew, often a minute or less, because the two systems' clocks do not match exactly.
The checks in order
A verifier in Python
This script does the same checks a cloud provider does. It reads a token from the TOKEN environment variable and needs pip install "pyjwt[crypto]".
import os
import jwt
from jwt import PyJWKClient
ISSUER = "https://token.actions.githubusercontent.com"
JWKS_URL = f"{ISSUER}/.well-known/jwks"
AUDIENCE = "sts.amazonaws.com"
token = os.environ["TOKEN"]
# Fetches the JWKS and picks the key whose kid matches the token header.
signing_key = PyJWKClient(JWKS_URL).get_signing_key_from_jwt(token)
claims = jwt.decode(
token,
signing_key.key,
algorithms=["RS256"], # accept only the expected algorithm
audience=AUDIENCE, # checks aud
issuer=ISSUER, # checks iss
leeway=60, # allow 60 seconds of clock skew
options={"require": ["exp", "iat", "iss", "aud", "sub"]},
)
print("sub:", claims["sub"])
print("repository:", claims["repository"])PyJWT checks exp, nbf and iat automatically. If any check fails, jwt.decode raises an exception such as ExpiredSignatureError, InvalidAudienceError or InvalidIssuerError. Each one matches a step above.
Stage two: trust policy evaluation
After the token passes, the provider evaluates your policy. In the AWS trust policy from earlier chapters, the Principal names the OIDC provider. The Condition block compares claims to values:
token.actions.githubusercontent.com:audmust equalsts.amazonaws.com.token.actions.githubusercontent.com:submust equalrepo:octo-org/octo-repo:ref:refs/heads/main.
The provider does not use the claims for anything else. If your policy has no sub condition, any repository's workflow that passes stage one can try to assume the role.
A note on AWS and thumbprints
AWS used to require a certificate thumbprint when you created the OIDC provider, so it could trust the HTTPS connection to the issuer. For GitHub, AWS now validates the connection with its own library of trusted certificate authorities and does not rely on the thumbprint. Older tutorials and some tools still ask for one. Supplying a value is harmless, but it is no longer what protects you. The sub condition does that.
Mapping errors to checks
The error message usually tells you which step failed.
| Symptom | Likely failing step | What to check |
|---|---|---|
| `No OpenIDConnect provider found in your account for https://token.actions.githubusercontent.com` | Issuer (step 4) | The OIDC provider was never created in this AWS account, or the URL has a typo. |
| `Incorrect token audience` | Audience (step 5) | The token's `aud` is not in the provider's client ID list. Check the `audience` set when requesting the token. |
| `Not authorized to perform sts:AssumeRoleWithWebIdentity` | Trust policy (stage two) | A `Condition` value does not match the token. Compare `sub` character by character. |
| Token rejected as expired | Time claims (step 6) | The token was requested too early in a long job, or was saved and reused. Request it right before use. |
| `Credentials could not be loaded` from the action | Before validation | The job is missing `id-token: write`, so no token was ever issued. |
What validation does not protect against
- Code running in an allowed workflow. If your policy trusts
mainand an attacker gets a malicious change merged intomain, the token is genuine and the policy passes. - Over-broad
subpatterns. A wildcard such asrepo:octo-org/*trusts every repository in the organization. - Leaked tokens within their lifetime. Short expiry limits the damage but does not remove it. Do not log tokens.
Exercise
A workflow's token passes signature verification but the role assumption fails with "Not authorized to perform sts:AssumeRoleWithWebIdentity". Which stage failed, and what would you compare first?
Show answer
Stage two, trust policy evaluation. Signature, issuer, audience and expiry checks have passed. Compare the token's sub claim (and aud) with the values in the role's trust policy Condition block. A common cause is a sub for a pull request, such as repo:octo-org/octo-repo:pull_request, when the policy allows only refs/heads/main.
Exercise
Why does a verifier fetch the JWKS and match on kid instead of storing one public key?
Show answer
GitHub rotates its signing keys. The kid in the token header identifies which key signed it, so the verifier can pick the right key from the published set. If the kid is unknown, the verifier refetches the JWKS once to pick up a new key before rejecting the token.