Skip to content

fix(hooks): let deny rules reach kiro-cli's write and shell stamps - #18663

Closed
billyae wants to merge 1 commit into
kirodotdev:mainfrom
billyae:fix/host-builtin-alias-deny-rules
Closed

billyae wants to merge 1 commit into
kirodotdev:mainfrom
billyae:fix/host-builtin-alias-deny-rules

Conversation

@billyae

@billyae billyae commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A rule or governance profile written in Kiro Crew's own tool spelling reaches the matching kiro-cli built-in, whichever short name kiro-cli stamps on the call: a deny in either spelling refuses it, and an allow-mode profile in either spelling admits a provenance-verified stamp.

auto_deny_tools: ["fs_write"] does nothing on the kiro-cli backend. kiro-cli stamps its file-write built-in write, its shell shell and its file reader read (_meta.kiro.toolName), while rules, governance tools scopes and the read-only allowlist are spelled fs_write, execute_bash, fs_read. The deny tier compares the stamp letter for letter, so a rule spelled fs_write or execute_bash never matches. Only read was translated.

Why it matters

A "never write files" or "never run commands" rule that silently fails to fire is a security setting that does not work, on the default backend, with nothing unusual needed to hit it. The side chat's READ_ONLY proof already resolves read; the deny tier that runs before it must see the same name or the operator loses the only control that runs before any approval.

Not a goal

What changed (motivation → approach → change)

Piece What it does now
platform/tool_names.py KIRO_TOOL_ALIASES the three kiro-cli stamps -> spec spelling (shell->execute_bash, read->fs_read, write->fs_write); moved here so the gate reads the same table without crossing the agent-SDK boundary
acp/kas_permissions.py imports KIRO_TOOL_ALIASES from the leaf instead of defining it; same name, same value, same readers
hooks.py imports the table from the leaf; the hooks-side copy _HOST_READ_ONLY_BUILTIN_ALIASES is gone
hook_runtime/tool_identity.py _host_builtin_alias the one helper that resolves a stamp, "" for an MCP-served call or a stamp with no alias
hook_runtime/gate_tiers.py deny targets and governance query deny targets append the resolved name (a deny target can only deny); governance asks a trusted stamp and its spec spelling as one alias_groups entry, the shape #17280 uses for KAS ids, so an allow-mode profile in either spelling admits the call and a deny on either refuses it; an unverified stamp is asked on its own name with the alias in deny_aliases; the KAS branch from #17280 is untouched
read-only proof calls the same helper first, then #17280's KAS fold as before; the allowlist still decides what it may admit

The symptom: a deny rule in the spec spelling misses a short stamp. The root cause: the hooks-side alias table carried only read, and each consumer read it through its own copy of the server guard. The change: one table with all three stamps, owned by the stdlib-only leaf both the KAS projection and the gate already import, and one helper every consumer calls, so the deny tier, governance and the proof cannot disagree about which built-in a stamp names. Governance is asked the two spellings as one identity rather than two required items: on main, a read stamp beside fs_read as separate extra_titles meant an allow-mode profile written in either spelling refused it, since the other spelling was never listed. The read-only proof still admits only fs_read, glob, grep, web_fetch and web_search: write resolves to fs_write and shell to execute_bash, neither of which is on that list, so both are refused exactly as before. A server's own tool called read or write gets no alias. docs/system-specs/modules/side.md and memory-skills-hooks.md name the helper and the table's owner.

Backwards compatibility

Compatible for deny rules: every call a deny rule or deny-mode profile refused on main is refused here, and the only new denials are by a rule the operator already wrote in the spec spelling. Allow-mode profiles change in one direction only: a trusted read stamp that main refused under a tools: [..., "fs_read"] or tools: [..., "read"] allow set is now admitted, because the two spellings are one alias group; write and shell under tools: [..., "write"] / [..., "shell"] are admitted as on main, and now also under the spec spelling. acp.kas_permissions.KIRO_TOOL_ALIASES keeps its name and value (imported from the leaf, so kas_permissions.KIRO_TOOL_ALIASES still resolves for acp/harness_tool_names.py and the tests that read it there). hooks._HOST_READ_ONLY_BUILTIN_ALIASES is removed; it had no reader outside hooks.py, hook_runtime/ and test/.

Tests

  • test_hooks.py::TestClassifierOnlyHostTrustedProof: every alias resolves to a governed built-in; read is proven read-only; write/shell resolve outside the allowlist and are not proven; the helper gives "" for a server-backed read and for an unaliased stamp.
  • test_hooks.py::TestBuiltinToolIdentityGoverned, parametrized over the three stamps: a rule in the spec spelling denies the stamp at the deny floor (interactive and classifier_only) and on the governance plane; a server's tool under the same short name is not denied and never appears as the built-in; a trusted stamp reaches governance as one alias group and an unverified one as its own name plus a deny-only alias; end to end through the real gate_decision, an allow-mode profile in either spelling admits a trusted stamp, one naming neither refuses it and reports the spec spelling, a deny on either spelling refuses it, and the spec spelling cannot admit an unverified stamp.
  • test_llm_helpers_tool_gate.py: end to end, the rule's security deny is what the caller sees -- read under READ_ONLY, write and shell under HOOK_BASED, where without the rule the same calls auto-approve.

With the table shrunk back to {"read": "fs_read"}, exactly the six write/shell cases fail (deny floor, governance, end to end; two stamps each).

Manual verification

N/A — unit coverage sufficient: the gate is exercised through HookManager.on_tool_call and stream_and_collect, the same entry points the live surfaces use.

Related Issues

Fixes #18662

Pattern harvest

Rule candidate: review-prompt
Pattern: a name translated for one consumer of a shared identity (the approve path) but not for the consumers that run before it (deny, governance)

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@billyae
billyae requested review from a team and KiroCrewCaptain as code owners October 9, 2026 23:30
@billyae
billyae requested a review from buluoray October 9, 2026 23:30
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision dc19e44d63b361d4aeeb2cfff79c02d9d44fdaa2 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of dc19e44d63b361d4aeeb2cfff79c02d9d44fdaa2 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Check one thing before merge: an allow-mode profile listing fs_read now admits a trusted read stamp that main refused, so governance admits more calls.

What this change ships

Inventory (7 items) — 7 justified

Intent: make an operator's deny rule or governance profile, written in Kiro Crew's spelling (fs_write, execute_bash, fs_read), apply to the short names kiro-cli stamps on its built-ins (write, shell, read). FIX (#18662).

  1. A deny rule spelled fs_write or execute_bash now refuses kiro-cli's write or shell call, at the deny floor and on the governance plane — justified
  2. An allow-mode profile in either spelling admits a provenance-verified short stamp (for read, a widening from main) — justified
  3. An unverified stamp is still asked under its own name, and its alias can only deny — justified
  4. The alias table moves to the stdlib-only platform/tool_names.py; the hooks copy _HOST_READ_ONLY_BUILTIN_ALIASES is deleted — justified
  5. A new helper, _host_builtin_alias, resolves stamps for three callers: the deny targets, governance and the read-only proof — justified
  6. The deleted join test (test_host_read_only_aliases_agree_with_kiro_tool_aliases) was only needed while two tables existed; the rule it guarded, that write/shell are never proven read-only, is still pinned by test_kiro_cli_short_write_and_shell_names_are_not_read_only_proofs — justified
  7. The spec rows in side.md and memory-skills-hooks.md now name the helper and where the table lives — justified

[FIRST-PRINCIPLES-REVIEWED] dc19e44

Description read

[DESCRIPTION-READ] 3f5ef3a70821a5fb0437a23ee066e088c74874d6f659f87f367bd95dfd1ba0a9

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of dc19e44d63b361d4aeeb2cfff79c02d9d44fdaa2 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] dc19e44

Description read

[DESCRIPTION-READ] 716c144579b1403a59b56bc85f37f1d858d5c76ee0b56af8007649cb1c2df30d

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 10, 2026
@billyae
billyae force-pushed the fix/host-builtin-alias-deny-rules branch from e4fcb31 to 6d7d9a5 Compare October 12, 2026 02:12
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed dc19e44d63b361d4aeeb2cfff79c02d9d44fdaa2 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] dc19e44

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — 🟡 CONCERNS

Which legitimate operations does dc19e44d63b361d4aeeb2cfff79c02d9d44fdaa2 newly refuse? Model proposes, scripts/deny_diff.py decides — updated in place on each push. A script-confirmed regression blocks PR readiness.

the reviewer's own judgement; no confirmed regression

Scope-Verdict: CONCERNS

TIGHTENING: Tool-identity alias resolution in the deny-target and governance tiers. It moves from the read-only {"read": "fs_read"} table to the full KIRO_TOOL_ALIASES (shell→execute_bash, read→fs_read, write→fs_write) through _host_builtin_alias. The threat it refuses is an operator deny written in the spec spelling (auto_deny_tools=["fs_write"], a governance tools deny on execute_bash) that does nothing against kiro-cli's short write/shell stamps. The hunk is gate_tiers.py GateFacts deny targets: alias = _host_builtin_alias(call.mcp_tool, call.mcp_server) / if alias and alias not in targets: targets.append(alias). The same hunk in _tier_governance adds elif alias and call.identity_trusted: alias_groups = ((call.mcp_tool, alias),) and, for unverified stamps, if alias: deny_aliases = (alias,).

ADJUDICATED: 13 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: I wrote posix rows (bash-wrapped status check, cat/grep/git diff reads, the posix pytest invocation, a printf commit-message write, a python3 -c import check), windows rows (type and Get-Content with \ separators, an rg search over a backslash path, .venv\Scripts\python.exe pytest, Set-Content to $env:TEMP\…) and one any row (kirocrew logs --tail 200). The diff assumes no path, separator, interpreter or env-var spelling. Its only new assumption is the kiro-cli stamp vocabulary (read/write/shell with an empty mcpServerName), which is the same on every host. So the windows rows only check that nothing host-specific came in; they do not cover a platform gap. These rows cannot flip, because scripts/deny_diff.py _worker_main calls security.<tier>(command) on the command string alone, and this patch touches no kiro_crew.security module. The empty adjudicated set therefore says nothing either way about this tightening.

UNADJUDICATED:

  • Guard: the deny-rules target list (GateFacts deny targets in src/kiro_crew/hook_runtime/gate_tiers.py) and the governance query (_tier_governance → _governance_denial with alias_groups / extra_titles / deny_aliases). Both are keyed on tool identity, not on shell command text, so the classifier never reaches them.
  • Call path: ACP tool_call frame → AcpEvent (tool_name from _meta.kiro.toolName, mcp_server_name, mcp_identity_trusted) → ToolCall.from_event → HookManager.on_tool_call → GateFacts deny targets (now with fs_write or execute_bash appended for a server-less write/shell stamp) → the auto_deny_tools / denied-commands regex set and _tier_governance.
  • Narrowing I can argue but not confirm: at base, an UNVERIFIED (mcp_identity_trusted=False) server-less read stamp was asked under fs_read as an admitting identity. At head that alias is only in deny_aliases. So an allow-mode governance profile written tools: allow [<title>, "fs_read"] now refuses an unverified read call that base admitted. The PR's own test asserts this (with_profile(ScopedRuleset(MODE_ALLOW, ("Do the thing", rule))); assert call(trusted=False).action == TOOL_DENY, parametrized over read). It hits hand-built or inline-payload events and any surface that doesn't set mcp_identity_trusted: test doubles, provider events, and the auto-improvement runner's overridden kwargs. Whether those surfaces carry real read traffic under a fs_read-only allow profile is the open question. If it matters, the narrowest fix is to keep fs_read admitting for the unverified read stamp only, since base already admitted it there and write/shell never had it. write/shell would stay deny-only.
  • Side effect of the trusted branch: a trusted stamp with an alias now gets alias_groups=((stamp, alias),) and is no longer asked call.harness_builtin_tool. Only claude-agent-acp frames set that field, and those don't carry kiro short stamps, so I expect no loss, but nothing measured it.
  • Inputs I would have submitted to the identity gate (none can be expressed as a shell command line):
    • a trusted write stamp with title "Update the changelog" under an allow profile naming only write;
    • a trusted shell stamp running git status --porcelain under an allow profile naming only shell;
    • an unverified read stamp under an allow profile naming fs_read;
    • a server-qualified docs/read or docs/write tool under auto_deny_tools=["fs_write"] (must stay allowed);
    • a trusted shell stamp running a benign command under a denied-commands regex catalog. A broad user rule that matches the bare string execute_bash would now refuse every kiro-cli shell call. I found no built-in rule in src/kiro_crew/security that matches fs_write or execute_bash as a target, so this risk only comes from operator-authored rules.

[SCOPE-REVIEWED] dc19e44

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 8 classified, 0 newly refused, 8 still allowed.
  • ubuntu-latest (platform posix): 8 classified, 0 newly refused, 8 still allowed.
  • windows-latest (platform windows): 6 classified, 0 newly refused, 6 still allowed.

No candidate flipped from allowed to refused.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed dc19e44d63b361d4aeeb2cfff79c02d9d44fdaa2 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] dc19e44

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision labels Oct 12, 2026
@billyae

billyae commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

rebutted

  • Item 3 — oversized: allow-mode admission rides along with the deny fix span=294533fc82a3

Outcome: the code stays; the PR body's Goal now names both planes ("a deny in either spelling refuses it, and an allow-mode profile in either spelling admits a provenance-verified stamp"), the second of the two clearing conditions, taken by the author.
The admission change is the same defect on the same table, not a second feature: on main a trusted read stamp reached governance beside fs_read as two required extra_titles, so an allow-mode profile in either spelling refused it; write and shell were never resolved, so a profile written in the documented spelling (fs_write, execute_bash) refuses every kiro-cli write and shell call today.
A provenance-verified stamp and its spec spelling are one identity, asked the way #17280 asks a KAS id (alias_groups). The proposed subtraction (identity = (call.mcp_tool,) plus deny_aliases = (alias,)) would keep spec-spelled allow profiles refusing those calls and split the governance shape between the two backends.
Unverified stamps already have exactly the subtraction's shape (deny_aliases only), so a name the model could influence cannot admit anything.
Pinned by test_an_allow_mode_profile_in_either_spelling_admits_a_trusted_stamp and test_an_aliased_stamp_is_one_identity_in_two_spellings; the Backwards compatibility section states the one-direction change.

self-added: no

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Oct 12, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

This moves KIRO_TOOL_ALIASES (shell->execute_bash, read->fs_read, write->fs_write) into the stdlib leaf platform/tool_names.py. One helper, _host_builtin_alias, now feeds the deny targets, governance and the read-only proof, so auto_deny_tools: ["fs_write"] or ["execute_bash"] finally fires on kiro-cli's short stamps. That fixes the root cause rather than one consumer. I tried to break it. An MCP server's own tool named write or read gets no alias, because mcpServerName is set. An unverified stamp is asked on its own name and its alias can only deny. The read-only allowlist is unchanged, so write and shell stay unproven. The one widening (a trusted stamp now passes an allow-mode profile written in the spec spelling) is the correct reading of the operator's profile, and it needs provenance. I found no defect, and the Opus and GPT lanes have no findings. The blocker is procedural: Sensitive Change Review fails on head 6d7d9a5. The gate reports that a fork PR changing gate_tiers.py, tool_identity.py and hooks.py cannot pass it, and that a maintainer has to take it over on a branch of this repository (Co-authored-by the author, Supersedes #18663), run the sandbox, and drive that PR green. A maintainer needs to do that takeover. — crew-pr-reviewer (deep re-check)

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 14, 2026
kiro-cli stamps its three built-ins `read`, `write` and `shell` where an
operator's `auto_deny_tools` and a governance `tools` rule are written
`fs_read`, `fs_write` and `execute_bash`. The gate compared the stamp as
stamped, so a rule in the spec spelling never fired on `write` or `shell`;
only `read` was translated, for the side chat's read-only proof.

Move `KIRO_TOOL_ALIASES` into the stdlib-only `platform.tool_names` leaf
(the ACP projection imports it from there under its old name) and resolve
a stamp through one helper, `_host_builtin_alias`, for the deny tier,
governance and the read-only proof. Governance is asked a trusted stamp
and its spec spelling as one alias group, so an allow-mode profile in
either spelling admits the call and a deny on either refuses it; an
unverified stamp keeps its own name and the alias may only deny. The
proof's allowlist is unchanged, so `write` and `shell` resolve to names
it does not hold and stay unproven.

Fixes kirodotdev#18662
@billyae
billyae force-pushed the fix/host-builtin-alias-deny-rules branch 2 times, most recently from 6d7d9a5 to dc19e44 Compare October 14, 2026 17:50
@github-actions github-actions Bot removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: passed Eligible automated validation passed for the current revision labels Oct 14, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Oct 14, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you, @billyae, for this fix and for the careful write-up.

The Sensitive Change Review gate cannot pass on a fork PR that touches gate_tiers.py, tool_identity.py and hooks.py, so a maintainer carried it onto a same-repo branch: #21761. Your commit is cherry-picked with your authorship kept, rebased onto current main (merged beside main's new deepseek alias path). All checks are green there.

I'm closing this one in favor of #21761. Your branch is left as is. All credit for the fix stays with you.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auto_deny_tools written as fs_write / execute_bash does not fire on kiro-cli's write / shell stamps

2 participants