Skip to content

fix(bw): mount the pixi home read-only - #54

Open
Stuart B. Wilkins (stuwilkins) wants to merge 6 commits into
NSLS2:mainfrom
stuwilkins:fix_pixi_home_read_only
Open

Stuart B. Wilkins (stuwilkins) wants to merge 6 commits into
NSLS2:mainfrom
stuwilkins:fix_pixi_home_read_only

Conversation

@stuwilkins

@stuwilkins Stuart B. Wilkins (stuwilkins) commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Mount the pixi home ($PIXI_HOME, default ~/.pixi) read-only in every bw* sandbox, so a session can no longer replace the tools that the host runs from ~/.pixi/bin.

Closes #46.

Description

build_pixi_mounts bound $PIXI_HOME with --bind. A session could overwrite ~/.pixi/bin/* (zellij, nvim, ruff, prek and any other pixi global tool), and the host would run the changed file the next time the user started it outside the sandbox. It is now --ro-bind. All six launchers call the function, so one change covers bwclaude, bwcodex, bwcopilot, bwopenchamber, bwopencode and bwopencode2.

  • Nothing needs to write there. With PIXI_HOME read-only (permissions only, not a bind mount), pixi exec, pixi add and pixi run worked in a scratch project. Only pixi global install and pixi self-update fail ("Permission denied" here, read-only file system in the sandbox). Both are host commands.
  • The mount is repeated after every other read-write mount (pin_pixi_home_read_only, called first thing in build_sandbox_context, so the context file lists the final mounts and the binary masks stay last): at its own path, at its real path if that differs, and wherever a read-write bind has the pixi home, a directory in it, or a directory above it as its source. A PIXI_HOME inside the read-write npm, ccache or prek caches, a ~/.pixi that is a symlink into one, or a ~/.npm that is a symlink to ~/.pixi or to a directory that holds it, stays read-only. --rw-path on the pixi home (~ is expanded, a symlinked home included) is the one way to make it writable.
  • A different PIXI_HOME is mounted read-only as well. The issue also suggested mounting the default ~/.pixi read-only in that case. I did not: the home is a tmpfs, so the default ~/.pixi is not in the sandbox at all and adding it would only expose more.
  • Comments and docs/bw-wrappers.md that said ~/.pixi is writable from the sandbox are corrected, and a short section describes the change. bwopenchamber's Node probe is unchanged. It still never runs a node on the host, because an activated project environment is still writable.

Open point for reviewers: this closes the pixi home only. The working directory is read-write by design, and the host later runs things from it (.git/hooks, core.hooksPath and core.fsmonitor in .git/config, pixi tasks, .envrc). The new doc section says so. I think that needs its own issue (for example read-only binds of .git/hooks and .git/config), so I left it out here.

Testing

  • tests/test-bwopenchamber.sh: 126 passed. It has new dry-run checks that the default and a custom PIXI_HOME get --ro-bind and no --bind, that the default ~/.pixi is not mounted when PIXI_HOME is elsewhere, that a PIXI_HOME inside ~/.npm is read-only after the npm mount, that --rw-path on the pixi home (also written with ~) wins, that a symlinked ~/.pixi is covered by its real path, that the binary masks still come after the pin (PIXI_HOME=/usr), that a ~/.npm symlinked to the pixi home is covered, that a ~/.npm symlinked to a directory above the pixi home is covered, that the sandbox context file lists a nested pixi home as read-only (also with --no-sandbox-context), and that --rw-path on a symlinked home is writable at the configured path. With the library change reverted, the mount checks fail. The test helper clears PIXI_HOME and NPM_CONFIG_CACHE, so exported ones do not change the result.
  • tests/test-bwopencode2-serve.sh (72) and tests/test-bla-git-config.sh (49) pass.
  • pixi run -e dev lint-files on the five changed files passed, and the same hooks passed again at commit.
  • pixi exec, pixi add, pixi run and pixi global install tried with a read-only PIXI_HOME (chmod 555) in an agent sandbox, not through a launcher: the first three worked, the last failed as described above.
  • Not tested: a real bw* launch with the read-only bind on a managed host, or bwopenchamber against a real pixi global Node.

Checklist

  • Edit the sections above with relevant information
  • Update in-repo documentation, if applicable
  • Run pixi run -e dev lint locally (or wait for CI) — see .github/workflows/lint.yml
  • Test the changes on a representative managed host (or runansible deployment)

Assisted-by: opencode:claude-sonnet-5-5

The host runs the tools in ~/.pixi/bin outside the sandbox, so a program
replaced there from inside a session escaped it. Project work and pixi exec
write elsewhere; only pixi global and pixi self-update need the host.

Closes NSLS2#46

Assisted-by: opencode:claude-sonnet-5-5
Copilot AI balanced review requested due to automatic review settings December 3, 2026 13:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A later writable npm mount overrides Pixi’s read-only protection for nested custom paths, preserving a host-binary replacement vulnerability, while the default-home test also depends on the invoking shell’s environment.

2 open issues
What changed in this PR

This PR addresses #46 by making the shared Pixi-home mount read-only across all six sandbox launchers, protecting host-run tools from modification inside sessions.

Changes:

  • Switch the Pixi-home bind to read-only.
  • Add dry-run checks for default and custom PIXI_HOME paths.
  • Update security documentation and comments without changing browser or Node probing behavior.
File Description
tests/​test-bwopenchamber.sh Add Pixi-home mount assertions.
lib/​bwrap_sandbox_lib.sh Make the shared Pixi-home mount read-only.
docs/​bw-wrappers.md Explain protection, limitations, and host-only operations.
bin/​bwopencode2 Update the browser security comment.
bin/​bwopenchamber Update the Node-probe security comment.

Review effort: Balanced

Comment thread lib/bwrap_sandbox_lib.sh Resolved
Comment thread tests/test-bwopenchamber.sh Resolved
A PIXI_HOME inside a read-write cache such as ~/.npm was covered again by
that cache's mount. Mount it read-only once more after all other mounts,
unless --rw-path names it. The test helper now clears PIXI_HOME.

Assisted-by: opencode:claude-sonnet-5-5
Copilot AI balanced review requested due to automatic review settings December 3, 2026 13:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical Pixi mount issues can re-expose masked binaries and leave host tools writable through symlink aliases, while path normalization and cache-dependent regression checks also need fixes.

4 open issues
2 resolved since last review

Review effort: Balanced

Comment thread lib/bwrap_sandbox_lib.sh Resolved
Comment thread lib/bwrap_sandbox_lib.sh Resolved
Comment thread lib/bwrap_sandbox_lib.sh Resolved
Comment thread tests/test-bwopenchamber.sh Resolved
Call the pin from build_binary_masks so the masks stay last, expand ~ in
--rw-path the way the extra-path mounts do, and also mount the real path of
a symlinked pixi home. The test helper clears NPM_CONFIG_CACHE.

Assisted-by: opencode:claude-sonnet-5-5
Copilot AI balanced review requested due to automatic review settings December 3, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

A writable ~/.npm symlink alias still bypasses ~/.pixi protection, allowing host-tool replacement without --rw-path, while the documented write opt-out also fails for symlinked pixi homes.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

High severity Protect writable bind aliases of the Pixi directory

lib/​bwrap_sandbox_lib.sh:5980

The reverse symlink layout still bypasses this protection: with ~/.npm -> ~/.pixi, build_npm_mounts emits a writable bind at ~/.npm, backed by the same host directory. These pins cover only ~/.pixi, so a session can still replace host tools through ~/.npm/bin without --rw-path. Resolve writable bind sources and protect their corresponding destination aliases too, or reject such overlaps; add a regression check for this inverse symlink layout.

Medium severity Honor --rw-path for symlinked Pixi home

lib/​bwrap_sandbox_lib.sh:5977

When ~/.pixi is a symlink to ~/.npm/pixi, --rw-path ~/.pixi mounts only the canonical ~/.npm/pixi destination. This early return leaves the initial read-only mount at ~/.pixi intact, so commands using the configured pixi home still cannot write despite the documented opt-out. Make the override writable at the configured path too, while preserving nested --ro-path overrides, and add a regression check combining the symlink and opt-out cases.

4 resolved since last review

Review effort: Balanced

Mount the pixi home read-only again wherever a read-write bind has it as
its source (a ~/.npm that is a symlink to ~/.pixi), and mount it read-write
at the configured path when --rw-path names a symlinked pixi home.

Assisted-by: opencode:claude-sonnet-5-5
Copilot AI balanced review requested due to automatic review settings December 3, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because a symlink and ancestor-bind interaction can expose host tools for modification without explicit write permission.

No open issues 🎉

Review effort: Balanced

A read-write bind whose real source is an ancestor of the pixi home showed
the home at destination/<relative path>. Mount it read-only there too.

Assisted-by: opencode:claude-sonnet-5-5
Copilot AI balanced review requested due to automatic review settings December 3, 2026 15:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Pixi permissions are pinned after the sandbox context is rendered, causing the agent’s access table to omit the read-only exception when PIXI_HOME is nested under the writable npm mount.

1 open issue

Review effort: Balanced

Comment thread lib/bwrap_sandbox_lib.sh Resolved
The context file lists the mounts as they are when it is built, so the pin
has to come first. It now runs at the start of build_sandbox_context, which
every launcher calls after its other mounts and before the binary masks, and
also with --no-sandbox-context.

Assisted-by: opencode:claude-sonnet-5-5
Copilot AI balanced review requested due to automatic review settings December 3, 2026 15:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because interacting path-resolution and mount-order edge cases can produce incorrect dry-run mappings or cause actual sandbox launches to fail.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bw* sandboxes mount ~/.pixi read-write, letting a session replace binaries the host runs

2 participants