Skip to content

feat(policy): bind a tool pack on the program file and the command name - #246

Merged
ferdingler merged 3 commits into
mainfrom
feature/tool-packs-pack-bindings
Oct 31, 2026
Merged

ferdingler merged 3 commits into
mainfrom
feature/tool-packs-pack-bindings

Conversation

@ferdingler

@ferdingler ferdingler commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

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, rustc and cargo are 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 cargo and npm are both mise shims:

~/.local/share/mise/shims/cargo -> /usr/local/bin/mise
~/.local/share/mise/shims/npm   -> /usr/local/bin/mise

Both resolve to the same file, so if we bound on the file alone, the cargo pack would also parse npm install, 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.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## 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.
@ferdingler
ferdingler marked this pull request as ready for review October 30, 2026 22:34
@ferdingler ferdingler changed the title feat(policy): bind a tool pack on the program file and the called name feat(policy): bind a tool pack on the program file and the command name Oct 30, 2026
Comment thread crates/policy/src/pack/bindings.rs Resolved
Comment thread crates/policy/src/pack/bindings.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment

The binding model is sound for a single-program file. The Unmodeled catch-all, and the exact-string match on the called name, give wrong results for multiplexer binaries and for path spellings. Both should be fixed before a caller depends on coverage. Neither is reachable yet, because the module is under #[expect(dead_code)].

Checked and held
  • NamedTwice (head commit): every duplicate name is refused in any order, and the result does not depend on order (BTreeMap). Pack names are identifiers, so no two names can share a namespace.
  • bind refuses a second pack on a bound file, and leaves its state unchanged when it refuses.
  • A file with no binding stays shell:spawn under every name, and an agent-written git script does not claim the pack.
  • Root premise "absent policy is default-deny": unmodeled is denied unless a rule permits it.
  • Frozen surfaces: none change. Everything here is pub(crate), and the policy pub use façade does not change.
  • Tests compare the full (kind, pack) result in one assertion, and each case names its row.
  • cargo test -p strands-box-policy --lib pack::: 19 pass.

The table-driven tests make the binding rules easy to read.

@kevin-orellana

Copy link
Copy Markdown
Collaborator

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 shell:spawn permissions instead of the pack’s restrictions.

Would it make sense to match checked file identity and add hard-link regression cases before integration?

Details

Tested f720aa2 on Linux ARM64 with two reviewer-added unit tests:

  • Setup: Bind a file to the git pack, then create hard and symbolic links to it.
  • Observed: Coverage through the hard link returns None. Binding a different pack through that link also succeeds.
  • Expected: An undeclared name for the bound file returns Unmodeled. A second pack on that file is refused, as the design decision specifies.
  • Controls: The hard link and original share the same filesystem identity. The original-path and symbolic-link checks pass.

Both added tests fail on these expectations. This demonstrates the lookup gap; I have not yet reproduced an end-to-end authorization bypass.

kevin-orellana
kevin-orellana previously approved these changes Oct 30, 2026
@ferdingler

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread crates/policy/src/pack/bindings.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review of 88f37cf)

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 Unmodeled catch-all for multiplexer binaries and on the exact-string called name, have not changed in this commit and are still open.

Checked and held at this head
  • A hard link and a symbolic link to a bound file both resolve to the same identity and keep coverage. Kevin's cases are now regression tests.
  • A second pack on a bound file is refused through any path that names it.
  • A program file that cannot be read is refused with its path (UnreadableProgramFile), and is not silently left unbound.
  • A copy of a bound binary, or an in-place update of one, stays a shell:spawn. The decision entry states this as a cost.
  • Frozen surfaces: no change. Everything here is still pub(crate).
  • cargo test -p strands-box-policy --lib pack::bindings: 6 pass.

@ferdingler
ferdingler merged commit e4ca8b8 into main Oct 31, 2026
22 of 23 checks passed
@ferdingler
ferdingler deleted the feature/tool-packs-pack-bindings branch October 31, 2026 17:38
ferdingler added a commit that referenced this pull request Nov 12, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants