Repository navigation
fix(bubblewrap): start bwrap with an empty environment - #1807
Carlos Alexandro Becker (caarlos0) wants to merge 3 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
Clearing the environment breaks existing bubblewrap test wrappers that rely on inherited executable paths and per-case settings, so those wrappers must be updated alongside the change.
1 open issue
What changed in this PR
Addresses #1783 by clearing the Bubblewrap launcher's environment, preventing sandboxed commands from reading inherited host secrets through /proc while preserving request-supplied variables.
Changes:
- Starts
bwrapwith an empty environment. - Adds regression checks for host-variable exposure and explicit environment delivery.
- Documents launcher and workload environment handling.
| File | Description |
|---|---|
tests/scripts/run_bwrap_environment_test.sh |
Adds environment-leak and readability assertions. |
tests/configs/bwrap_env_host_environ.json |
Adds the sandbox environment probe request. |
src/mxc-sdk/src/backends/bubblewrap/common/bwrap_runner.rs |
Clears the environment before launching bwrap. |
docs/backends/bwrap/bubblewrap-backend.md |
Explains launcher environment isolation. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The containment-sensitive Linux launcher change has only macOS validation, leaving Linux compilation and the relevant regression suites unverified on a supported host.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
Gudge (MGudgin)
left a comment
There was a problem hiding this comment.
Summary
Please address the two inline findings. Keep the launcher-side env_clear(): the common spawn is the right place to close the reported leak, and this is consistent with Seatbelt's environment clearing in #555 and the separate workload-default rules in #1195.
Reviewed commit 0ffa457ac94111ad607510e903ab2dcbcf1e27d0 against merge-base a1afe6b18859690f1ad0d2705b36dfff9bd12f4f. Both comments are anchored to added lines, and their attribution was independently rechecked before posting.
Verified clean with receipts: the shared spawn clears the launcher environment while retaining request-supplied workload values through --clearenv/--setenv. For this head, GitHub Actions run 44383538499, Ubuntu 24.04 job 135119226929, records 19 streaming tests and 15 Bubblewrap executor-characterization tests passing, including the updated cancellation wrapper. The inspected build log does not establish execution of the new CLI environment regression. Local Linux execution was unavailable; the findings are source-supported rather than locally reproduced.
Findings outside the diff
No separate out-of-diff finding. Finding 1 is anchored to the new launch-side clearing at bwrap_runner.rs:703 and concerns the resulting mismatch with unchanged native and Node probes (bwrap_version.rs:429-430, sdk/node/src/bwrap-probe-helper.ts:132-135).
Verified pre-existing - not attributed to this PR
The native and Node probes already inherited their environment; both files are byte-identical between base and head. Their existence is not charged as an old defect. Finding 1 is newly_exposed_by_change because this PR changes the actual launch environment while leaving those checks unchanged. No unrelated pre-existing issue is a merge condition.
| // The confined command can read bwrap's exec-time environment through | ||
| // /proc, so bwrap must not inherit the host's. The command's own | ||
| // environment is passed as --clearenv/--setenv arguments. | ||
| command.env_clear().args(&args); |
There was a problem hiding this comment.
Medium (reliability/correctness) - Apply the same environment rule to availability probes.
Attribution: newly_exposed_by_change - clearing the real launch here makes the unchanged native and Node probes test different execution conditions.
bwrap_version.rs:429-430 still runs bwrap --version with inherited variables, as does sdk/node/src/bwrap-probe-helper.ts:132-135. A resolved wrapper such as #!/bin/sh followed by exec "$REAL_BWRAP" "$@" therefore passes probing when the host supplies REAL_BWRAP, but fails when this launch clears it. Discovery/dry-run validation can report success and the actual run then fails after startup preparation. The test-wrapper repairs in this PR demonstrate the same dependency mechanism; ordinary distro binaries are not claimed to require these variables.
Fix: keep this env_clear(), clear the native version probe's environment too, and pass env: {} to the Node helper's bwrap spawn. Update environment-dependent probe fixtures and check that such a wrapper is rejected during probing rather than failing only during execution. This scenario was source-verified, not locally reproduced on Linux.
There was a problem hiding this comment.
Declining for this PR. The scenario needs a bwrap that is a wrapper script reading host variables; no distro bwrap does, and the only wrappers like that were this repo's own test wrappers, which are fixed here. bwrap --version only checks that the binary runs, so passing the host environment there is not a sandbox exposure. Changing the native and Node probes is a separate behavior change; I can file it as its own issue if you want it tracked.
bwrap was spawned with the host process environment. The sandboxed command could read it from /proc/1/environ, even with a cleared command environment, because --clearenv only affects the final command. Call env_clear() on the bwrap command. The command's environment is unchanged: it is built from the request and passed to bwrap as --clearenv/--setenv arguments. Add a functional check to the Bubblewrap environment test and update the backend guide. Fixes #1783 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 780d59bc-8382-46d2-85a5-a617cb08e582 Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
bwrap now starts with an empty environment, so the test wrappers that stand in for bwrap can no longer read variables from it. Write the real bwrap path, the per-case failure mode and the scratch directory into the generated wrappers instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 780d59bc-8382-46d2-85a5-a617cb08e582 Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
The environ probe read /proc/self/environ through a redirect that opens before tr runs, so CONTROL_SELF read empty and LEAK_self could never fail. $PPID is always 1, and an unreadable pid printed no LEAK line and still passed. Sweep every /proc/[0-9]*/environ, count only after a successful read, and fail on any unreadable pid. Also assert in the PR-gated bubblewrap_clears_host_env_by_default test that /proc/1/environ holds no host variable, so dropping env_clear() fails on pull requests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 780d59bc-8382-46d2-85a5-a617cb08e582 Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
0ffa457 to
7833735
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The security-sensitive Linux containment change lacks completed Linux runtime validation, with CI still running and the /proc environment regression and related isolation fixtures awaiting confirmation.
No open issues 🎉
Review effort: Balanced

📖 Description
bwrapwas started with the full environment of the calling process. The sandbox's PID 1 isbwrap, so a confined command could read that environment from/proc/1/environ, even withinheritDefaultEnvironment: falseand an explicitenvironment.--clearenvonly changes the environment of the final command, notbwrap's own.This change calls
env_clear()on the singlebwraplaunch inspawn_bwrap, sobwrapstarts with an empty environment. The confined command's environment does not change: it is built from the request and passed tobwrapas--clearenv/--setenvarguments, andbwrapis already started by absolute path.The Bubblewrap environment test now checks that
/proc/self/environ,/proc/1/environand$PPIDdo not hold the host'sMXC_LEAK_PROBE. It also checks that each file is readable (so an unreadable file cannot pass as a zero count) and thatFOO=barfrom the request still reaches the command. The "Process environment" section of the Bubblewrap guide describes the behavior.Not covered: the
unsharesupervisor inproxy_network.rsalso inherits the host environment, but it runs in the host PID namespace and cannot be read from inside the sandbox, so it is left unchanged.🔗 References
Fixes #1783
🔍 Validation
Run on macOS (the Bubblewrap module is Linux-only, so
bwrap_runner.rsis not compiled there):cargo fmt --all -- --check(fromsrc/): passedcargo clippy -p mxc-sdk --all-targets -- -D warnings(fromsrc/): passedcargo test -p mxc-sdk --lib bwrap_runner(fromsrc/): passed, 0 tests matched on macOSbash -n tests/scripts/run_bwrap_environment_test.sh: passedtests/configs/bwrap_env_host_environ.json: passedNot run:
bash tests/scripts/run_bwrap_environment_test.sh, because no Linux host or container daemon was available. This PR is a draft until the Linux CI and scheduled Bubblewrap validation confirm it. The new test is part ofrun_bwrap_all_tests.sh.✅ Checklist
feature-acceptedCargo.lock, thedependency-feed-checkcheck passes (see pull request builds)📋 Issue Type
Microsoft Reviewers: Open in CodeFlow