Skip to content

feat(infra): make terraform applies unattended on merge to main - #355

Merged
athvin merged 1 commit into
mainfrom
bm/infra-unattended-apply
Oct 30, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/infra-unattended-apply

Conversation

@athvin

@athvin athvin commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Operator decision: merge to main is the trigger and the only trigger. The
required-reviewer gate on infra-apply-{core,dev,prod} is removed, so §14.2
reads literally — plan on the PR, apply on merge, no click in between.

The environments themselves are kept. Without reviewers they still give each env
its own deployment history, and protected_branches: true on each means only
main can deploy to them regardless of what a workflow file claims.

What now guards an apply, stated honestly

Nothing else does. er-ci-tf-apply holds AdministratorAccess, and §8.2's two
prod deny statements ride the permission sets — so they constrain humans, not
this role. That section already says the apply role "walks through the guardrail
legitimately" and therefore that "its trust policy is part of this claim".

With the gate gone, that trust condition — sub pinned to refs/heads/main —
plus branch protection and PR review IS the entire control. The plan tier is
where a human sees the diff, and it is now the ONLY place a human sees it before
infrastructure changes.

That matters most for prod, which is unprovisioned: plan (prod) currently
reports 61 resources to add, including an RDS cluster, two instances, EFS
and security groups. A merged PR touching infra/terraform/envs/prod provisions
production and starts that bill, with no approval step behind it. That is the
intended behaviour now, and the plan output on the PR is the place to catch it.

A consequence I had previously waved away

§14.2's chained prod-scoped apply role — whose trust names the CI apply role
plus ProdAdmin as break-glass — is still not built. Two commits ago I
described that gap as "covered by the required-reviewer GitHub environment". It
is not covered any more, because that environment no longer requires anyone.

So it goes from nice-to-have to the only remaining defence-in-depth for prod,
and it should land before prod carries data. Recorded in ci-terraform.tf, the
workflow header and roadmap 0.5b rather than left as a note in a merged PR
nobody re-reads.

Co-Authored-By: Claude Opus 5 (1M context) [email protected]

🤖 Generated with Claude Code

Operator decision: merge to `main` is the trigger and the only trigger. The
required-reviewer gate on `infra-apply-{core,dev,prod}` is removed, so §14.2
reads literally — plan on the PR, apply on merge, no click in between.

The environments themselves are kept. Without reviewers they still give each env
its own deployment history, and `protected_branches: true` on each means only
`main` can deploy to them regardless of what a workflow file claims.

## What now guards an apply, stated honestly

Nothing else does. `er-ci-tf-apply` holds AdministratorAccess, and §8.2's two
prod deny statements ride the *permission sets* — so they constrain humans, not
this role. That section already says the apply role "walks through the guardrail
legitimately" and therefore that "its trust policy is part of this claim".

With the gate gone, that trust condition — `sub` pinned to `refs/heads/main` —
plus branch protection and PR review IS the entire control. The `plan` tier is
where a human sees the diff, and it is now the ONLY place a human sees it before
infrastructure changes.

That matters most for prod, which is unprovisioned: `plan (prod)` currently
reports **61 resources to add**, including an RDS cluster, two instances, EFS
and security groups. A merged PR touching `infra/terraform/envs/prod` provisions
production and starts that bill, with no approval step behind it. That is the
intended behaviour now, and the plan output on the PR is the place to catch it.

## A consequence I had previously waved away

§14.2's chained **prod-scoped** apply role — whose trust names the CI apply role
plus `ProdAdmin` as break-glass — is still not built. Two commits ago I
described that gap as "covered by the required-reviewer GitHub environment". It
is not covered any more, because that environment no longer requires anyone.

So it goes from nice-to-have to the only remaining defence-in-depth for prod,
and it should land before prod carries data. Recorded in ci-terraform.tf, the
workflow header and roadmap 0.5b rather than left as a note in a merged PR
nobody re-reads.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 2e22ac3 into main Oct 30, 2026
22 checks passed
@athvin
athvin deleted the bm/infra-unattended-apply branch October 30, 2026 05:05
athvin added a commit that referenced this pull request Nov 1, 2026
…sed) (#363)

This file has carried a "NOT built yet" note about §14.2's prod-scoped
apply role since the plan/apply gate landed, and the note's premise went
stale: it said the gap was "briefly covered by a required-reviewer
environment", which stopped requiring anyone in #355, and prod has held an
Aurora cluster since #352. So the only thing between a merge and a
production teardown has been branch protection plus the destroy guard.

`er-ci-tf-apply-prod`: AdministratorAccess, reachable from exactly two
principals.

**What the hop buys, narrowly stated**, because overclaiming it would be
worse than not having it:

1. Auditability — a prod write becomes a distinct `AssumeRole` into a
   prod-named role in CloudTrail instead of being indistinguishable from a
   dev write by the same principal, and the chained session carries the
   GitHub session tags (Repository, Workflow, Actor, Commit, Branch), so
   the trail records who merged what.
2. No *accidental* prod apply from the non-prod path, once the companion
   PR denies `er-ci-tf-apply` the prod state object.
3. A break-glass path with the same permissions CI uses, so a human
   recovering prod is not improvising a different identity.

**What it does not buy:** containment of a compromised `er-ci-tf-apply`.
That role can assume this one — that is the design — so anyone holding it
reaches prod through the front door. The control there is still its own
`main`-only trust policy plus branch protection.

AdministratorAccess for a sharper reason than the apply role's: narrowing
it would buy nothing, because both principals that can reach it already
hold AdministratorAccess. A tighter policy would only block Terraform,
never an actor, while adding the mid-apply AccessDenied failure mode.

**`sts:TagSession` is in the trust policy and is load-bearing.** Read from
configure-aws-credentials' own source at the SHA this repo pins: both
web-identity paths `delete params.Tags`, which is why no other role here
needs it — but role CHAINING takes the plain `AssumeRole` path, which keeps
them. Without this grant the prod apply would have failed on an
AccessDenied for TagSession with nothing in the diff explaining it, the
same shape as the three bugs #354 found. Allowing it is also the better end
of the trade: `role-skip-session-tagging: true` would have worked and
thrown away the tags that make reason 1 true.

**ProdAdmin is trusted by pattern, not by ARN.** `envs/prod/eks.tf`
hardcodes today's `AWSReservedSSO_ProdAdmin_<hash>`, which is fine for an
EKS access entry and wrong for a trust policy: IAM resolves a principal ARN
to the role's unique id on write, so once the permission set is recreated
the policy holds a dangling id. Account root plus an `ArnLike` on the
caller's own ARN survives that, and is not "anyone in the account" — the
effective set is principals matching a ProdAdmin SSO session that also hold
`sts:AssumeRole`. `PlatformAdmin` does not match; neither does the
`er-dev-builder` key.

**Nothing uses it yet, on purpose.** The chaining step and the companion
deny land separately, because `apply (core)` creates this role and
`apply (prod)` would consume it in the same run. They do run in that order
today — measured core → dev → prod, strictly sequential under
`max-parallel: 1` — but GitHub documents no ordering guarantee for a
matrix, and resting a prod apply on undocumented ordering is the #358 trap
again. Split, it is order-independent.

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants