Repository navigation
feat(policy): bind a tool pack on the program file and the command name - #246
Conversation
## Problem Box has no record of which tool pack covers which program. A pack must apply only to the program that the operator declared for it. The resolved file alone is not sufficient: a shim such as mise runs many tools through one binary, and cargo and rustc can be links to one binary. The called name alone is not sufficient: any file with that name would get the pack. Also, a binding that names an unknown pack, or that binds two packs to one file, is a misconfiguration. A silent ignore hides it. With two packs on one file, the pack for an undeclared name is not defined. ## Solution Add the crate-private `PackBindings` in `crates/policy/src/pack/bindings.rs`. It holds the installed packs and maps a pair (resolved program file, called name) to a pack: - `declare` records that a `[tool]` runs a file under a name. - `bind` binds a pack to a pair. - `coverage` returns `Parsed(pack)` for a bound pair. It returns `Unmodeled(pack)` when the file is bound but no `[tool]` declares the name. It returns `None` for a declared name with no pack, and for a file that no pack binds. `None` keeps the spawn a `shell:spawn`. `bind` returns a `BindingRefusal`. It refuses a pack name that is not installed (`UnknownPack`). It refuses a file that is bound to a different pack, under any name (`BoundToAnotherPack`). Thus a file has at most one pack, and `Unmodeled` always names that pack. A second name on a bound file, to the same pack, is accepted. A refused bind changes nothing. No production code calls the type yet. Routing in the shell adapter and the exports come in a follow-up PR. The crate `pub use` set does not change. Add the decision entry `a-tool-pack-binds-on-the-program-file-and-the-called-name` to `docs/design/decisions.md`, and cite it from the module. ## Tests `cargo build`, `cargo test`, `cargo clippy --all-targets`, and `cargo fmt --check` with `-p strands-box-policy --all-features` pass. Clippy reports zero warnings in `crates/policy`. - `each_spawn_resolves_by_its_program_file_and_its_called_name` pins each `coverage` answer: a bound pair, two packs on two files, a declared unbound name, an undeclared name on a bound file, an unbound file, and the mise shim with one bound name, two declared names, and one undeclared name. - `an_undeclared_name_on_a_file_that_no_pack_binds_stays_a_spawn` pins the shared-shim residual: an undeclared name on a file that no pack binds gives `None`. - `a_binding_that_names_no_installed_pack_or_a_second_pack_on_one_file_is_refused` pins both refusals, for the same name and for another name on the mise shim binary. It also pins the accepted binds to the same pack, and that a refused bind leaves the bindings unchanged. I broke each guard and saw a test fail, then restored it: the bound pair check, the declared-name check, the `Unmodeled` answer, both refusals, and the acceptance of a second bind to the same pack. I did not run the workspace suite or a macOS build. Known limit: on a mise shim binary, only one managed tool can have a pack.
|
Assessment: Comment The binding model is sound for a single-program file. The Checked and held
The table-driven tests make the binding rules easy to read. |
|
A hard link to a bound executable loses pack coverage, even though it names the same file. Once this lookup controls authorization, that could route a command through broader Would it make sense to match checked file identity and add hard-link regression cases before integration? Details Tested
Both added tests fail on these expectations. This demonstrates the lookup gap; I have not yet reproduced an end-to-end authorization bypass. |
…eps pack coverage
|
good catch, thanks Kevin. I have fixed in commit 88f37cf: the bindings now key on file identity (device + inode) instead of the path, and your hard-link cases are regression tests. |
|
Assessment: Comment (re-review of Keying on file identity fixes the hard-link gap that @kevin-orellana reported. The new key can outlive the file it was read from, which the inline comment shows. My two earlier threads, on the Checked and held at this head
|
…ts pipeline starts Upstream #246 adds Kernel::check_fallback. The kernel now decides a host-binary or python stage there, before any stage of the pipeline starts, and uses that decision when the stage runs. A decided stage that never runs is recorded as indeterminate. box_shell_cwd.rs::a_denied_tool_directory_stops_every_pipeline_stage passes again. The only other upstream change in the range, #244, edits a comment.
Description
This PR adds the lookup that decides which tool pack, if any, covers a program that the agent spawns. We need it because neither the file nor the name alone is enough. For instance,
rustcandcargoare links to the same file, so the file itself is ambiguous, we need to rely on the name (e.g. rustc vs cargo).A pack should bind on the pair: the identity of the resolved program file plus the name it was called by. The identity is the file's device and inode, so a hard link or a symbolic link to a bound file is the same file, and a different path can't get past the binding. A bound pair parses with the pack's grammar.
Example
For instance, take a box where
cargoandnpmare both mise shims:Both resolve to the same file, so if we bound on the file alone, the
cargopack would also parsenpminstall, which would obviously be wrong. Binding on the name alone breaks the other way: an agent can write its own script called git, and we'd parse and decide it as if it were the real git. With the pair, (mise, cargo) parses with the cargo pack, (mise, npm) stays a shell:spawn, and a link like./g->/usr/bin/git, hard or symbolic, comes back as unmodeled instead of slipping past the git pack.Related Issues
#38
Type of Change
New feature
Testing
I ran the policy crate's build, tests, clippy, and fmt on Linux, and all pass with no new warnings. I did not run the whole workspace or a local macOS build. CI covers macOS.
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.