Repository navigation
Description
Surfaced while landing #906 (PR #925). Two separate defects in scripts/hooks/aws-write-guard.sh, found by it firing when it should not have and not firing when it would have.
1. The message states a rule that is not the policy
On deny it says:
Destructive infrastructure command. All infrastructure here is Terraform under infra/ and is applied by a human, never from an agent session.
Both halves are now wrong. Cluster objects under infra/k8s/ are not Terraform — they are Kubernetes manifests that Terraform deliberately does not own (modules/eks/main.tf says so) and that make cluster-objects applies by hand. And "never from an agent session" is not the operating rule: the owner decided on 2026-11-08 that an agent session applies cluster objects directly and discloses each one, while Terraform applies stay CI-owned. The message should say that, because a guard whose stated reason is wrong teaches the wrong rule every time it fires.
2. Its matching is bypassed by the two commonest invocation shapes
The graded branch is anchored:
if [[ $bare =~ ^[[:space:]]*(aws|terraform|kubectl|helm)[[:space:]] ]]
So it sees nothing when the call is wrapped, and both wrappers are everyday usage here:
make cluster-objects ER_ENV=prod— first wordmake; this is the documented way to apply cluster objects.cat <<YAML | kubectl apply -f -— first wordcat; the natural way to apply an inline manifest.
Measured: a full set of NodePool, PriorityClass and ConfigMap applies against er-prod went through unexamined, while the deny list fired on a gh pr create whose body text contained the string kubectl delete inside a heredoc. So it is simultaneously over- and under-matching — it greps a command line for substrings without knowing which token is the command.
Scope
- Rewrite the deny message to state the actual rule, separating Terraform (CI-owned, never by hand) from cluster objects (hand-applied, agent-applied with disclosure).
- Decide whether to widen matching. The honest options are to detect the wrapped forms (
maketargets that shell out, pipelines whose last stage is the mutating command) or to accept that a determined caller can route around a regex and lean on the deny list for genuinely irreversible verbs only. The second is defensible — but it should be written down as a choice rather than left as an accident. - Either way, do not let a string inside a quoted heredoc be read as a command. That is the over-match, and it blocks ordinary work.
Acceptance
- the deny message, read cold, describes what is actually allowed
- a test asserts the heredoc-text case is NOT denied — this is the regression that blocked a pull request body
- a test asserts whichever wrapped form the decision says should be caught, and a comment names the ones deliberately left uncaught
-
scripts/ci/self-test covers both, since a guard breaks by noticing nothing and that reads exactly like a clean tree
Activity
athvin commentedon Nov 9, 2026
Claiming. Design: strip heredoc BODIES before analysis (heredoc content is data — that kills the measured
gh pr createfalse positive at the root), then split everywhere a command can start (pipes,&&/||,;, newlines) and grade each segment by its own head; the destructive list keeps scanning the whole stripped string sobash -c-wrapped shapes stay denied;make cluster-objectsjoins the graded path as the documented manual apply; both messages get rewritten for the post-#927 world (Terraform applies are CI-owned, cluster objects apply from CI on merge or by hand with disclosure). Ships withscripts/ci/aws-write-guard-test.shcarrying the measured shapes as fixtures, wired intoagent-bridge-checkand rust.yml's S9 job.