Repository navigation
feat(policy): emit tool pack action instead of shell:spawn - #252
Conversation
## Problem The policy crate can parse a command line with a tool pack, but no code decides the pack action that the parse gives. So the box cannot use a pack action as a decision, and a temporal rule cannot read what a pack action did. Also, the golden corpus test built the event with its own private copy of the event builder, and decided it with the Dogwood authorizer directly. Thus the test did not pin the production code. ## Solution - Add `PolicyEngine::decide_pack_action` (crate-private). It builds the `context.input` record from a parsed pack action (`Parsed::Action` or `Parsed::Unmodeled`), with the base fields `program`, `program_path`, `cwd`, `args`, `effects`, and `credential_reads`. It decides the record through the one live authority, with the same request gate, the same durable history, and the same observer as every other decision. - Add `PolicyEngine::record_pack_response` (crate-private). It records the `::response` of a decided pack action, with the exit status in `output.status`. - Add `PackInvocation` and `PackResponse` in the `pack` module, and the `ActionIdentity::PackAction` variant. - Let the complete open path take tool pack schema fragments. Only a test constructor, `PolicyEngine::open_with_packs`, uses it now. A later change adds the production load. - The corpus test now opens an engine with the pack, and decides each case through `decide_pack_action`. The private event builder and the direct authorizer are deleted. The exact rules and the negated rules of a corpus load into one engine, so each case takes one decision. - Add two entries to `docs/design/decisions.md`: a pack action names no enforcement point, and `unmodeled` is denied by default. The user asked for them in this change. Nothing calls the new functions outside tests. The `pub use` set does not change, and `adapters/shell.rs` does not change. ## Tests - `pack::corpus::every_corpus_case_is_typed_and_decided_by_the_policy_engine` pins that the engine types and decides each golden case, that the rule over the exact values allows it, and that no negated rule allows it. - `pack::corpus::a_group_permit_never_reaches_an_unmodeled_command_and_an_explicit_permit_does` pins that `unmodeled` is denied under only a `"*"` group permit, and that an explicit permit on `unmodeled` allows it. - `pack::invocation::tests::a_temporal_rule_reads_the_exit_status_that_a_pack_response_records` pins that `git push` is allowed only after `cargo test` exits 0. - `pack::invocation::tests::a_pack_decision_enters_the_one_history_and_reaches_the_observer` pins that a `shell:spawn` rule reads a pack decision from the same history, and that the observer sees the pack action and its resource. - `pack::invocation::tests::an_input_that_its_action_schema_does_not_type_is_refused_as_a_fault` pins that the request gate refuses an input that the action schema does not type, as an internal fault. - I broke each guard on purpose and the test failed: `unmodeled` in the `"*"` group, an unmodeled event with no `effects`, a wrong exit status, a wrong event namespace, no observer call, an inverted field value, and no request gate. - I ran build, test, clippy, and fmt for `strands-box-policy` with all features, on Linux. Clippy shows 0 warnings in `crates/policy`. I did not build on macOS; CI does that. - The corpus test now takes about 35 seconds in a debug build, because each corpus opens a durable engine.
…cide-pack-action # Conflicts: # docs/design/decisions.md
…engine decision path
## Problem
The policy crate can decide a tool pack action and record its response,
and it can bind a pack to a program file and a called name. But no
enforcement point uses them. A spawn of a program that a pack covers is
still decided as `shell:spawn`. Also, a program file can bind to only one
pack, so only one tool on the mise shim binary can have a pack. And a
name that no `[tool]` declares on a bound file becomes the pack's
`unmodeled` action, so a rule that permits `unmodeled` admits a program
that the operator did not name.
## Solution
- The Shell adapter decides a spawn as its pack action when a pack binds
the program file and the called name. The adapter reads the file
identity (device and inode) at decision time, from the canonical path
that the Shell resolved. It does not use an identity from startup. An
allowed pack action records its `::response` with the exit status, or
-1 when the run ends with no status. A spawn that no pack covers is
decided as `shell:spawn`, as before.
- Several packs can bind one file. A bind is refused only when another
pack binds the same (file, name) pair.
- Coverage has a new answer: refused. The adapter refuses the spawn, and
no policy can permit it, in two cases: a name that no `[tool]` declares
on a bound file, and a bound path (or a bound link) that leads to a
different file now. The old answer "undeclared name gives `unmodeled`"
is removed. `unmodeled` now means only that the grammar cannot read the
command.
- `ProgramFile::read` canonicalizes the path before it reads the
identity. `PackInvocation` takes the `ProgramFile` instead of a path
string.
- New public names. Fernando approved them on one condition: no operator
can reach the feature yet. Nothing in `crates/box` calls them, and there
is no config key and no flag. The names are `BindingRefusal`, `Pack`,
`PackBindings`, `PackError`, `ProgramFile`, `UnreadableProgramFile`, and
the method `ShellPolicyInterceptor::into_handle_with_pack_bindings`.
`Pack::load`, `PackBindings::{new, declare, bind}`, and
`ProgramFile::{read, path}` are public. The facade count is now 58 with
all features and 52 by default.
- Decision entries, which Fernando asked for in this change: a new entry
`a-pack-action-replaces-shell-spawn`, and a rewrite in place of
`a-tool-pack-binds-on-the-program-file-and-the-called-name`.
- MCP staging is not changed. No path outside the tests composes a pack
schema into an engine, so a pack cannot reach the staged schema.
## Tests
- `adapters::shell::tests::a_bound_spawn_is_decided_as_its_pack_action_and_never_as_shell_spawn`
pins that a `shell:spawn` permit does not admit a bound program, and a
`shell:spawn` forbid does not refuse it.
- `an_admitted_pack_action_records_its_response_with_the_exit_status`
pins the recorded status (1, -1, then 0) through a temporal rule.
- `an_undeclared_name_or_a_replaced_file_is_refused_whatever_the_policy_permits`
and `a_removed_bound_file_is_refused` pin the refusal and its message
under a policy that permits all actions.
- `empty_bindings_decide_every_spawn_as_the_shell_spawn_path_does`
compares a table of spawns with direct `shell:spawn` decisions, for
empty bindings and for a binding on another file.
- `pack::bindings::tests` pin two packs on one shim binary, the refused
undeclared names (a symlink `g`, a hard link), a replaced file, a new
file behind a bound link, and the bind refusal on a bound pair.
- I broke each guard and the tests failed.
- Gates for `-p strands-box-policy`: build, test, clippy with and without
`--all-features` (0 warnings in `crates/policy`), and fmt are green.
`crates/box` is not changed. macOS was not compiled locally.
- Known gaps: the file can change between the decision and the exec
(the same gap as `shell:spawn`). An undeclared name on a file that no
pack binds is still `shell:spawn`. A stdio MCP server start is still
decided as `shell:spawn`. A refusal does not enter history and does not
reach the decision observer.
…e-gate # Conflicts: # crates/policy/src/dogwood.rs # crates/policy/src/pack/corpus.rs # crates/policy/src/pack/invocation.rs # crates/policy/src/pack/mod.rs # crates/policy/src/policy.rs # crates/policy/src/policy/authority.rs # crates/policy/src/request.rs # crates/policy/src/schema.rs # docs/design/decisions.md
|
Assessment: Request Changes The one-gate logic holds for each case I traced. The blocker is that the new public entry point, Assumptions and rules I checked that held
The tests are thorough, and each guard has a case that fails when the guard is broken. |
…pener loads the packs
|
Assessment: Approve I re-reviewed at Assumptions and rules I checked that held
The follow-up opener needs to give the engine and the bindings a single owner. That is the remaining risk. |
Description
This PR makes it so that when a shell command matches a Tool Pack action, Box emits the Dogwood event for that action instead of emitting
shell:spawn. It also records its response with the exit status when the run ends. A spawn that no pack covers is decided asshell:spawn, just like before.Gaps I did not close, on purpose:
shell:spawnhas the same gap today.[tool]declares, on a file that no pack binds, is stillshell:spawn.shell:spawn.Related Issues
#38
Type of Change
New feature
Testing
I added tests for each claim: a
shell:spawnrule neither admits nor refuses a bound program, the recorded exit status feeds a temporal rule, two packs share the mise shim binary, an undeclared name and a replaced file are refused under a policy that permits everything, and a table of spawns with empty bindings decides the same as before. I broke each guard on purpose and the tests caught it. I did not compile macOS locally, so CI covers it.just check, orcargo test --workspace --all-features)cargo fmt --allandcargo clippy --workspace --all-targets --all-features -- -D warningsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.