Sub topic 1
Why CI workflows use OIDC instead of stored cloud keys
Prerequisites
This chapter assumes you know the following:
- Basic CI/CD concepts: workflows, jobs, and branches.
- GitHub Actions workflow YAML.
- What a cloud IAM role and policy are.
- That a JSON Web Token (JWT) is a signed, readable set of claims.
The problem with stored keys
A common way to let a pipeline deploy to a cloud account is to create an access key and save it as a repository secret. This works, but it has costs:
- The key is long-lived. It stays valid until someone rotates or deletes it.
- Anyone who can read the secret, or who can change a workflow that uses it, can copy it.
- The key is not tied to a specific repository, branch, or environment. A leaked key works from anywhere.
- Rotation is manual, so keys tend to stay in place for years.
How OIDC federation replaces the key
OpenID Connect (OIDC) federation lets the cloud account trust the CI provider's identity instead of a stored secret. Nothing secret is stored in the repository. Each job asks GitHub for a short-lived, signed token that describes the job. The cloud provider checks that token and, if it passes your rules, returns temporary credentials.
Setup happens once, in the cloud account:
- Register GitHub as an identity provider. For AWS this is an IAM OIDC provider for
token.actions.githubusercontent.com. - Create an IAM role with a trust policy. The policy states which tokens may assume the role.
- Give the role only the permissions the job needs.
At run time, the flow looks like this:
The credentials expire on their own, usually within an hour. A copy taken from a log or a compromised runner is useless soon after.
Where the security comes from
Removing the stored key is only half of the benefit. The other half is that the token carries claims about who is asking. The most important is the subject (sub) claim, which names the repository and the branch, tag, pull request, or environment that started the job.
The trust policy is the only gate between a token and your role. If it is too loose, any workflow that GitHub signs a token for could pass it. That includes workflows in repositories you do not own, because GitHub issues tokens for every repository using the same provider. The rest of this tutorial is about writing trust policies that accept only the workflows you intend.
Comparison
| Aspect | Stored access key | OIDC federation |
|---|---|---|
| Lifetime | Until rotated | Minutes to an hour |
| Secret in repository settings | Yes | No |
| Scoped to repo, branch, environment | No | Yes, through trust policy conditions |
| Rotation work | Manual | None |
What to carry forward
- OIDC replaces a stored secret with a signed token that is exchanged for temporary credentials.
- The trust policy decides which tokens succeed.
- The next chapters cover the claims in the token, then the conditions that restrict them.
Exercise
A team removes its stored AWS access key and registers GitHub as an OIDC provider. The role's trust policy allows the provider as a principal but has no conditions. Why is this unsafe, even though no long-lived key exists?
Show answer
The trust policy is the only check on which tokens can assume the role. With no conditions on the audience or subject, any workflow in any GitHub repository can obtain a signed token and assume the role. The conditions are what limit access to the intended repository, branch, or environment.