문제: provider를 띄우는 우리 단계(cgroup 강제 게이트, scope wrapper)는 provider 전에 exit 125로 멈추며 stderr에 이유를 쓴다. waitForProvider는 bwrap·prlimit·systemd-run·systemctl 접두 줄만 남기고 나머지를 provider 출력으로 보고 버린다. 그래서 FE-GATE-013의 exit=125 묶음 (ci-artifact-contract 671줄부터 18개)이 `exit=125, signal=none`만 남겨 원인을 볼 수 없었다. scope wrapper가 감독자 채널을 잃고 provider 전에 125로 끝나는 길은 아무 줄도 쓰지 않았다. 고른 방법: 줄 고르기를 scripts/lib/provider-sandbox-diagnostics.ts로 옮기고, 우리 단계가 쓰는 고정 문구를 접두가 아니라 끝까지 맞는 template 으로 받는다. cgroup 값은 max와 숫자만, 오류 코드는 errno·Node 오류 이름(E…, ERR_…)만 받고, 그 모양은 scope wrapper와 한 곳에서 정한다. 줄은 개행이 온 뒤에만 판정하고(조각난 줄이 잘린 채 남지 않게), 512자 넘는 줄은 나머지 조각까지 버리며, 8줄까지 둔다. scope wrapper는 provider 전에 멈출 때 `provider scope stopped before launch: <이유>`를 쓴다. 시험은 실제 gate shell과 그 limit 확인 함수를 돌려 나온 줄이 남는지 본다. gate 문구를 바꾸면 시험이 실패한다. 버린 대안: 허용 접두를 `provider `로 넓히기는 provider가 같은 접두로 비밀을 쓰면 실패 메시지에 싣는다. 실패 때 stderr 전부를 남기기는 provider 출력의 자격 증명을 CI 로그에 싣는다. 위험·한계: 기존 도구 접두 네 개(bwrap: 등)는 전처럼 접두만 보고 그 뒤는 512자까지 자유 문구다. liveness 채널 줄도 우리 고정 접두 뒤에 Node 오류 문구를 싣는다(출력 가능한 ASCII 200자까지). provider가 그 접두나 우리 template과 똑같은 줄을 쓰면 남는다. 검증: 노트북 감싸개에서 새 시험이 옛 허용 목록으로 13개 실패(RED), 고친 뒤 provider-sandbox-diagnostics·task3-selective-integration· test-timeout-declarations 통과. 변이 셋(끝 앵커 제거, 긴 줄 표시 제거, gate printf 문구 변경)에 시험이 각각 5·1·1개 실패. check:types·lint rc=0. desktop 시스템 컨테이너에서 이 파일 전체 4회 중 1회 125 묶음이 났고 메시지에 `sandbox reported: provider cgroup enforcement failed: cannot read memory.max`가 남았다(11건).
148 lines
7.4 KiB
TypeScript
148 lines
7.4 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
formatProviderCgroupUnitName,
|
|
systemdRunProviderArguments,
|
|
} from "../../scripts/lib/provider-cgroup.ts";
|
|
import { createProviderSandboxDiagnostics } from "../../scripts/lib/provider-sandbox-diagnostics.ts";
|
|
import { childProcessTimeout } from "../helpers/child-process-timeout.ts";
|
|
|
|
const CREDENTIAL = "provider-credential-must-not-reach-ci";
|
|
const GATE_LINE = "provider cgroup enforcement failed: ";
|
|
|
|
/** The command systemd-run starts in the scope: `/bin/sh -eu -c <gate> <unit> …`. */
|
|
function gateShell(): string[] {
|
|
const unit = formatProviderCgroupUnitName("vulnerability", 4242, "0".repeat(24));
|
|
const systemdRun = systemdRunProviderArguments(unit, 1_000, 1, "/bin/node", "/wrapper.ts", "/r", 1, 1);
|
|
return systemdRun.slice(systemdRun.indexOf("--") + 1);
|
|
}
|
|
|
|
describe("provider sandbox diagnostics", () => {
|
|
it("keeps the line the real cgroup gate writes when it refuses a scope", () => {
|
|
// Outside a provider scope the gate's own membership check fails, which is
|
|
// the same shell, text, and exit code a broken scope produces.
|
|
const shell = gateShell();
|
|
const gate = spawnSync(shell[0]!, shell.slice(1), { encoding: "utf8" });
|
|
|
|
expect(gate.status).toBe(125);
|
|
expect(gate.stderr).toMatch(/^provider cgroup enforcement failed: \S/u);
|
|
const diagnostics = createProviderSandboxDiagnostics();
|
|
diagnostics.consume("stderr", gate.stderr);
|
|
expect(diagnostics.lines()).toEqual([gate.stderr.trimEnd()]);
|
|
}, childProcessTimeout(4));
|
|
|
|
it("keeps the line the real gate check writes for every unreadable or wrong limit", async () => {
|
|
// The gate's own limit check and its own calls, run against a stand-in
|
|
// cgroup directory: 2026-11-14's exit 125 was `cannot read memory.max`.
|
|
const gate = gateShell()[3]!;
|
|
const start = gate.indexOf("require_cgroup_value() {");
|
|
const definition = gate.slice(start, gate.indexOf("\n}\n", start) + 2);
|
|
const calls = gate.split("\n").filter((line) => line.startsWith("require_cgroup_value "));
|
|
expect(calls).toHaveLength(4);
|
|
const root = await mkdtemp(path.join(tmpdir(), "provider-cgroup-limits-"));
|
|
try {
|
|
for (const content of [undefined, "max\n"]) {
|
|
for (const call of calls) {
|
|
const file = path.join(root, call.split(" ")[1]!);
|
|
if (content === undefined) await rm(file, { force: true });
|
|
else await writeFile(file, content);
|
|
const check = spawnSync("/bin/sh", ["-eu", "-c", `cgroup_root=$1\n${definition}\n${call}`, "check", root], {
|
|
encoding: "utf8",
|
|
});
|
|
expect(check.status, call).toBe(125);
|
|
const written = check.stderr.split("\n").filter((line) => line.startsWith(GATE_LINE));
|
|
expect(written, call).toHaveLength(1);
|
|
const diagnostics = createProviderSandboxDiagnostics();
|
|
diagnostics.consume("stderr", check.stderr);
|
|
expect(diagnostics.lines(), call).toEqual(written);
|
|
}
|
|
}
|
|
} finally {
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
}, childProcessTimeout(40));
|
|
|
|
it.each([
|
|
"provider cgroup enforcement failed: unified cgroup v2 membership is required",
|
|
"provider cgroup enforcement failed: unit membership is invalid",
|
|
"provider cgroup enforcement failed: cannot read memory.max",
|
|
"provider cgroup enforcement failed: memory.max is max, expected 1073741824",
|
|
"provider cgroup enforcement failed: memory.swap.max is , expected 0",
|
|
"provider cgroup enforcement failed: cpu.max is max 100000, expected 100000 100000",
|
|
"provider scope stopped before launch: supervisor channel ended",
|
|
"provider scope stopped before launch: supervisor channel error EPIPE",
|
|
"provider scope stopped before launch: supervisor channel error ERR_STREAM_DESTROYED",
|
|
"provider scope stopped before launch: supervisor channel error UNKNOWN",
|
|
"provider scope stopped before launch: protocol failure",
|
|
"provider scope frame length is invalid",
|
|
"provider scope liveness channel is unavailable: Unsupported fd type: FILE",
|
|
"bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted",
|
|
])("keeps the launch-stage line %j", (line) => {
|
|
const diagnostics = createProviderSandboxDiagnostics();
|
|
diagnostics.consume("stderr", `${line}\n`);
|
|
expect(diagnostics.lines()).toEqual([line]);
|
|
});
|
|
|
|
it.each([
|
|
CREDENTIAL,
|
|
`provider cgroup enforcement failed: memory.max is ${CREDENTIAL}, expected 1073741824`,
|
|
`provider cgroup enforcement failed: cannot read ${CREDENTIAL}`,
|
|
`provider scope stopped before launch: ${CREDENTIAL}`,
|
|
`provider scope stopped before launch: supervisor channel error ${CREDENTIAL}`,
|
|
// Upper case alone is not enough: a key-like value is not an errno or Node error name.
|
|
"provider scope stopped before launch: supervisor channel error ABCDEFGHIJKLMNOPQRST",
|
|
` provider cgroup enforcement failed: unit membership is invalid`,
|
|
// A whole template followed by more text is provider output, not ours.
|
|
`provider cgroup enforcement failed: cannot read memory.max ${CREDENTIAL}`,
|
|
`provider cgroup enforcement failed: memory.max is max, expected 1073741824 ${CREDENTIAL}`,
|
|
`provider scope stopped before launch: supervisor channel ended ${CREDENTIAL}`,
|
|
`provider scope frame length is invalid ${CREDENTIAL}`,
|
|
`provider scope liveness channel is unavailable: ${"x".repeat(201)}`,
|
|
`bwrap:${CREDENTIAL}`,
|
|
])("drops provider output that only resembles a launch-stage line: %j", (line) => {
|
|
const diagnostics = createProviderSandboxDiagnostics();
|
|
diagnostics.consume("stdout", `${line}\n`);
|
|
diagnostics.consume("stderr", `${line}\n`);
|
|
expect(diagnostics.lines()).toEqual([]);
|
|
expect(JSON.stringify(diagnostics.lines())).not.toContain(CREDENTIAL);
|
|
});
|
|
|
|
it("judges a line only once it is whole, per stream", () => {
|
|
const diagnostics = createProviderSandboxDiagnostics();
|
|
diagnostics.consume("stderr", "provider cgroup enforcement failed: cannot ");
|
|
diagnostics.consume("stdout", "provider output\n");
|
|
expect(diagnostics.lines()).toEqual([]);
|
|
diagnostics.consume("stderr", "read pids.max\nprovider cgroup enforcement failed: unit");
|
|
expect(diagnostics.lines()).toEqual(["provider cgroup enforcement failed: cannot read pids.max"]);
|
|
});
|
|
|
|
it("drops the rest of an overlong line even when that rest arrives as its own write", () => {
|
|
const diagnostics = createProviderSandboxDiagnostics();
|
|
diagnostics.consume("stderr", "x".repeat(600));
|
|
diagnostics.consume("stderr", `bwrap: ${CREDENTIAL}\n`);
|
|
expect(diagnostics.lines()).toEqual([]);
|
|
});
|
|
|
|
it("drops an overlong line even when it starts like a diagnostic", () => {
|
|
const diagnostics = createProviderSandboxDiagnostics();
|
|
diagnostics.consume("stderr", `bwrap: ${"x".repeat(600)}`);
|
|
diagnostics.consume("stderr", `${CREDENTIAL}\nbwrap: ${"y".repeat(600)}\n`);
|
|
expect(diagnostics.lines()).toEqual([]);
|
|
});
|
|
|
|
it("keeps at most eight distinct lines", () => {
|
|
const diagnostics = createProviderSandboxDiagnostics();
|
|
for (let index = 0; index < 12; index += 1) {
|
|
diagnostics.consume("stderr", `bwrap: failure ${index % 10}\nbwrap: failure ${index % 10}\n`);
|
|
}
|
|
expect(diagnostics.lines()).toEqual(
|
|
Array.from({ length: 8 }, (_unused, index) => `bwrap: failure ${index}`),
|
|
);
|
|
});
|
|
});
|