Skip to content

fix(hooks): aws-write-guard grades every segment, strips heredoc bodies, tells the true rule - #953

Merged
athvin merged 1 commit into
mainfrom
issue/926-guard-fix
Nov 9, 2026
Merged

athvin merged 1 commit into
mainfrom
issue/926-guard-fix

Conversation

@athvin

@athvin athvin commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Closes #926

What

Reworks scripts/hooks/aws-write-guard.sh's matching and its messages, plus twelve new cases in codex-hooks-sync-test.sh (31 pass total). Heredoc BODIES are stripped before anything matches (heredoc content is data — the measured gh pr create false positive dies at the root); the rest is split everywhere a command can start (pipes, &&/||, ;, newlines) and each segment is graded by its own head; make cluster-objects joins the graded path. The destructive list still scans the whole stripped string, so bash -c-wrapped evasions stay denied.

Why

The guard stated a rule that was wrong in both halves (cluster objects are not Terraform; agents may apply them with disclosure — and since #927 CI applies them on merge) and its first-word anchor was bypassed by the two commonest invocation shapes while firing on a heredoc body. A guard whose stated reason is wrong teaches the wrong rule every time it fires; a guard that blocks legitimate work gets disabled.

Proof

codex-hooks-sync-test.sh — 31 passed, 0 failed, including the new: pipe-wrapped apply denied (Codex semantics), heredoc-piped apply denied, make cluster-objects denied, second-line mutation denied, read-past-pipe passes, the heredoc-body string passes, and the Claude-side mapping still returns ask for the graded shapes while ER_GUARD_ASK_AS_DENY=1 collapses them to deny. kimi-hooks-sync-test.sh 14/0, scripts-home-check.sh clean, bash -n clean. Documented residual, failing toward refusal: a multi-line QUOTED string (not heredoc) still splits on its newlines, so a body written that way with a deny-list string inside still trips.

Risk & rollback

Risk: an over-match regression blocks legitimate commands — mitigated by the test table driving all three agents' payload shapes, and by the failure direction being refusal (annoying, not silent). Rollback: git revert <merge-sha>; the hooks re-sync from the reverted file.

Post-merge ledger

Closed by: agent · Codex session 01a1be1a-66a7-72f3-8e78-32c20c5e0da9 on Mac.lan · 2026-11-09T02:27:41.268226+00:00

  • main is green with this change on it — the merge SHA, and the run that proves it: e036803; rust run 42548210698, frontend 42548210747, infra 42548210714 and devcontainer 42548210710 succeeded.
  • images built, or correctly never ran because nothing that goes into an image changed: n/a — only hook scripts and their tests changed; no image inputs.
  • deploy converged — proved by a line the running process emitted, not by the image digest and not by the workflow conclusion: n/a — this hook-only change triggers no deployment.
  • the push-only surface no pull request can pre-test (deploy, drift, kind's nightly leg) is green, or knowingly red for a reason that is not this change: Latest observed deploy 42550495391, drift 42453080846 and kind 42455973323 all succeeded.
  • the board card reached Done through the automation rather than by hand, and the issue closed: Issue aws-write-guard: its stated rule and what it enforces disagree, in both directions #926 is CLOSED; its Product Roadmap card is Done.
  • follow-ups — none owed.
  • what was learned is written down where the next session will find it (a skill, a reference, memory) — or nothing new was learned: Guard comments and this PR Context record the matching limitations and command ownership.

Specific to this change

  • the guard is re-synced where it is installed — scripts/codex-hooks-sync.sh and the Kimi equivalent install by reference to this file, so a merge updates what sessions run; confirm one live session evaluates the new table (a graded command returns the new message): Primary checkout contains e036803; invoking scripts/hooks/aws-write-guard.sh with a synthetic kubectl apply payload returns the new CI-owned Terraform / cluster-objects disclosure message. No cluster mutation was executed.
Context — plan, discoveries, measurements, files

Plan

  1. Strip heredoc bodies. 2. Segment on pipes/booleans/;/newlines; grade per segment. 3. make cluster-objects into the graded path. 4. Rewrite both messages for the post-The deploy never applies infra/k8s cluster objects, so a new cluster is born without them #927 rule. 5. Tests for every measured shape, both mappings.

Discoveries

  • The latent hole was bigger than the issue's two shapes: kubectl get pods && kubectl apply -f x passed silently, because the reads exemption matched the whole string unanchored. Per-segment grading closes it.
  • bash -c '…' shows only bash as a segment head; keeping the destructive list on the whole stripped string preserves today's coverage of that shape without re-introducing the heredoc false positive.
  • The er-builder identity check stays whole-string and untouched: it is identity-triggered, not command-triggered.

Measurements

  • 16-case manual battery against the rewritten guard, both mappings — all correct (session transcript).
  • bash scripts/ci/codex-hooks-sync-test.sh → 31 passed, 0 failed (12 new).

Files

  • scripts/hooks/aws-write-guard.sh — the rework.
  • scripts/ci/codex-hooks-sync-test.sh — the new cases.

@athvin
athvin marked this pull request as ready for review November 9, 2026 01:56
@athvin
athvin merged commit e036803 into main Nov 9, 2026
44 checks passed
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.

aws-write-guard: its stated rule and what it enforces disagree, in both directions

2 participants