Repository navigation
fix(box): refuse credential stores beneath the Shell and Monty floor - #434
priyasingh2111 wants to merge 7 commits into
Conversation
|
|
||
| The agent's filesystem lists govern its sandbox alone. Each tool gets its reach from its own | ||
| `[tool.<name>]` table. An absent filesystem section grants no direct reach. These grants bypass | ||
| The agent's filesystem lists govern its sandbox, with one exception: a `read` or `write` entry that |
There was a problem hiding this comment.
Important (blocks merge until a maintainer records approval): This PR changes frozen surfaces and governance files, and the record does not show the explicit approval that the root AGENTS.md requires.
Rules: The root AGENTS.md says:
- "Get the user's explicit approval before writing code that changes … An interface … Additions, renames, and narrowings count", and the frozen surfaces include "each mechanism crate's
pub useset". - "An agent cannot approve its own change."
- "Edit this file only when the user explicitly asks."
- From the Decisions section: "Record an entry in
docs/design/decisions.mdonly after the user decides it."
This PR:
- adds
credential_store_anchorsto thestrands-box-containmentpub useset (19 → 20 names); - narrows what policy can permit through Shell and Monty, which is a premise-level change to "Filesystem reach";
- rewrites this paragraph of the root
AGENTS.md; - replaces the
no-credential-floor-sits-beneath-the-interpretersdecision with a new one under the same anchor.
The description names each of these, which is what the contract asks for. It does not say who approved them.
Suggestion: Have a maintainer approve each of the four on the PR, for example in a comment or with the api/needs-review label, before merge. Then the decision rewrite and the AGENTS.md edit carry a recorded decision rather than the author's own.
There was a problem hiding this comment.
The approval request above was posted before 4ccdbea, and it now describes a design this PR no longer has. Its item 2 says an [agent.filesystem] entry opens a store. After 4ccdbea, only a permit that names a path inside the store opens it, and an agent entry opens nothing (an_agent_entry_naming_a_store_opens_it_to_neither_interpreter). An approval given for that list would cover the old design. This is the current set that needs a maintainer's approval:
- The
strands-box-containmentpub useset gainscredential_store_anchors(19 → 20). - The
strands-box-policyfaçade gainsPathPermit(60 → 61 with--all-features) andPolicyEngine::path_permits.crates/policy/AGENTS.mdsays: "This crate is interface-frozen: thepub usefaçade… An operator's policy file is their source code." - A foundational premise changes. The root
AGENTS.mdpremise "Policy is the only authorizer… Deny-only floors stay beneath policy" now has an exception. Under it, a permit's literal text lifts a floor, even when that permit doesn't decide the request.crates/box/AGENTS.mdrecords the residual: "A lifted path skips the naming rule's other conditions." The "Filesystem reach" paragraph is also rewritten. - The
no-credential-floor-sits-beneath-the-interpretersdecision is rewritten again, for the permit-based design. - A behavior change for Shell and Monty: stores are refused even under a home-wide permit, unless a permit names a path inside the store. Box also prints a new
strands-box: policy: … opens … to the Shell and Pythonstderr line.
The root AGENTS.md says: "Get the user's explicit approval before writing code that changes… A foundational premise", and "An agent cannot approve its own change." Could the maintainer approve against this list?
There was a problem hiding this comment.
Updated for the current design (4ccdbea and 182fa1e): the exception is now a policy rule that names a path inside the store, not a box.toml entry. Could a maintainer confirm these?
- The new
pub useexportcredential_store_anchorsinstrands-box-containment(19 → 20 names). - The new policy API
PathPermitandPolicyEngine::path_permits()instrands-box-policy(60 → 61 names with--all-features). - The root
AGENTS.mdpremise "deny-only floors stay beneath policy" now has one exception: apermitthat names a path inside a credential store, with no wildcard above it, lifts the Shell and Monty floor for that path. The "Filesystem reach" paragraph goes back to "the agent's filesystem lists govern its sandbox alone". - The rewrite of the decision
no-credential-floor-sits-beneath-the-interpreters, with its anchor kept. - The behavior change: Shell and Monty refuse credential stores even under a home-wide permit, unless a
permitnames the path, and Box prints each such rule at startup.
cc @ferdingler
|
Assessment: Request Changes The floor works for the operator home: it is deny-only, it sits beneath policy, and it reads one store list. Two problems remain. The floor is stricter than the sandbox for a declared Review details
Assumptions and rules checked that held
The |
|
Assessment: Request Changes (re-review of 07973aa) 07973aa fixes the declared-home finding. Its change to the encloses check opens a new path: renaming a parent directory moves a granted store's content outside its Checked in this commit and held
I verified this with temporary unit-test probes on Linux x86_64 and removed them afterwards. I did not run the end-to-end suite. |
07973aa to
bd7cf9c
Compare
|
Assessment: Request Changes (re-review of bd7cf9c) bd7cf9c closes the parent-directory rename path from my last review. The one blocker left is the recorded maintainer approval for the frozen-surface and governance edits; the thread on Checked in this commit and held
Verification: the 19 |
|
Assessment: Request Changes (re-review of fdd4533, which squashes the branch onto fdd4533 resolves my last non-blocking note (reply on that thread), and I found no new correctness problems. One blocker remains. The PR edits frozen surfaces and governance files: the containment Checked in this commit and held
Verification: the 19 |
|
Assessment: Request Changes (re-review of 4ccdbea) 4ccdbea moves what lifts the floor from
Checked in this commit and held
Verification: the 22 |
The sandbox refuses every grant that encloses a credential store (`~/.ssh`, `~/.aws`, keychains, browser profiles), but the hosted Strands Shell and Monty never consulted that list. With a policy such as `permit fs:read when path like "~/*"`, a prompt-injected workload read `~/.ssh/id_rsa` through the `python3` or `zsh` alias, and appended `credential_process` to `~/.aws/config`, which the AWS CLI later ran as the operator outside any box. `decisions.md` recorded the gap and named the fix: a deny-only floor beneath policy that carries the sandbox's credential list. - `containment` exports `credential_store_anchors(home)`: every spelling of each `credential_store` row under a home (as written, through symbolic links, and on the macOS data volume). `credential_store_path` now reads it, so the grant check and the new floor read one store list. This is one additive `pub use` name (20 exports); the user approved it. - `Reach::refuse_forbidden` refuses a path at or inside a store under the operator home or the agent's home, and a change to a directory that holds a store. A store matches by folded spelling (`folded` maps each letter whose Unicode case fold is ASCII, such as U+017F, which APFS treats as `s`) and by the on-disk identity each store spelling has at decision time, so a store created or linked after startup counts too. A missing path inside a store gets the same refusal, so the message does not disclose whether the store exists. - An `[agent.filesystem]` entry that names a store or a path inside it lifts the floor for that path: `read`/`read_file` for reads, `write`/`write_file` for changes. Policy still decides each access. A `deny` entry inside the store stays refused. `Reach::refuse_store_relocation` refuses a Shell or Monty rename that carries store content outside the `write` entry that opened it. - New refusal strings: "resolves into a credential store, ...", "contains a credential store, ...", and "would move credential-store content outside ...". No CLI, `box.toml` key, record, protocol, alias, policy action, or environment name moved. The behaviour change narrows what a policy permits through the interpreters. The user decided it, and the decision entry `no-credential-floor-sits-beneath-the-interpreters` is rewritten in place (anchor kept). The root `AGENTS.md` "Filesystem reach" rule now states the store exception, with the user's approval. - `box_shell.rs::a_matching_leaf_reads_and_writes_announced_credentials_and_the_main_workload_does_not` used `[tool.wc]` and `[tool.touch]`. The Shell implements both, so `bare_names` skips those tools and the Shell's own builtins read and wrote `~/.aws` in the trusted process: the test passed through this defect. It now uses `cksum` and `dd`, which run in their own leaf sandboxes. - Residuals, stated in the docs rather than closed: a `write` entry on a store also lets the agent's own system calls move the store's files elsewhere, where the interpreters can read them; the fold table is not a full Unicode fold; the floor covers only the listed stores, so a broad permit still reaches everything else; a script that inspects each entry of the home gets a refusal on each store. - Docs: decisions, policy, shell, monty, containment, architecture, and limitations design pages; security, shell (exit statuses), shell-policy, monty, and config user pages; containment README and AGENTS.md; box AGENTS.md; root AGENTS.md. macOS 26.6 arm64: - `reach.rs::credential_store_tests` (16): home-wide refusal; read, write, and file entries; list and metadata entries lift nothing; a linked store; an enclosing directory; a declared `env.HOME`; letter case on an absent store; Unicode spellings that fold to a store name; a store linked after startup; missing paths; `deny` inside a store; a rename out of a `write` entry. Each fix was removed in turn and its test failed. - `floors.rs::the_credential_store_anchors_carry_every_spelling_of_each_store`. - `box_credential_store_floor.rs` (5, end to end through the real aliases): `a_home_wide_permit_reaches_no_credential_store_through_either_interpreter` (the finding's policy: key not returned, config not appended, ordinary file still reads), `a_store_named_by_a_read_entry_reads_and_stays_unwritable`, `a_write_entry_cannot_move_a_store_file_out_through_either_interpreter`, and `an_absent_store_cannot_be_created_under_a_spelling_that_folds_to_its_name`, and `a_prepared_directory_cannot_be_renamed_onto_an_absent_store`. Each fails with its fix removed, which reproduces the attack. - A `stat` of every code point from U+0080 to U+10FFFF on case-insensitive APFS: only U+00DF, U+017F, U+1E9E, U+212A, and U+FB00 to U+FB06 compare equal to ASCII, and `folded` maps all eleven. - Each request now costs one `stat` per store spelling (about 70 microseconds a read in a debug build); only a change to a directory also resolves each store. - `cargo test -p strands-box --all-features --lib`: 944 passed, 1 ignored. `box_shell` 72, `box_filesystem` 24, `box_shell_cwd` 15, `box_protected_state` 4, `site_manifest`, `documented_commands`, `documented_inputs`: passed. `cargo test -p strands-box-containment --all-features`: 331 passed. - A full `cargo test --workspace --all-features --no-fail-fast` before the last fixes: 5087 passed, 1 failed (`runtime_mcp_catalog_scaling`, a timing ratio that matched `origin/main` in a 5-run A/B). The deterministic suite's `SH-NEG-CURL-403` and `CN-L-03` failed once on a DNS lookup inside the box, then passed on this branch and on the base commit. - clippy: no owned warnings. fmt: clean. - Not run: Linux (not compiled on this host), and the full workspace suite after the last fixes.
…x refuses write-only
…or that home's stores
…essage that names the real cause
… a permit that names it, not an agent entry
4ccdbea to
3d816f2
Compare
…only content readable
|
Assessment: Request Changes (re-review of 3d816f2) 3d816f2 rebases 4ccdbea onto
Checked in this commit and held
Verification: the 22 |
|
Assessment: Request Changes (re-review of 182fa1e). The code is ready. The one remaining blocker is the maintainer approval. 182fa1e closes the rename leak inside a store (my reply is on the Checked in this commit and held
Verification: all 25 |
… in the interpreters ## Problem Strands Shell and Monty refused a change at a `reads` or `deny` path of a secret source, inside it, or above it. To do that, `ConfiguredCommands` matched each mutation against those paths by spelling, by on-disk identity, by a case-folded spelling for a path that is absent, and against each symbolic link on the way. The review of this pull request asked to take that out (comments 4621726643 and 4621802834): - It is a second path matcher behind the interpreters' hook, with case folding, links, and absent paths, and `limitations.md` still listed gaps in it (two Unicode forms of one name, and each read). - A floor beneath policy is the place for this. An open pull request (#434) builds that floor for the well-known credential stores, for reads and for changes. A vault at another path is the job of the operator's policy. ## Solution Remove `ConfiguredCommands::source_paths` and `source_links`, the three checks in `mutation_refusal` that used them, `CommandMutationRefusal::SourcePath`, its reason text in `run/broker/reach.rs`, and `folded`. `ConfiguredCommands::load` and `of_secret_sources` hold the programs alone, as before this pull request. What stays is the sandbox side, with no changed line: - Box refuses a grant of the agent, a tool, or a local MCP server that reaches a `reads` or `deny` path, and a write grant over the folder of a symbolic link on the way to one (`filesystem::require_outside_source_paths`), before a source program starts. - Each sandbox denies those paths. - The interpreters still refuse a change to the program of a source. Stated limit: with a declared source, Strands Shell and Monty do not refuse a read or a change of a `reads` or `deny` path, or a change of a symbolic link on the way to one. Policy decides, as it does on `main` for any path. `docs/user/config.md` ("What Box protects"), `docs/design/limitations.md`, and `docs/design/credentials.md` say so, with what an operator can do today: a path condition on each `fs:*` permit and a `forbid` rule for the paths of the vault. This change adds no folder to the credential store list of `containment`. Interface: the refusal "is at, inside, or above a path that a secret source keeps from each workload, or a link on the way to one" no longer exists. The design page `team/designs/0006-secret-providers.md` said "These protections must also cover the hosted Shell and Python paths". That sentence now says what Box does. ## Tests Linux x86_64 (an Amazon Linux 2023 container), on the tree of this commit: - `cargo fmt --all --check`, `cargo build --workspace --all-features --locked`, and `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` pass. The clippy gate refuses dead code, so it proves that each item with no caller left is gone. - The five doc guard targets pass: `site_manifest`, `documented_inputs`, `four_inputs`, `documented_commands`, `credential_method_scope` (38 tests). - `cargo test -p strands-box --all-features --lib`: 1,199 passed, 5 failed, 1 ignored. The commit below this one: 1,202 passed, the same 5 failed, 1 ignored. By name, the difference is the three removed tests and one test that has a new name. The 5 failures are the same on `main` in this container: two `kernel::tests::fallback` tests, `a_leafs_shebang_resolves_past_the_alias_directory`, and two `native_enforcement::probe` tests. - `strands-box-credentials`: 297 and 33 passed. `strands-box-telemetry`: 107 passed, and `the_vault_attaches_a_credential_on_an_ipv6_address` fails here and on `main`, because the container has no IPv6 loopback. macOS (arm64, Rust 1.96.0), on the tree of this commit: `box_credentials` 38 passed and 1 ignored, `mcp_schema_generation` 27 passed, `run_config` 26 passed. The unit tests of `run::secret_sources`, `run::credential`, `record::config`, and `command` passed (360), and those of `run::commands`, `run::broker::reach`, `run::contain::boundary`, and `record::config::filesystem` passed (164). A secret source loads on macOS only, so these binary tests cover all three commits of this series. Removed with the code: `a_path_of_a_secret_source_cannot_change_through_an_interpreter`, `a_link_on_the_way_to_a_path_of_a_secret_source_cannot_change_through_an_interpreter`, `an_absent_path_of_a_secret_source_cannot_change_under_another_case`. Two tests now pin the stated limit, so they fail when a floor in `Reach` refuses one of these paths: - `reach.rs::the_interpreters_leave_a_path_of_a_secret_source_to_policy` (it was `a_path_of_a_secret_source_refuses_mutation_and_names_its_reason`). A change at a `reads` path, inside it, at an absent `deny` path, and above it passes the reachable paths check, and a change to the program of the same source is refused. An undo patch that puts a stand-in floor under the interpreters makes it fail. - `box_credentials.rs::a_tool_cannot_see_a_path_of_a_secret_source_and_policy_decides_the_shell` (macOS, a real sandbox; it was `a_tool_cannot_see_and_the_shell_cannot_change_a_path_of_a_secret_source`). A tool cannot see a file under a `reads` path. With a permit for `fs:write`, the Shell changes that file. A `forbid` rule keeps a file under the `reads` path of a second source. The sandbox side still refuses, and these tests pass unchanged: `filesystem::tests::a_grant_that_reaches_a_path_of_a_secret_source_is_refused`, `a_grant_that_reaches_a_path_of_a_secret_source_through_a_link_is_refused`, `a_grant_that_reaches_an_absent_path_of_a_secret_source_is_refused`, `a_credential_store_of_a_secret_source_is_refused_when_named_exactly`, `boundary::tests::each_boundary_refuses_each_path_of_a_secret_source`, `secret_sources::tests::a_grant_over_a_path_of_a_source_is_refused_and_starts_no_program`, and on macOS `box_credentials.rs::a_grant_over_a_path_of_a_secret_source_is_refused`. Three undo patches on this tree, one for each protection that stays in this series, each made its tests fail: the name rule finds no owner of a variable (3 tests), the source programs are left out of the protected files (4 tests), and a grant is not judged against the `reads` and `deny` paths (7 tests). Not run: the full workspace suite, the Linux sandbox suites, and a real `op` or `aws`.
leo237
left a comment
There was a problem hiding this comment.
Assessment: Comment. I probed the floor adversarially and found no bypass at 182fa1e. Four things need follow-up. The branch is stale and conflicts with main in the files this floor lives in. The floor misses credential stores that environment variables relocate. A write lift on ~/.aws/config reopens the documented credential_process RCE through the interpreters. A few tests are missing. The earlier bot findings (declared home, parent rename, rename leak) are fixed, and I don't repeat them here. The governance approval thread on AGENTS.md is still the maintainers' to close.
What I tried that holds (no action needed)
- Wildcard or
..above a store.like "~/.aws/../*"passesnames_in_storebecause its fixed text starts with~/.aws/. It still lifts nothing outside the store, becausestore_liftchecks the canonical spelled path against the store prefix again."~/.aw?","~/*"and"~/.aw*"lift nothing. - Disjunctions. In
path == "~/.aws/config" || path like "~/*", only the in-store literal lifts.if/then/else,!andunlesslift nothing, so they fail closed. - Symlinks. A link planted into a store, a store linked elsewhere, and a store linked after startup are all caught, because
approve_hostcanonicalizes andhas_ancestor_amongreads identities at decision time. A link the Shell creates has to pass a read lift on its target. - Leaks inside a store after 182fa1e. A file rename onto a read-lifted path, a symlink to write-only content, and a directory rename while any
fs:readpermit opens the store are all refused. Monty has no hard-link or copy primitive, and the Shell has no hard-link pair operation. SetTimesfrom main (#471) falls into the_ => truearm ofmutates, so after the rebasetouchon a store counts as a change.matches_pattern: taking the leftmost match for each middle literal and checkingends_withfor the last one is correct for Cedar*.pattern_elementsmerges runs of single-character literals, sofixed_textsees the whole prefix.- A poisoned policy lock gives no permits, and no policy gives no lift. Both fail closed.
Findings
-
Stale against
main(must rebase before merge). The merge base is 1ccd68a, 103 commits behindmain.git merge-treereports conflicts incrates/box/src/run/broker/reach.rs,crates/box/src/run/broker/host.rs,crates/policy/src/lib.rs,crates/policy/AGENTS.md,crates/policy/README.mdanddocs/design/policy.md. Two changes onmaintouch this design and need a look on the rebased head:- #617 adds log-only mode. In a log-only box this floor is the only thing between the workload and
~/.aws. A test that a store stays refused withPolicyEngine::log_onlyon would pin that. - #193 adds Linux filesystem operations. Please check that every new
FsOperationor pair operation reachesapprove_mutationorapprove_rename.
The CI results below are for the stale head.
- #617 adds log-only mode. In a log-only box this floor is the only thing between the workload and
-
Stores that environment variables relocate are not covered (inline on
reach.rs:167). -
A write lift on
~/.aws/configreopens thecredential_processRCE thatlimitations.mddocuments, now through the Shell or Monty (inline onhost.rs:133). This is not a regression: a home-wide permit already allowed it before this PR. But this PR adds the supported way to grant it, so the disclosure should say what that means. -
The store list is incomplete. This PR reuses the sandbox's 12 rows from
forbidden-paths.json, which is the right call for consistency. Neither floor names these common stores:~/.azure,~/.config/gh,~/.git-credentials,~/.npmrc,~/.pypirc,~/.cargo/credentials.toml,~/.terraform.d/credentials.tfrc.json,~/.vault-token,~/.pgpass,~/.password-storeand~/.local/share/keyrings.decisions.mdalready says that the floor covers only the listed stores. A follow-up issue to widen the shared list would be worth filing, ideally making it operator-extensible. -
Test gaps (inline on the integration test): no single-file store through rename or write, no false-positive check for sibling prefixes, and no relative-path or
cdroute. -
Docs and message accuracy (nits, inline).
Tests run locally (Linux x86_64, glibc 2.26): cargo fmt --all --check passes, and cargo test -p strands-box-policy --all-features --test path_permits passes 5/5. I didn't run the strands-box unit or integration suites locally, so for those I relied on CI. At 182fa1e every check is green: Rust unit tests on macos-latest, ubuntu-24.04 and ubuntu-24.04-arm, Lint, Containment Deterministic on all three, and CodeQL. That is CI on the pre-rebase head.
| roots.push(canonical); | ||
| } | ||
| } | ||
| let mut credential_stores: Vec<PathBuf> = Vec::new(); |
There was a problem hiding this comment.
Important (non-blocking): stores that environment variables relocate are not covered. The anchors come only from the operator home and the agent's home, through credential_store_anchors(home). An operator can set AWS_SHARED_CREDENTIALS_FILE or AWS_CONFIG_FILE (for example ~/work/aws/credentials), KUBECONFIG, DOCKER_CONFIG, GOOGLE_APPLICATION_CREDENTIALS, CLOUDSDK_CONFIG or GNUPGHOME. Real credentials then live at a path this floor doesn't name. Chrome under a non-default XDG_CONFIG_HOME is the same case.
Concrete case: set AWS_SHARED_CREDENTIALS_FILE=~/work/creds/aws and use the home-wide permit from credential_store_tests::HOME_WIDE. Then cat ~/work/creds/aws through the Shell is allowed.
The sandbox floor has the same gap, so this is consistent and not a regression. It's still the most likely way a real operator's secrets reach the interpreters. Two options:
- Derive extra anchors from the operator's environment at startup, inside
containment::credential_store_anchors, so both floors gain them together. - Name the gap in a sentence in
security.mdanddecisions.md.
Either is fine for this PR. A follow-up issue for the first would be good.
| thread: Option<std::thread::JoinHandle<()>>, | ||
| } | ||
|
|
||
| /// Disclose on stderr each `permit` that opens a credential store to the interpreters. |
There was a problem hiding this comment.
Important (non-blocking): an fs:write lift on ~/.aws/config hands the workload the trusted process. limitations.md:59 documents that write access to ~/.aws plus any aws:// route is remote code execution in the box's trusted process, through credential_process. With this PR, permit(... fs:write ...) when { context.input.path like "~/.aws/*" } becomes the supported way to lift the floor. After that, printf '[default]\ncredential_process = /tmp/x\n' > ~/.aws/config through the Shell gets exactly that RCE.
The disclosure line here reads like any other store permit. Two suggestions:
- When an
fs:writestore permit covers~/.aws/configor the~/.awsdirectory and the record declares anaws://route, refuse it at startup, or print a distinct line that names the RCE. - Add the interpreter route to the
limitations.mdrow, which today covers only the agent's own write access.
This isn't a regression, since a home-wide permit already allowed it before this PR. But the PR's docs present the write lift as the safe, deliberate path.
| if in_store && self.store_lift(approved, mutates).is_none() { | ||
| return Err(Refused::new(reported_as, CREDENTIAL_STORE)); | ||
| } | ||
| if mutates |
There was a problem hiding this comment.
nit: stores_inside(approved, false) counts absent anchors. On a fresh home, mkdir ~/.config is therefore refused with contains a credential store, so no policy may change this directory, and so is mkdir -p ~/.config/myapp when ~/.config doesn't exist yet. No store exists there.
I think counting absent anchors is right, because it stops the workload from planting a ~/.config symlink that would redirect where a later gcloud writes its credentials. But the message misleads, and a missing ~/.config breaks a lot of tools. Two options:
- A separate reason for the absent case, such as
would change where a credential store is created. - Allow a plain
CreateDirof a real directory, sinceSymlinkandRenameare the operations that redirect.
A test that pins whichever you choose would help.
| .chars() | ||
| .flat_map(char::escape_default) | ||
| .collect(); | ||
| let line = format!( |
There was a problem hiding this comment.
nit: spelling goes through escape_default, but permit.rule() and store reach the operator's stderr raw, and the @id annotation behind rule() can hold \n or ESC. Policy is operator-authored, so the risk is low. Escaping all three would stop a reloaded rule from forging a strands-box: line or emitting terminal control sequences.
| const NOTES: &str = "ordinary-notes"; | ||
|
|
||
| fn plant(home: &Path) { | ||
| for store in [".ssh", ".aws"] { |
There was a problem hiding this comment.
Test gaps worth closing. The logic looks right to me; these tests would pin it.
- A single-file store.
plantcreates only.sshand.aws, which are both directories.~/.netrcis a file anchor. It takes thefixed == store && spelling == storebranch ofnames_in_store, and the same-store check inrefuse_store_relocationbehaves differently for it. Cover reading, writing and renaming~/.netrcout through both interpreters. - No false positives on sibling prefixes. The comparison is component-wise today, but nothing pins that. Under
HOME_WIDE,~/.aws-backup/x,~/.sshrc,~/.netrc.bakand~/.config/gcloud-old/xshould all stay readable and writable. - Relative-path and
cdroutes through the Shell. Covercd ~/.aws && cat credentialsandcat ~/notes/../.aws/config. I expectabsolute()plus canonicalization to refuse both, but only the absolute spelling is tested end to end. - After the rebase (summary item 1): a store stays refused under
PolicyEngine::log_only.
| ``` | ||
|
|
||
| The second rule protects credential stores, such as `~/.ssh`, `~/.aws`, a keychain, or a browser | ||
| profile, under the operator's home: the stores the agent's own grants can never enclose. Strands Shell |
There was a problem hiding this comment.
nit: "under the operator's home" is narrower than the code. Reach::over_with_floor also anchors the stores under a declared [agent] env.HOME, which a_declared_home_carries_its_own_stores tests. Suggest "under the operator's home and the agent's declared home".
| it, as in `context.input.path == "~/.aws"`. `box run` prints each such rule at startup. Your | ||
| `[agent.filesystem]` lists don't lift this refusal: they decide what the agent's own system calls | ||
| reach, and Strands Shell and Monty stay refused unless a `permit` names the path. Box refuses a | ||
| store under every spelling the file system treats as the same name, including one created after the |
There was a problem hiding this comment.
nit: "under every spelling the file system treats as the same name" understates the refusal on Linux. folded applies on every platform, so case-sensitive ext4 also refuses ~/.KUBE and ~/.Aws/config, and a_store_is_refused_in_every_letter_case_whether_or_not_it_exists asserts this on Linux. Failing closed is fine, but the text should say "in any letter case, on every file system". Otherwise a Linux user whose ~/.AWS is refused won't know why.
Description
Human readable section
Problem: Box keeps an agent away from credential files such as SSH keys and AWS config, but that protection only covered the agent's own sandbox. A request through Box's built-in shell or Python (
zsh -c ...,python3 -c ...) went around it. So a broad policy like "allow reading everything under the home" let a prompt-injected agent read~/.ssh/id_rsa, or plant a line in~/.aws/configthat the AWS CLI later runs as the operator, outside any box.Solution: The built-in shell and Python now apply the same credential-file protection as the sandbox, from the same list of protected locations (
~/.ssh,~/.aws,~/.gnupg,~/.netrc,~/.docker,~/.kube, gcloud, keychains, browser profiles). A store stays off limits however broad the policy is, unless a policy rule names the path inside that store: for examplepermit fs:read when { context.input.path == "~/.aws/config" }orlike "~/.aws/*". A pattern with a wildcard above the store, such as"~/*"or"~/.aw*", never opens it. Box prints each such rule at startup, and the policy still decides each access. The agent's own[agent.filesystem]entries no longer have any say over the shell and Python: they decide only what the agent's sandbox reaches.Why a policy rule and not a
box.tomlentry: an earlier commit in this PR let an[agent.filesystem]entry that names a store open it to the shell and Python too, to match the sandbox. That tied two things together: to let the shell read~/.awsunder policy, the operator also had to give the agent's own sandbox direct access to~/.aws, with no policy decision in the path. The last commit removes that coupling and uses the rule the ticket suggested instead.Before and after: the sandbox and Shell/Monty side by side
read = ["~"], or a policylike "~/*")path == "~/.aws/config"orlike "~/.aws/*")[agent.filesystem]entry names a store (read = ["~/.aws"])fs:readrule vs anfs:writerulefs:readopens reads only,fs:writeopens changes only ✅!or inunless, or aforbid~/.config)~/.AWS,~/.awſ)Trade-off: A policy that relied on a broad rule to reach a store through the shell or Python now gets a refusal until a rule names the path inside the store. This floor is now the one floor a
permitcan lift, so it no longer sits fully beneath policy: once a rule names a store path, a second, broader permit can also decide that path without the naming rule's other conditions (for example a temporal budget or anunlessclause). Write aforbidfor a file that must stay closed. Anfs:writerule opens every kind of change on the paths it names, because the floor sees "a change", not which verb. Only the listed stores are covered; a broad rule still reaches everything else under the home. A script that walks the home and inspects every entry gets a refusal on each store. Each request costs one disk lookup per store spelling (about 70 µs per read in a debug build).What we tested:
a_home_wide_permit_reaches_no_credential_store_through_either_interpreter~/*policy; read~/.ssh/id_rsaand append to~/.aws/configthroughzshandpython3a_store_a_read_permit_names_reads_and_stays_unwritable~/*policy pluspermit fs:read when path like "~/.aws/*"~/.aws/configreads, a write is refused,~/.sshstays refused, the rule is printed at startup ✅an_agent_entry_naming_a_store_opens_it_to_neither_interpreter~/*policy andread = ["~/.aws"]inbox.tomla_write_permit_cannot_move_a_store_file_out_through_either_interpreterfs:writerule on~/.aws/sso/cache/*; move a token into the homean_absent_store_cannot_be_created_under_a_spelling_that_folds_to_its_name~/.awsabsent;mkdir ~/.awſand write a config into ita_prepared_directory_cannot_be_renamed_onto_an_absent_store.aws,.AWS,.awſa_declared_home_granted_to_the_agent_keeps_its_stores_from_the_interpretersenv.HOMEis its own directory withreadandwritegranted.aws; Shell and Python are refused ✅a_parent_of_a_lifted_store_cannot_be_moved_out_through_either_interpreterGoogleelsewherereach.rscredential_store_tests(22 unit tests)!/unless/forbid, a reload, letter case, Unicode spellings, links, enclosing directories, a declared home, disclosurepolicy/tests/path_permits.rs(5 tests)strands-boxandstrands-box-policy,--all-features, plusfmt,clippy,cargo doc -D warningsmodern_cancellation_releases_active_capacity, which passes alone ✅box_shell,box_filesystem, box unit tests, policy suitesbox_shell_cwdandbox_installationfail identically on unmodifiedmainin that VM, because its image linkspwd,ln, andenvto a multi-call binary; CI runs them ✅Details
The sandbox refuses any grant that encloses a credential store (
~/.ssh,~/.aws,~/.gnupg, keychains, browser profiles), but the hosted Strands Shell and Monty never consulted that list. With a broad policy such aspermit fs:read when path like "~/*", a prompt-injected workload could read~/.ssh/id_rsathrough thepython3orzshalias, or appendcredential_processto~/.aws/config, which the AWS CLI later runs as the operator outside any box.What changes for an operator
permitlifts that refusal for the paths its owncontext.input.pathliteral orlikepattern matches, when the text before its first wildcard sits inside the store (or the literal is the store itself). Only comparisons in awhenclause count, outside every!;unless,if, andforbidopen nothing.fs:readopens reads,fs:writeopens changes;fs:deleteorfs:movealone opens nothing.strands-box: policy: … opens ~/.aws/config in the credential store ~/.aws to the Shell and Python (fs:read)), and prints a rule a policy reload adds before it first opens anything.[agent.filesystem]entries affect the agent's sandbox only.Interfaces and decisions this depends on
strands-box-containment: one additivepub use,credential_store_anchors(home), so the grant check and the new floor read one store list.strands-box-policy: one additive façade type,PathPermit, andPolicyEngine::path_permits(), which lists the paths the installed permits name and follows a reload. Matching is linear in the path length.AGENTS.md: "Policy is the only authorizer" now states this one floor a permit can lift; the "Filesystem reach" paragraph goes back to "the agent's filesystem lists govern its sandbox alone".no-credential-floor-sits-beneath-the-interpretersis rewritten in place (anchor kept) and records why thebox.tomlcoupling, an interpreter-only key, aforbid, and a warning each lost.box.tomlkey, record, protocol, alias, policy action, or environment name moves.One existing test changed, and why.
box_shell.rs::a_matching_leaf_reads_and_writes_announced_credentials_and_the_main_workload_does_notdeclared[tool.wc]and[tool.touch]. The Shell implements both commands, so its own builtins read and wrote~/.awsin the trusted process, and the test passed through this defect. It now usescksumanddd, which really run in their own leaf sandboxes.Residuals, stated in the docs rather than closed
crates/box/AGENTS.md).fs:writerule opens every change on its paths, becauseapprove_mutationdoes not carry the verb.writeentry on a store lets the agent's own system calls move the store's files elsewhere, where a broad rule then reads them through the interpreters.Related Issues
Closes the gap recorded in
docs/design/decisions.md#no-credential-floor-sits-beneath-the-interpreters.Type of Change
Bug fix
Testing
On macOS 26.6 arm64 and in a local Ubuntu 26.10 arm64 VM, on the final commit:
cargo test -p strands-box --all-featuresandcargo test -p strands-box-policywith and without--all-features.cargo fmt --check,cargo clippy --all-targets(with and without--all-featuresfor the policy crate), andRUSTDOCFLAGS="-D warnings" cargo doc -p strands-box-policy: clean, no warnings in the changed crates.A
feature-criticreview before the commit; its findings (a backtrackinglikematcher, the reload disclosure, and doc gaps) are fixed in the same commit.Linux:
box_shell_cwdandbox_installationfail with the same test names on unmodifiedmainin that VM (itspwd,ln, andenvare links to a multi-call binary); everything else passes.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.