Skip to content

feat(infra): route the prod apply through the prod role, and deny it the old path - #364

Merged
athvin merged 1 commit into
mainfrom
bm/infra-prod-apply-chain
Nov 1, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/infra-prod-apply-chain

Conversation

@athvin

@athvin athvin commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Companion to #363, which created er-ci-tf-apply-prod but left it unused. This makes envs/prod actually apply through it — and, the part that matters, makes that the only path Terraform has.

The deny is scoped to the state object, not to prod resource types

er-ci-tf-apply gets an explicit Deny (overriding its AdministratorAccess) on envs/prod.tfstate and envs/prod.tfstate.tflock — the second because use_lockfile = true makes taking the lock an S3 write of its own.

Enumerating prod resources would be the instinct and doesn't work. The prod stack manages a VPC and its subnets, NAT, EKS, Aurora, EFS, S3 and KMS, while §8.2's PlatformAdmin guard — which does enumerate — covers only the destructive verbs on five services. Copying that shape here would leave the apply role able to reconfigure prod's network while unable to delete its database, which is not a boundary anyone can reason about.

Terraform cannot apply a stack whose state it cannot read. Two objects deny the whole stack, with nothing to keep in step as prod grows.

What this is, and is not

Is: the thing that stops the hop being decorative. Without the deny, deleting the chaining step would silently restore a direct prod apply and nothing would report it. With it, the audited hop is the only route, and its absence fails loudly at terraform init.

Is not: containment. er-ci-tf-apply holds AdministratorAccess and may assume the prod role — by design — so it reaches prod deliberately. What's ruled out is the accident: a matrix entry, a -chdir, or a copied job pointed at envs/prod from the non-prod identity now fails on state access instead of reconfiguring production.

The workflow change

One step, if: matrix.key == 'prod', with role-chaining: true so the action reuses the credentials the OIDC step exported rather than exchanging again — which is why the prod role's trust names er-ci-tf-apply rather than the OIDC provider.

Session tags survive this path (the web-identity paths call delete params.Tags; plain AssumeRole does not), so CloudTrail records the actor, commit and branch behind every prod write. STS caps a chained session at one hour, which is this job's timeout anyway.

What to expect on this PR vs. on the merge

  • plan (core) → 1 to add (aws_iam_role_policy.ci_tf_apply_no_prod_state), 0 to destroy.
  • plan (prod) → empty. Note the plan tier is unaffected either way: it runs under er-ci-tf-plan, which keeps its own envs/*.tfstate read.
  • On merge, apply (core) lands the deny and then apply (prod) is the first real exercise of the chain. If the chaining step is wrong, that job fails on state access — loud and non-destructive, since prod's plan is empty. That's the intended failure mode and the reason this is split from feat(infra): §14.2's prod-scoped apply role (the role only, not yet used) #363: apply (core) creates what apply (prod) consumes, and GitHub documents no ordering guarantee for a matrix even though it measures core → dev → prod today.

Verification

  • terraform fmt -check -recursive, offline validate on envs/core, actionlint clean.
  • The apply job's step order confirmed by parsing the YAML: credentials → chain (prod only) → plan-to-file → destroy guard → apply → summary.
  • role-chaining confirmed to exist as an input on configure-aws-credentials at the exact SHA this repo pins, read from its action.yml rather than from docs.
  • scripts/skills-check.sh all green, including the aws-account-operations footprint count (10 → 11 aws_iam_role_policy).
  • scripts/ci/tf-helpers-test.sh green.

Docs: §14.2 and the infra-platform skill now describe three roles rather than two, with the break-glass procedure spelled out — assume ProdAdmin, then sts assume-role into the same prod role CI uses, rather than improvising an identity while recovering production.

🤖 Generated with Claude Code

…the old path

The companion to #363, which created `er-ci-tf-apply-prod` but left it
unused. This makes `envs/prod` actually apply through it, and — the part
that matters — makes that the only path Terraform has.

**`er-ci-tf-apply` is denied the prod state object.** An explicit Deny
overrides its AdministratorAccess, scoped to
`envs/prod.tfstate` and `envs/prod.tfstate.tflock` (`use_lockfile = true`
makes taking the lock a write of its own).

Scoping it to the STATE rather than to prod resource types is the trick.
Enumerating would be the instinct and does not work: the prod stack manages
a VPC and its subnets, NAT, EKS, Aurora, EFS, S3 and KMS, while §8.2's
PlatformAdmin guard — which does enumerate — covers only the destructive
verbs on five services. Copying that shape here would leave the apply role
able to reconfigure prod's network while unable to delete its database,
which is not a boundary anyone can reason about. Terraform cannot apply a
stack whose state it cannot read, so two objects deny the whole stack with
nothing to keep in step as prod grows.

**What this is:** the thing that stops the hop being decorative. Without
the deny, deleting the chaining step would silently restore a direct prod
apply and nothing would report it. With it, the audited hop is the only
route and its absence fails loudly at `terraform init`.

**What this is not:** containment. `er-ci-tf-apply` holds
AdministratorAccess and may assume the prod role — by design — so it
reaches prod deliberately. What is ruled out is the accident: a matrix
entry, a `-chdir`, or a copied job pointed at `envs/prod` from the non-prod
identity now fails on state access instead of reconfiguring production.

The workflow gains one step, `if: matrix.key == 'prod'`, using
`role-chaining: true` so the action reuses the OIDC credentials rather than
exchanging again — which is why the prod role's trust names
`er-ci-tf-apply` instead of the OIDC provider. Session tags survive this
path (the web-identity paths drop them, plain `AssumeRole` does not), so
CloudTrail records the actor, commit and branch behind every prod write.
STS caps a chained session at one hour, which is this job's timeout anyway.

§14.2 and the infra-platform skill now describe three roles rather than
two, with the break-glass procedure spelled out: assume `ProdAdmin`, then
`sts assume-role` into the same prod role CI uses, rather than improvising
an identity while recovering production.

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

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

terraform plan

c8b1d4f · run log and full plans

env add change destroy
state-backend (plan only) 0 0 0
core 1 0 0
dev 0 0 0
prod 0 0 0

Planned with -refresh=false, so this is the config-versus-state diff and
not out-of-band drift. That is a security choice, not a speed one: a refreshing
plan reads secret values, and the plan role is assumable from any PR branch —
which can edit the workflow it runs under. Drift is caught at apply time, which
refreshes fully.

core — 1 to add, 0 to change
module.identity_center.data.aws_ssoadmin_instances.this: Reading...
data.aws_iam_policy_document.ci_tf_plan_state: Reading...
data.aws_iam_policy_document.ci_tf_plan_state: Read complete after 0s [id=2883378100]
data.aws_iam_policy_document.ci_tf_apply_no_prod_state: Reading...
data.aws_iam_policy_document.ci_tf_apply_no_prod_state: Read complete after 0s [id=2395007408]
data.aws_iam_policy_document.sccache_read: Reading...
data.aws_iam_policy_document.sccache_write: Reading...
data.aws_iam_policy_document.sccache_read: Read complete after 0s [id=2701062528]
module.github_oidc.data.aws_iam_policy_document.trust: Reading...
data.aws_iam_policy_document.sccache_write: Read complete after 0s [id=786296009]
data.aws_iam_policy_document.config_bucket: Reading...
module.github_oidc.data.aws_iam_policy_document.trust: Read complete after 0s [id=4060172364]
data.aws_iam_policy_document.config_bucket: Read complete after 0s [id=4067691321]
data.aws_iam_policy_document.audit_bucket: Reading...
data.aws_iam_policy_document.ci_tf_plan_trust: Reading...
data.aws_iam_policy_document.sccache_trust_write: Reading...
data.aws_iam_policy_document.sccache_trust_read: Reading...
data.aws_iam_policy_document.audit_bucket: Read complete after 0s [id=3031279952]
data.aws_iam_policy_document.ci_tf_apply_trust: Reading...
data.aws_iam_policy_document.ci_tf_plan_trust: Read complete after 0s [id=1630650595]
data.aws_iam_policy_document.sccache_trust_write: Read complete after 0s [id=4060172364]
module.github_oidc.data.aws_iam_policy_document.push: Reading...
data.aws_iam_policy_document.sccache_trust_read: Read complete after 0s [id=1630650595]
data.aws_iam_policy_document.cur_delivery: Reading...
data.aws_iam_policy_document.ci_tf_apply_trust: Read complete after 0s [id=2538345208]
module.github_oidc.data.aws_iam_policy_document.push: Read complete after 0s [id=3422899916]
data.aws_iam_policy_document.cur_delivery: Read complete after 0s [id=2207400467]
data.aws_iam_policy_document.ci_tf_apply_prod_trust: Reading...
data.aws_iam_policy_document.ci_tf_apply_prod_trust: Read complete after 0s [id=3513372776]
module.identity_center.data.aws_ssoadmin_instances.this: Read complete after 0s [id=us-east-2]
module.identity_center.data.aws_identitystore_user.admin: Reading...
module.identity_center.data.aws_identitystore_user.admin: Read complete after 0s [id=b17b2500-e0b1-7046-405b-23c088cf392b]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_iam_role_policy.ci_tf_apply_no_prod_state will be created
  + resource "aws_iam_role_policy" "ci_tf_apply_no_prod_state" {
      + id          = (known after apply)
      + name        = "deny-prod-state"
      + name_prefix = (known after apply)
      + policy      = jsonencode(
            {
              + Statement = [
                  + {
                      + Action   = "s3:*"
                      + Effect   = "Deny"
                      + Resource = [
                          + "arn:aws:s3:::er-terraform-state-797781631727/envs/prod.tfstate.tflock",
                          + "arn:aws:s3:::er-terraform-state-797781631727/envs/prod.tfstate",
                        ]
                      + Sid      = "DenyProdStateAccess"
                    },
                ]
              + Version   = "2012-10-17"
            }
        )
      + role        = "er-ci-tf-apply"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

@athvin
athvin merged commit 841d944 into main Nov 1, 2026
26 checks passed
athvin pushed a commit that referenced this pull request Nov 1, 2026
… sightings

Second real drift run (41283281935) after #369. `dev` and `prod` went
GREEN — the `-detailed-exitcode` false positives are gone, which was the
main thing #369 fixed. `state-backend` and `core` still failed, and the
classifier is why that was useful rather than opaque: it reported exactly
which attributes it ignored and which it did not.

  state-backend  ignored  aws_kms_key.state [tags]
                 real     aws_s3_bucket.state
                          [server_side_encryption_configuration, versioning]
  core           real     aws_iam_role.ci_tf_drift [inline_policy]

All three are the SAME class as the ones #369 already ignored — an
attribute the provider deprecated in favour of a separate resource and now
computes from it. Run 1's truncated text output had simply hidden them
behind the `# ... has changed` headline.

So the list stops being a record of sightings and becomes a rule: ignore an
attribute on a type when a SIBLING RESOURCE owns it. What makes that safe
rather than convenient is that nothing hides — turn bucket versioning off
in the console and `aws_s3_bucket_versioning` drifts; the deprecated
`aws_s3_bucket.versioning` mirror saying so too is duplicate noise, not the
signal.

That rule is also the boundary, and it is the reason the entries stay
type-scoped. `policy` is ignored on `aws_s3_bucket` and nowhere else,
because a real change to an `aws_iam_role_policy` document must stay loud.
`managed_policy_arns` moved out of the ignore-anywhere list for the same
reason.

With the rule stated, the `aws_s3_bucket` family is listed in full rather
than one sighting at a time — every one of those is owned by an
`aws_s3_bucket_*` resource — so this does not need a third round.

42 assertions now, and the two entries run 2 surfaced are mutation-checked:
removing `aws_s3_bucket:versioning` and `aws_iam_role:inline_policy` turns
the suite red on "deprecated sibling mirrors are NOT drift".

Also corrected the test file's own header, which still claimed three
helpers and that §14.2's prod-scoped apply role was unbuilt — it has been
since #363/#364 — and now states the opposite risk the classifier carries:
an over-broad ignore entry retires drift detection while leaving the
workflow in the tree.

One process note, since it cost a redo: `reset --hard` on uncommitted work
loses it, and the repo's own memory says to check `git status` before any
git operation here. I did not, and rewrote these two edits.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin added a commit that referenced this pull request Nov 1, 2026
… sightings (#370)

Second real drift run (41283281935) after #369. `dev` and `prod` went
GREEN — the `-detailed-exitcode` false positives are gone, which was the
main thing #369 fixed. `state-backend` and `core` still failed, and the
classifier is why that was useful rather than opaque: it reported exactly
which attributes it ignored and which it did not.

  state-backend  ignored  aws_kms_key.state [tags]
                 real     aws_s3_bucket.state
                          [server_side_encryption_configuration, versioning]
  core           real     aws_iam_role.ci_tf_drift [inline_policy]

All three are the SAME class as the ones #369 already ignored — an
attribute the provider deprecated in favour of a separate resource and now
computes from it. Run 1's truncated text output had simply hidden them
behind the `# ... has changed` headline.

So the list stops being a record of sightings and becomes a rule: ignore an
attribute on a type when a SIBLING RESOURCE owns it. What makes that safe
rather than convenient is that nothing hides — turn bucket versioning off
in the console and `aws_s3_bucket_versioning` drifts; the deprecated
`aws_s3_bucket.versioning` mirror saying so too is duplicate noise, not the
signal.

That rule is also the boundary, and it is the reason the entries stay
type-scoped. `policy` is ignored on `aws_s3_bucket` and nowhere else,
because a real change to an `aws_iam_role_policy` document must stay loud.
`managed_policy_arns` moved out of the ignore-anywhere list for the same
reason.

With the rule stated, the `aws_s3_bucket` family is listed in full rather
than one sighting at a time — every one of those is owned by an
`aws_s3_bucket_*` resource — so this does not need a third round.

42 assertions now, and the two entries run 2 surfaced are mutation-checked:
removing `aws_s3_bucket:versioning` and `aws_iam_role:inline_policy` turns
the suite red on "deprecated sibling mirrors are NOT drift".

Also corrected the test file's own header, which still claimed three
helpers and that §14.2's prod-scoped apply role was unbuilt — it has been
since #363/#364 — and now states the opposite risk the classifier carries:
an over-broad ignore entry retires drift detection while leaving the
workflow in the tree.

One process note, since it cost a redo: `reset --hard` on uncommitted work
loses it, and the repo's own memory says to check `git status` before any
git operation here. I did not, and rewrote these two edits.

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