Files
Holocron/docs/adr/0032-credentials-not-hooks-are-the-agent-safety-boundary.md
Defame1297andClaude Opus 5.5 d4226e152b fix(delivery): keep inbound-rule stops out of the handoff trail
Why: every Stop posted a Handoff comment whose Next command relaunched the
stopping agent, including stops raised by the inbound rule itself. A second
launch then passed the inbound check, and a wrong-agent stop buried the
correct pointer.

Implementation Notes:
- Stops before the inbound check passed (Steps 1-2) post a plain comment;
  later stops keep the relaunching Handoff comment.
- gates.md defines a Handoff comment strictly and owns the inbound stop
  wordings; the planner stops at the inbound check in v1.
- Heading names and where-to-post live once, in handoff-comment.md.
- Gotcha and delivery-repo-doc checklist item: the two Status labels must
  not share an exclusive scope.
- GLOSSARY gains Step mode and Run mode; ADR-0032 scopes the gate-label
  check to stages that have one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012CqgnwEGtmfsjcoG9QwByN
2026-11-23 17:21:51 +00:00

8.5 KiB

Credentials, not hooks, are the agent safety boundary

The infra packages (ansible, gitops, k8s, later tofu) and the delivery team keep agents safe by what they cannot do, not by what they are told: stage sessions hold no apply credentials, no vault password and no Secret read, and every infra change applies by merge after a human approves the PR. Hooks and skill instructions sit above that boundary as guardrails, because every provider documents hooks as a guardrail rather than a security boundary and a hook "ask" works only in Claude Code and Copilot CLI. Decided in holocron#172.

Action tiers

Every package skill classifies each command it drives into one tier:

  • Read — lint, syntax check, dry run, diff, kubectl get/describe/logs, flux get, an offline render or rendered diff (kustomize build, flux build --dry-run). Free. Live kubectl diff and flux diff are server-side dry runs that need write RBAC, so they fail under the read-only kubeconfig and are not used.
  • Propose — branch, commit, push, open a PR, comment. Free.
  • Apply-by-merge — every change to infrastructure. Happens only through an approved merge; the agent never runs it.
  • Odd job — ansible-playbook outside check mode, tofu apply, flux reconcile. The agent runs it, only in a HITL session the human started and supplied the apply credentials to; that session takes its instruction from the human and loads no issue or PR text. The guard hook asks before each command.
  • Never — kubectl apply/delete/edit/patch/scale, helm install/upgrade/rollback, tofu destroy, tofu state rm|mv|push|pull|show, git commit|push --no-verify and SKIP=, ansible-vault view/decrypt/edit, kubeseal --recovery-unseal, reading vault password files, private keys, .tfstate or Secret objects.

Secrets

Agents never decrypt Ansible Vault or Sealed Secrets and never read the material that would. Stage sessions use a kubeconfig bound to the built-in view ClusterRole (which excludes Secrets) plus a read-only aggregated role for SealedSecret objects. Ansible stage work runs only what succeeds with a placeholder vault password (--syntax-check, ansible-lint, inventory reads). A real --check --diff before merge is reopened: check mode still runs PR-controlled code (lookups, delegate_to: localhost, check_mode: false tasks, plugins) with the production credentials, so running it in CI on a bot PR hands the bot those credentials. Decided in Pre-merge Ansible dry run without exposing production credentials.

Enforcement layers

  1. Skill instructions name each command's tier.
  2. delivery ships one portable guard hook: deny the Never tier everywhere; ask for odd-job commands where the runtime supports ask (Claude Code, Copilot CLI), deny them elsewhere.
  3. Host permission settings are documented, not shipped.
  4. Credential boundary in each consuming repo — the real control:
    • agents act as a dedicated Gitea bot user;
    • branch protection: approvals allowlist of humans only, dismiss stale approvals, bot off the merge allowlist, protected file patterns for agent config, AGENTS.md and CI workflows; test paths stay out, because protecting them would block the test author's own commits;
    • every PR carries the dry run as a required status and a PR comment; apply happens after merge. Flux's is an offline rendered diff of base and head that holds no cluster credential; a live flux diff needs write RBAC, because Kubernetes authorises dry-run requests like real ones, so it is not used. Ansible's pre-merge --check --diff is reopened (see Secrets); later tofu plan;
    • in step mode (v1) the human launching a stage is the approval, and stage leads check gate state only: the stage's gate label, if it has one, is present, and for verify the PR is merged with a non-stale, non-dismissed approval by a user on the human allowlist in docs/agents/delivery.md. The who-set-the-label check moves to the run-mode launcher, which checks the triggering event's sender against the allowlist before starting an agent; it is deterministic, so it belongs in the workflow, not an agent;
    • a CI test-path check, run from main's copy, fails if a commit after the test author's (trailer Delivery-Stage: test-author) touches the globs in .gitea/test-paths; this check, not file protection, guards tests. The implementer hands disputed tests back instead of editing them.
  5. Pre-commit and CI in the consuming repo are the deterministic backstop.

Considered Options

  • Agent drafts odd jobs, human runs them (no agent ever holds apply credentials): rejected by the owner in favour of agent-run odd jobs in HITL sessions with per-command ask.
  • Gated vault-touching check runs, or a scoped vault credential for agents: rejected — moving --check --diff to CI removes the conflict without loosening the read rule.
  • Apply before merge (Atlantis model): rejected — Gitea has no native support; merge-then-apply with the dry run as a required check is the existing pattern in the reference repo.
  • A deny hook on test paths: rejected for v1 — a repo-wide hook cannot portably tell the test author from the implementer, and misses edits made through the shell.
  • PATH wrapper scripts: rejected — trivially bypassed.

Consequences

  • Most of the safety model is setup in each consuming repo, not code in these packages; it is documented there (docs/agents/delivery.md) and checked before the destination test.
  • Accepted risk: odd jobs leave no durable record beyond the session itself. This departs from the governance rule to log agent actions in reviewable form; the owner accepted it.
  • Accepted risk: an odd-job session holds apply credentials; its safety rests on the human starting it, keeping untrusted text out of it, and answering each ask.
  • Headless sessions running repo-controlled config are not addressed here; launching from pinned config is part of run mode.
  • Accepted risk: agent sessions run as root on the dev box until Agent unix user for delivery sessions is done. Root can read the vault password, the host SSH key and the admin kubeconfig, so on that machine the credential boundary is a guardrail only. Partial mitigation: delivery sessions export KUBECONFIG to a read-only kubeconfig, so accidental cluster writes fail.
  • Accepted risk: same-repo branches reach repo secrets. The bot (the existing Claude Gitea user) pushes same-repo branches; Gitea runs a pull_request workflow from the PR branch's own copy and gives same-repo PRs the repo secrets, so a bot branch can read them. Protected file patterns block the merge, not the run.
  • Accepted risk: Copilot CLI's TUI auto-approves a hook ask (github/copilot-cli#3590, open since v1.0.53), so on Copilot an odd-job ask may run without a human answer. The owner kept ask on Copilot rather than deny; Copilot is untested in v1 and the credential boundary still holds.
  • The guard hook (plugins/delivery/.apm/hooks/guard.py) also checks file-tool paths (Read, Grep, Edit, Write, Copilot's view, Codex's apply_patch) against the secret-path globs, not only shell commands. kubectl, helm, flux and tofu are allowlists of subcommands that change no cluster or state and print no secret: anything not on the list is denied, so an unlisted mutating subcommand fails safe. Codex cannot ask, so odd jobs are denied there; an unrecognised runtime is treated the same way.
  • Amended 2026-11-23 (delivery-handoff skill): stage leads check gate state only and the who-set-the-label check moved to the run-mode launcher, because gitea-mcp v1.13.0 has no timeline method, the timeline needs a token on private repos, and in step mode the human already launches each stage.
  • Amended 2026-11-23 (delivery guard hook): Copilot ask kept as an accepted risk; the guard covers file tools and uses read-verb allowlists.
  • Amended 2026-11-22 (Credential boundary setup in ansible-homelab-mono): test paths left the protected file patterns for the test-path check; the Flux dry run became an offline render, and live kubectl diff left the Read tier; the CI --check --diff, and with it the rejection of gated vault-touching check runs, were reopened; the root-session and same-repo-branch risks were accepted.