Skip to content

dist: use bubblewrap for overlayFS mounts, run sccache-dist without root - #2728

Open
rrbutani wants to merge 2 commits into
mozilla:mainfrom
rrbutani:dist-without-root
Open

rrbutani wants to merge 2 commits into
mozilla:mainfrom
rrbutani:dist-without-root

Conversation

@rrbutani

@rrbutani rrbutani commented Jun 6, 2026 •

Copy link
Copy Markdown

Note

I've opened this PR to get feedback on whether the direction here is acceptable. There are still a few items that need to be addressed (see pending below) before this is ready for merge.

The approach here is more or less the same as in #1628: use CLONE_NEWUSER (unprivileged user namespace) to be able to create a mount namespace + mount the overlayFS mounts without permissions

Unlike #1628, this PR leverages bubblewrap's overlay mount functionality (added in v0.11.0) to create the overlayFS mounts at the sccache-dist → bwrap compile command process boundary. This has a couple of upsides:

other notes:

  • previously deleting the build directory/the per-compile directories did not run into permission issues because sccache-dist was running as root

pending/open questions:

  • fallback support for running on Linux <5.11 and/or with bubblewrap versions older than v0.11.0?
  • fallback support for running on machines where unprivileged user namespaces are disabled?
  • manual checks for whiteout files/files with userxattr.overlay xattrs in the compile inputs tarball?
    • (see these docs for context)
    • previously this issue was sidestepped by unpacking directly into the overlay mountpoint (target dir); now that we're having bubblewrap handle creating the mountpoint this isn't an option
    • unclear to what degree this is an issue (does not seem like users could do anything nefarious with whiteouts or opaque dirs — worst case a toolchain file is masked?)
    • also: tar::Archive defaults to not restoring xattrs so I think the only consideration is whiteouts?

closes #326, closes #1660, closes #1688, supersedes #2706

@codecov-commenter

codecov-commenter commented Jun 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.81818% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.73%. Comparing base (5e4f9fd) to head (63dbffe).
⚠️ Report is 163 commits behind head on main.

Files with missing lines Patch % Lines
src/bin/sccache-dist/build.rs 0.00% 30 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2728      +/-   ##
==========================================
- Coverage   76.32%   75.73%   -0.60%     
==========================================
  Files          72       72              
  Lines       40180    39205     -975     
==========================================
- Hits        30668    29692     -976     
- Misses       9512     9513       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rrbutani
rrbutani marked this pull request as ready for review June 9, 2026 04:37
@rrbutani
rrbutani force-pushed the dist-without-root branch from 223e16b to 03b3fcf Compare June 9, 2026 04:39
@rrbutani

Copy link
Copy Markdown
Author

@sylvestre friendly ping; is there anything I can do to make this PR easier to review?

@luhenry

luhenry commented Jun 26, 2026

Copy link
Copy Markdown

Getting that PR to be merged would unblock PyTorch's build of sccache on riscv64. See https://github.com/pytorch/pytorch/pull/182278/changes#diff-0a862d15a4e6dff44196719a594b983aece596c7dc38eba416d83e12a95206e6 for details

@sylvestre

Copy link
Copy Markdown
Collaborator

having tests that cover this change would be helpful :)

@luhenry

luhenry commented Jul 24, 2026

Copy link
Copy Markdown

@rrbutani gentle ping on that issue? happy to have a look on adding tests a well.

@rrbutani

Copy link
Copy Markdown
Author

Thanks for the ping, apologies for the delay.

I've updated the existing sccache-dist tests to run sccache-dist server as an unprivileged user.

The first commit in this PR has only these changes; running (for example) cargo test --test dist --features dist-tests -- test_dist_basic at that commit will (as we expect) fail with EPERM. The next commit (unchanged from earlier) updates sccache-dist server to work w/o privileges and gets the dist-tests passing again.

having tests that cover this change would be helpful :)

@sylvestre Is ^ sufficient?

@rrbutani
rrbutani force-pushed the dist-without-root branch from 2c9184b to 05bb9da Compare August 6, 2026 18:44
@rrbutani

rrbutani commented Aug 6, 2026

Copy link
Copy Markdown
Author

@sylvestre friendly ping

@rrbutani

Copy link
Copy Markdown
Author

@sylvestre could I get another CI run for this PR?

@rrbutani

rrbutani commented Sep 1, 2026

Copy link
Copy Markdown
Author

@sylvestre friendly ping

currently this fails with:
```
[2026-07-30T20:04:59Z WARN  sccache::dist::http::server] Res 2 error: run build failed, caused by: Compilation execution failed, caused by: Failed to enter a new Linux namespace, caused by: EPERM: Operation not permitted
```

this error comes from:
```rust
nix::sched::unshare(nix::sched::CloneFlags::CLONE_NEWNS)
```
and is expected.

---

The next commit will update `sccache-dist server` to run successfully
without root.
… root

the approach here is more or less the same as in mozilla#1628: use
`CLONE_NEWUSER` (unprivileged user namespace) to be able to create a
mount namespace + mount the overlayFS mounts without permissions

unlike mozilla#1628, this PR leverages [`bubblewrap`'s overlay mount functionality](containers/bubblewrap@f371022)
(added in `v0.11.0`) to create the overlayFS mounts at the
`sccache-dist` → `bwrap` compile command process boundary. This has a
couple of upsides:
  - sidesteps the [safety issues](https://github.com/mozilla/sccache/blob/9fb6a2542c0d2e82846252be19bb377e5ca8885b/src/bin/sccache-dist/build.rs#L447-L458)
    in mozilla#1628 caused by forking the `sccache-dist` process
  - avoids the [issue](mozilla#1688)
    with overlay fs mounts not being unmounted once the compile command
    finishes that ultimately led to mozilla#1628 being
    [reverted](mozilla#1689)
    + though, I think this issue was actually caused by mozilla#1628 changing
      the default sandboxing codepath (i.e. `current_ns`) to call
      `CLONE_NEWNS` [in the `sccache-dist`'s `rouille` request handler thread](https://github.com/mozilla/sccache/blob/9fb6a2542c0d2e82846252be19bb377e5ca8885b/src/bin/sccache-dist/build.rs#L422-L429) instead of [in the thread spawned for a compile](https://github.com/mozilla/sccache/blob/c72eed63d78c8550b93133e9fa461a0c6ef7a30d/src/bin/sccache-dist/build.rs#L272-L276)
      (and not anything to do with the unprivileged user namespace
      logic)

other notes:
  - previously deleting the build directory/the per-compile directories
    did not run into permission issues because `sccache-dist` was
    running as root

closes mozilla#326, closes mozilla#1660

closes mozilla#1688

supersedes mozilla#2706
@rrbutani

Copy link
Copy Markdown
Author

@sylvestre could I get a CI run for this PR?

@sylvestre

Copy link
Copy Markdown
Collaborator

hi, this one can't be merged as it is:

  • failing: test windows-2022 rust 1.91.0 cuda12.8, test windows-2022 rust nightly cuda12.8, test windows-2022 rust beta cuda12.8
  • it needs a rebase
  • tests/harness/mod.rs: this breaks the windows builds (clippy + tests are red) please gate it with #[cfg(unix)] or the dist-server feature
  • tests/harness/mod.rs: rustfmt is failing on this import order, and on the double blank line below
  • src/bin/sccache-dist/build.rs: why unwrap here? the function already returns io::Result, ? works
  • src/bin/sccache-dist/build.rs: --overlay needs bubblewrap >= 0.11 but the check below still says 0.3.0 could you please bump it? otherwise users get an obscure bwrap error at the first compile
  • src/bin/sccache-dist/build.rs: the old comment explained why we didn't unpack into upperdir (overlayfs marker files) now that we do, could you please add a test with a whiteout / char device entry in the inputs tarball?
    could you please have a look? otherwise, i will close it, thanks

@rrbutani

rrbutani commented Oct 25, 2026 •

Copy link
Copy Markdown
Author

Thank you for the feedback. I'll carve out some time to rebase this PR and address these comments in the coming week.

the old comment explained why we didn't unpack into upperdir (overlayfs marker files) now that we do, could you please add a test with a whiteout / char device entry in the inputs tarball?

As mentioned in the OP I'm not sure what danger there being whiteouts in the compile inputs tarball would pose... as implemented, whiteouts in the form of 0/0 character devices are allowed. Do you want me to add an explicit check for such files (and have the test you requested ensure that such inputs are rejected)?

@sylvestre

Copy link
Copy Markdown
Collaborator

needs to be rebased

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

Labels

None yet

Projects

None yet

4 participants