Skip to content

feat(infra): terraform plan on every PR, apply on main behind a reviewer gate - #352

Merged
athvin merged 1 commit into
mainfrom
bm/infra-ci-plan-apply
Oct 29, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/infra-ci-plan-apply

Conversation

@athvin

@athvin athvin commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Builds infrastructure.md §14.2 — "plan on every PR under a read-only role;
apply on main under the apply role" — which was roadmap 0.5b and had been
waiting on the prod-apply decision. infra.yml grows two tiers over the
existing credential-free one, per env:

validate credential-free, every PR (unchanged; still covers fork PRs)
plan er-ci-tf-plan, read-only, posts the diff to the step summary
apply er-ci-tf-apply, main only, behind a required-reviewer environment

No repository secrets

Deliberately, not incidentally. Every AWS identity here federates through §11's
existing GitHub OIDC provider and lives an hour. gh secret list is empty, §11
records that CI "consumes zero repository secrets", and §9.3's SES work went out
of its way not to mint a second static key. A long-lived AWS access key in a
PUBLIC repository's secrets would be strictly worse than a role whose trust
names one branch, so the roles are the answer rather than secrets.

The trust policies ARE the control

er-ci-tf-plan holds ReadOnlyAccess plus state READ, and trusts any ref of
this repository — a plan has to run on the PR, which is the point. A fork gets
nothing regardless: GitHub issues no id-token to a fork's pull_request, so
that job is skipped by condition rather than failing open.

er-ci-tf-apply holds AdministratorAccess and trusts ONLY
ref:refs/heads/main. §8.2 is explicit that this role "walks through the
guardrail legitimately" — the two prod deny statements ride the permission
sets
, so they constrain humans and not a role — and therefore that "its trust
policy is part of this claim". A curated policy was the instinct and is the
wrong answer: this Terraform manages IAM, Identity Center, KMS, RDS, EKS, S3,
ECR, Secrets Manager, Budgets and CUR, so enumerating it produces a policy that
fails on the next resource type with an opaque AccessDenied mid-apply, and
prevents little, since a role that can write IAM can grant itself the rest.

prod IS wired, and this supersedes a recorded decision

Roadmap 0.5 recorded "prod stays plan-only until a tenant". That is superseded
by operator decision: prod apply is wired. What makes it safe is that every
apply job sits behind a required-reviewer GitHub environment
(infra-apply-{core,dev,prod}, protected-branches-only, reviewer athvin), so
a merge QUEUES an apply and a human releases it. One environment per env on
purpose — a scary prod diff stays holdable while core goes through.

prod's first apply still creates EKS, Aurora and NAT gateways. That cost
decision is now a click instead of a code change, deliberately, and the click is
the gate.

Two things NOT built, named rather than left implicit

  • §14.2's chained prod-scoped apply role, whose trust names the CI apply
    role plus ProdAdmin as break-glass. er-ci-tf-apply reaches prod directly
    for now; the reviewer gate covers it. Build the hop before prod carries data.
  • The bootstrap is irreducible: these roles cannot create themselves, so the
    FIRST envs/core apply must come from a human AWS_PROFILE=er-mgmt. This
    removes every recurring manual apply, not the first one.

Details worth knowing

plan passes -lock=false because the plan role holds no S3 write and taking
the S3 lockfile IS a write; the apply job's max-parallel: 1 is what actually
serialises writes. plan also uses -detailed-exitcode, because without it a
plan that ERRORS and a plan with no changes are the same exit code — which is
how a broken plan gets read as "nothing to do". apply is never parallel and
never fail-fast: these three share one state bucket, and a half-applied account
is worse than a slow one.

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

What you have to do, once

  1. Merge this.
  2. Run the one human Terraform apply against infra/terraform/envs/core with
    AWS_PROFILE=er-mgmt. That creates er-ci-tf-plan and er-ci-tf-apply —
    and, since it is the same env, the sccache bucket and roles from feat(infra): terraform the sccache S3 bucket and its two CI roles (not applied) #346 that
    are already on main.
  3. From then on CI plans every infra PR and applies on merge, behind the
    reviewer gate. Then mark perf(ci): point sccache at S3 — DO NOT MERGE UNTIL THE TERRAFORM IS APPLIED #350 ready and merge it to put sccache on S3.

The environments already exist (infra-apply-core, -dev, -prod; required
reviewer athvin, protected branches only), so the gate is live the first time
the apply job runs.

Worth noting: writing this PR body initially tripped the repo's own
PreToolUse Bash guard — "all infrastructure here is Terraform under infra/
and is applied by a human, never from an agent session" — because the text
contained the command. That guard is a layer §8.2 describes, it fired
correctly, and it is a second reason step 2 is yours rather than mine.

🤖 Generated with Claude Code

…wer gate

Builds infrastructure.md §14.2 — "plan on every PR under a read-only role;
apply on `main` under the apply role" — which was roadmap 0.5b and had been
waiting on the prod-apply decision. `infra.yml` grows two tiers over the
existing credential-free one, per env:

  validate  credential-free, every PR (unchanged; still covers fork PRs)
  plan      er-ci-tf-plan, read-only, posts the diff to the step summary
  apply     er-ci-tf-apply, main only, behind a required-reviewer environment

## No repository secrets

Deliberately, not incidentally. Every AWS identity here federates through §11's
existing GitHub OIDC provider and lives an hour. `gh secret list` is empty, §11
records that CI "consumes zero repository secrets", and §9.3's SES work went out
of its way not to mint a second static key. A long-lived AWS access key in a
PUBLIC repository's secrets would be strictly worse than a role whose trust
names one branch, so the roles are the answer rather than secrets.

## The trust policies ARE the control

`er-ci-tf-plan` holds `ReadOnlyAccess` plus state READ, and trusts any ref of
this repository — a plan has to run on the PR, which is the point. A fork gets
nothing regardless: GitHub issues no `id-token` to a fork's `pull_request`, so
that job is skipped by condition rather than failing open.

`er-ci-tf-apply` holds **AdministratorAccess** and trusts ONLY
`ref:refs/heads/main`. §8.2 is explicit that this role "walks through the
guardrail legitimately" — the two prod deny statements ride the *permission
sets*, so they constrain humans and not a role — and therefore that "its trust
policy is part of this claim". A curated policy was the instinct and is the
wrong answer: this Terraform manages IAM, Identity Center, KMS, RDS, EKS, S3,
ECR, Secrets Manager, Budgets and CUR, so enumerating it produces a policy that
fails on the next resource type with an opaque AccessDenied mid-apply, and
prevents little, since a role that can write IAM can grant itself the rest.

## prod IS wired, and this supersedes a recorded decision

Roadmap 0.5 recorded "prod stays plan-only until a tenant". That is superseded
by operator decision: prod apply is wired. What makes it safe is that every
apply job sits behind a required-reviewer GitHub environment
(`infra-apply-{core,dev,prod}`, protected-branches-only, reviewer `athvin`), so
a merge QUEUES an apply and a human releases it. One environment per env on
purpose — a scary prod diff stays holdable while core goes through.

prod's first apply still creates EKS, Aurora and NAT gateways. That cost
decision is now a click instead of a code change, deliberately, and the click is
the gate.

## Two things NOT built, named rather than left implicit

- §14.2's chained **prod-scoped** apply role, whose trust names the CI apply
  role plus `ProdAdmin` as break-glass. `er-ci-tf-apply` reaches prod directly
  for now; the reviewer gate covers it. Build the hop before prod carries data.
- The bootstrap is irreducible: these roles cannot create themselves, so the
  FIRST `envs/core` apply must come from a human `AWS_PROFILE=er-mgmt`. This
  removes every recurring manual apply, not the first one.

## Details worth knowing

`plan` passes `-lock=false` because the plan role holds no S3 write and taking
the S3 lockfile IS a write; the apply job's `max-parallel: 1` is what actually
serialises writes. `plan` also uses `-detailed-exitcode`, because without it a
plan that ERRORS and a plan with no changes are the same exit code — which is
how a broken plan gets read as "nothing to do". `apply` is never parallel and
never fail-fast: these three share one state bucket, and a half-applied account
is worse than a slow one.

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

athvin commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

The three plan jobs are red here, and that is the bootstrap rather than a defect.

plan (core)  ##[error]Could not assume role with OIDC:
             Not authorized to perform sts:AssumeRoleWithWebIdentity

er-ci-tf-plan does not exist yet — this PR is what creates it. The roles cannot
create themselves, so the first apply has to come from a human identity, which is
the irreducible step called out in the description.

The other eight checks pass, and plan/apply are not required contexts on
main (I checked: the required eight are fmt + clippy + docs, test,
DuckLake + extensions e2e, cargo-deny, entities, lint + types + unit,
playwright functional tier, pnpm audit + licenses), so this red does not
block the merge.

Recommended order — apply before merging, so main never goes red

  1. Check this branch out locally.
  2. Run the Terraform apply against infra/terraform/envs/core with
    AWS_PROFILE=er-mgmt. It creates er-ci-tf-plan and er-ci-tf-apply, plus
    the sccache bucket and roles from feat(infra): terraform the sccache S3 bucket and its two CI roles (not applied) #346 that are already on main.
  3. Re-run this PR's checks. The three plan jobs should go green and show you
    real diffs — the first state-diff this repo has ever had in CI.
  4. Merge. From then on CI plans every infra PR and applies on merge, behind the
    infra-apply-* reviewer gate.
  5. Mark perf(ci): point sccache at S3 — DO NOT MERGE UNTIL THE TERRAFORM IS APPLIED #350 ready and merge it to put sccache on S3.

Merging first also works — the red is non-blocking — but then main's infra
workflow is red until the apply, which I would rather not leave sitting there.

What I deliberately did not do

Make the plan job tolerant of a missing role, which would have turned this PR
green. A plan job that passes when it cannot reach AWS is exactly the
never-ran-looks-like-success failure this repo keeps writing gates against —
skills-check's zero-skills exit and check-bff-authz's zero-routes exit are
the same idea. Better one visibly-red bootstrap than a gate that lies afterwards.

@athvin
athvin merged commit 56ef38f into main Oct 29, 2026
21 of 27 checks passed
@athvin
athvin deleted the bm/infra-ci-plan-apply branch October 29, 2026 13:34
athvin added a commit that referenced this pull request Oct 29, 2026
…elm half) (#353)

Completes infrastructure.md §14.2. The Terraform half landed in #352; this is
"Dev platform releases apply from CI on `main`; `make dev-up` stays a human
command."

## §14.2's clause had no target, so this gives it one

`er-platform` is only ever installed into a PER-DEVELOPER namespace: its
`developer` value defaults to the release namespace and names the §9 Secrets
Manager entries `er/{environment}/{developer}/…`. There is no shared dev
release. That left two readings of "applies from CI on main":

  (a) redeploy every developer's namespace — which restarts a pod someone is
      mid-debug on, and contradicts the very next clause in the same sentence;
  (b) give CI a namespace of its own.

(b), by operator decision. CI owns exactly one namespace and cannot touch a
developer's; `make dev-up` is untouched.

The namespace is **`ci`**, not the suggested `dev`: the name becomes the
`developer` value and lands in secret paths, where `er/dev/dev/erserver` reads
like a mistake, and `ci` cannot collide with a real developer's name.

## Promote-by-digest, enforced rather than assumed

§14.2 requires a deploy to pass a DIGEST, never a tag, and to gate on that
digest being present first — and `er-platform`'s own values.yaml already cites
that section next to its `digest` fields. The job resolves both digests from
ECR and refuses to continue if either is absent.

Images are sha-tagged and built only when their own tree moved, so for any given
commit one of them may legitimately have no sha tag. That case reuses the newest
digest already in the registry — which IS what is running — and logs that it
did. Nothing is ever deployed by tag.

`needs: [detect, er-api, er-web]` with `always() && !cancelled()`, because a
rust-only commit SKIPS er-web and a plain `needs` would skip the deploy with it.
A skipped image job and a FAILED one must not mean the same thing, so the first
step inspects both results and refuses to deploy a failed build rather than
rolling out a half-built commit.

`--atomic` on the platform release: a failed upgrade rolls back instead of
leaving half a release in the namespace.

## Also

- `images.yml` now triggers on `infra/k8s/**` and `scripts/dev_env.sh`, because
  a change to either IS a platform release even when no image moved. Previously
  a chart-only commit would have deployed nothing.
- The namespace's EFS access point and secrets come from the same
  `scripts/dev_env.sh up` that `make dev-up` runs, so CI and a human provision a
  namespace identically rather than by two drifting paths.
- The eks module gains a `cluster_arn` output, so the role's
  `eks:DescribeCluster` is scoped to this cluster instead of `*`.
- helm is a version-pinned tarball, not a third-party action — the same choice
  rust.yml's disk-reclaim step documents, and it avoids adding a `uses:` whose
  SHA I would have had to pin.

## NOT verified, and one caveat worth reading

`er-ci-deploy-dev` does not exist until `envs/dev` is applied, so this job's
first run fails at role assumption exactly as infra.yml's plan jobs do. Nothing
here has touched the live cluster.

The role gets cluster-admin, because that is what this module's
`admin_principal_arns` grants (the access entry associates
AmazonEKSClusterAdminPolicy). A namespace-scoped access entry is the narrower
shape and is worth doing if this role gains a second caller; for one
namespace-scoped release whose trust is pinned to pushes on `main`, the extra
moving part buys little. Said out loud in eks.tf rather than left to be noticed.

Prefer making the first real rollout a deliberate `workflow_dispatch` rather
than whatever the next merge happens to be.

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 Oct 30, 2026
…nd (#354)

* fix(infra): make the plan gate actually pass — three real gaps it found

PR #352's plan gate ran for the first time against live state and found three
things. None was a workflow bug; all three were pre-existing.

## 1. `plan (core)`: ReadOnlyAccess does not cover bcm-data-exports

    AccessDeniedException: User: …assumed-role/er-ci-tf-plan/GitHubActions is
    not authorized to perform: bcm-data-exports:GetExport … because no
    identity-based policy allows the bcm-data-exports:GetExport action

`aws_bcmdataexports_export.cur2` (the CUR 2.0 export) cannot refresh without
it, which fails the whole env. AWS's `ReadOnlyAccess` managed policy simply
omits that service — the same shape as the KMS Decrypt gap already handled a
few lines above. Added the four read actions; a plan never writes.

## 2. `plan (dev)`: the env was never plannable non-interactively

Two required variables with no defaults and no tfvars file — so
`terraform plan` prompted, and in CI got "No value for required variable". But
supplying them would not have been enough: `ses.tf`'s own line 28 says
"running a plan over this needs `CLOUDFLARE_API_TOKEN` exported", and the
Cloudflare provider cannot authenticate without it. `envs/dev` has therefore
never been plannable by anything that did not already hold that token.

**SES is now opt-in.** Both variables default to `null`, and with either unset
the module, the three DNS records and the mail policy all drop to `count = 0`.
Supply both plus the token and it returns in full.

Safe because nothing here has ever been applied: `terraform state list` over
dev's 101 resources matched no ses/cloudflare/mail resource, so switching to
`count` destroys nothing. Verified before changing it rather than trusted to
the commit message that said SES was written-but-unapplied.

The alternative was putting a real Cloudflare token in repository secrets,
which trades a planning gap for a long-lived credential in a PUBLIC repo's
secrets — the thing §11's zero-secrets property exists to avoid. A planning gap
on one dormant subsystem is the cheaper side of that trade.

The three `output`s needed `one(module.ses[*].…)` rather than
`module.ses[0].…`: an output has no `count`, so it evaluates even when the
module is empty and fails with "module.ses is empty tuple". The resource
references are fine as `[0]` because they sit under `count = 0` and are never
evaluated.

## 3. dev's lockfile was missing a provider it declares

`.terraform.lock.hcl` had no `cloudflare/cloudflare` entry despite versions.tf
requiring it, so `init` resolved it unpinned within `~> 5.0` — exactly the drift
a lockfile exists to stop. Now pinned at 5.28.1.

## Verified

`terraform plan` run locally against live state, both envs:

    envs/core → (was failing) now reaches the diff
    envs/dev  → 4 to add, 0 to change, 0 to destroy

and dev's four are precisely the intended ones: `aws_iam_role.ci_deploy_dev`,
its policy, and the EKS access entry + policy association. No destroys in
either env.

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

* fix(infra): plan with -refresh=false instead of widening the plan role

Correcting both the fix and my verification of it.

## The verification mistake

I claimed the previous commit was "verified locally against live state". It was
not, in the way that mattered: I ran the plan as `er-mgmt`, which holds
AdministratorAccess. That proves the CONFIG is valid; it says nothing about what
`er-ci-tf-plan` can do. The gate then failed again in CI on a permission the
local run never exercised, which is exactly the hole that kind of verification
leaves.

## What the second failure showed

`plan (core)` still failed on `bcm-data-exports:GetExport` — my grant for it was
in the Terraform but not APPLIED, and the plan role's policy only changes when
`envs/core` is applied. And `plan (dev)` failed on something new:

    not authorized to perform: secretsmanager:GetSecretValue on resource:
    …secret:er/dev/shared/postgres-… / s3-… / builder-…

AWS leaves `GetSecretValue` out of `ReadOnlyAccess` on purpose: reading a
secret's VALUE is the sensitive action, not a read. Terraform needs it to
refresh `aws_secretsmanager_secret_version`.

## Why granting it would have been wrong

This role is assumable from ANY ref, because a plan has to run on the pull
request. A same-repo PR can also edit `.github/workflows/infra.yml`, since
`pull_request` runs the PR's own copy of the workflow. So granting secret-read
to this role lets a PR print dev's Postgres and S3 credentials into a public
build log. Chasing two AccessDenied errors with two grants would have quietly
turned a read-only gate into a credential-exfiltration path.

## The fix needs no permissions at all

`-refresh=false`. A non-refreshing plan makes neither privileged call, so both
failures disappear and the role stays genuinely read-only — the
`bcm-data-exports` grant from the previous commit is removed rather than kept,
because an unused permission is the thing least-privilege is against.

What is lost is out-of-band drift detection. What is kept is the
config-versus-state diff, which is what a reviewer is actually reading on a PR.
Drift is still caught at APPLY time, where the apply role refreshes fully and
the plan output is visible before the environment gate is released — so the
property moves from "every PR" to "every apply", which is where it matters.

## Verified, with the limit stated

Locally, `-refresh=false` plans cleanly in both envs: `core` reports no changes
(correct — dropping the unapplied grant returns it to the applied state) and
`dev` reports the same 4 to add, 0 to change, 0 to destroy. That is a
config-validity check, NOT a permission check: I cannot assume `er-ci-tf-plan`
from here, since its trust requires a GitHub OIDC token. CI is the only thing
that can prove the permission question, and this time I am letting it.

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]>
athvin added a commit that referenced this pull request Oct 31, 2026
…ded apply (#360)

* feat(infra): show the terraform plan on the PR, and guard the unattended apply

The service-account half of §14.2 has been live since #352: two federated
OIDC roles, zero repository secrets, plan on every PR and an unattended
apply on merge. Four gaps around it, closed here.

**The plan never reached the PR.** It went only to the run summary, so
reviewing an infra PR meant leaving the PR. A new `comment` job upserts
ONE sticky comment per PR by an HTML marker, carrying a per-stack
add/change/destroy table — destroy counts bolded, and a warning block
when any is non-zero — over collapsed per-stack diffs. Upserted, so a
ten-push PR has one comment and not ten. It is the only job in the file
with a write scope.

**The plan was not a required check, and could not become one.** The
workflow carried `paths:` filters, and a workflow a path filter skips
never reports, so a required check there would block every backend-only
PR forever. Replaced with the `detect`-job pattern `rust.yml` and
`frontend.yml` already use. Its push path FAILS SAFE: an absent, all-zero
or unreachable before-SHA reports "changed" rather than "unchanged",
because a wrongly-skipped plan is cosmetic while a wrongly-skipped apply
silently diverges the account from config until someone notices.

**"All our terraform" was three of five stacks.** The matrix is now a
list of `{key, dir}` objects, so `bootstrap/state-backend` joins the plan
tier — planned and never applied, since it owns the bucket its own backend
lives in. `bootstrap/organization` joins the credential-free `validate`
tier only: its one required variable is a root account email deliberately
absent from a public repo, and `terraform validate` evaluates no
variables, which is exactly why it fits there and cannot fit the plan
tier. Every matrix job now sets `name:` explicitly — left alone GitHub
would name it `plan (core, infra/terraform/envs/core)` and silently
un-protect `plan (core)`.

**The apply had no speed bump and left no record.** It now plans to a
file, shows it, guards it, and applies THAT file rather than letting
`-auto-approve` re-plan invisibly; the shown plan goes to the run summary.
`tf-destroy-guard.sh` refuses any non-zero destroy count unless the commit
message carries `ALLOW-DESTROY` — the repo squash-merges, so that means
the PR title, reviewed in the same diff as the destroy. A speed bump, not
a policy engine: it cannot tell a benign replace from losing Aurora, and a
replace trips it too. §14.2's prod-scoped apply role is still the real
remaining defence-in-depth.

Three helpers under `scripts/ci/` rather than heredocs, because a gate is
not trusted until it has been observed failing and a parser inside a
matrix job can only be exercised by pushing a commit. All three are
fixture-verified, including the guard observed RED on a real destroy and
failing closed on unparseable input.

Two bugs caught by reviewing this diff rather than by running it:

- `skills-check.sh` reported the block indicator `>-` as the `if:`
  condition for any job using a folded scalar, so the generated reference
  would have stated something false. It now collects the block.
- the comment upsert looked the comment id up through a pipeline,
  `gh api … | jq …`. GitHub's default shell is `bash -e {0}` and
  `pipefail` is added only by an explicit `shell: bash`, which nothing
  here sets — so a FAILING `gh` was invisible: jq succeeds on empty input,
  the id comes back empty, and the job posts a brand-new comment on every
  push instead of updating the existing one. Silent duplicates rather than
  a red job. Split into two statements so the assignment carries gh's exit
  status and `-e` aborts; verified against a stubbed failing `gh` under
  `bash -e`, which now exits 1.

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

* fix(infra): mark the plan-only stack in the comment, and scope the destroy warning

Reading the first real comment this posted (#360), a `state-backend` row
sitting beside `core`/`dev`/`prod` reads as "merging applies this". For
that stack it is exactly wrong: it is planned for drift detection and
never applied, because it owns the bucket its own backend lives in.

So the table marks it `(plan only)`, and the `[!WARNING]` block — whose
whole claim is "merging applies it unattended" — now skips plan-only
stacks. Their destroy count is still bolded in the table, because config
and state disagreeing about the state bucket is worth seeing; it just is
not about to happen on merge.

`PLAN_ONLY` has to be kept in step with the apply matrix by hand, which
the comment beside it says.

Verified over three fixtures: the clean case marks the row; a destroy on
`prod` still names prod in the warning; a destroy on `state-backend` alone
is bolded with zero warning blocks.

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]>
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