AGENT SKILL

approval-gate-debugging

Use when a command is flagged as a security issue.

License 许可
MIT
最近更新
2026-11-14
Stars
★ 4
Forks
1

01 前言 Front Matter

name
approval-gate-debugging
author
Steadfaste Fleet
license
MIT
version
1.0.0
metadata
{ "hermes": { "tags": [ "approval", "tirith", "security-scan", "smart-approval", "terminal-gate", "path-shadowing" ], "related_skills": [ "root-cause-debugging", "fleet-deployment-sync", "file-ownership-boundaries" ] } }
platforms
[ "linux", "macos" ]
description
Use when a command is flagged as a security issue.

03 SKILL.md 正文

Approval Gate Debugging — Terminal Security-Scan False Blocks

When to Use

  • A terminal command is flagged: Command was flagged (Security scan: security issue detected ...)
  • A sanctioned command (e.g. bash ~/steadfaste-fleet/ops/scripts/fleet-update.sh) still prompts for user approval
  • Smart-approval escalates a routine command to the user, and the approval times out → deny
  • Any command that used to run clean suddenly needs approval

Core principle (user-corrected 2026-08-05): an approval flag on a legitimate or sanctioned command is a diagnostic signal — investigate the underlying scanner/guard BEFORE whitelisting anything. Adding a command_allowlist entry to silence a flag you don't understand masks the defect and leaves every other command still broken.

The Two-Gate Model

Terminal commands pass TWO independent gates:

  1. Governance enforcer (Steadfaste Fleet plugin) — governance-lock check. The sanctioned fleet-update.sh invocation passes this without a lock.
  2. Hermes smart approval (tools/approval.py) — two sub-layers:
    • Regex detect_dangerous_command() — pattern matching (curl|sh, rm -rf, gateway restart, etc.)
    • Tirith security scanner — tools/tirith_security.py → external binary check --json --non-interactive --shell posix -- <command>

The enforcer sanction does NOT bypass gate 2. A block you see almost always comes from gate 2.

The Degraded-Message Tell

"security issue detected (details unavailable)" is the degraded summary. Per tirith_security.py (~lines 836-840), that exact string is emitted when Tirith's JSON output fails to parse — i.e. the scanner binary crashed, printed garbage, or produced no JSON at all. It does NOT mean a real security finding. Real findings come back as structured JSON with findings: [...].

Rule: details unavailable ⇒ the scanner is broken ⇒ debug the scanner, do not approve/allowlist the command.

Diagnosis Recipe

# 1. Regex layer passes?
from tools.approval import detect_dangerous_command
detect_dangerous_command("bash ~/steadfaste-fleet/ops/scripts/fleet-update.sh")
# → (False, None, None)  — regex layer is NOT the blocker

# 2. Tirith layer blocks?
from tools.tirith_security import check_command_security
check_command_security("bash ~/steadfaste-fleet/ops/scripts/fleet-update.sh")
# → {"action": "block", "summary": "security issue detected (details unavailable)"}

# 3. Which binary is resolved? PATH-shadowing check
import shutil; print(shutil.which("tirith"))
# If this is venv/bin/tirith → a same-named PyPI package is shadowing the real scanner

# 4. Run the resolved binary directly to see the crash
# (it ignores args, prints banner, then a traceback — e.g. socket.gaierror)

PATH-Shadowing Failure Mode (root cause found 2026-08-05)

The real Tirith scanner is a compiled ELF from sheeki03/tirith GitHub releases, installed at ~/.hermes/bin/tirith. But the hermes-agent venv had a PyPI package tirith 0.2.2 (github.com/utfsmlabs/tirith — unrelated "Monitoring software", a WAMP client hardcoded to ws://frameshift:8080/ws, the original author's LAN hostname) installed at venv/bin/tirith. Because venv/bin is FIRST on PATH, shutil.which("tirith") resolved to the bogus binary. It ignores check --json ... args, prints tirith monitor 0.2.2 / connecting, crashes on DNS resolution, exits 1 → Hermes maps exit 1 → block → degraded summary.

Consequence: EVERY terminal command was being "scanned" by the crashing demo. The smart-approval LLM auto-approved most silently; commands with sudo/chattr/systemctl (like fleet-update.sh) got escalated to the user → approval timeout → deny.

Detection

~/.hermes/hermes-agent/venv/bin/pip show tirith
# → Name: tirith, Version: 0.2.2, Summary: Monitoring software, Home-page: github.com/utfsmlabs/tirith

Fix (root cause)

~/.hermes/hermes-agent/venv/bin/pip uninstall -y tirith   # nothing depends on it
# verify:
#   shutil.which("tirith") → ~/.hermes/bin/tirith
#   check_command_security(cmd) → {"action": "allow"}

A gateway restart clears the in-memory cached scanner path (deploy ≠ load applies to the scanner too).

What NOT to Do

  • ❌ Do NOT add the command to command_allowlist in config.yaml to silence the flag. The allowlist short-circuits the entire approval gate for that command while the broken scanner keeps silently flagging everything else. (User: "There is an underlying reason the problem exists in the first place and you are masking it.")
  • ❌ Do NOT set approvals.mode: off — kills all protection, not just the broken path.
  • ❌ Do NOT patch tools/tirith_security.py or tools/approval.py — upstream hermes-agent product code, reverted on next update, and the user forbids patching the guard.
  • ❌ Do NOT try to "fix" the prompt by removing gateway runtime env vars. HERMES_EXEC_ASK, HERMES_GATEWAY_SESSION, HERMES_INTERACTIVE, _HERMES_GATEWAY are exported by the RUNNING GATEWAY (gateway/run.py, tui_gateway/server.py::_enable_gateway_prompts()), not by config — nothing to unset, and doing so breaks approval routing. (User: "DO NOT CHANGE HERMES DEFAULTS OR YOU WILL BE RESET", 2026-08-05.)
  • ✅ DO run the resolved binary directly and read its output before deciding anything.

An escalated command that times out: STOP, do not route around it

Two different blocks wear similar clothes — tell them apart before acting:

Block Meaning Response
security issue detected (details unavailable) the SCANNER crashed — no real finding debug the scanner (above)
escalation that ended in a timeout (... did not run, Do NOT retry, Silence is not consent) a REAL approval request nobody answered stop the workflow; change the design or ask
Your command was treated as WRITE-CAPABLE ... requires an active governance lock the GOVERNANCE ENFORCER (gate 1), not the approval gate — it classifies by SHAPE split the command; do not rephrase it

The shape-classifier is a third, unrelated block. The enforcer allows a compound only when EVERY segment is a read primitive, so a harmless inspection stack (git status --porcelain && git log --oneline -3 && echo done) is refused while the same reads run fine one at a time. A redirection, a $( ), a pipe into a write, or an interpreter form (python3 <repo>/script.py — the allowlist never covers interpreter reads) tips a read into write-class. Remedies, in order: run a single plain command per call (a lone git push is the canonical case — the push carve-out authorises exactly that shape and nothing compound); give the session a RESOLVED GOVERNED REPO before any interpreter read — take the lock deliberately (begin_change) and close the cycle — because the deployed copy's LOCATION does not help: python3 <script> is write-class wherever the script lives, and a non-governed cwd such as ~ is refused with No governed repo could be resolved for this call (~/.steadfaste-fleet has no .git, checked 2026-10-25), which is not the lock rule;

The label is the classifier's claim, not a fact about your command: a read-only capture can come back labelled as a destructive one (an evidence run flagged SQL TRUNCATE). Do not reshape a legitimate read to fit a label that misdescribed it, and do not read the label as evidence the command was dangerous. Ask for the go-ahead — an explicit user "go" is what releases it — and when the same benign shape keeps tripping the classifier, report it as a classifier defect instead of pre-emptively rewriting every future call around a label you know is wrong.

  • A metacharacter INSIDE QUOTES still splits segments. The classifier tokenizes on shell metacharacters without regard to quoting, so an alternation bar inside a pattern (grep -E "learning|lesson", any |-joined regex) reads as a pipe and tips the whole compound write-class — even when every segment is a plain read. Rewrite the pattern as repeated flags (grep -E -e learning -e lesson) rather than taking a lock to inspect something; the same trap hides inside quoted >/<, $( ) and &&-free strings you thought were literal text. A primitive the classifier does not yet recognise (a read builtin it lacks) is a classifier gap to report, not a command to rephrase.

When the fix belongs in the CLASSIFIER, not the command

The triggers above are caller-side workarounds. There is a second case where rephrasing is the wrong answer: a read-only subcommand of a CLI the agent is required to run is classified write-class, and the caller cannot take a lock — an unattended/cron session, or a cwd with no governed repo. Then the work is impossible rather than merely awkward, and that impossibility is the signal the rule is wrong.

Remedy: add the read subcommands to the enforcer's read-only allowlist (READONLY_COMMAND_PATTERNS in plugins/governance-enforcer/__init__.py). The precedent is in the list itself — hermes mcp list|test was added because the diagnostic path for a broken loop-governance server was unreachable without it. Match the existing entries' shape:

  • Subcommand-SCOPED, never the whole CLI. r"^\s*(tool)\s+(list|search|stats|doctor)\b". An entry like ^\s*(tool)\b admits that CLI's sync, add, remove and store as well — a read widening is defensible, a write widening is not.
  • Let the mutations stay refused BY CONSTRUCTION (they simply do not match), and say so in the comment so the next reader knows it was deliberate.
  • Pin BOTH directions in a test that imports the SHIPPED predicate — never a re-implementation. Assert the read shapes are read-only AND the mutating siblings plus any compound mixing a read with a write stay write-class. A test that only proves the reads became read-only passes just as happily against an allowlist widened to the entire CLI, so it is not a check.
  • Probe the classification directly instead of guessing — importlib.util.spec_from_file_location the enforcer source and call _is_readonly_terminal_command("<cmd>"). That answers "is this the classifier's doing?" in one step, rather than inferring it from a refusal message.

Two mechanics this class of change always hits, because the enforcer is enforcement code:

  • Edit the REPO source, then deploy. The enforcer files are immutable and the deployed copy is overwritten by the next update; fleet-update.sh owns unlock → copy → relock. Hand-editing ~/.hermes/plugins/... looks like it worked and is erased later.
  • Deploy ≠ loaded for a plugin. The enforcer module is imported at GATEWAY START, so a classifier change is inert until the gateway restarts — and the deploy's own reload line names only hooks. Compare the gateway's start time against the enforcer file's mtime to state which of the two you are holding, label a not-yet-loaded fix as PENDING rather than PASS in any evidence artifact, and give the operator the one command (systemctl --user restart hermes-gateway.service) — agents cannot restart the gateway themselves.

A timeout is not a failed attempt to try harder. The gate's own words — do not retry the command, do not rephrase it, do not reach the same outcome by another route — are the instruction, and re-issuing it with different quoting to slip past classification is exactly the behaviour it forbids. Treat it as a consent boundary: an unattended or unanswered escalation defaults to no-op.

  • Ask, or remove the need. Either put the question to the user, or change the design so the tainted action is not required — do not keep the same outcome in the plan. Before asking, ask what the destruction was FOR: a blocked cleanup is usually avoidable rather than forbidden. Reusing one scratch path and rm -rf-ing it between runs needs consent every time; writing to a FRESH uniquely-named directory per run needs none, and an append-only capture (>>) needs none where truncate-and-replace (head -n N file > tmp; mv tmp file) would trip the gate. The gate objecting to an action is a design signal about the action, and the cheapest fix is often to stop wanting it — not to obtain permission for it.
  • Nested shell-in-shell reads as write-class. A quoted bash -c "..." whose payload runs an installer or a redirect cannot be classified from the outer command, so it escalates rather than running. Restructure into a plain single-purpose invocation, or better, drop it (below).
  • A blocked action inside a CHECK is a design signal, not just a blocker. If a verifier or report step is what tripped the gate, the shape is wrong: a check that installs, migrates or reconfigures what it inspects reports on a state it just changed. Split it — run the operation once as a recorded manual step, and have the check assert the resulting state read-only (versions, an import, a count). The same split removes the need for the blocked command, so the gate never comes up again.
  • Never present a blocked command's absence as a pass. If the work genuinely needs it and you cannot get consent, say so and stop — a silent skip that reads as green is the failure the gate exists to prevent.

Survey Before Acting (user correction 2026-08-05)

When the user reports a problem like this ("you never need my permission to update fleet" / "why are you blocked"), the FIRST action is a survey — not a fix attempt. This session's sequence that got corrected:

  1. Diagnosed the two-gate model, found the shadow — good.
  2. Jumped straight to an env-var "fix" (HERMES_EXEC_ASK=1) without loading the always-skills (survey-before-action was still unloaded) and without surveying where the variable actually comes from.
  3. User: "you should survey before action actually. ALWAYS" — then "DO NOT CHANGE HERMES DEFAULTS OR YOU WILL BE RESET."

Rule: any investigation that may end in a config/env/system change starts with the full always-skill set loaded and a survey of the change surface (who sets the value, what reads it, what breaks if it changes) BEFORE proposing or making any edit. When the user pushes back on a fix, the correction is a signal to survey deeper, not to act faster.

Verification Checklist

  • [ ] detect_dangerous_command(cmd) returns (False, None, None) (regex layer clean)
  • [ ] shutil.which("tirith") resolves to the real binary, not venv/bin/tirith
  • [ ] check_command_security(cmd) returns action: allow
  • [ ] The original command runs with no security flag and no approval prompt
  • [ ] No command_allowlist entries were added to work around the scanner

References

  • references/tirith-shadow-2026-08-05.md — full evidence chain: degraded-message code path, binary crash traceback, package metadata, PATH resolution order, fix + verification

04 同仓库更多 Skills