Sub topic 8
How a cloud provider validates the token
This chapter assumes you know what a JWT is, what the claims iss, aud, and sub mean, and how a workflow gets a token with id-token: write. Here you will see what a cloud provider checks before it hands out credentials.
Validation happens in two stages
The cloud provider never contacts the workflow. It receives the token and decides on its own. It does this in two stages.
- Token validation. Is this a genuine, current token from the issuer I was told to trust, meant for me?
- Policy evaluation. Do the claims in this token satisfy the conditions on the role?
Stage 1 is automatic and the same for every workflow. Stage 2 is the trust policy that you write. The next chapter covers it.
The checks in order
Issuer
The iss claim must be https://token.actions.githubusercontent.com. You tell the cloud provider to trust this issuer ahead of time. In AWS you do this by creating an IAM OIDC identity provider. A token from any other issuer is rejected, however well formed it is.
Signature
A JWT is signed with the issuer's private key. The provider finds the matching public key by following a discovery document. This is a JSON file at /.well-known/openid-configuration under the issuer URL. It contains a jwks_uri field, which points to the JSON Web Key Set, the list of current public keys. The token header carries a kid (key ID) that selects the right key from that set.
You can look at this yourself:
curl -sS https://token.actions.githubusercontent.com/.well-known/openid-configuration | jq '{issuer, jwks_uri}'
curl -sS https://token.actions.githubusercontent.com/.well-known/jwks | jq '.keys[0] | {kid, kty, alg}'If the signature does not verify against the key, the token was altered or forged. This check is what lets the provider trust the claims without any shared secret.
Audience
The aud claim must match what the provider expects. For AWS this is sts.amazonaws.com. This stops a token meant for one service from being replayed against another.
Time window
The token carries iat (issued at), nbf (not before), and exp (expiry). The provider rejects a token outside that window. GitHub tokens are short-lived, so a leaked one is useful for only a few minutes.
What validation does not tell you
A valid token proves only that GitHub issued it for some workflow. Every repository on GitHub gets tokens from the same issuer with the same signing keys. If the cloud provider stopped after stage 1, any GitHub user could assume your role.
The claims, mainly sub, are what separate your repository from everyone else's. That is why the trust policy conditions are the real security boundary.
Common validation failures
| Symptom | Likely cause |
|---|---|
| Invalid identity token or provider not found | The OIDC provider is not registered in the cloud account, or the issuer URL is misspelled |
| Audience mismatch | The workflow requested a different `audience` than the provider expects |
| Token expired | The token was requested long before use, for example in a slow job |
| Signature failure | The token was modified, or truncated when copied between steps |
Failures in stage 2 look different. They usually report that the identity is not authorized to assume the role. Treat that as a claim mismatch, not a token problem.
Exercise
A cloud provider confirms that a token has a valid signature, the right issuer, the right audience, and an unexpired timestamp. Why is that not enough to grant access to your role, and what closes the gap?
Show answer
Every GitHub repository receives validly signed tokens from the same issuer, so passing these checks shows only that GitHub issued the token. The trust policy must also check claims such as sub to limit access to your repository, branch, or environment.
Exercise
Which part of the discovery process lets the provider verify a signature without holding any secret?
Show answer
The jwks_uri in the issuer's discovery document points to the issuer's public keys. The provider picks the key matching the token's kid and verifies the signature with it. Only the issuer holds the private key.