Public: anyone can read this; the crew can change it.
A check step behind Landlock stacked under its cell says so too, on the forge and on a runner #16996
Check · Review · Land · Live done — Landed and live in production.
fix/look-floor-in-cells → main 0 commits
7 files
changed +39
−10
docs/features/landlock-floor.md +1 −1
| @@ -35,7 +35,7 @@ holds the work instead, with no root and no namespace. | ||
| 35 | 35 | - **Never silent.** The kernel's ABI is probed; rights it lacks are dropped and named. UDP is never |
| 36 | 36 | covered before ABI 10 and every record says so. |
| 37 | 37 | - `FORGE_LANDLOCK=off` declines the floor on purpose. |
| 38 | - A no-cell check step carries `FORGE_CHECK_FLOOR=landlock`. Under the floor no user namespace can be made (writing `/proc/self/uid_map` is denied), so the loopback-only look test skips there and names the floor, rather than failing as a missing prerequisite. | |
| 38 | - A check step behind Landlock, alone or stacked under its cell, carries `FORGE_CHECK_FLOOR=landlock`. Under the floor no user namespace can be made (writing `/proc/self/uid_map` is denied), so the loopback-only look test skips there and names the floor, rather than failing as a missing prerequisite. | |
| 39 | 39 | |
| 40 | 40 | Not covered: network. Crew runs must reach their model's API and checks start servers on loopback |
| 41 | 41 | ports, so TCP connect is not confined yet (the plan supports `connect: [ports]`, ABI 4+, for a |
src/apps/contain.ts +3
| @@ -484,6 +484,9 @@ async function probe(): Promise<{ ok: true } | { ok: false; reason: string }> { | ||
| 484 | 484 | /** The Landlock floor stacked under every cell on this host, once `cellsAvailable` has asked. */ |
| 485 | 485 | let cellFloor: Extract<LandlockProbe, { ok: true }> | undefined; |
| 486 | 486 | |
| 487 | /** Whether a cell on this host runs its command behind the Landlock floor (`floored`). */ | |
| 488 | export const cellsFloored = (): boolean => cellFloor !== undefined; | |
| 489 | ||
| 487 | 490 | /** |
| 488 | 491 | * The command a cell runs, behind Landlock where the kernel holds it: read-only outside what the |
| 489 | 492 | * cell may write, signals and abstract sockets scoped. TCP is left to the cell's own network |
src/checks/run_tier.ts +6 −3
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | |
| 2 | 2 | import { checkFloor } from "./floor.ts"; |
| 3 | import { CHECK_FLOOR_ENV, READS_PARTLY } from "../sandbox/landlock.ts"; | |
| 3 | import { READS_PARTLY, stepFloorEnv } from "../sandbox/landlock.ts"; | |
| 4 | 4 | import { probeLandlock } from "../sandbox/landlock_probe.ts"; |
| 5 | 5 | import { cellHides } from "../spawn/hosted-mark.ts"; |
| 6 | 6 | import { forgeApiKey } from "../crew/runner_env.ts"; |
| @@ -29,7 +29,7 @@ import { BASE_GATE_FILE, runsAsBaseGate, withBaseGate } from "./base_gate.ts"; | ||
| 29 | 29 | import { childEnv, killedStep, runStep } from "../apps/process.ts"; |
| 30 | 30 | import { noteReached } from "../apps/egress_report.ts"; |
| 31 | 31 | import { capacityEnv, checkShardCpus, egressSetting, shardsInForce, shardsLine } from "../core/capacity.ts"; |
| 32 | import { cellsAvailable, origin, limitWarnings, resolveLimits, STEP_HOSTS, stoppedForCpu, type CellSpec } from "../apps/contain.ts"; | |
| 32 | import { cellsAvailable, cellsFloored, origin, limitWarnings, resolveLimits, STEP_HOSTS, stoppedForCpu, type CellSpec } from "../apps/contain.ts"; | |
| 33 | 33 | import { summariseCheckFailure } from "./summary.ts"; |
| 34 | 34 | import { withPlan } from "./plan_line.ts"; |
| 35 | 35 | import { err, type Result } from "../kernel/result.ts"; |
| @@ -284,7 +284,10 @@ async function runTierOnce(lane: LaneState, x: Execution, sample: (green: LentGr | ||
| 284 | 284 | // nested cells, and those never answer in time. Its children run as |
| 285 | 285 | // plain processes here — as they do on a runner without bwrap. |
| 286 | 286 | FORGE_CELLS: "off", |
| 287 | ...(floor === undefined ? {} : { TMPDIR: `${dir}.tmp`, HOME: home, [CHECK_FLOOR_ENV]: "landlock" }), | |
| 287 | ...(floor === undefined ? {} : { TMPDIR: `${dir}.tmp`, HOME: home }), | |
| 288 | // The step is behind Landlock alone (no cell) or stacked under its cell (`floored`): either | |
| 289 | // way it can make no user namespace, and a test may say so rather than blame the runner. | |
| 290 | ...stepFloorEnv({ alone: floor !== undefined, inCell: cell !== undefined, cellsFloored: cell?.floor !== undefined || cellsFloored() }), | |
| 288 | 291 | }); |
| 289 | 292 | let ran: Result<void, string>; |
| 290 | 293 | const checkLines: string[] = []; |
src/runner/main.ts +5
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | * FORGE_CELLS `off`: never use cells here; jobs that require one go back to the forge |
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | import { stepFloorEnv } from "../sandbox/landlock.ts"; | |
| 24 | 25 | import { existsSync, mkdirSync } from "node:fs"; |
| 25 | 26 | import { rm } from "node:fs/promises"; |
| 26 | 27 | import { tmpdir } from "node:os"; |
| @@ -28,6 +29,7 @@ import { join } from "node:path"; | ||
| 28 | 29 | import { exportTree } from "../apps/checkout.ts"; |
| 29 | 30 | import { |
| 30 | 31 | cellsAvailable, |
| 32 | cellsFloored, | |
| 31 | 33 | resolveLimits, |
| 32 | 34 | type CellSpec, |
| 33 | 35 | } from "../apps/contain.ts"; |
| @@ -321,6 +323,9 @@ export async function runRunner(options: RunnerOptions): Promise<void> { | ||
| 321 | 323 | ...checkVars(job.env), |
| 322 | 324 | FORGE_CELL_CPUS: String(limits.cpus), |
| 323 | 325 | ...scratchEnv(cell === undefined ? undefined : home), |
| 326 | // The cell runs its command behind the Landlock floor (`floored`) where this kernel has | |
| 327 | // it: the step can make no user namespace, and a test may say so (#16888). | |
| 328 | ...stepFloorEnv({ alone: false, inCell: cell !== undefined, cellsFloored: cellsFloored() }), | |
| 324 | 329 | }); |
| 325 | 330 | const timeoutMs = |
| 326 | 331 | Math.min(Math.max(Number(job.timeoutS) || 900, 1), 7_200) * 1000; |
src/sandbox/landlock.ts +11 −3
| @@ -162,12 +162,20 @@ export function landlockNote(plan: LandlockPlan): string { | ||
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | * Set to `landlock` in a check step's environment when the step is held by the Landlock floor alone | |
| 166 | * (no cell): a test can then tell a namespace it cannot make there (the floor denies writing | |
| 167 | * `/proc/self/uid_map`) from a prerequisite the runner truly lacks. | |
| 165 | * Set to `landlock` in a check step's environment when the step runs behind the Landlock floor, | |
| 166 | * alone (no cell) or stacked under its cell: a test can then tell a namespace it cannot make there | |
| 167 | * (the floor denies writing `/proc/self/uid_map`) from a prerequisite the runner truly lacks. | |
| 168 | 168 | */ |
| 169 | 169 | export const CHECK_FLOOR_ENV = "FORGE_CHECK_FLOOR"; |
| 170 | 170 | |
| 171 | /** | |
| 172 | * What a check step's environment says of the floor: `landlock` when the step runs behind it, held | |
| 173 | * by it alone (no cell) or stacked under a cell whose host floors its cells; nothing otherwise. | |
| 174 | */ | |
| 175 | export function stepFloorEnv(step: { readonly alone: boolean; readonly inCell: boolean; readonly cellsFloored: boolean }): Record<string, string> { | |
| 176 | return step.alone || (step.inCell && step.cellsFloored) ? { [CHECK_FLOOR_ENV]: "landlock" } : {}; | |
| 177 | } | |
| 178 | ||
| 171 | 179 | /** What a floor used alone, with no bubblewrap above it, leaves open: said wherever it is named. */ |
| 172 | 180 | export const READS_OPEN = "reads are not hidden (the whole filesystem stays readable) and tcp is not confined"; |
| 173 | 181 |
test/look-loopback-only-verdict.test.ts +10
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | import { describe, expect, test } from "bun:test"; |
| 7 | 7 | import { verdict } from "./look-loopback-only.verdict.ts"; |
| 8 | import { stepFloorEnv } from "../src/sandbox/landlock.ts"; | |
| 8 | 9 | |
| 9 | 10 | describe("loopback-only look verdict", () => { |
| 10 | 11 | test("in the check, a missing prerequisite fails and names it", () => { |
| @@ -37,6 +38,15 @@ describe("loopback-only look verdict", () => { | ||
| 37 | 38 | expect(verdict(namespace, { FORGE_CHECK: "01abc", FORGE_CHECK_FLOOR: "" }).kind).toBe("fail"); |
| 38 | 39 | }); |
| 39 | 40 | |
| 41 | test("a step behind the floor is told so, alone or stacked under its cell, on the forge and on a runner", () => { | |
| 42 | expect(stepFloorEnv({ alone: true, inCell: false, cellsFloored: false })).toEqual({ FORGE_CHECK_FLOOR: "landlock" }); | |
| 43 | // A runner's or a forge's cell whose host floors its cells: what the verify lane runs in. | |
| 44 | expect(stepFloorEnv({ alone: false, inCell: true, cellsFloored: true })).toEqual({ FORGE_CHECK_FLOOR: "landlock" }); | |
| 45 | expect(stepFloorEnv({ alone: false, inCell: true, cellsFloored: false })).toEqual({}); | |
| 46 | // Uncontained: no floor, so a namespace the runner cannot make is the runner's gap and fails. | |
| 47 | expect(stepFloorEnv({ alone: false, inCell: false, cellsFloored: true })).toEqual({}); | |
| 48 | }); | |
| 49 | ||
| 40 | 50 | test("nothing missing runs, in the check or not", () => { |
| 41 | 51 | expect(verdict(undefined, { FORGE_CHECK: "01abc" })).toEqual({ kind: "run" }); |
| 42 | 52 | expect(verdict(undefined, {})).toEqual({ kind: "run" }); |
test/look-loopback-only.verdict.ts +3 −3
| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | * namespace) is a skip that says why; inside it — the check sets |
| 5 | 5 | * `FORGE_CHECK` to its run id — the same gap is a failure that names it, so a |
| 6 | 6 | * green check always means a picture was taken. One gap is the check's own |
| 7 | * doing, not the runner's: a step held by the Landlock floor alone (#16888, | |
| 8 | * `FORGE_CHECK_FLOOR=landlock`) cannot write `/proc/self/uid_map`, so no user | |
| 9 | * namespace can be made there by design. That one skips, naming the floor; | |
| 7 | * doing, not the runner's: a step behind the Landlock floor, alone or stacked | |
| 8 | * under its cell (#16888, `FORGE_CHECK_FLOOR=landlock`), cannot write | |
| 9 | * `/proc/self/uid_map`, so no user namespace can be made there by design. That one skips, naming the floor; | |
| 10 | 10 | * every other gap in the check still fails. |
| 11 | 11 | */ |
| 12 | 12 | import { findChromium } from "../src/looks/capture.ts"; |
new above
offline