Runbook: changing what the CI roles trust#

Every change to a CI role's trust policy can lock CI out of AWS. If the token GitHub mints and the policy AWS evaluates disagree, the role refuses, and AWS's error does not say which condition failed. One of the roles, testz-gha-bootstrap, is also how changes to the others reach the account, and its own trust policy can only be changed by re-running the seed.

Read the first two sections before changing any trust policy. The last section is the procedure for one such change, binding the deploy path to main (ADR-0019).

Who can repair whom#

RoleTrust policy lives inApplied byIf its trust breaks, repair it with
testz-gha-planterraform/bootstrapbootstrap-accountbootstrap-account
testz-gha-applyterraform/bootstrapbootstrap-accountbootstrap-account
testz-gha-deployterraform/bootstrapbootstrap-accountbootstrap-account
testz-gha-bootstrapterraform/seedseed-account, with a temporary IAM userseed-account with a new temporary user, or the seed from a laptop with administrator access (terraform/seed/README.md)

A broken plan, apply or deploy role costs one revert and one bootstrap-account run. A broken bootstrap role costs a seed run, but the site, applies and deploys carry on meanwhile: only changes to the CI roles wait.

Rules#

  1. **Never change, in one step, the trust of the role you would repair it

with.** Change the bootstrap layer first, while the bootstrap role is untouched. Change the seed last.

  1. Prove a new kind of condition where a mistake is cheap (the bootstrap

layer) before putting it where a mistake is expensive (the seed).

  1. Verify both directions. A role that lets main in has been tested

once. Also watch it refuse a branch. A control seen only allowing is not verified.

  1. Anything that changes the token itself changes every role at once. A

custom OIDC subject template (the repository's OIDC settings, or PUT /repos/{owner}/{repo}/actions/oidc/customization/sub) rewrites sub for every job. Every trust policy would have to accept the new form first, including the seed's. Do not enable one without a plan for that. Nothing here uses one.

  1. Debugging a refusal. `Not authorized to perform

sts:AssumeRoleWithWebIdentity means some condition failed. Compare the job's claims with the policy: seed-account prints sub, environment and ref` before it assumes the bootstrap role.

Changing the seed later#

The seed is the one layer CI cannot change: the bootstrap role is denied changing itself, so a stolen CI session cannot widen its own trust. Changing the seed therefore always needs the account owner, signed in with administrator access (the root user with MFA, or OrganizationAccountAccessRole from an Organization's management account). What differs is how much ceremony the change deserves.

ChangeHowWhy
A trust-policy edit that merged seed code already describes, such as adding one conditionThe owner makes the same edit in the IAM console: Roles → the role → Trust relationships → EditNo key and a couple of minutes. The code and the account then agree, so the next seed plan shows no change, which confirms the edit matched
Anything else in the seed: permissions, the OIDC provider, the state bucketA seed run, from seed-account with a temporary user or from a laptop with administrator access (terraform/seed/README.md)The plan should be read before it is applied
A new accountseed-account with a temporary userNothing else can get in yet

For a console edit: merge the code first, copy the condition exactly, then verify both directions as in steps 3 and 4 below. bootstrap-account from main must assume the bootstrap role and plan no changes, and a branch must be refused. To roll back, undo the edit in the console.

Binding the deploy path to main (November 2026)#

Status, 25 November 2026: done. Step 5 was made as a console edit (see Changing the seed later). After step 6, the probe branch's jobs were refused by GitHub in all three environments before they started.

What changes. The apply, deploy and bootstrap trust policies gain a second condition, token.actions.githubusercontent.com:ref equal to refs/heads/main. The subject condition stays exactly as it is. The apply role is denied writes to the bootstrap/ and seed/ state keys. The workflows that use these roles refuse any branch but main. Then the owner restricts the three environments to main in GitHub.

Why this order. No token changes, so nothing has to accept two forms at once. The bootstrap layer goes first because the bootstrap role can undo it. AWS's refusal has to be observed before the environments are restricted, because afterwards GitHub refuses a branch first and AWS is never asked. The seed goes last, after the condition has worked in this account.

Who does it. The repository owner, in order. Each step says how to confirm it and how to roll it back. Do not start a step until the previous one is confirmed. Allow about an hour in total, half of it for the seed.

1. Merge, then read the bootstrap plan#

Do: merge the pull request. Then Actions → bootstrap-account → Run workflow, from main, with apply unticked.

Merging changes nothing in AWS. It does change the workflows at once, and from then on they refuse to run from any branch but main.

Confirm: the plan in the run summary has exactly three in-place updates and nothing to add or destroy:

  • aws_iam_role.apply: assume_role_policy gains

"token.actions.githubusercontent.com:ref": "refs/heads/main";

  • aws_iam_role.deploy: the same;
  • aws_iam_role_policy.apply_state_write: gains the

ProtectUpperLayerState statement.

Anything else means the account has drifted from the bootstrap layer, or an earlier change to it was merged and never applied. Stop and find out which first.

Roll back: nothing to roll back. Reverting the merge removes the workflow guards.

2. Apply the bootstrap layer#

Do: run bootstrap-account again from main, with apply ticked.

Confirm: the run is green. The bootstrap role, which is unchanged, applied it.

Roll back: revert the change to terraform/bootstrap on main and run bootstrap-account with apply ticked. This always works at this point, because the bootstrap role has not changed.

3. Prove main still gets in#

Do, both from main:

  • Actions → site-deploy → Run workflow. It assumes the deploy role.
  • Actions → alarm-delivery-test → Run workflow. It assumes the apply

role, and sends one ALARM and one OK email. It changes no infrastructure, which a terraform-apply run would.

Confirm: both runs are green, and both emails arrive.

If either fails with Not authorized to perform sts:AssumeRoleWithWebIdentity, the condition is not working in this account. Roll back as in step 2, stop, and do not touch the seed.

4. Prove a branch is refused, by AWS#

This has to happen before step 6. Once the environments are restricted, GitHub stops a branch's job before it can ask AWS, so AWS's answer can no longer be seen.

Do: create a branch named probe/deploy-path from main, add this file as .github/workflows/deploy-path-probe.yml, and push. The push runs it. It asks AWS for each role with a branch token and passes only if AWS refuses. It uses nothing but the runner's curl, jq and AWS CLI, and it never merges.

name: deploy-path-probe

on:
  push:
    branches: ["probe/deploy-path"]

permissions: {}

jobs:
  probe:
    name: AWS refuses ${{ matrix.role }} to a branch
    runs-on: ubuntu-latest
    environment: ${{ matrix.environment }}
    permissions:
      id-token: write
    strategy:
      fail-fast: false
      matrix:
        include:
          - { environment: prod, role: testz-gha-apply }
          - { environment: prod-deploy, role: testz-gha-deploy }
    steps:
      - name: Ask for the role and expect a refusal
        env:
          AWS_REGION: us-east-1
          ROLE: ${{ matrix.role }}
          ROLE_ARN: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ matrix.role }}
        run: |
          token="$(curl -sSf -H "Authorization: bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
            "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=sts.amazonaws.com" | jq -r .value)"
          if out="$(aws sts assume-role-with-web-identity --role-arn "${ROLE_ARN}" \
              --role-session-name "probe-${GITHUB_RUN_ID}" --web-identity-token "${token}" \
              --query AssumedRoleUser.Arn --output text 2>&1)"; then
            echo "::error::GRANTED: AWS issued ${ROLE} to ${GITHUB_REF}. The ref condition is not in force."
            exit 1
          fi
          if grep -q "AccessDenied" <<<"${out}"; then
            echo "Refused, as required, for ${GITHUB_REF}: ${out}"
          else
            echo "::error::Inconclusive, not an AWS refusal: ${out}"
            exit 1
          fi

Confirm: both jobs are green, and each log says Refused, as required. Leave the branch for steps 5 and 6.

If a job reports GRANTED, AWS gave a role to unmerged code. The probe discards the credentials unused. Stop, check the ref condition on that role (IAM console → Roles → the role → Trust relationships), and do not go on to the seed.

5. Re-run the seed (the bootstrap role)#

The owner decides when to do this (ADR-0019 recommends straight away). It costs a temporary IAM user, about half an hour, and no money. Until it is done, the bootstrap role, which can rewrite the other roles, still accepts any branch that names the bootstrap environment.

This change is a single condition that the merged seed code already describes, so it can also be made in the IAM console with no temporary user (Changing the seed later). That is how it was done in November. If you use the console, skip to the last two bullets of Confirm.

Do: follow option A in terraform/seed/README.md: create a new testz-seed-temp user with an expiry a few hours ahead, and add its key to the bootstrap environment. Then Actions → seed-account → Run workflow from main, apply unticked.

Confirm the plan: one in-place update, aws_iam_role.bootstrap, whose assume_role_policy gains the same ref condition. Anything else: stop.

Do: run seed-account again with apply ticked. After the seed it switches to the bootstrap role over OIDC, under the new condition, then deletes the temporary user. Delete the two SEED_* secrets afterwards, as always.

Confirm:

  • The run is green. Its Switch to the bootstrap role over OIDC step is the

proof that main still gets in: it ran after the new policy was applied.

  • bootstrap-account from main, apply unticked, is green and plans no

changes.

  • On probe/deploy-path, add

- { environment: bootstrap, role: testz-gha-bootstrap } to the matrix and push. All three jobs are green, each refused.

Roll back: if the switch to the bootstrap role fails, the seed has applied a policy that refuses main. The temporary user still works until its expiry. Revert the seed change on main and re-run seed-account with apply ticked and the same secrets. That restores the previous policy, and the cleanup completes. If the expiry passes first, create a new temporary user, or run the seed from a laptop (terraform/seed/README.md, option B). Nothing in phase 2 is affected meanwhile.

6. Restrict the environments to main#

Do: for each of prod, prod-deploy and bootstrap: Settings → Environments → the environment → Deployment branches and tags → Selected branches and tags → Add deployment branch or tag rule → type Branch, name main.

Confirm:

  • Each of the three environments lists main as its only rule.
  • Push any commit to probe/deploy-path. Every job now fails before its

first step, with a message that the branch is not allowed to deploy to the environment. This is GitHub refusing, before AWS is asked.

  • The next run from main that uses each environment is green, for example

site-deploy → Run workflow.

If the setting is not offered: GitHub documents deployment branches for private repositories only on its paid plans (Pro, Team and Enterprise), and this repository is private on GitHub Free. It already uses environment secrets, which GitHub documents with the same limit, so the setting may be offered anyway. If it is missing, say so in the roadmap and in a status note on ADR-0019. The trust policies refuse a branch whether or not it is there.

Roll back: set Deployment branches and tags back to No restriction.

7. Clean up and record#

  • Delete the probe/deploy-path branch.
  • Update the documentation in a pull request. The roadmap's item 3 is done,

with the date. The "not yet in force" notes on the security posture page, in the README and in ADR-0006's status notes come out. Add a status note to ADR-0019 if step 6 was not possible.

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