Repository navigation
feat(infra): route the prod apply through the prod role, and deny it the old path - #364
Merged
Merged
Conversation
…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]>
Contributor
terraform plan
core — 1 to add, 0 to changemodule.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.
|
This was referenced Nov 1, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Companion to #363, which created
er-ci-tf-apply-prodbut left it unused. This makesenvs/prodactually 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-applygets an explicit Deny (overriding its AdministratorAccess) onenvs/prod.tfstateandenvs/prod.tfstate.tflock— the second becauseuse_lockfile = truemakes 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-applyholds 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 atenvs/prodfrom the non-prod identity now fails on state access instead of reconfiguring production.The workflow change
One step,
if: matrix.key == 'prod', withrole-chaining: trueso the action reuses the credentials the OIDC step exported rather than exchanging again — which is why the prod role's trust nameser-ci-tf-applyrather than the OIDC provider.Session tags survive this path (the web-identity paths call
delete params.Tags; plainAssumeRoledoes 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 underer-ci-tf-plan, which keeps its ownenvs/*.tfstateread.apply (core)lands the deny and thenapply (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 whatapply (prod)consumes, and GitHub documents no ordering guarantee for a matrix even though it measures core → dev → prod today.Verification
terraform fmt -check -recursive, offlinevalidateonenvs/core,actionlintclean.role-chainingconfirmed to exist as an input onconfigure-aws-credentialsat the exact SHA this repo pins, read from itsaction.ymlrather than from docs.scripts/skills-check.sh allgreen, including theaws-account-operationsfootprint count (10 → 11aws_iam_role_policy).scripts/ci/tf-helpers-test.shgreen.Docs: §14.2 and the infra-platform skill now describe three roles rather than two, with the break-glass procedure spelled out — assume
ProdAdmin, thensts assume-roleinto the same prod role CI uses, rather than improvising an identity while recovering production.🤖 Generated with Claude Code