From 9ebd0856a167f30a374cfe986e506f0cdeafe215 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 04:55:00 +0900 Subject: [PATCH] =?UTF-8?q?fix(ci):=20provider=20job=EC=97=90=20sandbox=20?= =?UTF-8?q?runner=20=EC=9A=94=EA=B5=AC=EB=A5=BC=20=EC=A0=81=EA=B3=A0=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=20=EB=95=8C=20namespace=EB=A5=BC=20=EC=A0=90?= =?UTF-8?q?=EA=B2=80=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: release의 provider job 둘(vulnerability·provenance)은 FE-GATE-013과 같은 provider sandbox(systemd-run scope, bwrap --unshare-pid/ipc/uts/net)를 돈다. 그런데 생성 workflow의 runner 요구 주석은 게이트의 hostRequirements에서 나와 merge_test에만 붙고, provider job에는 없다. provider 감독 스크립트의 시작 점검도 실행 파일이 있는지만 봐서, 비특권 user namespace를 막는 runner에서는 나중에 bwrap 원문 오류로 끝난다. 고른 방법: - 계약 job에 선택 칸 `hostRequirements`를 두고 provider job 둘에 FE-GATE-013과 같은 요구를 적는다. 계약이 provider job의 요구가 FE-GATE-013과 같은지 보고(갈라지면 거절), provider 밖 job은 이 칸을 못 쓴다. 생성기가 그 job의 runs-on 옆에 주석을 쓴다. - `check-system-test-prerequisites.ts`에서 namespace 점검만 함수로 내보내고 (`findProviderSandboxNamespaceFailure`), `run-and-validate-provider.ts`가 provider를 띄우기 전에 부른다. 실패하면 test:system 사전 점검과 같은 문구(제한 이름, bwrap stderr, host 설정, 고치는 법)로 멈춘다. - 버린 대안: 생성기가 hostEnvironment 게이트의 요구를 provider job에 저절로 붙이기. 연결이 계약에 보이지 않는다. 위험·한계: provider job은 release 단계라 PR run에서 돌지 않는다. 새 점검은 desktop FE-GATE-013의 provider 시스템 시험(감독 스크립트를 실제로 띄움)으로 본다. 「provider 없이 배포할 때」 문서 절은 소유자 결정이라 이 커밋에 없다. 검증(desktop): 구현을 main으로 되돌리고 새 시험만 둔 상태에서 4개 실패 (RED), 고친 뒤 system-test-prerequisites·ci-workflow-generation 445개 통과, generate:ci-workflow·스냅샷 갱신, check:ci·check:types·eslint rc=0, verify:documentation PASS_SCOPED. desktop `scripts/verify.sh gate FE-GATE-013` rc=0 226초(시스템 컨테이너, system 시험 115개 통과 — provider 감독 스크립트를 실제로 띄워 새 점검을 거친다). 로그 /tmp/claude-gates/w2fe2-prov1/, w2fe2-prov013/. Refs: 1101/13-03 --- .gitea/workflows/quality-gates.yml | 6 ++- config/ci/gates.json | 10 ++++- docs/operations/ci-quality-gates.md | 6 ++- scripts/check-system-test-prerequisites.ts | 18 +++++++-- scripts/contracts/ci-gates.ts | 17 ++++++++ scripts/generate-ci-workflow.ts | 14 +++++-- scripts/run-and-validate-provider.ts | 8 ++++ .../ci-workflow-generation.test.ts.snap | 6 ++- tests/unit/ci-workflow-generation.test.ts | 39 ++++++++++++++++++- tests/unit/system-test-prerequisites.test.ts | 33 ++++++++++++++++ 10 files changed, 144 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/quality-gates.yml b/.gitea/workflows/quality-gates.yml index 57025662..44f3c4d3 100644 --- a/.gitea/workflows/quality-gates.yml +++ b/.gitea/workflows/quality-gates.yml @@ -82,7 +82,7 @@ jobs: name: "merge / tests" if: ${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }} # FE-GATE-013 runner requirement: Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers - # FE-GATE-013 runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs + # FE-GATE-013 runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs runs-on: ubuntu-latest timeout-minutes: 45 steps: @@ -303,6 +303,8 @@ jobs: vulnerability_provider: name: external-vulnerability-provider needs: immutable_build + # provider sandbox runner requirement: Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers + # provider sandbox runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs runs-on: ubuntu-latest timeout-minutes: 45 outputs: @@ -349,6 +351,8 @@ jobs: provenance_provider: name: external-provenance-provider needs: immutable_build + # provider sandbox runner requirement: Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers + # provider sandbox runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs runs-on: ubuntu-latest timeout-minutes: 45 outputs: diff --git a/config/ci/gates.json b/config/ci/gates.json index 233bc9d9..0dc2be09 100644 --- a/config/ci/gates.json +++ b/config/ci/gates.json @@ -1807,7 +1807,7 @@ "retentionClassId": "release-coherence", "hostRequirements": [ "Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers", - "unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs" + "unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs" ], "hostEnvironment": "system-container" }, @@ -2506,6 +2506,10 @@ "provider-evidence/vulnerability-report.json" ] } + ], + "hostRequirements": [ + "Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers", + "unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs" ] }, { @@ -2593,6 +2597,10 @@ "provider-evidence/provenance-attestation.json" ] } + ], + "hostRequirements": [ + "Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers", + "unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs" ] }, { diff --git a/docs/operations/ci-quality-gates.md b/docs/operations/ci-quality-gates.md index 754b5cff..34af595b 100644 --- a/docs/operations/ci-quality-gates.md +++ b/docs/operations/ci-quality-gates.md @@ -197,7 +197,11 @@ sandbox는 `bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net`으로 이 옵션마다 비특권 user namespace가 필요하다. 이 조건은 provider job과 merge 게이트 FE-GATE-013(`test:system`의 provider 테스트) 둘 다에 걸린다. `config/ci/gates.json`의 FE-GATE-013 `hostRequirements`에 같은 조건이 있고, -생성 workflow는 그것을 merge job의 `runs-on` 옆 주석으로 보여 준다. +생성 workflow는 그것을 merge job의 `runs-on` 옆 주석으로 보여 준다. release의 +provider job 둘도 같은 조건을 job의 `hostRequirements`로 갖고(계약이 FE-GATE-013과 +같은지 본다), 생성 workflow가 그 job의 `runs-on` 옆에 같은 주석을 쓴다. +`scripts/run-and-validate-provider.ts`는 provider를 띄우기 전에 아래 검사와 같은 +namespace 점검을 돌아, 이 조건이 없는 runner에서 이름과 host 설정을 대며 멈춘다. - Ubuntu 23.10부터는 `kernel.apparmor_restrict_unprivileged_userns=1`이 기본이다(24.04도 같다). `/usr/bin/bwrap`에 `userns`를 허용하는 AppArmor diff --git a/scripts/check-system-test-prerequisites.ts b/scripts/check-system-test-prerequisites.ts index 50462fc7..f3aa5ec9 100644 --- a/scripts/check-system-test-prerequisites.ts +++ b/scripts/check-system-test-prerequisites.ts @@ -88,14 +88,24 @@ export async function findSystemTestPrerequisiteFailures( } if (executable.get(BWRAP)) { - const probe = host.spawn(BWRAP, NAMESPACE_PROBE_ARGUMENTS, PROBE_TIMEOUT_MS); - if (probe.error || probe.status !== 0) { - failures.push(await namespaceFailure(host, probe)); - } + const failure = await findProviderSandboxNamespaceFailure(host); + if (failure !== undefined) failures.push(failure); } return failures; } +/** + * 1101/13-03. Whether this host lets the provider sandbox create its + * namespaces, and if not, why and what to do. The release provider jobs run + * it before the provider (scripts/run-and-validate-provider.ts). + */ +export async function findProviderSandboxNamespaceFailure( + host: SystemTestHost = nodeSystemTestHost, +): Promise { + const probe = host.spawn(BWRAP, NAMESPACE_PROBE_ARGUMENTS, PROBE_TIMEOUT_MS); + return probe.error || probe.status !== 0 ? namespaceFailure(host, probe) : undefined; +} + async function namespaceFailure( host: SystemTestHost, probe: ReturnType, diff --git a/scripts/contracts/ci-gates.ts b/scripts/contracts/ci-gates.ts index 8e9175dd..86014ffd 100644 --- a/scripts/contracts/ci-gates.ts +++ b/scripts/contracts/ci-gates.ts @@ -432,6 +432,9 @@ const jobSchema = z browserGateIds: z.array(id).max(64), environment: z.array(environmentBindingSchema).max(32), steps: z.array(jobStepSchema).min(1).max(64), + // 1101/13-03. What the runner of a job without a gate needs (the provider + // jobs' sandbox). Rendered beside its runner label like a gate's. + hostRequirements: z.array(nonEmpty.max(512)).min(1).max(8).optional(), }) .strict(); @@ -862,6 +865,20 @@ function validateContractSemantics( // paired backend's nightly lanes. main_gate: ["FE-GATE-029", "FE-GATE-030"], }; + // 1101/13-03. The provider jobs run FE-GATE-013's sandbox (systemd-run + // scope, bwrap with the same namespace options), so they need its host. + const sandboxRequirements = JSON.stringify( + contract.gates.find(({ id: gateId }) => gateId === "FE-GATE-013")?.hostRequirements ?? [], + ); + for (const job of contract.jobs) { + if (job.kind === "provider") { + if (JSON.stringify(job.hostRequirements ?? []) !== sandboxRequirements) { + issue(`provider job host requirements must equal FE-GATE-013's: ${job.id}`); + } + } else if (job.hostRequirements !== undefined) { + issue(`only a provider job declares host requirements of its own: ${job.id}`); + } + } if (JSON.stringify(contract.jobs.map(({ id }) => id)) !== JSON.stringify(Object.keys(expectedJobOwnership))) { issue("job registry must contain the exact thirteen canonical jobs in semantic order"); } diff --git a/scripts/generate-ci-workflow.ts b/scripts/generate-ci-workflow.ts index f34e0bc1..86b0aef0 100644 --- a/scripts/generate-ci-workflow.ts +++ b/scripts/generate-ci-workflow.ts @@ -267,11 +267,17 @@ function renderHostRequirements( job: CiWorkflowJob, index: ReturnType, ): string[] { - return job.gateIds.flatMap((gateId) => - (index.gates.get(gateId)?.hostRequirements ?? []).map( - (requirement) => ` # ${gateId} runner requirement: ${requirement}`, + return [ + ...job.gateIds.flatMap((gateId) => + (index.gates.get(gateId)?.hostRequirements ?? []).map( + (requirement) => ` # ${gateId} runner requirement: ${requirement}`, + ), ), - ); + // 1101/13-03. A provider job runs the provider sandbox and has no gate. + ...(job.hostRequirements ?? []).map( + (requirement) => ` # provider sandbox runner requirement: ${requirement}`, + ), + ]; } /** diff --git a/scripts/run-and-validate-provider.ts b/scripts/run-and-validate-provider.ts index 268318ab..a662ca3f 100644 --- a/scripts/run-and-validate-provider.ts +++ b/scripts/run-and-validate-provider.ts @@ -30,6 +30,7 @@ import { type ProviderGuardianLease, } from "./lib/provider-guardian-client.ts"; import { createProviderOutputLimiter } from "./lib/provider-output-limiter.ts"; +import { findProviderSandboxNamespaceFailure } from "./check-system-test-prerequisites.ts"; import { PROVIDER_SANDBOX_NAMESPACE_ARGUMENTS } from "./lib/provider-sandbox-namespaces.ts"; import { providerProcessTraceEnvironment, @@ -125,6 +126,13 @@ await access("/usr/bin/systemd-run", constants.X_OK).catch(() => { await access("/usr/bin/systemctl", constants.X_OK).catch(() => { throw new Error("provider cgroup unavailable: /usr/bin/systemctl is required"); }); +// 1101/13-03. A runner that refuses the sandbox's unprivileged user and +// network namespaces fails here, by name and with its host settings, instead +// of later with bwrap's raw error. +const namespaceFailure = await findProviderSandboxNamespaceFailure(); +if (namespaceFailure !== undefined) { + throw new Error(`provider sandbox unavailable: ${namespaceFailure}`); +} await assertProviderCgroupManagerAvailable(); const trust = await readProviderTrust(workspaceRoot, publicKeyPath, keyId); if (!trust) throw new TypeError("provider supervisor trust key is invalid"); diff --git a/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap b/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap index c5653ebc..2be72e85 100644 --- a/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap +++ b/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap @@ -85,7 +85,7 @@ jobs: name: "merge / tests" if: \${{ gitea.event_name != 'workflow_dispatch' || (inputs.stage != 'documentation' && inputs.stage != 'main') }} # FE-GATE-013 runner requirement: Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers - # FE-GATE-013 runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs + # FE-GATE-013 runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs runs-on: ubuntu-latest timeout-minutes: 45 steps: @@ -306,6 +306,8 @@ jobs: vulnerability_provider: name: external-vulnerability-provider needs: immutable_build + # provider sandbox runner requirement: Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers + # provider sandbox runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs runs-on: ubuntu-latest timeout-minutes: 45 outputs: @@ -352,6 +354,8 @@ jobs: provenance_provider: name: external-provenance-provider needs: immutable_build + # provider sandbox runner requirement: Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers + # provider sandbox runner requirement: unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs and scripts/run-and-validate-provider.ts before a provider runs runs-on: ubuntu-latest timeout-minutes: 45 outputs: diff --git a/tests/unit/ci-workflow-generation.test.ts b/tests/unit/ci-workflow-generation.test.ts index 3f97be55..48d2b71a 100644 --- a/tests/unit/ci-workflow-generation.test.ts +++ b/tests/unit/ci-workflow-generation.test.ts @@ -1724,7 +1724,44 @@ describe("CI workflow generation", () => { expect(header.split("\n").filter((line) => line.startsWith(" # "))).toEqual( requirements.map((requirement) => ` # FE-GATE-013 runner requirement: ${requirement}`), ); - expect(workflow.match(/ runner requirement: /gu)).toHaveLength(requirements.length); + // FE-GATE-013 in merge_test, and the two release provider jobs. + expect(workflow.match(/ runner requirement: /gu)).toHaveLength(requirements.length * 3); + }); + + // 1101/13-03. The release provider jobs run the same sandbox (systemd-run + // scope, bwrap with the same namespace options) on whatever runner picks + // them up, and nothing beside their runner label said what it needs. + it("states the provider sandbox's runner requirements beside each provider job's runner label", async () => { + const contract = await loadCiGateContract(process.cwd()); + const index = indexCiGateContract(contract); + const requirements = index.gates.get("FE-GATE-013")?.hostRequirements ?? []; + expect(requirements.length).toBeGreaterThan(0); + const providerJobs = contract.jobs.filter(({ kind }) => kind === "provider"); + expect(providerJobs.map(({ id }) => id)).toEqual(["vulnerability_provider", "provenance_provider"]); + for (const job of providerJobs) expect(job.hostRequirements).toEqual(requirements); + + const workflow = renderCiWorkflow(contract); + for (const [job, next] of [ + ["vulnerability_provider", "provenance_provider"], + ["provenance_provider", "promotion"], + ] as const) { + const block = workflow.slice(workflow.indexOf(` ${job}:\n`), workflow.indexOf(` ${next}:\n`)); + const header = block.slice(0, block.indexOf(" runs-on: ubuntu-latest\n")); + expect(header.split("\n").filter((line) => line.startsWith(" # ")), job).toEqual( + requirements.map((requirement) => ` # provider sandbox runner requirement: ${requirement}`), + ); + } + + // A provider job's requirements are the sandbox's: they cannot drift from FE-GATE-013's. + const drifted = { + ...contract, + jobs: contract.jobs.map((job) => + job.id === "provenance_provider" ? { ...job, hostRequirements: ["a different runner"] } : job, + ), + }; + expect(() => parseCiGateContract(drifted)).toThrow( + /provider job host requirements must equal FE-GATE-013's: provenance_provider/u, + ); }); // The job container has neither systemd nor bubblewrap, so FE-GATE-013 runs diff --git a/tests/unit/system-test-prerequisites.test.ts b/tests/unit/system-test-prerequisites.test.ts index 3ff28dc4..8821bc42 100644 --- a/tests/unit/system-test-prerequisites.test.ts +++ b/tests/unit/system-test-prerequisites.test.ts @@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises"; import { describe, expect, it } from "vitest"; import { + findProviderSandboxNamespaceFailure, findSystemTestPrerequisiteFailures, formatSystemTestPrerequisiteReport, NAMESPACE_PROBE_ARGUMENTS, @@ -123,3 +124,35 @@ describe("system test prerequisites (1105/12-01)", () => { expect(calls.map(({ command }) => command)).toEqual(["/usr/bin/systemctl"]); }); }); + +// 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 +// error and without the host settings. +describe("provider sandbox namespace check (1101/13-03)", () => { + it("passes on a host that creates the namespaces and probes only with bwrap", async () => { + const { host, calls } = fakeHost({ status: 0, stderr: "" }); + + expect(await findProviderSandboxNamespaceFailure(host)).toBeUndefined(); + expect(calls).toEqual([{ command: "/usr/bin/bwrap", args: NAMESPACE_PROBE_ARGUMENTS }]); + }); + + it("names the restriction, bwrap's stderr and the host settings on a host that refuses them", async () => { + const { host } = fakeHost( + { status: 1, stderr: `${RTM_NEWADDR}\n` }, + { "/proc/sys/kernel/apparmor_restrict_unprivileged_userns": "1\n" }, + ); + + const failure = (await findProviderSandboxNamespaceFailure(host)) ?? ""; + expect(failure).toMatch(/^this host does not allow unprivileged user and network namespaces/u); + expect(failure).toContain(`bwrap stderr: ${RTM_NEWADDR}`); + expect(failure).toContain("kernel.apparmor_restrict_unprivileged_userns = 1"); + }); + + it("runs before the provider supervisor launches anything", async () => { + const provider = await readFile("scripts/run-and-validate-provider.ts", "utf8"); + const check = provider.indexOf("await findProviderSandboxNamespaceFailure()"); + expect(check).toBeGreaterThan(0); + expect(check).toBeLessThan(provider.indexOf("superviseProviderEvidence({")); + }); +});