Skip to content

fix(infra): read bootstrap state in the plan role, and stop running the Rust gate on terraform-only PRs - #358

Merged
athvin merged 2 commits into
mainfrom
bm/infra-plan-role-bootstrap-state
Oct 31, 2026
Merged

athvin merged 2 commits into
mainfrom
bm/infra-plan-role-bootstrap-state

Conversation

@athvin

@athvin athvin commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Two infra-CI fixes. The first is a prerequisite for the next PR; the second came out of watching this one burn 14 minutes of CI it had no use for.

1. The plan role can read bootstrap state

Prerequisite for the follow-up PR, which adds bootstrap/state-backend to the terraform plan matrix. The plan role's state-read policy allows only envs/*.tfstate, so that matrix leg would fail on the PR that introduces it — the policy only goes live once CI applies it on merge. Same ordering trap as #350, so this lands first, on its own.

  • bootstrap/state-backend will be planned and never applied from CI. It owns the bucket its own backend lives in, so applying it from CI is the circular case — but a plan still catches drift in the bucket's configuration.
  • bootstrap/organization stays out of the plan tier entirely. Its one required variable is a root account email deliberately kept out of a public repository (variables.tf:1-3, terraform.tfvars is gitignored), and supplying it would mean introducing the first repository secret into a pipeline whose stated property is that it has none. It joins the credential-free validate tier instead, which needs no variable value.

Enumerated rather than widening to /*: the point of the statement is that the role reads Terraform state and nothing else in the bucket.

2. A terraform-only PR no longer runs the Rust gate

This PR started as one changed Terraform file and still ran test, entities, cargo-deny, fmt + clippy + docs and the 14-minute DuckLake e2e.

rust.yml's detect is a denylist — it counts changed paths not under .claude/, so every other tree counts as code. frontend.yml and infra.yml use allowlists, which is why terraform already skipped the frontend gate, and images.yml runs on push only and never sees a PR. rust.yml was the only one paying for this.

infra/terraform/** joins the denylist. Verified rather than assumed: no crate or manifest under rust/ references infra/ (the two mentions are prose in comments), and no make check target touches it.

The one real coupling, which looks like a hole and is not: scripts/skills-check.sh derives generated skill references from infra/terraform/** — resource "aws_*" counts, IAM users, Pod Identity associations, pinned provider versions. So a terraform-only PR can make a reference stale. It is caught by the skills job, which runs the same drift check and is deliberately not gated on detect. That job existing separately is exactly what makes this skip safe.

The skip stops there. docs/** still runs the gate (entities verifies docs/erd.md staleness) and infra/k8s/** still runs it too — this is scoped to Terraform.

Verification

  • terraform fmt -check -recursive infra/terraform — clean.
  • Offline validate (dummy creds, metadata disabled) across core, dev, prod and both bootstrap stacks — all five succeed. That is also the check that bootstrap/organization validates without its gitignored tfvars.
  • plan (core) on this PR shows exactly aws_iam_role_policy.ci_tf_plan_state will be updated in-place, Plan: 0 to add, 1 to change, 0 to destroy — the intended change and nothing else.
  • actionlint clean; every uses: still SHA-pinned per S9.
  • scripts/skills-check.sh all green.
  • The new denylist simulated over nine PR shapes: terraform-only, multi-file terraform, .claude-only and terraform+.claude all skip; terraform+rust, terraform+docs, helm, a workflow edit and rust-only all still run.

This PR cannot demonstrate its own skip. Adding rust.yml to it means it is no longer terraform-only, so the Rust gate correctly runs here one final time — that run is the must-run half of the evidence, and the simulation above is the skip half. The detect step now prints the changed paths it decided on, so the next terraform-only PR can be read straight from its log.

🤖 Generated with Claude Code

bmoore813 and others added 2 commits October 31, 2026 09:20
Prerequisite for the next PR, which adds `bootstrap/state-backend` to the
terraform plan matrix. The plan role's state-read policy allows only
`envs/*.tfstate`, so that matrix leg would fail on the PR that introduces
it — the policy only goes live once CI applies it on merge. Same ordering
trap as #350, so this lands first, on its own.

`bootstrap/state-backend` will be planned and never applied from CI: it
owns the bucket its own backend lives in, so applying it there is the
circular case, but a plan still catches drift in the bucket's
configuration. `bootstrap/organization` stays out of the plan tier
entirely — its one required variable is a root account email deliberately
kept out of a public repository, and supplying it would introduce the
first repository secret into a pipeline whose stated property is that it
has none.

Enumerated rather than widening to `/*`: the point of the statement is
that the role reads Terraform state and nothing else in the bucket.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This PR changes one Terraform file and still ran `test`, `entities`,
`cargo-deny`, `fmt + clippy + docs` and the 14-minute DuckLake e2e.

`rust.yml`'s detect is a DENYLIST — it counts changed paths *not* under
`.claude/`, so every tree except that one counts as code. `frontend.yml`
and `infra.yml` use allowlists, which is why terraform already skips the
frontend gate; `images.yml` runs on `push` only and never sees a PR. So
`rust.yml` was the only one paying for this.

`infra/terraform/**` joins the denylist. Verified it is safe rather than
assumed: no crate or manifest under `rust/` references `infra/` (the two
mentions are prose in comments) and no `make check` target touches it.

The one real coupling is worth recording, because it looks like a hole and
is not: `scripts/skills-check.sh` derives generated skill references FROM
`infra/terraform/**` — `resource "aws_*"` counts, IAM users, Pod Identity
associations, pinned provider versions — so a terraform-only PR can make a
reference stale. That is caught by the `skills` job, which runs the same
drift check and is deliberately not gated on `detect`. That job existing
separately is exactly what makes this skip safe.

The skip stops at those two trees. `docs/**` still runs the gate, because
`entities` verifies docs/erd.md staleness. `infra/k8s/**` still runs it
too — this change is scoped to Terraform.

Simulated over nine PR shapes before pushing: terraform-only, multi-file
terraform, .claude-only and terraform+.claude all skip; terraform+rust,
terraform+docs, helm, a workflow edit and rust-only all still run.

Note this PR cannot demonstrate its own skip: adding `rust.yml` to it
means it is no longer terraform-only, so the gate correctly runs here one
last time. Its `detect` log now prints the changed paths it decided on,
so the next terraform-only PR can be read directly.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin athvin changed the title fix(infra): let the plan role read bootstrap state, not just envs/ fix(infra): read bootstrap state in the plan role, and stop running the Rust gate on terraform-only PRs Oct 31, 2026
@athvin
athvin merged commit 3a78417 into main Oct 31, 2026
22 checks passed
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]>
athvin added a commit that referenced this pull request Nov 6, 2026
…ng them exposed (#708)

* fix(skills): the new-stack rule was imprecise, and an eval demanded the wrong answer

Doing the follow-ups from #685 started by checking the premise of one, and the
premise was wrong.

The plan role's state grant is two PREFIX wildcards — `envs/*.tfstate` and
`bootstrap/*.tfstate` (envs/core/ci-terraform.tf:112-118). So a new stack under
either prefix needs no IAM change at all. The rule read "A new stack needs the
plan role's state read first, in its own PR", which is true only for a stack
introducing a NEW prefix. That is what #358 actually did: it added
`bootstrap/*.tfstate` so `bootstrap/state-backend` could join the plan matrix.
#350 is cited alongside it as the same apply-before-merge ordering trap, but on
sccache roles rather than state, so it no longer reads as evidence for this rule.

Eval 7, which #685 added, was worse: it made that claim a MUST and used
`envs/staging` as its example, so a session answering correctly — no grant
needed, the wildcard covers it — would have been scored as failing. It now
tests the precise rule, with a must-not for the imprecise one.

What a new stack does need is the part the rule never mentioned, and it is the
quieter failure: the `validate` tier's `for d in …` loop and the `plan` job's
`matrix.include` are both hand-written enumerations. A stack in neither is
never checked and nothing turns red. The next commit derives that gap.

make skills-check: ok.

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

* feat(skills): derive infra coverage, because the gap is what nobody maintains

the follow-up that stops them coming back. This is it — but not the one that
was proposed, and the difference is the point.

The proposal was a NodePool inventory plus a stack list. Checked against the
tree, half of that is worthless: `make cluster-objects` runs
`kubectl apply -f infra/k8s/nodepools/`, which is non-recursive, so the deployed
set is the top level and `measure/` is excluded by the layout itself. A set
difference there is empty by construction.

What is NOT covered is the stack enumerations. `infra.yml` lists stacks three
separate times — the `validate` shell loop, `plan`'s `matrix.include` and
`apply`'s — and nothing cross-checks them against the tree. A stack missing from
one is never checked and no job goes red. Same shape for `infra/k8s`: the skill
carried a hand-written manifest table that had already gone stale (it omitted
`priorityclasses/`, added later).

So `infra-coverage` derives three tables, each a set difference:

- stacks in the tree (by `backend.tf`) against all three tiers, flagging any
  stack no tier reaches
- every `infra/k8s` path against the sites referencing it — which surfaced that
  `secrets/` and `network-policy-controller.yaml` are referenced by NOTHING in
  the tree, so they are hand-applied or not applied at all. Nobody would guess
  that from the old table
- the NodePool manifests against the non-recursive apply, which derives the
  `measure/` exclusion that #685 had to state by hand

Verified by running it, not by reading it: `bash -n` passed while the generator
was fatally broken. Under `set -o pipefail` the no-match `grep` that IS the gap
case exits 1 and killed the entire regen, twice — once for the search and again
for the filter stage — with an empty generated block as the only symptom. Both
stages are now explicitly tolerant, and the committed output exercises both
(three rows resolve to "nothing in the tree"). That trap is now recorded in
docs/agent-skills.md for the next generator author.

make skills-check: ok, 14 generated files.

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

* fix(skills): a spliced file missing from generated_files was never drift-checked

Found by mutation-testing the previous commit rather than trusting it: added a
fake `envs/staging` stack so the committed coverage block went stale, ran
`skills-check check`, and it reported "generated references are current" and
exited 0.

Adding a generator takes TWO edits that nothing tied together — the `splice`
call in `run_regen`, and an entry in `generated_files`, which is the list
`run_drift_check` iterates. `infra-coverage` had the first and not the second,
so the file regenerated locally and was never compared against HEAD. A stale
committed block would have sailed through CI, which is the one failure mode this
gate exists to prevent.

Nothing hinted at it. The "regenerated N generated files" line prints
`${#generated_files[@]}` — the array length, not what was actually spliced — so
the count was identical whether or not the new file was registered.

Two changes: the missing entry, and a guard so the pairing cannot be forgotten
again. `splice` already knows its target, so it now asserts membership and fails
with the reason rather than leaving the file silently unguarded.

Verified by mutation, all three ways:
- stale committed block  -> exit 1, names the file and prints the diff
- clean tree             -> exit 0
- splice with no array entry -> exit 1, "spliced but missing from
  generated_files, so the drift check would never see it"

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

* docs(skills): the manifest table omitted a directory and miscounted another

The consistency sweep over what the merge left behind. Both defects are the
class the new generated coverage table exists to end, which is why they were
worth finding rather than just fixing.

- `infra/k8s/priorityclasses/` was missing from the non-chart manifest table.
  It exists, holds the task PriorityClass, and is applied by the same target as
  the node pools and again by the kind probe.
- "the namespace and the **three** upstream chart value files" was already
  wrong: there are four value files plus `openobserve.yaml` beside
  `namespace.yaml`. The count is gone, not corrected.
- The closing claim that these are "applied directly" was doing less work than
  it sounds. `secrets/` and `network-policy-controller.yaml` are referenced by
  no target, script or workflow anywhere in the tree, so they are applied by
  hand or not at all — stated now, because a reader assumes the opposite.
- The table is marked purpose-only, deferring the inventory to the generated
  table. It names `coverage.md` in prose rather than linking it, since a
  reference must not link a sibling.
- `make nodepools` is now `make cluster-objects`, with the old name kept
  callable. The bullet also names the mechanism that matters: the apply is
  non-recursive, which is the entire reason `measure/` stays out of the cluster.

Checked and found still accurate, so left alone: `docs/infrastructure.md` §5.1
is titled "Karpenter disruption settings", and every skill this one routes to
exists.

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

* fix(skills): the generator piped a writer into grep -q, which CI forbids by test

CI caught this; `make skills-check` could not. The membership tests in
`gen_infra_coverage` were spelled as a `printf` piped into a quiet exact-match
grep — the form `scripts/ci/skills-check-test.sh` exists to forbid in this
file, because a quiet grep closes the pipe at its first match, SIGPIPEs the
writer under `pipefail`, and can report a FOUND match as missing. Three lines,
one per tier, each a latent false "—" in the coverage table.

Replaced with `in_list`, a pure-bash `[[ ]]` membership test: no subprocess, no
pipe, nothing to race. The needle is quoted inside the pattern so a stack path
matches literally rather than as a glob.

Two things worth recording, because both cost a round trip:

- The gate I verified was not the gate CI runs. `make skills-check` runs
  `skills-check.sh all`; the meta-test is a SEPARATE workflow step
  (`rust.yml:388`) that the Makefile target does not invoke. Running the local
  target to green says nothing about it.
- That test is TEXTUAL, so the first fix failed it again on the explanatory
  comment, which quoted the bad form as an example. The comment now describes
  the shape instead of spelling it, and says why.

Verified: skills-check-test 5 passed / 0 failed, `skills-check check` exit 0
with regen a no-op, and the regenerated table is byte-identical to the
committed one — so `in_list` agrees with what the piped form produced.

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

---------

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