Repository navigation
[Bubblewrap] Stop sandboxed workloads from creating user namespaces - #1808
Open
Soham Das (SohamDas2021) wants to merge 1 commit into
Open
Soham Das (SohamDas2021) wants to merge 1 commit into
Soham Das (SohamDas2021) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 2db7a539-ced7-4b9b-aa54-d51317a11d8e
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The namespace regression lacks root-caller CI coverage and skips all sandbox probes when host clone3 is unavailable, causing strict validation to fail in otherwise supported environments.
2 open issues
What changed in this PR
This PR strengthens Bubblewrap containment by preventing workloads from creating user namespaces. It extends the existing always-on seccomp filter without changing request schemas or SDK APIs.
Changes:
- Rejects
CLONE_NEWUSERthroughcloneandunshare, and returnsENOSYSforclone3across supported ABIs. - Adds regression coverage for namespace denial and ordinary thread/process creation, wired into Linux builds and scheduled validation.
- Documents the restrictions and compatibility limitations for nested sandbox tools.
| File | Description |
|---|---|
tests/scripts/run_bwrap_user_namespace_test.sh |
Adds functional checks across isolated, firewall, and proxy modes. |
tests/scripts/run_bwrap_all_tests.sh |
Registers the regression and requires its completion marker. |
tests/scripts/README.md |
Updates the aggregate suite’s Python prerequisite. |
src/mxc-sdk/src/backends/bubblewrap/common/seccomp_filter.rs |
Adds namespace restrictions and ABI interpreter tests. |
docs/development/build-and-test/ci-validation-infrastructure.md |
Documents the added CI coverage. |
docs/backends/bwrap/bubblewrap-backend.md |
Explains namespace denial, fallback behavior, and limitations. |
.github/workflows/Build.Linux.Job.yml |
Runs the new regression in Linux builds. |
Review effort: Balanced
| working-directory: ${{ github.workspace }} | ||
| env: | ||
| LXC_EXEC: ${{ github.workspace }}/src/target/${{ matrix.target }}/release/lxc-exec | ||
| run: bash tests/scripts/run_bwrap_user_namespace_test.sh |
| ) | ||
| host_results = probe_results(host.stdout) | ||
| if host_results is None or any( | ||
| host_results[name] != "OK" for name in ("clone", "clone3", "unshare") |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

📖 Description
Workloads in a Bubblewrap sandbox could create their own user namespace in every network mode, whether MXC ran as root or not. For example,
unshare -Ur idsucceeded and reported uid 0. The workload gets a full set of capabilities inside that namespace. That is not host root, but it opens kernel interfaces the sandbox otherwise keeps out of reach, such as mounting filesystems and setting up network namespaces.The always-on seccomp filter now blocks user namespace creation:
unshareandclonecalls that request a new user namespace fail withEPERMin isolated, firewall, and proxy modes, for root and non-root callers.clone3fails withENOSYS, because seccomp cannot read its flags. glibc then falls back toclone, so threads and child processes still start.setnsis not filtered. Joining an existing user namespace already requires capabilities the workload does not have.--disable-usernsneeds 0.8.0, while MXC supports 0.5.0 and later, and Ubuntu 22.04 and RHEL 9 ship older versions. It also requires--unshare-user, which firewall and proxy modes do not use because they join their network supervisor's user namespace.🔗 References
Fixes #1495.
unshare -Urfails, but any workload could still create a user namespace and hold full capabilities inside it.🔍 Validation
WSL (Ubuntu 24.04, kernel 6.18, Bubblewrap 0.9.0) on
mainat 0165e85, which includes #1734. Commands run fromsrc/unless noted:cargo fmt --all -- --check: passedcargo clippy --locked -p mxc-sdk --lib --tests -- -D warnings: passedcargo test --locked --release -p mxc-sdk --lib "backend_modules::bubblewrap::common::seccomp_filter::": 16 passed. Three new tests run the generated filter through the test interpreter on all five ABIs:unshareandclonewithCLONE_NEWUSERfail withEPERM, including when the upper 32 bits of the flags are set.unsharewithoutCLONE_NEWUSER, are still allowed.clone3fails withENOSYS, and its neighboring syscall numbers are still allowed.capability_check,resolver_file,bwrap_command,bwrap_runner,host_tools,bwrap_version,missing_denials, andproxy_network: all passed. Oneproxy_networktest failed once and passed in six reruns; this change does not touch that module.MXC_BWRAP_TESTS_REQUIRE_EXECUTION=1 cargo test --locked --release -p mxc-sdk --test wxc_e2e_tests_e2e_bubblewrap_characterization: 15 passed, including the socket-family and io_uring tests from [Bubblewrap] Restrict socket address families and io_uring with an always-on seccomp filter #1529cargo test --locked --release -p mxc-sdk --test streaming_bubblewrap: 19 passedbash tests/scripts/run_bwrap_user_namespace_test.sh(new; from the repository root): passed in isolated, firewall, and proxy modes, both unprivileged and as root. Inside the sandbox it checks thatunshareandclonewithCLONE_NEWUSERfail withEPERM,clone3fails withENOSYS, andunshare -Ur id -ufails, while a thread,subprocess.run, andposix_spawnstill work. It skips when the host itself cannot create user namespaces. The Linux PR build (x64 and arm64) and the nightly Bubblewrap suite now run it, and the nightly suite fails if it does not pass.bash tests/scripts/run_bwrap_capabilities_test.sh(from [Bubblewrap] 1/2: Drop all capabilities from the container #1734; from the repository root): passed unprivileged and as root.main's filter, the new script fails for both callers because all three calls succeed. Unprivileged,unshare -Ur id -ualso exits 0; as root, [Bubblewrap] 1/2: Drop all capabilities from the container #1734 already makes it fail. With the user namespace checks removed from the filter, the two new denial unit tests fail.tests/scripts/run_bwrap_all_tests.shexcept the four that need sudo, run unprivileged against release builds: 21 passed, and inbound deny skipped because it needs root. This matchesmainplus the new test.clone3themselves. Only glibc's fallback was exercised.✅ Checklist
feature-acceptedCargo.lock, thedependency-feed-checkcheck passes (see pull request builds)📋 Issue Type
Microsoft Reviewers: Open in CodeFlow