Skip to content

feat(permissions): map crush bash pattern rules to safe_commands and blocked_commands - #3818

Merged
dyoshikawa merged 6 commits into
mainfrom
resolve-issue-3672-crush-command-permissions
Nov 8, 2026
Merged

dyoshikawa merged 6 commits into
mainfrom
resolve-issue-3672-crush-command-permissions

Conversation

@dyoshikawa

@dyoshikawa dyoshikawa commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

Crush v0.100.0 (stable, 2026-11-05) added permissions.safe_commands and permissions.blocked_commands. Until now rulesync skipped every canonical bash pattern rule for Crush. This PR maps those rules onto the two new keys, on generate and import, but only where the semantics match. No deny/ask is ever widened.

How Crush v0.100.0 behaves (checked in config.go, tools/bash.go, tools/safe.go, shell/{shell,wrappers}.go):

  • safe_commands: Crush skips the prompt only for the exact tokens of an entry, with no extra arguments and no flags. It resolves wrappers first (env, nohup, nice, timeout; wrapper names are normalized, and time is judged by what it wraps). A trailing -- still matches. Compositions of safe lines are approved too.
  • blocked_commands: adds normalized names to the dangerous list.
    • A direct invocation is still prompted for, and runs unprompted in yolo mode or with bash in allowed_tools.
    • On the paths Crush does not prompt for (its read-only commands and safe_commands) the block list is enforced at exec time, so those forms are refused. Indirect invocations are refused too.
  • allowed_commands: only drops names from the dangerous list. Those commands still prompt, so it is not an allow.

Changes

  • Generate
    • allow on a literal command line → safe_commands. The line can have no wildcards, quoting or shell syntax, no leading wrapper, and its command name must be in normalized form. The line is withheld, with a warning, when any canonical deny/ask (from bash or *) overlaps a command Crush would approve through it:
      • the line itself, or the line followed by --…
      • the line behind a wrapper or time, including a wrapper spelled with an absolute path or in another case (/usr/bin/env, NICE)
    • deny on <name> / <name> * → blocked_commands. This is the strictest Crush can express, but it is not a full deny, so it comes with a warning. It is withheld, with a warning, when <name> is the command of a written safe line, because Crush would refuse that line.
    • Pattern ask is skipped with a warning. Writing it to blocked_commands would refuse git status-style read-only forms instead of prompting for them.
    • Wildcard allow rules and other patterns are skipped, as before.
  • Existing entries
    • All existing blocked_commands entries are kept, because rulesync can't tell its own entries from hand-written ones.
    • An existing safe_commands entry is dropped (with a warning) when a canonical restriction covers it, or when it can't be read exactly and the config restricts anything.
    • allowed_commands is never touched.
    • The twin-file leftover warning now covers the new keys.
  • Import
    • safe_commands entry → bash allow for the exact line. The command name is normalized; entries with wildcards, shell syntax or wrappers are skipped with a warning.
    • blocked_commands entry → deny for <name> and <name> *. This round-trips the generate mapping, and ask would read looser than Crush's refusal.
    • Side effect: regenerating a config imported with bash in allowed_tools plus blocked names no longer writes bash to allowed_tools. That is the fail-closed direction, and it is documented.
  • Docs: updated the Crush permissions note in docs/reference/file-formats.md, including the composition caveat, and regenerated docs-content.ts.
  • Compatibility: older Crush versions decode the config with plain json.Unmarshal, so they ignore the new keys.

Verification

  • Unit tests cover:
    • the mapping
    • the overlap guard: --, wrapper, path/case wrapper spellings, catch-all ask, all-tools deny
    • no block on the command of a safe line
    • hand-written blocked entries are kept
    • preserving and dropping safe entries
    • import with normalization and prototype-key safety
  • e2e tests: crush generate and import cases.
  • pnpm cicheck passes: 16834 tests, plus the content checks.

Refs #3672

🤖 Generated with Claude Code

https://claude.ai/code/session_01QUBBebviXSBQtiRAmDopZ7

dyoshikawa and others added 6 commits November 8, 2026 21:03
…blocked_commands

Crush v0.100.0 added permissions.safe_commands (exact command lines that
skip the prompt) and permissions.blocked_commands (commands added to the
dangerous list, still prompted for in normal mode). Map canonical bash
rules onto them where the semantics match: an allow on a literal command
line becomes a safe command unless any deny/ask covers a command Crush
would approve through it (including the `--` and wrapper spellings Crush
resolves), and an ask on `<name>` / `<name> *` becomes a blocked command.
A pattern deny stays skipped with a warning, since blocked_commands would
still prompt. Import maps both lists back to bash rules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QUBBebviXSBQtiRAmDopZ7
…ush-command-permissions

# Conflicts:
#	src/generated/docs-content.ts
Crush enforces blocked_commands at exec time on the paths it does not
prompt for (its read-only commands and safe_commands), so a blocked name
refuses those forms. Writing a canonical ask there turned it into a deny
for `git status`-style commands. Map a whole-command deny to
blocked_commands instead (reported as not a full deny), skip asks, never
block the command of a written safe line, keep every existing blocked
entry, import blocked entries as denies, and compare wrapper spellings
with an absolute path or another case in the safe-line overlap check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QUBBebviXSBQtiRAmDopZ7
Compare safe lines' wrapper spellings against restrictions whose command
word is normalized the way Crush normalizes a wrapper name (any
directory, case, Windows suffix), skip denies on wrappers and the `time`
keyword (Crush resolves them before matching blocked_commands), and warn
when a kept blocked entry would refuse a written safe line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QUBBebviXSBQtiRAmDopZ7
…wrapper name

A `*` in a restriction's command word can cross a directory and land
inside a wrapper's name (`/u*v` globs `/usr/bin/env`), so fold the word
whenever the text after its last `*` is a tail of a wrapper name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QUBBebviXSBQtiRAmDopZ7
…ush-command-permissions

# Conflicts:
#	src/generated/docs-content.ts
@dyoshikawa
dyoshikawa merged commit 05051bf into main Nov 8, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-3672-crush-command-permissions branch November 8, 2026 13:25
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.

1 participant