Sub topic 2
How OIDC Federation Replaces Stored Secrets
This chapter explains the mechanism that lets a GitHub Actions job get AWS credentials without any stored access key. It assumes you know basic GitHub Actions workflows (jobs, steps, triggers), basic IAM concepts (users, roles, policies), JSON and YAML, and basic AWS CLI usage. Later chapters build each piece in detail. Here you learn how the pieces fit together and why the design is safer.
The problem being solved
A workflow that deploys to AWS needs credentials. The traditional answer is an IAM user with an access key pair, stored as GitHub secrets. That key is long-lived. It stays valid until someone rotates or deletes it, and it works from any machine, not only from GitHub's runners. If it leaks through a log, a compromised dependency, or a copied secret, an attacker can use it until you notice.
OIDC federation changes the question. Instead of "does the caller know the secret?", AWS asks "did a trusted identity provider vouch for this caller, and does that identity match what I allow?"
Key terms
- OpenID Connect (OIDC) is a standard for proving identity. An identity provider issues a signed token that states who or what the caller is.
- Identity provider (IdP) is the service that issues tokens. Here it is GitHub, at
https://token.actions.githubusercontent.com. - Federation means AWS trusts an outside IdP instead of keeping its own credentials for the caller.
- JSON Web Token (JWT) is the format of the token. It holds claims (facts about the caller) and a digital signature.
- AWS Security Token Service (STS) is the AWS service that issues temporary credentials.
- Web identity is the AWS term for a caller that authenticates with a token from an OIDC provider.
The core idea
No secret is shared in advance. AWS and GitHub instead set up a trust relationship once, using public information:
- In your AWS account, you register GitHub as an IAM OIDC identity provider. This tells AWS which issuer it may accept tokens from.
- You create an IAM role whose trust policy says which token claims are allowed to assume it.
- At run time, GitHub signs a short-lived token for the job. The job presents it to STS, and STS returns temporary credentials.
AWS checks the token's signature using the issuer's public signing keys, which it can retrieve from the issuer. There is nothing to store in GitHub secrets, because the token is created fresh for each job and expires quickly.
The exchange step by step
In more detail:
- The job asks for a token. GitHub exposes a token endpoint to jobs that have the
id-token: writepermission. The job requests a token for a given audience. - GitHub signs a JWT. The token contains claims about the run: the issuer (
iss), the audience (aud), and the subject (sub), which encodes the repository and the branch, environment, or other context. - The job calls STS. It uses the
sts:AssumeRoleWithWebIdentityAPI with the role ARN and the token. This call needs no AWS credentials, because the token is the proof of identity. - STS validates. It checks the signature against the registered provider, confirms the token has not expired, and evaluates the role's trust policy against the token's claims.
- STS returns temporary credentials. These are an access key ID, a secret access key, and a session token, all with an expiry time.
- The job calls AWS. Subsequent CLI or SDK calls use those temporary credentials, and only the role's permissions policy limits what they can do.
In a real workflow, the aws-actions/configure-aws-credentials action performs steps 1 to 3 and exports the results as environment variables. You will use it in a later chapter.
What changes compared with stored keys
| Property | Stored access key | OIDC federation |
|---|---|---|
| Secret kept in GitHub | Yes, key ID and secret | None |
| Lifetime | Until rotated or deleted | Token in minutes, session up to the role's limit |
| Usable outside GitHub | Yes, from anywhere | Only with a valid GitHub-signed token matching the trust policy |
| Scope control | Whatever the IAM user can do | Per repository, branch, or environment through trust conditions |
| Rotation | Manual process | Not needed |
| Attribution | One shared IAM user | Each run is a distinct role session |
The most important difference is in the third row. A stolen temporary credential expires on its own. A stolen OIDC token is only useful for a short time and only if it matches your trust policy's conditions.
Where the security actually comes from
Removing the secret is not enough on its own. The trust policy is now the security boundary, so a loose policy gives away access just as a leaked key would. Three checks matter:
- Issuer. The IAM OIDC provider limits tokens to those from
token.actions.githubusercontent.com. - Audience (
aud). The trust policy should requirests.amazonaws.com, so a token minted for another purpose is rejected. - Subject (
sub). The trust policy should name the repository and, ideally, the branch or environment. Without it, any repository on GitHub that obtains a token could try to assume your role.
A minimal look at the pieces
You will build each of these properly in the following chapters. Here is only a preview of how they connect.
The identity provider registration tells AWS to trust GitHub:
aws iam create-open-id-connect-provider \
--url https://token.actions.githubusercontent.com \
--client-id-list sts.amazonaws.comThe role's trust policy says which tokens may assume it:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
},
"StringLike": {
"token.actions.githubusercontent.com:sub": "repo:my-org/my-repo:ref:refs/heads/main"
}
}
}
]
}The workflow grants itself the right to request a token, then assumes the role:
permissions:
id-token: write
contents: read
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/github-deploy
aws-region: us-east-1Notice what is missing: no AWS_ACCESS_KEY_ID, no AWS_SECRET_ACCESS_KEY, and no reference to secrets.*. The role ARN is an identifier, not a secret. Knowing it grants nothing without a token that satisfies the trust policy.
Limits and edge cases
- Federation does not remove the need for least privilege. The role's permissions policy still decides what a job can do. A trusted job with an administrator role can still do damage.
- A trusted repository is a trusted code path. Anyone who can change a workflow on an allowed branch can use the role. Protect those branches with required reviews.
- Pull requests from forks. Jobs triggered by fork pull requests do not receive write access to
id-tokenby default, which keeps untrusted code from requesting a token for your role. Do not weaken this by running untrusted code in privileged triggers. - Tokens are not reusable credentials. The OIDC token only proves identity to STS. The AWS services never see it. Only the temporary credentials from STS are used for API calls.
- Session length is bounded. The credentials expire after the role's session duration. Long deployments must fit inside it or request a longer maximum on the role.
- Clock and expiry. STS rejects expired tokens. Because the action requests a token immediately before the call, this rarely matters in practice.
Exercises
Exercise
A teammate says, "OIDC is safer because the token is encrypted so nobody can steal it." What is wrong with this explanation, and what is the actual reason it is safer?
Show answer
The safety does not come from hiding a secret. The token is a signed JWT that proves identity, and it is short-lived. It is safer because there is no long-lived credential to leak or rotate. AWS only issues temporary credentials after checking the token's signature, issuer, and claims against the role's trust policy, so a stolen credential expires quickly and only works for tokens matching the trust conditions.
Exercise
Your IAM OIDC provider is registered for GitHub, and the role trust policy checks only that the audience is sts.amazonaws.com. Why is this dangerous, and which claim should you add a condition on?
Show answer
Every GitHub Actions workflow in the world gets tokens from the same issuer with the same audience. With no condition on the subject, a workflow in any repository could assume your role. Add a condition on the sub claim, for example repo:my-org/my-repo:ref:refs/heads/main, so only that repository and branch can assume the role.
Exercise
Put these events in order: (a) STS returns temporary credentials, (b) the job requests an ID token from GitHub, (c) the job calls sts:AssumeRoleWithWebIdentity, (d) STS checks the token against the trust policy.
Show answer
b, c, d, a. The job gets a signed token, sends it to STS, STS validates it against the provider and trust policy, and then returns the credentials.