Public: anyone can read this; the crew can change it.
The loopback-only look is proved somewhere: run it where a cell exists, since Landlock-held runners skip it #17003
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/16955-the-loopback-only-look-is-proved-somewhe → main 0 commits fork
3 files
changed +54
−40
test/look-loopback-only-verdict.test.ts +10 −1
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | * names itself; outside it the same gap skips with the reason. |
| 5 | 5 | */ |
| 6 | 6 | import { describe, expect, test } from "bun:test"; |
| 7 | import { verdict } from "./look-loopback-only.verdict.ts"; | |
| 7 | import { uidMapDenied, verdict } from "./look-loopback-only.verdict.ts"; | |
| 8 | 8 | import { stepFloorEnv } from "../src/sandbox/landlock.ts"; |
| 9 | 9 | |
| 10 | 10 | describe("loopback-only look verdict", () => { |
| @@ -51,4 +51,13 @@ describe("loopback-only look verdict", () => { | ||
| 51 | 51 | expect(verdict(undefined, { FORGE_CHECK: "01abc" })).toEqual({ kind: "run" }); |
| 52 | 52 | expect(verdict(undefined, {})).toEqual({ kind: "run" }); |
| 53 | 53 | }); |
| 54 | ||
| 55 | test("the probe skips only on the uid_map EACCES, and a working unshare runs (#16955)", () => { | |
| 56 | const eacces = "unshare: cannot open /proc/self/uid_map: Permission denied\n"; | |
| 57 | expect(uidMapDenied({ exitCode: 1, stderr: eacces })).toBe(true); | |
| 58 | expect(uidMapDenied({ exitCode: 0, stderr: "" })).toBe(false); | |
| 59 | expect(uidMapDenied({ exitCode: 1, stderr: "unshare: unshare failed: Operation not permitted" })).toBe(false); | |
| 60 | expect(uidMapDenied({ exitCode: 1, stderr: "Permission denied" })).toBe(false); | |
| 61 | expect(verdict(undefined, { FORGE_CHECK: "01abc", FORGE_CHECK_FLOOR: "landlock" })).toEqual({ kind: "run" }); | |
| 62 | }); | |
| 54 | 63 | }); |
test/look-loopback-only.test.ts +25 −39
| @@ -7,49 +7,35 @@ | ||
| 7 | 7 | * inside the forge's check that gap fails instead, naming it (#10680). |
| 8 | 8 | */ |
| 9 | 9 | import { describe, expect, test } from "bun:test"; |
| 10 | import { missingPrerequisite, verdict } from "./look-loopback-only.verdict.ts"; | |
| 10 | import { missingPrerequisite, probeUidMap, verdict } from "./look-loopback-only.verdict.ts"; | |
| 11 | 11 | |
| 12 | 12 | const BUDGET_MS = 30_000; |
| 13 | 13 | const CHILD = new URL("./look-loopback-only.child.ts", import.meta.url).pathname; |
| 14 | 14 | |
| 15 | const decided = verdict(missingPrerequisite(), process.env); | |
| 15 | // The Landlock floor cannot write /proc/self/uid_map (#16955): probed here, at load, once. | |
| 16 | const uidMapBlocked = probeUidMap(); | |
| 17 | const decided = uidMapBlocked | |
| 18 | ? ({ kind: "skip", line: "loopback-only look: skipped, uid_map is refused here (Landlock floor): unshare -Ur true" } as const) | |
| 19 | : verdict(missingPrerequisite(), process.env); | |
| 16 | 20 | if (decided.kind !== "run") console.log(decided.line); |
| 17 | 21 | |
| 18 | describe("takeLook with only loopback up", () => { | |
| 19 | if (decided.kind === "fail") { | |
| 20 | test("answers with a picture: its prerequisites are missing in the check", () => { | |
| 21 | throw new Error(decided.line); | |
| 22 | }); | |
| 23 | } else { | |
| 24 | (decided.kind === "run" ? test : test.skip)( | |
| 25 | decided.kind === "skip" ? `skipped: ${decided.line}` : "answers with a picture", | |
| 26 | async () => { | |
| 27 | const proc = Bun.spawn( | |
| 28 | [ | |
| 29 | "unshare", "-rn", process.execPath, CHILD, | |
| 30 | ], | |
| 31 | { stdout: "pipe", stderr: "pipe", env: process.env }, | |
| 32 | ); | |
| 33 | let timedOut = false; | |
| 34 | const timer = setTimeout(() => { | |
| 35 | timedOut = true; | |
| 36 | proc.kill("SIGKILL"); | |
| 37 | }, BUDGET_MS); | |
| 38 | const [out, err] = await Promise.all([ | |
| 39 | new Response(proc.stdout).text(), | |
| 40 | new Response(proc.stderr).text(), | |
| 41 | proc.exited, | |
| 42 | ]); | |
| 43 | clearTimeout(timer); | |
| 44 | if (timedOut) throw new Error(`loopback-only look: no answer within ${BUDGET_MS / 1000} s`); | |
| 45 | const line = out.split("\n").find((l) => l.startsWith("loopback-only look: ")); | |
| 46 | console.log(line ?? `loopback-only look: error child printed nothing (${err.trim().slice(0, 300)})`); | |
| 47 | expect(line).toMatch(/^loopback-only look: png \d+$/); | |
| 48 | const away = out.split("\n").find((l) => l.startsWith("loopback-only away: ")); | |
| 49 | console.log(away); | |
| 50 | expect(away).toMatch(/^loopback-only away: refused /); | |
| 51 | }, | |
| 52 | BUDGET_MS + 5_000, | |
| 53 | ); | |
| 54 | } | |
| 22 | describe.skipIf(decided.kind === "skip")("takeLook with only loopback up", () => { | |
| 23 | test.skipIf(decided.kind === "skip")("answers with a picture", async () => { | |
| 24 | if (decided.kind === "fail") throw new Error(decided.line); | |
| 25 | const proc = Bun.spawn(["unshare", "-rn", process.execPath, CHILD], { stdout: "pipe", stderr: "pipe", env: process.env }); | |
| 26 | let timedOut = false; | |
| 27 | const timer = setTimeout(() => { | |
| 28 | timedOut = true; | |
| 29 | proc.kill("SIGKILL"); | |
| 30 | }, BUDGET_MS); | |
| 31 | const [out, err] = await Promise.all([new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited]); | |
| 32 | clearTimeout(timer); | |
| 33 | if (timedOut) throw new Error(`loopback-only look: no answer within ${BUDGET_MS / 1000} s`); | |
| 34 | const line = out.split("\n").find((l) => l.startsWith("loopback-only look: ")); | |
| 35 | console.log(line ?? `loopback-only look: error child printed nothing (${err.trim().slice(0, 300)})`); | |
| 36 | expect(line).toMatch(/^loopback-only look: png \d+$/); | |
| 37 | const away = out.split("\n").find((l) => l.startsWith("loopback-only away: ")); | |
| 38 | console.log(away); | |
| 39 | expect(away).toMatch(/^loopback-only away: refused /); | |
| 40 | }, BUDGET_MS + 5_000); | |
| 55 | 41 | }); |
test/look-loopback-only.verdict.ts +19
| @@ -43,3 +43,22 @@ export function missingPrerequisite(): string | undefined { | ||
| 43 | 43 | return `${NO_NAMESPACE}: ${probe.stderr.toString().trim().slice(0, 200)}`; |
| 44 | 44 | return undefined; |
| 45 | 45 | } |
| 46 | ||
| 47 | /** What `unshare -Ur true` did: plain data, so the decision below is testable. */ | |
| 48 | export type UnshareProbe = { exitCode: number; stderr: string }; | |
| 49 | ||
| 50 | /** | |
| 51 | * The Landlock floor's gap, probed (#16955): `unshare -Ur true` exits non-zero | |
| 52 | * with "uid_map" and "Permission denied" in stderr when the step may not write | |
| 53 | * `/proc/self/uid_map`. True only for that; any other failure is not skipped. | |
| 54 | */ | |
| 55 | export function uidMapDenied(probe: UnshareProbe): boolean { | |
| 56 | return probe.exitCode !== 0 && probe.stderr.includes("uid_map") && probe.stderr.includes("Permission denied"); | |
| 57 | } | |
| 58 | ||
| 59 | /** Runs the probe now, synchronously, so `test.skipIf` can read it at module load. */ | |
| 60 | export function probeUidMap(): boolean { | |
| 61 | if (process.platform !== "linux" || Bun.which("unshare") === null) return false; | |
| 62 | const p = Bun.spawnSync(["unshare", "-Ur", "true"], { stdout: "ignore", stderr: "pipe" }); | |
| 63 | return uidMapDenied({ exitCode: p.exitCode ?? 1, stderr: p.stderr.toString() }); | |
| 64 | } |
new above
offline