Public: anyone can read this; the crew can change it.

Protection test covers the crew falling back to Landlock when bwrap is missing #17125

opened this in answer to

Merged 41h 18m ago, live in production

mason/forge:mason/16947-protection-test-covers-the-crew-falling → main 0 commits fork

  • Merged. mason/16947-protection-test-covers-the-crew-falling was merged into main as 6e85472.

Review

Sign in to review this change.
3 files changed +40 −3
src/crew/dispatch.ts +2 −1
@@ -253,7 +253,7 @@ export async function startCrew(
253253 // hold a run to it, the runs say so instead of warning on every command.
254254 // The default the Capacity page shows and goes back to (`core/capacity.ts`).
255255 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);
257257 const noteShells = (probe: SandboxProbe): void =>
258258 noteProtection(app, "crew shells", probe, options.sandboxRequired === true ? `its runs are refused (${SANDBOX_ENV}=require)` : undefined);
259259 noteShells(sandbox);
@@ -291,6 +291,7 @@ export async function startCrew(
291291 // stops saying reduced, and what was held starts.
292292 const again = reprober({
293293 last: Date.now(),
294 ...(options.probeSandbox === undefined ? {} : { probe: options.probeSandbox }),
294295 heard: (answer) => {
295296 if (stopped) return;
296297 const probe = accepted(answer, options.sandboxRequired === true);
src/crew/runner.ts +3 −1
@@ -14,7 +14,7 @@
1414 import { existsSync } from "node:fs";
1515 import { rm } from "node:fs/promises";
1616 import { join } from "node:path";
17 import type { LandlockFloor } from "./sandbox.ts";
17 import type { LandlockFloor, SandboxAnswer } from "./sandbox.ts";
1818 import { dropBrief } from "../actions/drop.ts";
1919 import { announceRun } from "../actions/runs.ts";
2020 import type { App } from "../app.ts";
@@ -122,6 +122,8 @@ export interface CrewOptions {
122122 readonly sandboxFloor?: LandlockFloor | undefined;
123123 /** Refuse crew runs while the sandbox is unavailable (`sandbox_policy.ts`). */
124124 readonly sandboxRequired?: boolean | undefined;
125 /** How the host's sandbox is probed; tests fake it. @default `sandboxAvailable` */
126 readonly probeSandbox?: (() => Promise<SandboxAnswer>) | undefined;
125127 /** Milliseconds between the crew's ticks; tests pass a small one. @default 5000 */
126128 readonly tickMs?: number | undefined;
127129 /**
test/protection.test.ts +35 −1
@@ -2,6 +2,9 @@ import { mkdtemp, rm } from "node:fs/promises";
22 import { tmpdir } from "node:os";
33 import { join } from "node:path";
44 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";
58 import {
69 noteProtection,
710 protectionNotice,
@@ -77,4 +80,35 @@ test("AppsRuntime.start and startCrew each note what they lack", async () => {
7780 } finally {
7881 await rm(dir, { recursive: true, force: true });
7982 }
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);

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs