ADR-0006: GitHub OIDC, no static credentials#
- Status: accepted. Refined by ADR-0019.
- Date: 2026-07-30
Context#
CI needs to apply Terraform against AWS. The traditional approach is an IAM user with an access key stored as a repository secret. That key is long-lived, has no inherent scope beyond its policy, and is exactly the credential that turns a compromised repository into a compromised AWS account.
The repository is private now and will become public. Anything that would be a problem after that transition should be avoided from the start.
Decision#
Federate GitHub Actions to AWS via OIDC. No IAM users, no access keys anywhere in the account. (The bootstrap that creates these roles runs in Actions too: ADR-0014. The one exception is a temporary, scoped, self-removing key for the very first run: ADR-0016.)
Two roles with different trust conditions:
testz-gha-plan— trusted forrepo:<owner>@<owner_id>/<repo>@<repo_id>:pull_requestand the
default branch. ReadOnlyAccess plus state read, with an explicit Deny on state writes. CI runs tofu plan -lock=false, so no write is needed.
testz-gha-apply— trusted only for
repo:<owner>@<owner_id>/<repo>@<repo_id>:environment:prod. Scoped service permissions plus state read/write.
Plus a permissions boundary that every CI-created IAM role must carry.
Alternatives considered#
IAM user with an access key in repository secrets. Long-lived, exfiltratable, and the single most common cause of AWS compromise via CI. Rejected outright.
One role for both plan and apply. Simpler, but it means a pull request — from anyone who can open one — holds a credential that can mutate production. The whole value of splitting them is that a PR cannot.
Trusting only the branch for apply, not a GitHub environment. This is the subtle one, and the environment condition is the better choice. Because the apply role's trust policy requires an OIDC subject of ...:environment:prod, and GitHub does not mint a token with that subject until a required reviewer approves the deployment, the approval gate becomes cryptographic rather than advisory. A branch-only condition can be satisfied by anything that lands on the branch.
Trusting the OIDC provider without a sub condition. A well-known misconfiguration: it lets any GitHub repository in the world assume the role. The sub claim is the actual identity.
Consequences#
Positive: no long-lived credential exists to leak. Credentials are minted per-job, expire in an hour, and are scoped to a specific repository and workload. A fork pull request cannot obtain anything that mutates state. Production changes require a human approval that is enforced by the token itself. Privilege escalation via role creation is closed by construction — the apply role can only create testz-* roles carrying the boundary, and is explicitly denied any IAM action against the CI roles, the boundary, or the OIDC provider.
Negative: the trust policy is subtle, and getting the sub pattern wrong is either a lockout or a serious over-grant. It requires a one-time human bootstrap. Debugging a failed assumption means reading CloudTrail. Some service permissions in the apply role are unavoidably resources = ["*"], because Route 53, CloudFront and ACM support little resource-level authorisation for create operations — that is documented in the policy itself rather than papered over.
Neutral: role ARNs are stored as GitHub variables, not secrets. An ARN is not a credential; the trust policy is what grants access.
Current status: approval gate inactive while private#
The gate described above depends on a required reviewer on the prod environment. GitHub Free does not offer required reviewers for private repositories, so while this repository is private nothing stops a job that names environment: prod from receiving the environment:prod token — the trust policy is still satisfied, but no human is in the loop.
The interim control is procedural rather than cryptographic: terraform-apply runs only on workflow_dispatch, so every apply is a deliberate act by someone with write access (today, one person). Pull requests and pushes cannot trigger an apply. The trust policy is unchanged, so restoring the stronger gate needs no IAM work: add a required reviewer to prod and restore the push trigger, which is kept as a comment in the workflow.
Status notes#
- 2026-11-24. Two statements above are now out of date without the decision
changing. There are four CI roles, not two: testz-gha-deploy for content deploys and testz-gha-bootstrap for phase 1 joined the plan and apply roles (ADR-0014). And role ARNs are no longer stored as GitHub variables: every ARN is derived in the workflow from the AWS_ACCOUNT_ID repository secret, so GitHub masks the account ID in logs (ADR-0011).
- 2026-11-24. The interim control in Current status is narrower than it
reads. "Only workflow_dispatch can apply" is true of the workflow file on main, but neither the environments nor the trust policies are bound to main yet. Binding them is on the roadmap.
- 2026-11-24. ADR-0019
adds a second condition to the apply and deploy roles' trust: the token's ref claim must be refs/heads/main. The environment subject above is unchanged. Written, not yet applied; the runbook gives the order. Until it is applied, the previous note still describes the account.
- 2026-11-25. The
refcondition is in force on the apply and deploy
roles (applied 24 November) and on the bootstrap role (25 November). The two notes above no longer describe the account: neither role can be held by a branch. The interim control in Current status is now a property of the roles, not only of the workflow file. The approval gate itself is still inactive.
Revisit when#
- The repository goes public (or moves to a paid plan): add the required
reviewer and restore apply-on-merge, per the section above.
- More than one person needs to apply, at which point per-person roles and
CloudTrail attribution matter more.
- GitHub changes its OIDC claim structure.
- Multi-account becomes justified, changing where the roles live.