Skip to content

fix(sandbox): use unprivileged bubblewrap for bounded previews - #2182

Merged
l0gicgate merged 3 commits into
lgse:mainfrom
dragonleopardpig:fix/unprivileged-bwrap-sandbox
Nov 12, 2026
Merged

l0gicgate merged 3 commits into
lgse:mainfrom
dragonleopardpig:fix/unprivileged-bwrap-sandbox

Conversation

@dragonleopardpig

Copy link
Copy Markdown
Contributor

Description

Fixes a failure where bounded media/PDF preview rendering fails when bwrap is installed as a setuid root wrapper (such as /run/wrappers/bin/bwrap on NixOS), because setuid bwrap refuses --unshare-all / user namespace creation when nested or invoked with unprivileged sandbox flags.

  • Resolves the underlying unprivileged bwrap binary when /run/wrappers/bin/bwrap is first on PATH (including checking /nix/store/*-bubblewrap-*/bin/bwrap when needed).
  • Adds unit tests covering bwrap path resolution and fallback behavior.

Visual evidence

N/A (sandbox process launch fix for bounded PDF and media previews).

How to test

  1. Run cargo test --bin strata sandbox::tests to verify the bwrap path resolution unit tests.
  2. On a system where /run/wrappers/bin/bwrap is setuid root (e.g. NixOS), preview a PDF or video file in Strata and verify that bounded preview rendering succeeds without sandbox permission errors.

Related issue

None

@JoeJoeflyn

Copy link
Copy Markdown
Collaborator

Just wondering why you closed this

Merges b978134. The trusted_command resolvers move to strata-core with the rest of the toolkit-free code, so resolve_unprivileged becomes public like resolve.
@l0gicgate

Copy link
Copy Markdown
Contributor

Review and cleanup

CI has not run on this PR. It is a draft, and ci.yml skips every job on drafts; the CI run for 8f1cc1907 is also waiting at action_required (first-time fork contributor). Only Metadata policy and Type label ran, both green. Everything under Validation is local.

Merged main at b97813450. One conflict, in crates/strata-core/src/trusted_command.rs: #2112 moved the module into strata-core and made resolve public, so resolve_unprivileged is public too and strata-preview and the binary can call it. The four sandbox call sites and the test followed their files into the new crates.

Review against the description (no linked issue)

  • The fix is correct and I found no blockers in the code. The mechanism differs from the description: bubblewrap up to 0.10 rejects --size in setuid mode (The --size option is not permitted in setuid mode), and 0.12.0 as built in the test image refuses any setuid use (setuid use of bubblewrap is not supported). Every sandbox spawn goes through runtime_command, which always passes --size, so a setuid bwrap could never start a preview sandbox and skipping it loses no working setup.
  • "including checking /nix/store/*-bubblewrap-*/bin/bwrap" is not implemented and not needed. After skipping the wrapper the search continues through the remaining fixed directories (/run/current-system/sw/bin) and then STRATA_TRUSTED_COMMAND_PATH, which the flake package points at bubblewrap in its closure.
  • A host whose only bwrap is setuid now reports the sandbox as unavailable, and Diagnostics says to install bubblewrap. That is the right advice there.
  • resolve is unchanged, so wrappers still win for every other helper.
  • "How to test" step 1 is stale after the merge: the test lives in strata-core and runs with ./scripts/test-headless.py trusted_command::.

Fix pushed

  • 8f1cc1907 docs(sandbox): docs/preview-sandbox.md said /run/wrappers/bin always keeps priority; it now documents the bubblewrap exception.

Tests. Both kept. sandbox_resolution_skips_privileged_wrappers_but_keeps_trust_checks fails if the mode filter is dropped, leaks into resolve_in, or lets the fallback skip the trust check. The png variant of camera-formats-preview-sandbox is the only QA assertion on the decoded pixels of an ordinary image in the Space preview. It cannot catch the setuid case in the normal QA container, which has no setuid bwrap; the unit test owns that.

Manual verification. In a throwaway container from the pinned test image, with a setuid-root copy of bwrap at /run/wrappers/bin/bwrap and the scenario run as an unprivileged user:

  • this branch: columns-png and columns-mp4 pass;
  • with resolve_unprivileged temporarily resolving like resolve (main's behaviour): both fail, with no thumbnail and no video preview.

Not tested on a real NixOS host.

Validation

  • ./scripts/test-headless.py trusted_command::: 9 passed
  • ./scripts/test-headless.py -- sandbox:: diagnostics: 101 and 13 passed
  • ./scripts/qa.sh --test-threads 6 camera-formats-preview-sandbox: 5 runs passed
  • ./scripts/quality.sh fmt, ./scripts/quality.sh clippy: clean
  • scripts/code-health.sh on trusted_command.rs and its tests: 9.38 and 10.0, same as main
  • Not run: the full Rust suite and the full QA suite. The change is confined to the resolver and its five bubblewrap call sites, which the runs above cover.

Not changed

  • The PR has no linked issue and the branch name has no issue number; the repository workflow is issue-first.
  • The description is left as written, including the two inaccuracies noted above.

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