diff --git a/scripts/check-system-test-prerequisites.ts b/scripts/check-system-test-prerequisites.ts index f3aa5ec9..9a355026 100644 --- a/scripts/check-system-test-prerequisites.ts +++ b/scripts/check-system-test-prerequisites.ts @@ -71,10 +71,13 @@ export async function findSystemTestPrerequisiteFailures( } } + let cgroupV2 = false; try { const controllers = await host.readFile("/sys/fs/cgroup/cgroup.controllers"); if (controllers.trim().length === 0) { failures.push("cgroup v2 controllers are unavailable"); + } else { + cgroupV2 = true; } } catch { failures.push("cgroup v2 is required at /sys/fs/cgroup/cgroup.controllers"); @@ -87,6 +90,10 @@ export async function findSystemTestPrerequisiteFailures( } } + // The user manager's cgroup path below is a cgroup v2 path; without v2 it would name the wrong cause. + const controllerFailure = cgroupV2 ? await findProviderScopeControllerFailure(host) : undefined; + if (controllerFailure !== undefined) failures.push(controllerFailure); + if (executable.get(BWRAP)) { const failure = await findProviderSandboxNamespaceFailure(host); if (failure !== undefined) failures.push(failure); @@ -141,6 +148,35 @@ async function namespaceFailure( ].join("\n"); } +/** The controllers every provider scope is limited by (scripts/lib/provider-cgroup.ts). */ +const PROVIDER_SCOPE_CONTROLLERS = Object.freeze(["cpu", "memory", "pids"] as const); + +/** + * Whether the systemd user manager that provider scopes run under was handed + * the cgroup controllers their limits need. A manager without them passed + * every check above, and then each provider stopped with `provider cgroup + * enforcement failed: cannot read memory.max` (2026-11-14: a `docker exec` + * sat in the system container's root cgroup while systemd started, so systemd + * delegated nothing). + */ +async function findProviderScopeControllerFailure(host: SystemTestHost): Promise { + const status = await host.readFile("/proc/self/status").catch(() => ""); + const uid = /^Uid:\s+(\d+)\s/mu.exec(status)?.[1]; + if (uid === undefined) return "this process's uid is unreadable at /proc/self/status"; + const manager = `/sys/fs/cgroup/user.slice/user-${uid}.slice/user@${uid}.service`; + let delegated: string[]; + try { + delegated = (await host.readFile(`${manager}/cgroup.controllers`)).trim().split(/\s+/u); + } catch { + return `a systemd user manager is required at ${manager}`; + } + const missing = PROVIDER_SCOPE_CONTROLLERS.filter((controller) => !delegated.includes(controller)); + return missing.length === 0 + ? undefined + : `the systemd user manager at ${manager} has no ${missing.join(", ")} cgroup controller ` + + `for provider scopes (it has: ${delegated.join(" ") || "none"})`; +} + export function formatSystemTestPrerequisiteReport(failures: readonly string[]): string { return [ "System/CI-runner test prerequisites are unavailable:", diff --git a/tests/unit/system-test-prerequisites.test.ts b/tests/unit/system-test-prerequisites.test.ts index 8821bc42..832a9b51 100644 --- a/tests/unit/system-test-prerequisites.test.ts +++ b/tests/unit/system-test-prerequisites.test.ts @@ -15,6 +15,7 @@ type SpawnCall = Readonly<{ command: string; args: readonly string[] }>; type SpawnResult = ReturnType; const RTM_NEWADDR = "bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted"; +const USER_MANAGER_CONTROLLERS = "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/cgroup.controllers"; /** A host that has every prerequisite, except what `bwrap` and `files` say. */ function fakeHost( @@ -25,8 +26,12 @@ function fakeHost( const host: SystemTestHost = { access: async () => undefined, readFile: async (target) => { - if (target === "/sys/fs/cgroup/cgroup.controllers") return "cpuset cpu io memory pids\n"; - const content = files[target]; + const content = { + "/sys/fs/cgroup/cgroup.controllers": "cpuset cpu io memory pids\n", + "/proc/self/status": "Name:\tnode\nUid:\t1000\t1000\t1000\t1000\n", + [USER_MANAGER_CONTROLLERS]: "cpu memory pids\n", + ...files, + }[target]; if (content === undefined) throw new Error(`ENOENT: ${target}`); return content; }, @@ -125,6 +130,46 @@ describe("system test prerequisites (1105/12-01)", () => { }); }); +// 2026-11-14. In one system container in four, systemd delegated no cgroup +// controller to the root user manager; this check printed PASS and then every +// provider stopped with `provider cgroup enforcement failed: cannot read +// memory.max`. +describe("system test prerequisites: provider scope controllers", () => { + it.each([ + ["none", "\n", "cpu, memory, pids", "none"], + ["memory", "cpu pids\n", "memory", "cpu pids"], + ])("names the controllers the user manager lacks (%s missing)", async (_label, delegated, missing, has) => { + const { host } = fakeHost({ status: 0, stderr: "" }, { [USER_MANAGER_CONTROLLERS]: delegated }); + + expect(await findSystemTestPrerequisiteFailures(host)).toEqual([ + "the systemd user manager at /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service " + + `has no ${missing} cgroup controller for provider scopes (it has: ${has})`, + ]); + }); + + it("reads the user manager only where cgroup v2 is there", async () => { + const { host } = fakeHost({ status: 0, stderr: "" }, { "/sys/fs/cgroup/cgroup.controllers": "\n", [USER_MANAGER_CONTROLLERS]: "\n" }); + + expect(await findSystemTestPrerequisiteFailures(host)).toEqual(["cgroup v2 controllers are unavailable"]); + }); + + it("names an unreadable uid", async () => { + const { host } = fakeHost({ status: 0, stderr: "" }, { "/proc/self/status": "Name:\tnode\n" }); + + expect(await findSystemTestPrerequisiteFailures(host)).toEqual([ + "this process's uid is unreadable at /proc/self/status", + ]); + }); + + it("requires a user manager for this process's own uid", async () => { + const { host } = fakeHost({ status: 0, stderr: "" }, { "/proc/self/status": "Uid:\t0\t0\t0\t0\n" }); + + expect(await findSystemTestPrerequisiteFailures(host)).toEqual([ + "a systemd user manager is required at /sys/fs/cgroup/user.slice/user-0.slice/user@0.service", + ]); + }); +}); + // 1101/13-03. The release provider jobs run the same sandbox on whatever // runner picks them up. The supervisor checked only that the executables // exist, so a host that refuses the namespaces failed later with bwrap's raw