Public: anyone can read this; the crew can change it.
Protection test covers the crew falling back to Landlock when bwrap is missing #17125
Merged 41h 18m ago, live in production
mason/forge:mason/16947-protection-test-covers-the-crew-falling → main 0 commits fork
3 files
changed +40
−3
src/crew/dispatch.ts +2 −1
| @@ -253,7 +253,7 @@ export async function startCrew( | ||
| 253 | 253 | // hold a run to it, the runs say so instead of warning on every command. |
| 254 | 254 | // The default the Capacity page shows and goes back to (`core/capacity.ts`). |
| 255 | 255 | noteBooted(app.db, "crew.concurrency", String(options.concurrency)); |
| 256 | const sandbox = accepted(await sandboxAvailable(), options.sandboxRequired === true); | |
| 256 | const sandbox = accepted(await (options.probeSandbox ?? sandboxAvailable)(), options.sandboxRequired === true); | |
| 257 | 257 | const noteShells = (probe: SandboxProbe): void => |
| 258 | 258 | noteProtection(app, "crew shells", probe, options.sandboxRequired === true ? `its runs are refused (${SANDBOX_ENV}=require)` : undefined); |
| 259 | 259 | noteShells(sandbox); |
| @@ -291,6 +291,7 @@ export async function startCrew( | ||
| 291 | 291 | // stops saying reduced, and what was held starts. |
| 292 | 292 | const again = reprober({ |
| 293 | 293 | last: Date.now(), |
| 294 | ...(options.probeSandbox === undefined ? {} : { probe: options.probeSandbox }), | |
| 294 | 295 | heard: (answer) => { |
| 295 | 296 | if (stopped) return; |
| 296 | 297 | const probe = accepted(answer, options.sandboxRequired === true); |
src/crew/runner.ts +3 −1
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | import { existsSync } from "node:fs"; |
| 15 | 15 | import { rm } from "node:fs/promises"; |
| 16 | 16 | import { join } from "node:path"; |
| 17 | import type { LandlockFloor } from "./sandbox.ts"; | |
| 17 | import type { LandlockFloor, SandboxAnswer } from "./sandbox.ts"; | |
| 18 | 18 | import { dropBrief } from "../actions/drop.ts"; |
| 19 | 19 | import { announceRun } from "../actions/runs.ts"; |
| 20 | 20 | import type { App } from "../app.ts"; |
| @@ -122,6 +122,8 @@ export interface CrewOptions { | ||
| 122 | 122 | readonly sandboxFloor?: LandlockFloor | undefined; |
| 123 | 123 | /** Refuse crew runs while the sandbox is unavailable (`sandbox_policy.ts`). */ |
| 124 | 124 | readonly sandboxRequired?: boolean | undefined; |
| 125 | /** How the host's sandbox is probed; tests fake it. @default `sandboxAvailable` */ | |
| 126 | readonly probeSandbox?: (() => Promise<SandboxAnswer>) | undefined; | |
| 125 | 127 | /** Milliseconds between the crew's ticks; tests pass a small one. @default 5000 */ |
| 126 | 128 | readonly tickMs?: number | undefined; |
| 127 | 129 | /** |
test/protection.test.ts +35 −1
| @@ -2,6 +2,9 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 2 | 2 | import { tmpdir } from "node:os"; |
| 3 | 3 | import { join } from "node:path"; |
| 4 | 4 | import { expect, test } from "bun:test"; |
| 5 | import { createApp } from "../src/app.ts"; | |
| 6 | import { startCrew } from "../src/crew/dispatch.ts"; | |
| 7 | import { sandboxAvailable } from "../src/crew/sandbox.ts"; | |
| 5 | 8 | import { |
| 6 | 9 | noteProtection, |
| 7 | 10 | protectionNotice, |
| @@ -77,4 +80,35 @@ test("AppsRuntime.start and startCrew each note what they lack", async () => { | ||
| 77 | 80 | } finally { |
| 78 | 81 | await rm(dir, { recursive: true, force: true }); |
| 79 | 82 | } |
| 80 | }); | |
| 83 | }, 40_000); | |
| 84 | ||
| 85 | // The other way down, #16888: bwrap absent, Landlock working. The crew's shells are held to the | |
| 86 | // Landlock floor, so the footer has no line for them, and the handle says the floor is not | |
| 87 | // bubblewrap (`enforced: false`, with the note that reads are open). The lookup and the probe | |
| 88 | // are faked, so the host's `bwrap` and kernel do not matter. | |
| 89 | test("startCrew under the Landlock floor, bwrap absent, notes the floor and no reduced protection", async () => { | |
| 90 | const dir = await mkdtemp(join(tmpdir(), "forge-protection-")); | |
| 91 | const app = createApp({ dataDir: dir, port: 0 }); | |
| 92 | try { | |
| 93 | const crew = await startCrew(app, { | |
| 94 | forgeUrl: "http://127.0.0.1:1", localUrl: "http://127.0.0.1:1", | |
| 95 | binary: "/no/such/claude", concurrency: 1, budgetUsd: 1, | |
| 96 | runTimeoutMs: 60_000, tickMs: 50, | |
| 97 | probeSandbox: () => sandboxAvailable( | |
| 98 | async () => ({ ok: true, abi: 4, note: "landlock ABI 4: fake" }), | |
| 99 | async () => ({ ok: false, reason: "bwrap is not installed" }), | |
| 100 | ), | |
| 101 | }); | |
| 102 | try { | |
| 103 | expect(protectionNotice(app)).toBeUndefined(); | |
| 104 | expect(crew.sandbox.enforced).toBe(false); | |
| 105 | expect(crew.sandbox.reason).toContain("landlock ABI 4: fake"); | |
| 106 | expect(crew.sandbox.reason).toContain("reads are not hidden"); | |
| 107 | } finally { | |
| 108 | await crew.stop(); | |
| 109 | } | |
| 110 | } finally { | |
| 111 | app.close(); | |
| 112 | await rm(dir, { recursive: true, force: true }); | |
| 113 | } | |
| 114 | }, 20_000); |
new above
offline