Repository navigation
feat(box): expose the interpreter alias names and a read-grant check to library callers - #242
Conversation
…to library callers ## Problem A library caller such as `boxy` keeps two lists of its own to refuse an MCP server before it writes `box.toml`: the program names a box keeps for its interpreters, and the paths a box refuses in a grant. Each copy can differ from Box. The path copy already differs: it treats every row as `overlap`, it holds 19 of the 58 rows of `forbidden-paths.json`, and it refuses a path in a credential store, which a box grants when a grant names it. ## Solution - `strands_box::INTERPRETER_ALIASES` holds the five names that the alias image takes (`zsh`, `bash`, `sh`, `python3`, `python`). It is built from `SHELL_ALIAS_NAMES` and `PYTHON_ALIAS_NAMES`, and a compile-time assertion fails the build when either list grows. The MCP program check in `record::config::mcp` now reads this constant. - `strands_box::check_read_grant(path) -> Result<bool, GrantRefused>` judges a read grant through `entry_grant`, the function that judges a `read` entry in `box.toml`, with the canonical operator home. It refuses an absent path, a link, a spelling that is not canonical, and a path under a floor. `Ok(true)` means the path is in a credential store. `GrantRefused` wraps `BoxError`, as `CheckFailed` does. - The check is a function and not the path list, because each row of `forbidden-paths.json` carries a rule (`exact` or `overlap`) and a class, and `entry_grant` refuses more than the rows. - `docs/design/containment.md` and `docs/design/binaries.md` state the two additions. ## Tests - `tests/library_grant_check.rs`: `a_read_grant_on_a_system_tree_or_the_whole_filesystem_is_refused`, `a_read_grant_on_an_ordinary_directory_passes_and_names_no_credential_store`, `a_read_grant_on_a_path_that_is_not_there_is_refused`, `a_read_grant_through_a_link_or_a_spelling_that_is_not_canonical_is_refused`. - `tests/library_grant_check_credential_store.rs`: `a_read_grant_in_a_credential_store_passes_and_says_so`, in its own binary, because it sets `HOME`. - `record::config::mcp` `a_program_that_collides_with_an_interpreter_alias_is_refused` now iterates `INTERPRETER_ALIASES` and asserts its five names. - Ran `cargo fmt --all --check`, `just clippy`, and `cargo test -p strands-box --all-features` (1019 passed, 0 failed). Not run: the workspace-wide `just check`, and Linux locally.
|
|
||
| /// Check a read grant on the absolute `path` as a box checks a `read` entry, and return whether it | ||
| /// lies in a credential store, which a box grants only when a grant names it, and announces. | ||
| pub fn check_read_grant(path: &Path) -> Result<bool, GrantRefused> { |
There was a problem hiding this comment.
Important (blocks the merge, because it contradicts the stated purpose): check_read_grant returns Ok for a read grant that box run refuses: a grant that encloses box_dir or lies inside it.
Example (I ran this on Linux at fb451c5): I made <tmp>/project and wrote a box.toml with box_dir = "<tmp>/project/state" and [agent.filesystem] read = ["<tmp>/project"]. A box directory inside the project is a normal layout.
strands_box::check_read_grant("<tmp>/project")returnsOk(false).strands-box run --config <tmp>/box.tomlfails:containment config failed: grant is too broad to be authorized: <tmp>/project (the grant would expose private Box state).
After the first run creates state/, check_read_grant("<tmp>/project/state") also returns Ok(false), and the run refuses that path with "the grant would expose the Box's own directory".
The cause is that entry_grant is only half of what judges a read entry. Boundary::translate also passes every operator grant through GuardedBoxState::judge (require_private_state_absent and require_box_directory_absent), and judge_read_grant never calls it. This is the same class of gap the description uses to reject a path list: "A caller with only the list accepts these, and box run then refuses them." docs/design/containment.md also says the function judges the path "through the same function that judges a read entry". That is true for entry_grant only, not for the whole decision.
Suggestion: The narrowest fix in code is to take the box directory, check_read_grant(path: &Path, box_dir: &Path), and run require_private_state_absent and require_box_directory_absent on the resolved path in judge_read_grant. The caller writes box_dir into the same box.toml, so it already has the value. If the approved signature has to stay as it is, the doc comment and containment.md must say that the function does not judge box_dir, deny entries, or how entries interact. Also add a test for the enclosing-box_dir case either way.
|
Assessment: Request Changes
Review Categories
Checks that held
Building the decision into a function, and not publishing the path list, is the right shape. |
Description
A library caller that writes
box.tomlhas no way to ask Box two questions before a run: which program names a box keeps for its own interpreters, and which paths a box refuses in a grant. Without them, the caller keeps its own copy of each list, and each copy can differ from Box. This change exposes Box's own answer to library callers.strands_box::INTERPRETER_ALIASES: the five names the alias image takes (zsh,bash,sh,python3,python). It is built fromSHELL_ALIAS_NAMESandPYTHON_ALIAS_NAMES, and a compile-time assertion fails the build when either list grows. Box's own MCP program check now reads this constant, so the public list and the check are one list.strands_box::check_read_grant(path) -> Result<bool, GrantRefused>: judges a read grant throughentry_grant, the function that judges areadentry inbox.toml, with the canonical operator home.Ok(true)means the path is in a credential store.Why item 2 is a function and not the path list. A path list does not carry the decision:
forbidden-paths.jsonhas a rule. Anexactrow (/,/usr,/var/db/SystemKey) refuses a grant on that path and allows a path inside it. Anoverlaprow refuses a grant at, under, or above it. A list of anchors loses this, so a caller has to restate each rule.entry_grantrefuses more than the rows: an absent path, a link, and a spelling that is not canonical (/tmpagainst/private/tmp). A caller with only the list accepts these, andbox runthen refuses them.~/.ssh,~/.aws) is not refused when a grant names it. Box grants it and announces it at startup. Thebooltells the caller, so a caller that wants a stricter rule takes it from Box's answer.forbidden-paths.jsonreaches every caller with no change in the caller.This follows
check_policy: Box decides, and the caller asks.Interface change. Two additions to the
strands_boxlibrary (INTERPRETER_ALIASES,check_read_grantand its errorGrantRefused). Nothing breaks. The operator approved this shape before the code was written. No CLI verb,box.tomlkey, or containment facade changes.Deferred.
crates/box/AGENTS.mdstill states that the crate has nolib.rs. That is false since #116, and it is a rewrite of that section, not of this change.Related Issues
None.
Type of Change
New feature
Testing
tests/library_grant_check.rs: a system tree and/are refused, an ordinary directory passes with no credential store, an absent path is refused, and a link and a dotted spelling are refused.tests/library_grant_check_credential_store.rs: a path in a credential store passes withOk(true). It is its own test binary, because it setsHOME.a_program_that_collides_with_an_interpreter_alias_is_refusednow iteratesINTERPRETER_ALIASES.cargo fmt --all --check,just clippy, andcargo test -p strands-box --all-features(1019 passed, 0 failed).Not run locally: the workspace-wide
just check, and Linux. Reviewed with one/code-reviewround;feature-criticwas not run.I ran the relevant suites (
just check, orcargo test --workspace --all-features)If I touched Rust, I ran
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.