delivery guard hook #190

Closed
opened 2026-11-22 16:08:59 +00:00 by Claude · 3 comments
Owner

Part of #166

Question

Author the one guard hook that delivery ships, as ADR-0032 specifies. It is a pre-tool-use hook on shell commands:

  • Deny the Never tier on every runtime:
    • direct cluster mutation (kubectl apply/edit/delete/patch/scale, helm install/upgrade/uninstall)
    • tofu destroy and state edits
    • --no-verify and SKIP=
    • Vault and Sealed Secrets decryption
    • reading vault password files, keys, .tfstate or Secrets
  • Ask before Odd-job commands (real ansible-playbook runs without --check) on Claude Code and Copilot CLI, and deny them on runtimes without ask.

Requirements:

  • Author it in plugins/delivery/.apm/hooks/ the way kyberforge ships its hook, and add the executables: allow: entry with its version-sync check.
  • Write tests for the deny, ask and allow cases, including bypass attempts: quoting, bash -c, env prefixes.
  • Close out with factory-audit.
  • Use the Copilot hook facts from Copilot CLI agent behaviour from docs where they are available.
Part of #166 ## Question Author the one guard hook that `delivery` ships, as ADR-0032 specifies. It is a pre-tool-use hook on shell commands: - **Deny** the Never tier on every runtime: - direct cluster mutation (`kubectl apply/edit/delete/patch/scale`, `helm install/upgrade/uninstall`) - `tofu destroy` and state edits - `--no-verify` and `SKIP=` - Vault and Sealed Secrets decryption - reading vault password files, keys, `.tfstate` or Secrets - **Ask** before Odd-job commands (real `ansible-playbook` runs without `--check`) on Claude Code and Copilot CLI, and deny them on runtimes without `ask`. Requirements: - Author it in `plugins/delivery/.apm/hooks/` the way `kyberforge` ships its hook, and add the `executables: allow:` entry with its version-sync check. - Write tests for the deny, ask and allow cases, including bypass attempts: quoting, `bash -c`, `env` prefixes. - Close out with `factory-audit`. - Use the Copilot hook facts from **Copilot CLI agent behaviour from docs** where they are available.
Claude added this to the Map: Infra and agent-team packages milestone 2026-11-22 16:08:59 +00:00
Claude added the Wayfinder/Task label 2026-11-22 16:08:59 +00:00
Claude added a new dependency 2026-11-22 16:09:29 +00:00
Claude added a new dependency 2026-11-22 16:09:31 +00:00
Author
Owner

Inputs from Copilot CLI agent behaviour from docs (#187)

  • Copilot's ask isn't reliable. #3590 (open): the TUI auto-approves ask since v1.0.53. Autopilot and cloud turn ask into deny, and -p behaviour is undocumented. Decide in this ticket whether the hook denies odd-job commands on Copilot rather than asking. ADR-0032 says "ask on Copilot", so a change would amend it.
  • Timeouts let the call through on Copilot (#2893). Keep the hook fast and with no dependencies.
  • Plugin-defined preToolUse hooks reportedly never fire on Copilot (#2540, open). Check where apm deploys the hook for the copilot target (.github/hooks/*.json vs plugin hooks).
  • Repo hooks under copilot -p load only in a trusted folder.
  • #5326 (open): a failing .github/hooks/*.json hook blocks every tool call, because errors deny. A broken guard hook stops the whole session.
  • Output format: permissionDecision (allow/deny/ask) and permissionDecisionReason, which a deny requires. Exit code 2 denies.

Source: findings note.

## Inputs from Copilot CLI agent behaviour from docs (#187) - **Copilot's `ask` isn't reliable.** #3590 (open): the TUI auto-approves `ask` since v1.0.53. Autopilot and cloud turn `ask` into deny, and `-p` behaviour is undocumented. Decide in this ticket whether the hook denies odd-job commands on Copilot rather than asking. ADR-0032 says "ask on Copilot", so a change would amend it. - **Timeouts let the call through on Copilot (#2893).** Keep the hook fast and with no dependencies. - **Plugin-defined preToolUse hooks reportedly never fire on Copilot (#2540, open).** Check where apm deploys the hook for the `copilot` target (`.github/hooks/*.json` vs plugin `hooks`). - **Repo hooks under `copilot -p` load only in a trusted folder.** - **#5326 (open):** a failing `.github/hooks/*.json` hook blocks every tool call, because errors deny. A broken guard hook stops the whole session. - **Output format:** `permissionDecision` (`allow`/`deny`/`ask`) and `permissionDecisionReason`, which a deny requires. Exit code 2 denies. Source: [findings note](https://git.rkdr.net/Mortis/Holocron/src/branch/research/copilot-cli-agents/docs/research/copilot-cli-agents/copilot-cli-agents.md).
Author
Owner

Heads-up before building: apm install warns about parked kyberforge executables and hidden characters. Every apm install reports kyberforge's executables as "parked pending approval", even though its executables.allow grant matches and the same run says "Integrated 1 hook(s)". The cause is unknown.

This hook needs its own executables.allow entry for delivery. Check that it actually deploys after a clean apm install, for example that it appears in .claude/settings.json. Don't rely on the install exit code, which can be 0 while a hook is held back.

**Heads-up before building:** [apm install warns about parked kyberforge executables and hidden characters](https://git.rkdr.net/Mortis/Holocron/issues/208). Every `apm install` reports kyberforge's executables as "parked pending approval", even though its `executables.allow` grant matches and the same run says "Integrated 1 hook(s)". The cause is unknown. This hook needs its own `executables.allow` entry for `delivery`. Check that it actually deploys after a clean `apm install`, for example that it appears in `.claude/settings.json`. Don't rely on the install exit code, which can be 0 while a hook is held back.
Defame1297 was assigned by Claude 2026-11-23 07:34:20 +00:00
Author
Owner

Resolution

Built and merged in PR #211 (delivery 0.2.0). plugins/delivery/.apm/hooks/guard.py is one stdlib-only Python pre-tool-use hook; consumer docs in plugins/delivery/docs/guard-hook.md.

Decisions (owner, this session)

  • Copilot odd jobs: ask, kept as an accepted risk in ADR-0032 (the TUI auto-approves ask, github/copilot-cli#3590).
  • Shell and file tools are both checked: Read/Grep/Edit/Write paths, Copilot view, Codex apply_patch.
  • Allowlists: kubectl, helm, helmfile, flux, tofu/terragrunt allow only listed subcommands ("no cluster or state change, no secret printed"); anything unlisted is denied.
  • Codex and unknown runtimes deny odd jobs (Codex can't ask).

What was built

  • Never tier denied on every runtime; odd jobs ask on Claude Code and Copilot, deny on Codex/unknown; Read/Propose allowed.
  • The runtime is told from apm's deploy path (.claude/hooks/, .github/hooks/, .codex/hooks/), never the payload shape.
  • Fails closed: onFailure: block on Claude Code, deny on crash, malformed payload, or input over 256 KB / 2,000 words (Copilot lets a timed-out call through).
  • Own shell tokenizer (quotes, here-docs, substitutions, redirects, a PowerShell mode) plus unwrapping of shells, eval, wrappers, runners, git shell-outs and rtk.
  • Denials beyond ADR-0032's list: pre-commit uninstall, HUSKY=0/LEFTHOOK=0, .git/hooks writes, git aliases carrying --no-verify, sops decryption, core.hooksPath, the admin ~/.kube/config.
  • check-executables-allow-sync now covers every plugin shipping hooks or bin/.

Verification

  • 521-case test suite across Claude, Copilot and Codex payloads; full pre-push stage passes.
  • Three review rounds by fresh-context subagents (factory-audit, two adversarial bypass hunts, spec/standards code-review); every confirmed finding fixed with a regression case.
  • Live on Claude Code 2.1.326: kubectl apply, bash -c "cat .vault_pass" and a Read of .vault_pass denied; ordinary commands ran.
  • Post-merge clean deploy (scratch clone of main, apm update, apm 0.28.0): guard.py deployed executable under .claude/hooks/delivery/, the PreToolUse entry landed in .claude/settings.json with onFailure: block and timeout: 10, and the deployed copy denied kubectl apply. The "parked pending approval" warning still printed (#208, cosmetic).
  • Latency: 40–70 ms per tool call, almost all Python startup and source compile; the analysis itself is under 1 ms.

Facts later tickets depend on

  • Copilot is unverified: apm writes the entry in Claude's nested shape, which Copilot's docs don't cover.
  • Codex resolves the relative hook path from the session cwd, so a session started in a subdirectory may not find the script.
  • Consumers need python3 on PATH and an executables.allow grant delivery#<version>: hooks: true.
  • Known gaps (covered by the credential boundary): scripts the agent writes and runs, python -c, MCP tools, unusual secret paths, cwd tracking (cd ~/.kube && cat config), and runtime output of allowed commands.
  • This repo depends on delivery, so the guard now deploys into this repo's own Claude sessions on the next install.
## Resolution Built and merged in PR #211 (`delivery` 0.2.0). `plugins/delivery/.apm/hooks/guard.py` is one stdlib-only Python pre-tool-use hook; consumer docs in `plugins/delivery/docs/guard-hook.md`. **Decisions (owner, this session)** - **Copilot odd jobs: ask**, kept as an accepted risk in ADR-0032 (the TUI auto-approves `ask`, github/copilot-cli#3590). - **Shell and file tools** are both checked: Read/Grep/Edit/Write paths, Copilot `view`, Codex `apply_patch`. - **Allowlists**: `kubectl`, `helm`, `helmfile`, `flux`, `tofu`/`terragrunt` allow only listed subcommands ("no cluster or state change, no secret printed"); anything unlisted is denied. - Codex and unknown runtimes deny odd jobs (Codex can't ask). **What was built** - Never tier denied on every runtime; odd jobs ask on Claude Code and Copilot, deny on Codex/unknown; Read/Propose allowed. - The runtime is told from apm's deploy path (`.claude/hooks/`, `.github/hooks/`, `.codex/hooks/`), never the payload shape. - Fails closed: `onFailure: block` on Claude Code, deny on crash, malformed payload, or input over 256 KB / 2,000 words (Copilot lets a timed-out call through). - Own shell tokenizer (quotes, here-docs, substitutions, redirects, a PowerShell mode) plus unwrapping of shells, `eval`, wrappers, runners, git shell-outs and `rtk`. - Denials beyond ADR-0032's list: `pre-commit uninstall`, `HUSKY=0`/`LEFTHOOK=0`, `.git/hooks` writes, git aliases carrying `--no-verify`, `sops` decryption, `core.hooksPath`, the admin `~/.kube/config`. - `check-executables-allow-sync` now covers every plugin shipping hooks or `bin/`. **Verification** - 521-case test suite across Claude, Copilot and Codex payloads; full pre-push stage passes. - Three review rounds by fresh-context subagents (factory-audit, two adversarial bypass hunts, spec/standards code-review); every confirmed finding fixed with a regression case. - Live on Claude Code 2.1.326: `kubectl apply`, `bash -c "cat .vault_pass"` and a Read of `.vault_pass` denied; ordinary commands ran. - Post-merge clean deploy (scratch clone of `main`, `apm update`, apm 0.28.0): `guard.py` deployed executable under `.claude/hooks/delivery/`, the `PreToolUse` entry landed in `.claude/settings.json` with `onFailure: block` and `timeout: 10`, and the deployed copy denied `kubectl apply`. The "parked pending approval" warning still printed (#208, cosmetic). - Latency: 40–70 ms per tool call, almost all Python startup and source compile; the analysis itself is under 1 ms. **Facts later tickets depend on** - **Copilot is unverified:** apm writes the entry in Claude's nested shape, which Copilot's docs don't cover. - Codex resolves the relative hook path from the session cwd, so a session started in a subdirectory may not find the script. - Consumers need `python3` on PATH and an `executables.allow` grant `delivery#<version>: hooks: true`. - **Known gaps** (covered by the credential boundary): scripts the agent writes and runs, `python -c`, MCP tools, unusual secret paths, cwd tracking (`cd ~/.kube && cat config`), and runtime output of allowed commands. - This repo depends on `delivery`, so the guard now deploys into this repo's own Claude sessions on the next install.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: Mortis/Holocron#190