--sandbox_block_path: help doesn't say an absent path isn't blocked, or that replacing the path unblocks a running action

Open Beginner friendly
#31,318 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Active
Tech stack
linux
Domain
build-system

Research direction

Search the Bazel source for the existing --sandbox_block_path help text and inspect the linux-sandbox option entry point. Update the help or documentation to state when the path is blocked and when replacement can unblock it, then run the relevant --help output to verify the wording.

Written by the indexing model from the issue text.

Description

team-Local-Exec type: documentation (cleanup)

The reporter of #4963 wanted --sandbox_block_path "to prevent likely cases of loss of hermeticity". Its help is one line: "For sandboxed actions, disallow access to this path." On Linux I found two cases where an action read a path passed to this flag. Neither is in the flag's help or in the docs.

The first is a path that does not exist when an action's sandbox is set up. linux-sandbox skips it. That is what #4963 asked for, and b6bb800 made it so, released in 7.3.0. The same issue asked for the flag's description to "document what this is", and the help still reads as quoted above. I'm not asking for a warning. I mention the silence because it leaves the build no way to show that the path wasn't blocked. On 9.2.0 the console output with the flag and an absent path was the same as without the flag, apart from timings and the output directory's name. It was still the same at --sandbox_debug -s once timestamps and PIDs are removed, and at that verbosity an applied block prints a bind mount line naming the path. 7.2.1 failed the build instead: "Mount target '...' does not exist."

Because the check runs for each action, a path that appears during the build was blocked for some actions and not others. I ran two genrules, B depending on A, with the blocked file absent at the start. A host process created it after A had started. Action A read it. B, set up afterwards, got Permission denied. With the file present from the start both were denied, and without the flag both read it.

The second case is a block that was applied. While an action ran, I replaced the blocked file from outside the sandbox, once by renaming a new file over it and once by deleting and recreating it. Both times the running action read the new file. Rewriting the file in place kept it blocked, and actions started afterwards were blocked again. With a blocked directory on 9.1.1, the action's /proc/self/mountinfo listed the bind mount before the replacement and not after. That matches mount_namespaces(7): a mount point replaced from another mount namespace is detached, as the kernel has done since Linux 3.18. Renaming a new file over the old one is the usual way to update a file atomically. So a blocked file that a host process updates that way while an action runs becomes an undeclared input of that action.

The mechanism isn't new. The kernel documents it, and another sandbox that hides paths with bind mounts ran into it and wrote it down when it changed its own cleanup (https://github.com/anthropics/sandbox-runtime/pull/184). What I couldn't find in Bazel's help or tracker is that an action already running can read a blocked path that appears, or is replaced, after its sandbox was set up. The nearest issue, #24514, is a different limit of the same flag, which a maintainer traced to symlink resolution.

All of this was on Linux, Debian 13 with kernel 6.12, under linux-sandbox. On 9.2.0 I ran every case twice, each from a fresh workspace and output root. The absent path and the path that appeared mid-build gave the same results on 8.8.0, and on 9.1.1 with a blocked directory. I didn't run macOS, where these paths are passed to sandbox-exec (#4963), and I didn't run the hermetic sandbox. processwrapper-sandbox ignores the flag altogether: under it the file was readable with the flag set.

For linux-sandbox, one sentence in the help would cover both: for each action, the path is blocked only if it exists when that action's sandbox is set up, and only until something replaces it while the action runs.

Dominant language
Java
Stars
26.2k
Forks
4.7k
Avg merge
3d 11h
Merged PRs (30d)
125

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bazelbuild/bazel

All issues in bazelbuild/bazel

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.