Skip to content

feat(filesystem): let a read entry name a link to a file - #456

Merged
opieter-aws merged 3 commits into
mainfrom
feature/read-entry-file-link
Nov 16, 2026
Merged

opieter-aws merged 3 commits into
mainfrom
feature/read-entry-file-link

Conversation

@opieter-aws

@opieter-aws opieter-aws commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

On Linux, a program often runs a helper by the name PATH finds, such as /usr/bin/cc, and that name is a symbolic link. Box refuses a filesystem entry that names a link, so a caller can only grant the real file (/usr/bin/gcc). The name the program opens is then missing in the box, and cargo stops with linker `cc` not found.

This change lets a read or read_file entry name a link to a file.

  • What the operator gets: read_file = ["/usr/bin/cc"] works. The box shows gcc's file at /usr/bin/cc and at /usr/bin/gcc, both read-only. The disclosure prints read_file /usr/bin/cc -> /usr/bin/gcc.
  • The trust it adds: one more read-only name for a file the entry already grants. The grant is still judged on the real file, so a link into ~/.ssh is refused like the file itself. The links in between, such as /etc/alternatives/cc, and the folders that hold the links are not granted.
  • Two links to one file, such as /usr/bin/cc and /usr/bin/gcc on Ubuntu, are two entries, and both names reach the file. A link beside a read folder that holds its file is kept too, such as /usr/bin/java next to the JDK folder, because its name is outside that folder.
  • Still refused: a link to a directory, a link reached through a linked folder, a link inside a credential store (such as ~/.ssh/config), a link listed next to its own file or inside the folder it points into, and a link in write, write_file, exec, list or metadata.
  • Each spawn re-checks that the link still points at the file the run judged.
  • macOS: Seatbelt refused two grants that resolve to one file (granted Read twice). It now refuses only one name granted twice, and renders each link name's own rules.
  • Interfaces: check_read_grant now accepts a read link to a file, and the GrantRefusal::Link doc lists which links are still refused.
  • Decisions: new entry, "A read entry may name a link to a file".
  • Docs: docs/user/config.md (entry rule and refusal table), docs/design/platform-differences.md, docs/design/containment.md.

Related Issues

None.

Type of Change

New feature

Testing

Check Result
a_read_entry_naming_a_link_to_a_file_reads_by_both_names (a real box reads the file by two link names and by its own name, not a sibling, and the disclosure shows the arrow) passes
every_refusal_class_fires_and_names_the_entry (accepted in read and read_file, as two links to one file, and beside a folder holding its file; refused in write_file, metadata, exec, through a linked folder, inside and into a credential store, inside the folder it points into, and twice with its file) passes
a_read_grant_naming_a_link_to_a_file_is_accepted (check_read_grant) passes
staging-boxy corpus RS-01 and RS-02 on ARM64 Amazon Linux 2023: staging-boxy 50bf296 plus its helper change, built against this change at 6061c66e plus #455's permit GREEN (RS-02: permits=232, denies=0). Without this change: linker `cc` not found
  • The corpus run was on 6061c66e, before the review fixes. The review fixes (92369795: credential-store links, two names for one file) were tested with fmt, clippy and the workspace tests on c061263c, then rebased onto a8009909 without a rerun.
  • cargo fmt --check, cargo clippy --workspace --all-targets --all-features -D warnings and cargo test --workspace --all-features pass. On the busy test host, mcp_alias_fallback (Text file busy), shell_dependency_guard (package-cache lock) and runs that hit a full disk failed in the parallel run. Each passed when run again on its own, and none touches filesystem entries.
  • the_enter_only_grant_renders_before_the_direct_grants reads boundary.rs source, so its search string follows the changed line.
  • Not run locally: macOS, including the new Seatbelt row in grouping_folds_one_path_into_one_rule_set; CI runs it. On macOS Seatbelt already allows each link node on a grant's path.

Still blocked

  • The staging-boxy side, which grants a helper by its PATH name and gives a GCC helper the files it links, needs this change in its pinned Box Core.
  • RS-03 (cargo install cargo-nextest) stops at the output budget and bash's setpgid EPERM, a separate wall.

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

@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

The link-to-a-file path works for the common non-store case. However, the link branch also accepts cases its guards were not built for: a link inside a credential store, and a link whose target another grant already covers. Details are in the inline comments.

Review Categories
  • Correctness / premise: A credential-store link escapes the per-spawn identity re-check (blocking).
  • Scope: The overlap rules still use only resolved, so they refuse the extra names this feature exists to grant.
  • Interface: box.toml filesystem lists and check_read_grant are frozen surfaces under root AGENTS.md. The PR names the change but doesn't record the approval. The public GrantRefusal::Link doc in lib.rs ("The path is a symbolic link.") is now inaccurate for a read link to a file.
  • Tests: The new unit test checks resolved, lexical and is_link() one field at a time. A single assert_eq! on the DirectGrant would catch a regressed operation, scope or credential_store.

Checked and held:

  • Every non-link entry keeps lexical == resolved, so is_link() is false for it and the boundary still grants resolved.
  • A link through a linked folder is still refused.
  • A link to a directory is still refused.
  • An outside link into ~/.ssh is still refused by the floor.
  • Links in write, write_file, exec and metadata are still refused.
  • guard.judge still checks the resolved identity for link grants.
  • For non-store links, require_judged_identities catches a re-pointed link.
  • Containment's reachable_paths and traversal_paths already carry the original spelling, so no containment change is needed.

The motivation and the staging-boxy evidence are clearly laid out.

@github-actions

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed at 9236979. Both earlier findings are fixed and covered by new test rows, and I found no new correctness problem in the changed branches.

Checked and held:

  • A credential-store link is refused at config time. A store file that becomes a link during a run still fails the spawn.
  • is_link() is now lexical != resolved, so every link grant gets the per-spawn re-check and the -> disclosure.
  • Two links to one file, and a link outside a tree pointing into it, are accepted.
  • A link next to its own file, the same link listed twice, and a link inside its own tree are still refused.
  • Entries that are not links behave as before (names() holds only resolved).
  • GrantRefusal::Link in lib.rs and docs/user/config.md now describe the narrowed link rule.

Still open, non-blocking: the unit test checks resolved, lexical and is_link() one field at a time. A single assert_eq! on the DirectGrant would also catch a regressed operation, scope or credential_store.

@opieter-aws
opieter-aws enabled auto-merge (squash) November 13, 2026 22:05
@github-actions

Copy link
Copy Markdown

Assessment: Approve

Re-reviewed at 77a38ca. The only change since 9236979 is in the Seatbelt group_by_path. The duplicate check now keys on (spelling, operation) instead of (resolved path, operation). This lets macOS render two links to one file, which the box layer now accepts. I found no wrong result in the changed check.

Checked and held:

  • Two links to one file now pass grouping. Each link gets its own file-read-metadata literal, because the renderer walks every grant and not the groups.
  • The same spelling granted the same operation twice is still refused. The new test covers this.
  • A link next to its own file now passes this check, but it is harmless: it renders one file-read* literal on the resolved file plus metadata on the link. The box layer refuses it earlier anyway.
  • Two spellings that differ only in . or // are equal as Paths, so they are still caught as duplicates.
  • One resolved path granted with two different scopes is still refused before the spelling check.
  • Different operations on one path still fold into one group, as before.
  • The with(Exec, File) executable check still sees every exec grant.
  • The pub use façade and the SBPL minimums are unchanged, so crates/containment/AGENTS.md treats this as "a defect fix behind the current shape" that needs no approval.
  • cargo test -p strands-box-containment --lib seatbelt passes 40/40 on Linux (render-only).

Still open, non-blocking: the DirectGrant unit test checks fields one at a time (noted in my earlier review).

@zastrowm

zastrowm commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

I dug into this a bit, trying to determine what we decided in the past; I think this is effectively giving parity with MacOS

Agent reply:

> I went through our earlier link work in box-staging, and this follows the pattern we've used every time: judge the real file, keep the name the program uses, and accept a link only in its real folder (the same rule as the command route and MAC-09). On macOS parity, the agent gets the same result on both platforms: it can read the file by the link's name and by its own, read-only, and nothing else in that folder. The mechanism differs, and the platform-differences row already says so: macOS keeps the host's real link and allows a metadata read on each link along the way, while Linux binds the file at the link's name, so there readlink /usr/bin/cc fails and the name looks like a plain file. One gap: the end-to-end test uses one link, but Ubuntu's cc -> alternatives/cc -> gcc is two, and a one-link test is what hid the MAC-09 chain bug on macOS, so a two-link case would be worth adding. Last, the old refusal message says a link "renders a rule that matches nothing", which MAC-02 showed is wrong for metadata rules, so this is a good time to fix that wording.

After looking into this a bit more, this is not a platform issue, this is a standlone feature that effects both platforms

@opieter-aws
opieter-aws merged commit 73fce44 into main Nov 16, 2026
21 checks passed
@opieter-aws
opieter-aws deleted the feature/read-entry-file-link branch November 16, 2026 16:33
} else {
&grant.resolved
};
allow_operator(containment, path, grant.operation, grant.scope)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the permission tied to the approved file

This can prepare a read grant for a different file from the one Box approved at startup. The gap occurs when a process can replace an intermediate link in a directory it has permission to write to.

For example, suppose the configured link is helper, which points through scratch/selector to approved.txt. Box checks that helper still reaches the approved file. Later, when preparing the read permission, it follows helper again. If a running process replaces scratch/selector between those steps, the second lookup can select other.txt. The configured link itself has not changed, but the file selected for the grant has.

Could we compare the prepared target with the approved target saved in grant.resolved, then finish creating the grant from that same prepared result? The existing guard checks could stay in place. Reusing the prepared result matters because following the link again after the comparison would reopen the same gap.

I reproduced this in a controlled test by running the existing identity check, replacing the intermediate link, and then preparing the grant. The resulting configuration granted other.txt instead of approved.txt. As a control, replacing the link before the identity check was rejected. This demonstrates the gap in the grant preparation sequence; I have not reproduced the timing in a concurrent full-Box run.

&& lexical
.parent()
.is_some_and(|folder| folder.canonicalize().is_ok_and(|real| real == folder))
&& lexical.canonicalize().is_ok_and(|target| target.is_file());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include the directory links needed to read the file on macOS

Some file links accepted by this change still cannot be read through their configured name on macOS. The final file is readable, but opening the link fails with a permission error. That leaves an accepted configuration unable to provide the read access it promises.

For example, suppose helper points to current/file, and current is a directory link pointing to data. Here, helper itself sits in a real directory, so it meets the new acceptance rules. The problem occurs farther along the path. The code finds data/file but leaves current out of the permissions it generates. macOS still needs to follow that directory link when the process opens helper, so the missing permission blocks the read.

Could we retain the directory links encountered along the target path and include the permissions needed to follow them? A regression test could check that both names are readable while neighboring files remain blocked. The code already had this gap, but this PR makes the affected configuration valid.

In a native macOS 27.2.1 test using this PR’s containment library, the configuration applied successfully and data/file was readable. Opening helper returned “operation not permitted.” Adding a metadata grant for current, which permits inspecting that link, made helper readable while data/sibling remained blocked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants