ADR-0019: Bind the deploy-path roles to main with the OIDC ref claim#

Context#

Three roles can change the account: testz-gha-apply (the stack), testz-gha-deploy (website content) and testz-gha-bootstrap (the CI roles themselves, so in effect the whole account). Each trusts exactly one OIDC subject, repo:<owner>@<owner_id>/<repo>@<repo_id>:environment:<name>.

That subject names an environment, not a branch. When a job names an environment, GitHub puts the environment in sub in place of the ref, so any branch whose workflow says environment: prod receives the apply role. The environments have no branch restriction either. The seed run on 24 November executed from a feature branch, received the bootstrap environment's secrets, and assumed the bootstrap role. Its token carried environment: bootstrap in sub and the feature branch in a separate ref claim, which nothing checked.

ADR-0006's interim control while the approval gate is inactive, "only workflow_dispatch can apply", is a property of the workflow file on main. A branch can carry a different workflow file, and the "Use workflow from" picker dispatches any branch's.

Separately, the apply role could write the state of the layers above it. Its state policy allows writes only under testz/, but the stack's bucket statement allows s3:Put* and s3:DeleteObject on testz-*/*, which also matches testz-tfstate-<id>/bootstrap/… and …/seed/….

The roadmap proposed customising the repository's OIDC subject to carry the ref, because a trust policy could once test only aud, sub and amr. Two facts changed that, both checked against the providers' documentation on 24 November 2026:

  • AWS STS evaluates GitHub's own claims. Since 2 February 2026, trust

policies can test token.actions.githubusercontent.com:ref, :environment, :repository_id, :job_workflow_ref and others as condition keys, in all commercial regions. IAM still requires a sub condition on any role that trusts GitHub, and rejects one that is only a wildcard.

  • Subject customisation is a repository-wide switch. GitHub's

documentation says a customisation template "results in a new format for the entire sub claim" for every job, and that the matching trust policy must exist before it is switched on.

This repository was created on 30 July 2026, after GitHub made the immutable subject (owner and repository IDs alongside the names) the default for new repositories on 15 July 2026. Its subject format comes from that default, not from a customisation.

Decision#

  1. **The apply, deploy and bootstrap trust policies also require

token.actions.githubusercontent.com:ref to equal refs/heads/main, with StringEquals, alongside the unchanged exact sub match. The repository's OIDC subject is not** customised.

  1. **The apply role is denied every action except reads on the bootstrap/

and seed/ state keys**, so no allow elsewhere in its policies can reach them.

  1. Every workflow that uses one of these roles refuses any ref but main

before its job enters the environment, with an error naming the problem. This is for accidents and clear errors. The trust policy is the control.

  1. **The prod, prod-deploy and bootstrap environments are restricted to

main** in GitHub as a second, independent layer, where the plan offers it. That is a repository setting, so it is the owner's step (runbook).

  1. The seed's trust policy changes now, in the same change as the others,

and is applied after the bootstrap layer has proven the condition in this account.

The plan role is unchanged. It is read-only, and already trusts only pull requests and pushes to main.

Alternatives considered#

Customise the OIDC subject to include the ref (the roadmap's proposal). It changes every token the repository mints at once, so all four trust policies must accept the new form before the switch, and one of them lives in the seed. That means two seed runs, one to accept both forms and one to remove the old, or a single run timed against the switch with a lockout if either side is late. And while both forms are accepted, a repository admin switching the template off silently restores the old subject, which carries no ref. Before February 2026 this was the only way. Now it is more risk and more work for the same control.

Deployment-branch rules on the environments alone. A setting rather than code, not reviewed or tested, and documented for private repositories only on GitHub's paid plans. AWS's own guidance recommends them in addition to a trust policy that is tight on its own. Kept as the second layer.

Workflow if: guards alone. A property of the workflow file on the branch being run, which that branch can change. This is the gap being closed, so guards cannot be the control.

Also pin job_workflow_ref, so only named workflow files can hold each role. Stronger, but alarm-delivery-test shares the apply role with terraform-apply, and renaming a workflow would lock its role out. Binding to main already means every workflow that can hold a role has been merged. Left for later (see Revisit when).

Leave the seed until it next has to run. The bootstrap role is the most powerful of the three. Binding the other two and not it would leave the largest gap open, guarded only by an environment setting that may not be available on this plan.

Consequences#

Positive: the binding lives in IAM, in code, under review and under test, and no GitHub setting can undo it. No token changes, so there is no transition window and no dual-form policy to clean up afterwards. Each role changes independently: a mistake locks out only that role, and every role in the bootstrap layer can be restored by the bootstrap role. Unmerged code, including a same-repository pull request that names an environment, can no longer hold any role that writes. The bootstrap layer's own state is out of the apply role's reach, as ADR-0014 said it was.

Negative: it relies on an AWS feature that is ten months old. A condition key that STS did not recognise would evaluate as absent and refuse every request: a lockout, never an over-grant. So the runbook proves the condition in this account, both allowing from main and refusing elsewhere, before it goes on the role that is expensive to recover. Changing the seed costs one more seed run with a temporary IAM user (ADR-0016): roughly half an hour of the owner's time and an access key that lives for minutes. No money. Nothing can be applied or deployed from a branch to try it out, which is the point. And main itself is now the whole boundary: while the approval gate is inactive, whoever can push to main can apply.

Neutral: the ref is not part of sub, so a refused AssumeRoleWithWebIdentity can now mean a wrong environment or a wrong branch. The seed-account workflow's diagnostic step prints both claims.

Status notes#

  • 2026-11-25. All five decisions are in force. The bootstrap layer

was applied by bootstrap-account on 24 November, and its plan held exactly the three expected changes. Decision 5 was carried out as an IAM console edit on 25 November rather than a seed run: the seed's code already described the change, so no temporary user was needed (ADR-0016's status notes). Verified both ways. main still assumed every role: site-deploy, alarm-delivery-test and a bootstrap-account plan that showed no changes. A probe branch was refused the deploy and bootstrap roles by AWS (AccessDenied), and its job naming prod was stopped by GitHub before AWS was asked. For decision 4, the owner then restricted all three environments to main, and the probe's jobs were refused by GitHub in each before they started. So on this repository's GitHub Free plan the setting is offered for private repositories, although GitHub documents it only for paid plans.

Revisit when#

  • GitHub changes its OIDC claims, or AWS changes which provider claims it

evaluates.

  • A second branch needs to deploy (a release branch, say): the condition

becomes a list, and the environments' rules with it.

  • The repository goes public and the environments get required reviewers

(ADR-0006). The binding stays; the reviewers add to it.

  • Each role is used by exactly one workflow, at which point pinning

job_workflow_ref costs little.

Built 2026-11-25 from commit 33bfabf6a27d4baeecf228c31bd5d636a3965070. This page was generated from the same source that provisions the infrastructure it describes.