Skip to content

[Bubblewrap] Stop sandboxed workloads from creating user namespaces - #1808

Open
Soham Das (SohamDas2021) wants to merge 1 commit into
mainfrom
sohamdas2021-investigate-bwrap-nested-userns
Open

Soham Das (SohamDas2021) wants to merge 1 commit into
mainfrom
sohamdas2021-investigate-bwrap-nested-userns

Conversation

@SohamDas2021

@SohamDas2021 Soham Das (SohamDas2021) commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📖 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 id succeeded 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:

  • unshare and clone calls that request a new user namespace fail with EPERM in isolated, firewall, and proxy modes, for root and non-root callers.
  • clone3 fails with ENOSYS, because seccomp cannot read its flags. glibc then falls back to clone, so threads and child processes still start.
  • The checks cover the same ABIs as the existing socket filter: x86-64 with x32 and i386 programs, and AArch64 with AArch32 programs.
  • setns is not filtered. Joining an existing user namespace already requires capabilities the workload does not have.
  • This works with every supported Bubblewrap version. Bubblewrap's --disable-userns needs 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.

🔍 Validation

WSL (Ubuntu 24.04, kernel 6.18, Bubblewrap 0.9.0) on main at 0165e85, which includes #1734. Commands run from src/ unless noted:

  • cargo fmt --all -- --check: passed
  • cargo clippy --locked -p mxc-sdk --lib --tests -- -D warnings: passed
  • cargo 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:
    • unshare and clone with CLONE_NEWUSER fail with EPERM, including when the upper 32 bits of the flags are set.
    • Ordinary fork and thread flags, and unshare without CLONE_NEWUSER, are still allowed.
    • clone3 fails with ENOSYS, and its neighboring syscall numbers are still allowed.
  • The same command for capability_check, resolver_file, bwrap_command, bwrap_runner, host_tools, bwrap_version, missing_denials, and proxy_network: all passed. One proxy_network test 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 #1529
  • cargo test --locked --release -p mxc-sdk --test streaming_bubblewrap: 19 passed
  • bash 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 that unshare and clone with CLONE_NEWUSER fail with EPERM, clone3 fails with ENOSYS, and unshare -Ur id -u fails, while a thread, subprocess.run, and posix_spawn still 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.
  • Mutation checks: with main's filter, the new script fails for both callers because all three calls succeed. Unprivileged, unshare -Ur id -u also 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.
  • Every script in tests/scripts/run_bwrap_all_tests.sh except the four that need sudo, run unprivileged against release builds: 21 passed, and inbound deny skipped because it needs root. This matches main plus the new test.
  • Not run:
    • The filesystem, filesystem object, most-specific path, and denied masking scripts, which need sudo.
    • Native arm64. The AArch64 and AArch32 filter is covered only by the interpreter tests until the PR build's arm64 jobs run.
    • Programs that call clone3 themselves. Only glibc's fallback was exercised.

✅ Checklist

  • Signed the Contributor License Agreement
  • Linked to an issue
  • For features or changes requiring a spec: linked the issue with maintainer-applied feature-accepted
  • For implementation: linked the required approved and merged design/API spec, or explained why no spec is required
  • Feature issue remains open unless this PR completes all agreed implementation, validation, and documentation
  • Updated documentation (if applicable)
  • Updated Copilot instructions (if build, architecture, or conventions changed)
  • If this PR changes Cargo.lock, the dependency-feed-check check passes (see pull request builds)

📋 Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2db7a539-ced7-4b9b-aa54-d51317a11d8e
@SohamDas2021
Soham Das (SohamDas2021) requested a review from a team as a code owner November 18, 2026 21:09
Copilot AI balanced review requested due to automatic review settings November 18, 2026 21:09
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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_NEWUSER through clone and unshare, and returns ENOSYS for clone3 across 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

No deployments
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.

[Bubblewrap] Sandboxed workloads can create user namespaces; add --disable-userns or a seccomp filter

2 participants