Sub topic 1
Deploying to AWS from GitHub Actions with OIDC and IAM Roles
Prerequisites
Assume you know basic GitHub Actions jobs and steps, AWS IAM users and roles, JSON, YAML, and AWS CLI commands.
Why Long-Lived Access Keys Are a Problem in CI
A long-lived AWS access key remains valid until someone revokes or rotates it. Storing one in a GitHub secret lets a workflow authenticate, but the key can still be exposed through a compromised action, an overly broad workflow, or an accidental log message.
The key also usually has no built-in relationship to a particular branch or workflow run. If an attacker obtains it, they can use it outside GitHub until it expires or is revoked.
How OIDC Federation Replaces Stored Secrets
OpenID Connect (OIDC) is a standard for exchanging an identity token for temporary credentials. GitHub acts as the identity provider. During a workflow run, GitHub issues a signed OIDC token. AWS Security Token Service (STS) validates that token and returns short-lived credentials for an IAM role.
The workflow stores no AWS secret. The IAM role controls both who may assume the role and what that role may do.
What GitHub Issues to a Running Job
A job can request an OIDC token only when its workflow grants the id-token: write permission. The token describes the workflow's identity and is presented to AWS by the configure-aws-credentials action.
The token includes claims, which are signed fields describing the token:
| Claim | Meaning |
|---|---|
| `iss` | The issuer, `https://token.actions.githubusercontent.com` |
| `aud` | The intended recipient, normally `sts.amazonaws.com` |
| `sub` | The subject, such as a repository and branch |
Reading the Token Claims
AWS uses iss to identify GitHub, aud to ensure the token is intended for AWS STS, and sub to restrict which repository, branch, or environment may assume a role. For example, a subject can identify my-org/my-repo running from the main branch.
Registering GitHub as an IAM OIDC Provider
First register GitHub's issuer in IAM. The client ID identifies AWS STS as the intended audience.
aws iam create-open-id-connect-provider \
--url https://token.actions.githubusercontent.com \
--client-id-list sts.amazonaws.comYou then reference this provider in an IAM role trust policy. That policy must allow sts:AssumeRoleWithWebIdentity and check the token's aud and sub claims. A separate permissions policy grants only the AWS actions required by the deployment.
Exercise
Why should a deployment role check both the token audience and subject?
Show answer
The audience confirms the token targets AWS STS, while the subject limits access to the intended repository, branch, or environment.