-
Notifications
You must be signed in to change notification settings - Fork 53
[Bubblewrap] Make Bubblewrap the default Linux backend #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ef031a3
Make Bubblewrap the silent default Linux process-sandbox backen
SohamDas2021 25bb4dd
Addressed PR comments
SohamDas2021 c824a36
Update ContainmentType JSDoc to reflect bubblewrap as Linux default
SohamDas2021 09017a3
Make proxy tests explicit about containment to fix macOS CI
SohamDas2021 13b6f46
Fix MicroVM workflow cache permissions
Copilot a4fa3ca
Install bubblewrap in Linux SDK integration CI job
SohamDas2021 be21417
Addressed PR comments
SohamDas2021 a830520
More fixes to LXC
SohamDas2021 59e4c6d
Comment clarification
SohamDas2021 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ on: | |
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| actions: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { describe, it } from 'node:test'; | ||
| import assert from 'node:assert'; | ||
| import { | ||
| sdk, | ||
| supportedVersions, | ||
| isLinuxRoot, | ||
| debugSpawnOptions, | ||
| spawnFromConfigAsync, | ||
| } from './test-helpers.js'; | ||
|
|
||
| // Bwrap fingerprint: when invoked with `--unshare-pid`, bubblewrap creates a | ||
| // new PID namespace and stays as PID 1 in that namespace, acting as init | ||
| // (reaping orphans, forwarding signals). It does NOT exec the child shell | ||
| // directly β the script runs as PID 2. So /proc/1/comm always reads "bwrap" | ||
| // from inside the sandbox, regardless of how bwrap is invoked or which user | ||
| // runs it. This is documented bubblewrap behavior (see bwrap(1)) and the | ||
| // most reliable cross-context signal β mount-count heuristics break under | ||
| // WSL2 where bind-mount propagation can produce 40+ entries. | ||
| const BWRAP_PROBE = | ||
| "PID1=$(cat /proc/1/comm 2>/dev/null || echo unknown); " + | ||
| "MOUNTS=$(wc -l </proc/self/mountinfo); " + | ||
| "echo \"pid1=$PID1 mountinfo_lines=$MOUNTS\"; " + | ||
| "[ \"$PID1\" = \"bwrap\" ] || { echo \"FAIL: not under bubblewrap (pid1=$PID1)\"; exit 1; }; " + | ||
| "echo 'OK: under bubblewrap (pid1=bwrap)'"; | ||
|
SohamDas2021 marked this conversation as resolved.
|
||
|
|
||
| for (const schemaVersion of supportedVersions) { | ||
| describe(`Linux Bubblewrap (schema ${schemaVersion})`, { | ||
| skip: !isLinuxRoot ? 'Linux Bubblewrap tests require Linux with root privileges (sudo npm test)' : undefined, | ||
| }, () => { | ||
| it('should default to Bubblewrap when containment is omitted (silent default)', async () => { | ||
| // spawnSandboxAsync routes through abstract `containment: 'process'`, | ||
| // which on Linux resolves to Bubblewrap in the binary. No --experimental | ||
| // flag is required for this path. | ||
| const result = await sdk.spawnSandboxAsync( | ||
| BWRAP_PROBE, | ||
| { version: schemaVersion.raw }, | ||
| debugSpawnOptions, | ||
| undefined, | ||
| `bwrap-default-${schemaVersion}`, | ||
| ); | ||
| assert.strictEqual(result.exitCode, 0, `[${schemaVersion}] silent-default Bubblewrap probe failed: ${result.stdout}`); | ||
| assert.ok(result.stdout.includes('OK: under bubblewrap'), `[${schemaVersion}] ${result.stdout}`); | ||
| }); | ||
|
|
||
| it('should select Bubblewrap for abstract containment="process"', async () => { | ||
| const config = sdk.createConfigFromPolicy( | ||
| { version: schemaVersion.raw }, | ||
| 'process', | ||
| `bwrap-process-${schemaVersion}`, | ||
| ); | ||
| config.process!.commandLine = BWRAP_PROBE; | ||
| assert.strictEqual(config.containment, 'process', 'wire-format containment should be "process"'); | ||
| const result = await spawnFromConfigAsync(config, debugSpawnOptions); | ||
| assert.strictEqual(result.exitCode, 0, `[${schemaVersion}] containment=process Bubblewrap probe failed: ${result.stdout}`); | ||
| assert.ok(result.stdout.includes('OK: under bubblewrap'), `[${schemaVersion}] ${result.stdout}`); | ||
| }); | ||
|
|
||
| it('should select Bubblewrap for explicit containment="bubblewrap" with experimental flag', async () => { | ||
| // Explicit "bubblewrap" still requires `experimental: true` per the SDK | ||
| // gate in helper.ts (`ExperimentalBackends`). | ||
| const config = sdk.createConfigFromPolicy( | ||
| { version: schemaVersion.raw }, | ||
| 'bubblewrap', | ||
| `bwrap-explicit-${schemaVersion}`, | ||
| ); | ||
| config.process!.commandLine = BWRAP_PROBE; | ||
| assert.strictEqual(config.containment, 'bubblewrap', 'wire-format containment should be "bubblewrap"'); | ||
| const result = await spawnFromConfigAsync(config, { ...debugSpawnOptions, experimental: true }); | ||
| assert.strictEqual(result.exitCode, 0, `[${schemaVersion}] explicit Bubblewrap probe failed: ${result.stdout}`); | ||
| assert.ok(result.stdout.includes('OK: under bubblewrap'), `[${schemaVersion}] ${result.stdout}`); | ||
| }); | ||
| }); | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.