Repository navigation
feat(box): report the kind of an env refusal and a read-grant refusal to library callers - #274
Merged
notowen333 merged 2 commits intoNov 3, 2026
Conversation
… to library callers ## Problem A library caller that writes `box.toml` must know, before it writes, which entries Box refuses, and the kind of each refusal. It drops an `env` name that Box sets itself, and it skips a server that needs a name that makes a runtime load code. It drops a read grant on a system tree, and it skips what needed any other refused grant. No library call reports an `env` refusal, and `GrantRefused` carries only a message. So the caller copies `reserved_workload_environment` and the rows of `forbidden-paths.json`, and a copy can differ from Box. ## Solution - Add `strands_box::check_workload_env(name, value) -> Result<(), EnvRefused>`. `EnvRefused::kind()` returns `EnvRefusal` (`InvalidName`, `SetByBox`, `LoadsCode`, `NotAbsolute`). `ProcessSpec::validate` and the check call the same functions in `record::config::env`. The refusal text and order at load do not change. - Add `GrantRefused::kind()`, which returns `GrantRefusal` (`NotAbsolute`, `Absent`, `Link`, `NotCanonical`, `Forbidden(ForbiddenClass)`, `Other`). `entry_grant` tags each refusal with its kind. - `containment` exports `ForbiddenClass` and `ContainmentError::forbidden_class()`, which reads the class of a floor refusal back from `GrantTooBroad`'s reason. `GrantTooBroad` keeps its fields. These are additive interface changes. Both enums are `#[non_exhaustive]`. ## Tests - `tests/library_env_check.rs` pins each env kind, and `the_check_and_a_box_load_refuse_the_same_entries_with_the_same_reason` pins that a load through `check_policy` refuses the same entries with the same text, in `[agent]` and in a stdio `[mcp.<name>]`. - `a_loader_hook_is_refused_as_loading_code_and_a_box_name_as_set_by_the_box` covers every private loader-hook entry. - `tests/library_grant_check.rs` and `tests/library_grant_check_credential_store.rs` pin each grant kind. - `containment` `error::tests` pin `forbidden_class` and its class list. - `just check` passed on macOS. Linux was not run locally.
notowen333
marked this pull request as ready for review
November 2, 2026 22:25
|
Assessment: Comment The shared Review Categories
Assumptions and rules checked that held
The env/grant split is well scoped and additive. |
…and LoadsCode names a family
|
Assessment: Approve (pending the
Remaining before merge
Checked in this round, and held
|
gautamsirdeshmukh
approved these changes
Nov 3, 2026
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
A library caller that writes
box.tomlmust know, before it writes, which entries Box refuses. Today it cannot learn the kind of a refusal, so it copies Box's private lists:env. A caller that writes[agent] env,[tool.<name>] env, or[mcp.<name>] envhas no check at all. One refused name fails the whole load. The caller handles two refusals differently: it drops a name that Box sets itself (a proxy variable, a CA bundle variable,OTEL_EXPORTER_OTLP_*,PWD,USER), and it skips the server that needs a name that makes a runtime load code (LD_*,DYLD_*,PYTHON*,NODE_OPTIONS, and others). To tell the two apart, it must copyreserved_workload_environment.check_read_grant(feat(box): expose the interpreter alias names and a read-grant check to library callers #242) returnsGrantRefused, which carries only a message. A caller drops a grant on a system tree such as/usror/opt/homebrew, and it skips what needed any other refused grant. To tell the two apart, it must copy the rows offorbidden-paths.json.A copy can differ from Box, and then the caller writes a
box.tomlthat Box refuses at load.Solution
Each refusal now states its kind. The kinds are the split that Box Core already has internally. This change adds no new rule.
1.
strands_box::check_workload_env(name: &str, value: &str) -> Result<(), EnvRefused>.EnvRefused::kind()returnsEnvRefusal(#[non_exhaustive]):InvalidNamevalid_environment_namerefuses the name.SetByBoxPWD,USER).LoadsCodeLD_*,DYLD_*,PYTHON*, and exact names). Box refuses the whole family, so a member that loads no code, such asPYTHONUNBUFFERED, is alsoLoadsCode.reserved_workload_environmentalready checked these first, and its comment called them "a different kind of refusal".NotAbsoluteHOMEorTMPDIRholds a relative path.The check takes the value, because
ProcessSpec::validaterefuses a relativeenv.HOMEorenv.TMPDIRat load. A check of the name only would pass an entry that the load then refuses, and that is the failure this check removes.ProcessSpec::validateand the new check call the same functions (env::refused_name,env::refused_value,env::refusal_reason). The refusal text and the order of the checks at load do not change.reserved_workload_environmentkeeps its name and its result. The check does not cover a credentialenv://name, which Box also refuses forHOMEandPATH.2.
GrantRefused::kind() -> GrantRefusal(#[non_exhaustive]):NotAbsolute,Absent,Link,NotCanonical,Forbidden(ForbiddenClass), andOther. These are the steps ofentry_grant, in its order.Absentis only a path that does not exist (NotFound, orNotADirectorywhen a parent is a file). Any other read error, such asPermissionDenied, isOtherwith the message "cannot read : ".Forbiddencarries the class of the floor row that refused the path, such asSystemTreefor/usr.Otheris every other refusal, for example a path that encloses a credential store without naming it./isOtherfor that reason: the credential-store check invalidate_grantruns before the rows.Ok(true)does not change. TheDisplaytext changes only for a read error that is not absence: it was "is not there: Permission denied", and it is now "cannot read".3.
containmentexportsForbiddenClass, andContainmentError::forbidden_class() -> Option<ForbiddenClass>. The class is what each row offorbidden-paths.jsonalready carries (class).GrantTooBroadkeeps its fields.forbidden_classmaps itsreasonback to the class, because each class has one constant reason. AGrantTooBroadthatboxbuilds for its own state maps toNone. I did not add a field toGrantTooBroad, because a new field breaks each caller that builds or matches the variant by its fields.Interface change. This is additive. It adds to the
strands_boxlibrary:check_workload_env,EnvRefused,EnvRefusal,GrantRefused::kind,GrantRefusal, and the re-exportForbiddenClass. It adds to thecontainmentcrate root:ForbiddenClassandContainmentError::forbidden_class. Nothing breaks. No CLI verb,box.tomlkey, or refusal text changes. The operator approved thestrands_boxadditions before the code was written. Thecontainmentexport is what carries the class tostrands_box, and it needs maintainer approval as a change to that crate'spub useset.Load-bearing choices.
ForbiddenClasskeeps itsDeserializederive, because the row loader reads it fromforbidden-paths.json. Itssnake_casenames are then a public form too. They are the names in that file.LoadsCoderefusal keeps the load's text, "is set by the box itself". This change does not change a message an operator reads. The kind now states the difference.forbidden_classreads the class back from the reason text.every_class_is_listed_once_and_states_its_own_reasonfails when a new class is missing fromForbiddenClass::ALL(an exhaustivematch) or when two classes share one text.Forbidden(WholeFilesystem)orForbidden(CredentialStore). The credential-store check invalidate_grantruns first, so those paths areOther. A caller that needs to know "encloses a credential store" needs a typed signal fromcontainment. I did not add one.Deferred.
crates/box/AGENTS.mdstill states that the crate has nolib.rs, as #242 noted. That section needs a rewrite of its own.Docs.
docs/design/containment.mdstates both kinds besidecheck_read_grant.crates/containment/README.mdlists the new export, and its export count now names all 19 names (the old count of 13 was stale).crates/containment/AGENTS.mdnamesforbidden_class.Related Issues
None.
Type of Change
New feature
Testing
tests/library_env_check.rs: each kind for its names (a_name_the_box_sets_itself_is_refused_as_set_by_the_box,a_name_that_makes_a_runtime_load_code_is_refused_as_loading_code,a_name_that_is_not_a_variable_name_is_refused_as_invalid,a_relative_home_or_tmpdir_is_refused_and_a_relative_path_is_not,a_member_of_a_loader_family_that_loads_no_code_is_refused_as_loading_codeforPYTHONUNBUFFERED,PYTHONIOENCODING, andLD_BIND_NOW), and ordinary names pass.the_check_and_a_box_load_refuse_the_same_entries_with_the_same_reasonwrites each entry into[agent] envand a stdio[mcp.<name>] env, loads it throughcheck_policy, and asserts that the load refuses each refused entry with the check's reason and accepts each accepted entry.record::config::tests::a_loader_hook_is_refused_as_loading_code_and_a_box_name_as_set_by_the_box: every entry of the privateLOADER_HOOKSandLOADER_HOOK_PREFIXESisLoadsCode, so a hook added there cannot be reported as another kind.tests/library_grant_check.rs:/usrand/usr/binareForbidden(SystemTree); on macOS,/private/etc/sudoers,/private/var/db/dslocal, and/Library/KeychainsareForbiddenwith their own classes;/isOther; a relative path isNotAbsolute; the absent, link, and dotted cases now also assertAbsent,Link, andNotCanonical.a_read_grant_through_a_file_is_refused_as_absentpinsNotADirectoryasAbsent.a_read_grant_under_an_unreadable_directory_is_not_refused_as_absentpins a0o000parent asOtherwith no "is not there" text; it fails before this change, and it skips as root.tests/library_grant_check_credential_store.rs: a home that encloses~/.sshisOther.containmenterror::tests::a_floor_refusal_names_its_class_and_any_other_refusal_names_none: each class maps back from its reason, and another reason maps toNone.every_class_is_listed_once_and_states_its_own_reasonguards the mapping.On Linux,
the_password_database_is_refused_as_a_floor_row_of_its_own_classchecks/etc/shadowwhen the host has it.just check(fmt check, clippy, andcargo test --workspace --all-features) on macOS: 4389 passed, 0 failed, 16 ignored.Not run: Linux. The Linux-only test runs in CI.
Reviewed by the repository's
feature-criticchecklist in a fresh context. It found no blocker. I fixed its findings on the docs, the guard onforbidden_class, two stale comments, and the Linux case. The items above under Load-bearing choices and Deferred are the ones I kept.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.