Skip to content

fix(infra): let the deploy role read the ONE shared secret dev_env.sh needs - #357

Merged
athvin merged 1 commit into
mainfrom
bm/infra-deploy-dev-shared-secret
Oct 30, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/infra-deploy-dev-shared-secret

Conversation

@athvin

@athvin athvin commented Oct 30, 2026

Copy link
Copy Markdown
Owner

The first real deploy dev run got through role assumption, digest resolution,
helm and kubeconfig, then failed provisioning the namespace:

dev_env: created EFS access point fsap-0fdf8d6c4ef38c8bb (root /ci)
dev_env: shared Aurora secret er/dev/shared/postgres missing
         — apply infra/terraform/envs/dev first

The secret is not missing. plan (dev) had already proved it exists by failing
to read er/dev/shared/postgres-PFkaGl earlier in this same effort. What
happened is that my policy scoped Secrets Manager to er/dev/ci/*, so
DescribeSecret on the shared one was denied — and dev_env.sh's existence
check cannot distinguish "denied" from "absent", so it reported the wrong cause.

dev_env.sh reads exactly one shared secret (its line 116, for the namespace's
database credentials); everything else is under er/dev/<namespace>/ and was
already covered.

Why this grants one secret by name rather than er/dev/shared/*

The wildcard is the obvious fix and it is the wrong one: er/dev/shared/* also
matches er/dev/shared/builder, which holds the TEMPORARY never-expiring
AdministratorAccess key (builder.tf, §8.1's deliberate exception). Granting that
would turn a namespace deploy role into a route to account admin for anything
able to run on main — a far worse outcome than the deploy being broken.
.claude/hooks/aws-write-guard.sh already singles that key out as the one
credential no guardrail layer constrains.

So the grant names er/dev/shared/postgres-* (the -* because Secrets Manager
appends a random suffix) and nothing else.

Side effect from the partial run, not a leak

That run did create the EFS access point fsap-0fdf8d6c4ef38c8bb (root /ci)
before failing. It is harmless and idempotent — dev_env.sh finds an existing
access point rather than making a second — so the next run reuses it.

This one needs no human apply: the pipeline now applies envs/dev itself on
merge.

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

🤖 Generated with Claude Code

… needs

The first real `deploy dev` run got through role assumption, digest resolution,
helm and kubeconfig, then failed provisioning the namespace:

    dev_env: created EFS access point fsap-0fdf8d6c4ef38c8bb (root /ci)
    dev_env: shared Aurora secret er/dev/shared/postgres missing
             — apply infra/terraform/envs/dev first

The secret is not missing. `plan (dev)` had already proved it exists by failing
to read `er/dev/shared/postgres-PFkaGl` earlier in this same effort. What
happened is that my policy scoped Secrets Manager to `er/dev/ci/*`, so
`DescribeSecret` on the shared one was denied — and `dev_env.sh`'s existence
check cannot distinguish "denied" from "absent", so it reported the wrong cause.

`dev_env.sh` reads exactly one shared secret (its line 116, for the namespace's
database credentials); everything else is under `er/dev/<namespace>/` and was
already covered.

## Why this grants one secret by name rather than `er/dev/shared/*`

The wildcard is the obvious fix and it is the wrong one: `er/dev/shared/*` also
matches `er/dev/shared/builder`, which holds the TEMPORARY never-expiring
AdministratorAccess key (builder.tf, §8.1's deliberate exception). Granting that
would turn a namespace deploy role into a route to account admin for anything
able to run on `main` — a far worse outcome than the deploy being broken.
`.claude/hooks/aws-write-guard.sh` already singles that key out as the one
credential no guardrail layer constrains.

So the grant names `er/dev/shared/postgres-*` (the `-*` because Secrets Manager
appends a random suffix) and nothing else.

## Side effect from the partial run, not a leak

That run did create the EFS access point `fsap-0fdf8d6c4ef38c8bb` (root `/ci`)
before failing. It is harmless and idempotent — `dev_env.sh` finds an existing
access point rather than making a second — so the next run reuses it.

This one needs no human apply: the pipeline now applies `envs/dev` itself on
merge.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 5ca70ff into main Oct 30, 2026
22 checks passed
@athvin
athvin deleted the bm/infra-deploy-dev-shared-secret branch October 30, 2026 06:13
athvin added a commit that referenced this pull request Nov 1, 2026
…367)

* feat(infra): detect out-of-band drift, which -refresh=false gives up

§14.2 gives up one thing on purpose: the plan tier runs `-refresh=false`,
because `er-ci-tf-plan` is assumable from any PR branch and a refreshing
plan reads secret VALUES. What that loses is drift — a console edit, a
manual fix during an incident, an AWS-side default that moved.

Nothing noticed. The only thing that refreshes is `apply` on `main`, which
then silently reconciles whatever it finds, so drift stayed invisible until
some unrelated infra PR merged and quietly fixed or failed on it with
nobody connecting the two. Dev has already shown this once: #357's apply
reported `0 added, 1 changed, 0 destroyed` against a PR plan that had shown
nothing.

`drift.yml` runs `plan -refresh-only` daily across all four stacks.
`-refresh-only` is a different question from the plan tier's and that is
why this is a separate workflow rather than a flag: it compares STATE
against REALITY and ignores the configuration entirely, so what it reports
is only ever "something changed outside Terraform", never "someone edited
a .tf file".

**A third read role, because the second one must not grow.**
`er-ci-tf-drift` holds the two reads `ReadOnlyAccess` omits —
`secretsmanager:GetSecretValue` and `bcm-data-exports:GetExport`, the two
that broke the first run of the plan gate in #354 — which a refresh needs
and the plan role must never have.

That is safe only because of who can reach it, and it takes TWO trust
conditions rather than one:

- `sub` pinned to `:ref:refs/heads/main`. No PR branch can mint that
  claim. On its own it still admits any `main`-ref job, including the plan
  tier on a push, so it is necessary and not sufficient.
- `job_workflow_ref` pinned to `drift.yml` on `main`. This is the condition
  that narrows it to one file's jobs, so adding a step to another workflow
  cannot quietly inherit secret-read.

Matched with `StringLike` and a leading wildcard deliberately: the
repository prefix in `job_workflow_ref` is not the customised immutable
`sub` prefix, and pinning a format that AWS and GitHub both have to agree
on would be a silent never-match rather than a visible error.
`GetSecretValue` is scoped to `er/*` in this account, not `*`.

Read-only including the lock, so `-lock=false` like the plan tier — the
role holds no S3 write and acquiring the lockfile is one. A refresh-only
PLAN writes no state; only `apply -refresh-only` would, and nothing here
applies. **Drift is reported for a human, never auto-reconciled:** writing
reality back into state is how a console change becomes permanent without
anyone deciding so.

Drift FAILS the run rather than warning, because a scheduled workflow that
goes red notifies and one that warns is a line in a log nobody opens. If an
environment turns out to drift chronically the answer is to fix the
configuration or record the exception, not to lower this to a warning —
which would retire the check while leaving it in the tree.

It can never be a required check: it never runs on a pull request.

One PR rather than the two the last three IAM changes needed. The ordering
trap does not apply here — `apply (core)` creates the role, and nothing
consumes it until the next cron or a manual dispatch, so there is no
same-run dependency to lose.

Verified by extracting both steps from the YAML and running them against a
stub terraform: exit 0 → `drifted=false` → job green; 2 → `drifted=true` →
red naming the env; 1 and an init failure → `drifted=error` → red saying it
is not a clean result; and an empty value fails closed. The summary step is
`always()` and ordered before the gate, so a red run explains itself
without opening the log.

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

* fix(ci): exempt drift.yml from the Rust gate too, and state the fail-safe rule

Noticed on this PR's own run: it correctly paid the full backend gate
(because it touches `docs/`, which is never exempt), but `drift.yml` is a
new workflow and #366 had only named `infra.yml`. Leaving an inconsistency
I created one commit earlier is worse than one more regex token.

Same argument as `infra.yml`: `drift.yml` defines no Rust job and cannot
affect the workspace build. `rust.yml`, `frontend.yml` and `images.yml` stay
out of the exempt set, because a change to a gate must keep reporting on
exactly the PR most likely to break it.

While here, the rule behind the enumeration is now written down rather than
implied: naming files, instead of exempting `^\.github/workflows/` and
listing exceptions, is the FAIL-SAFE direction. A workflow added later runs
the gate until someone argues it should not, rather than skipping it until
someone notices. Verified with a hypothetical `something-new.yml`, which
still runs.

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