diff --git a/.github/workflows/podman-cpu-proof.yaml b/.github/workflows/podman-cpu-proof.yaml index d88f523c1cd..9b3cb7c5550 100644 --- a/.github/workflows/podman-cpu-proof.yaml +++ b/.github/workflows/podman-cpu-proof.yaml @@ -474,6 +474,7 @@ jobs: esac done < <(podman --url "$endpoint" secret ls --format '{{.Name}}' 2>/dev/null || true) podman --url "$endpoint" network rm openshell-docker 2>/dev/null || true + # gateway-alias-cleanup portable_host_gateway_ip="" if portable_host_gateway_ip="$( node --input-type=module --eval ' diff --git a/docs/inference/set-up-openai-compatible-endpoint.mdx b/docs/inference/set-up-openai-compatible-endpoint.mdx index f053a55834e..1cff8063548 100644 --- a/docs/inference/set-up-openai-compatible-endpoint.mdx +++ b/docs/inference/set-up-openai-compatible-endpoint.mdx @@ -138,6 +138,23 @@ It carries authenticated mTLS plus sandbox-JWT callbacks to OpenShell on port `8 The managed local registry uses the distinct address `169.254.1.3` on port `5000`. Keeping the host-gateway address outside the sandbox subnet prevents a Portable workload from receiving that address. + +If Portable onboarding reports that the retired `169.254.1.2/32` address is still assigned to the loopback interface, remove only that exact assignment: + +```bash +sudo ip address delete 169.254.1.2/32 dev lo +``` + +Rerun Portable onboarding: + +```bash +$$nemoclaw onboard --experimental-profile portable +``` + +Do not run the loopback deletion command when onboarding reports another interface or prefix. +Investigate and resolve the conflicting assignment before you rerun onboarding. + + The portable profile handles the descriptor as follows: | Descriptor state | Onboarding result | diff --git a/src/lib/onboard/experimental/portable-host-preparation.test.ts b/src/lib/onboard/experimental/portable-host-preparation.test.ts index 940c47069e9..1dc3e868444 100644 --- a/src/lib/onboard/experimental/portable-host-preparation.test.ts +++ b/src/lib/onboard/experimental/portable-host-preparation.test.ts @@ -32,6 +32,13 @@ function result(status = 0, stdout = ""): SpawnResult { return { status, stdout, stderr: "" } as SpawnResult; } +const NO_RETIRED_GATEWAY_EVIDENCE = JSON.stringify([ + { ifname: "lo", addr_info: [{ family: "inet", local: "127.0.0.1", prefixlen: 8 }] }, +]); +const RETIRED_LOOPBACK_EVIDENCE = JSON.stringify([ + { ifname: "lo", addr_info: [{ family: "inet", local: "169.254.1.2", prefixlen: 32 }] }, +]); + function runtimeAuthority( homeDir: string, socketPath = "/run/user/1001/podman/podman.sock", @@ -95,7 +102,10 @@ function preparePortableExperimentalHost( : docker, ip: deps.ip ?? - (() => result(0, `1: lo inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global lo\n`)), + ((args) => + args[0] === "-j" + ? result(0, NO_RETIRED_GATEWAY_EVIDENCE) + : result(0, `1: lo inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global lo\n`)), sudo: deps.sudo ?? (() => result()), // Tests run on hosts without the /sys/fs/cgroup hierarchy the portable // CPU-delegation preflight reads; default to a passing stub and inject @@ -384,8 +394,10 @@ describe("preparePortableExperimentalHost", () => { .mockReturnValueOnce(result(0, JSON.stringify([{ Subnet: PORTABLE_DOCKER_NETWORK_SUBNET }]))) // retry network inspect: reuse .mockReturnValueOnce(result(1)) // retry registry inspect: absent .mockReturnValueOnce(result()); // retry registry run - const ip = vi.fn(() => - result(0, `1: lo inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global lo\n`), + const ip = vi.fn((args: readonly string[]) => + args[0] === "-j" + ? result(0, NO_RETIRED_GATEWAY_EVIDENCE) + : result(0, `1: lo inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global lo\n`), ); const sudo = vi.fn(() => result()); const env: NodeJS.ProcessEnv = { NEMOCLAW_EXPERIMENTAL_PROFILE: "portable" }; @@ -464,13 +476,15 @@ describe("preparePortableExperimentalHost", () => { } }, ); - const ip = vi.fn(() => - result( - 0, - hostGatewayConfigured - ? `1: lo inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global lo\n` - : "1: lo inet 127.0.0.1/8 scope host lo\n", - ), + const ip = vi.fn((args: readonly string[]) => + args[0] === "-j" + ? result(0, NO_RETIRED_GATEWAY_EVIDENCE) + : result( + 0, + hostGatewayConfigured + ? `1: lo inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global lo\n` + : "1: lo inet 127.0.0.1/8 scope host lo\n", + ), ); const sudo = vi.fn(() => { commands.push("add host gateway"); @@ -489,11 +503,19 @@ describe("preparePortableExperimentalHost", () => { }); it.each([ - ["missing network", false, "1: lo inet 169.254.1.2/32 scope global lo\n"], + ["missing network", false, RETIRED_LOOPBACK_EVIDENCE], [ "existing network and replacement gateway", true, - `1: lo inet 169.254.1.2/32 scope global lo\n1: lo inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global lo\n`, + JSON.stringify([ + { + ifname: "lo", + addr_info: [ + { family: "inet", local: "169.254.1.2", prefixlen: 32 }, + { family: "inet", local: PORTABLE_HOST_GATEWAY_IP, prefixlen: 32 }, + ], + }, + ]), ], ])( "rejects the retired gateway alias before inspecting the %s (#9587)", @@ -534,7 +556,16 @@ describe("preparePortableExperimentalHost", () => { preparePortableExperimentalHost( { NEMOCLAW_EXPERIMENTAL_PROFILE: "portable" }, portablePreparationDeps(home, docker, { - ip: () => result(0, "2: eth0 inet 169.254.1.2/24 scope global eth0\n"), + ip: () => + result( + 0, + JSON.stringify([ + { + ifname: "eth0", + addr_info: [{ family: "inet", local: "169.254.1.2", prefixlen: 24 }], + }, + ]), + ), sudo, }), ), @@ -543,6 +574,70 @@ describe("preparePortableExperimentalHost", () => { expect(sudo).not.toHaveBeenCalled(); }); + it.each<[string, SpawnResult, RegExp]>([ + [ + "nonzero address inspection", + result(2, "permission denied"), + /Inspecting the retired portable host gateway address failed: permission denied/u, + ], + [ + "address inspection process failure", + { ...result(), error: new Error("address inspection interrupted") }, + /Inspecting the retired portable host gateway address failed: address inspection interrupted/u, + ], + [ + "malformed target assignment", + result(0, '[{"ifname":"lo","addr_info":[{"family":"inet","local":"169.254.1.2"}]}]'), + /inspection returned invalid or ambiguous output/u, + ], + [ + "malformed non-target assignment beside target evidence", + result( + 0, + JSON.stringify([ + { + ifname: "lo", + addr_info: [ + { family: "inet", local: "169.254.1.2", prefixlen: 32 }, + { family: "inet", local: "127.0.0.1" }, + ], + }, + ]), + ), + /inspection returned invalid or ambiguous output/u, + ], + ["wholly invalid successful output", result(0, "not-json"), /invalid or ambiguous output/u], + [ + "multiple target assignments", + result( + 0, + JSON.stringify([ + { ifname: "lo", addr_info: [{ family: "inet", local: "169.254.1.2", prefixlen: 32 }] }, + { ifname: "eth0", addr_info: [{ family: "inet", local: "169.254.1.2", prefixlen: 24 }] }, + ]), + ), + /has a conflicting host assignment/u, + ], + ])("rejects %s before Portable network mutation (#9587)", (_case, inspection, error) => { + const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-portable-")); + tempDirs.push(home); + const docker = vi.fn<(args: readonly string[], env: NodeJS.ProcessEnv) => SpawnResult>(() => + result(), + ); + const ip = vi.fn(() => inspection); + const sudo = vi.fn(() => result()); + + expect(() => + preparePortableExperimentalHost( + { NEMOCLAW_EXPERIMENTAL_PROFILE: "portable" }, + portablePreparationDeps(home, docker, { ip, sudo }), + ), + ).toThrow(error); + expect(docker.mock.calls.map(([args]) => args)).toEqual([["--version"]]); + expect(ip).toHaveBeenCalledTimes(1); + expect(sudo).not.toHaveBeenCalled(); + }); + it("configures and verifies the portable gateway loopback alias before registry mutation (#9461)", () => { const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-portable-")); tempDirs.push(home); @@ -553,7 +648,7 @@ describe("preparePortableExperimentalHost", () => { .mockReturnValueOnce(result(0, `1 true ${PORTABLE_REGISTRY_IP}`)); const ip = vi .fn<(args: readonly string[], env: NodeJS.ProcessEnv) => SpawnResult>() - .mockReturnValueOnce(result()) + .mockReturnValueOnce(result(0, NO_RETIRED_GATEWAY_EVIDENCE)) .mockReturnValueOnce(result()) .mockReturnValueOnce( result(0, `1: lo inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global lo\n`), @@ -568,7 +663,7 @@ describe("preparePortableExperimentalHost", () => { ); expect(ip.mock.calls.map(([args]) => args)).toEqual([ - ["-o", "-4", "address", "show"], + ["-j", "-4", "address", "show"], ["-o", "-4", "address", "show"], ["-o", "-4", "address", "show"], ]); @@ -586,12 +681,18 @@ describe("preparePortableExperimentalHost", () => { result(), ); const sudo = vi.fn(() => result()); + const ip = vi + .fn<(args: readonly string[], env: NodeJS.ProcessEnv) => SpawnResult>() + .mockReturnValueOnce(result(0, NO_RETIRED_GATEWAY_EVIDENCE)) + .mockReturnValueOnce( + result(0, `2: eth0 inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global eth0\n`), + ); expect(() => preparePortableExperimentalHost( { NEMOCLAW_EXPERIMENTAL_PROFILE: "portable" }, portablePreparationDeps(home, docker, { - ip: () => result(0, `2: eth0 inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global eth0\n`), + ip, sudo, }), ), diff --git a/src/lib/onboard/experimental/portable-host-preparation.ts b/src/lib/onboard/experimental/portable-host-preparation.ts index 43b9c0fa58e..9afd004756c 100644 --- a/src/lib/onboard/experimental/portable-host-preparation.ts +++ b/src/lib/onboard/experimental/portable-host-preparation.ts @@ -3,6 +3,7 @@ import { spawnSync } from "node:child_process"; import fs from "node:fs"; +import { isIP } from "node:net"; import os from "node:os"; import path from "node:path"; @@ -110,6 +111,10 @@ function requireCommand(result: SpawnResult, description: string): void { throw new Error(`${description} failed: ${commandDetail(result)}`); } +function isRecord(value: unknown): value is Record { + return typeof value === "object" && value !== null && !Array.isArray(value); +} + /** * The portable profile points DOCKER_HOST at the rootless Podman socket but still * drives the managed registry — and the rest of onboarding's runtime preflight — @@ -154,25 +159,75 @@ function portableHostGatewayAliasState( ); } +function retiredPortableHostGatewayAliasState( + output: string, +): "absent" | "configured" | "conflicting" { + const parsed: unknown = JSON.parse(output); + if (!Array.isArray(parsed)) throw new Error("invalid address evidence"); + const assignments: Array<{ interfaceName: string; prefix: number }> = []; + for (const interfaceEntry of parsed) { + if ( + !isRecord(interfaceEntry) || + typeof interfaceEntry.ifname !== "string" || + interfaceEntry.ifname.length === 0 || + !Array.isArray(interfaceEntry.addr_info) + ) { + throw new Error("invalid address evidence"); + } + for (const addressEntry of interfaceEntry.addr_info) { + if ( + !isRecord(addressEntry) || + addressEntry.family !== "inet" || + typeof addressEntry.local !== "string" || + isIP(addressEntry.local) !== 4 || + !Number.isInteger(addressEntry.prefixlen) || + Number(addressEntry.prefixlen) < 0 || + Number(addressEntry.prefixlen) > 32 + ) { + throw new Error("invalid address evidence"); + } + if (addressEntry.local === RETIRED_PORTABLE_HOST_GATEWAY_IP) { + assignments.push({ + interfaceName: interfaceEntry.ifname, + prefix: Number(addressEntry.prefixlen), + }); + } + } + } + if (assignments.length === 0) return "absent"; + if ( + assignments.length === 1 && + assignments[0]?.interfaceName === "lo" && + assignments[0].prefix === 32 + ) { + return "configured"; + } + return "conflicting"; +} + function rejectRetiredPortableHostGatewayAlias( env: NodeJS.ProcessEnv, ip: NonNullable, ): void { - const result = ip(["-o", "-4", "address", "show"], env); + const result = ip(["-j", "-4", "address", "show"], env); requireCommand(result, "Inspecting the retired portable host gateway address"); - let state: "absent" | "configured"; + let state: "absent" | "configured" | "conflicting"; try { - state = portableHostGatewayAliasState( - String(result.stdout ?? ""), - RETIRED_PORTABLE_HOST_GATEWAY_IP, - ); + state = retiredPortableHostGatewayAliasState(String(result.stdout ?? "")); } catch { + throw new Error( + "The retired portable host gateway address inspection returned invalid or ambiguous output. " + + "Refusing to change Portable networking; investigate the host address assignments, then rerun " + + "`nemoclaw onboard --experimental-profile portable`.", + ); + } + if (state === "absent") return; + if (state === "conflicting") { throw new Error( `The retired portable host gateway address ${RETIRED_PORTABLE_HOST_GATEWAY_IP} has a conflicting host assignment. ` + "Resolve that assignment, then rerun `nemoclaw onboard --experimental-profile portable`.", ); } - if (state === "absent") return; throw new Error( `The retired portable host gateway address ${RETIRED_PORTABLE_HOST_GATEWAY_IP}/32 is still assigned to loopback. ` + `Remove it with \`sudo ip address delete ${RETIRED_PORTABLE_HOST_GATEWAY_IP}/32 dev lo\`, then rerun ` + diff --git a/test/e2e/live/portable-cpu-delegation-proof.test.ts b/test/e2e/live/portable-cpu-delegation-proof.test.ts index de5777fc8d0..3a13751667e 100644 --- a/test/e2e/live/portable-cpu-delegation-proof.test.ts +++ b/test/e2e/live/portable-cpu-delegation-proof.test.ts @@ -154,6 +154,30 @@ function proveAdmission( commandResult(0, `1 true ${PORTABLE_REGISTRY_IP}`), ], ]); + const ipResults: ReadonlyMap = new Map([ + [ + JSON.stringify(["-j", "-4", "address", "show"]), + [ + "retired portable host gateway address inspection", + commandResult( + 0, + JSON.stringify([ + { + ifname: "lo", + addr_info: [{ family: "inet", local: "127.0.0.1", prefixlen: 8 }], + }, + ]), + ), + ], + ], + [ + JSON.stringify(["-o", "-4", "address", "show"]), + [ + "portable host gateway address inspection", + commandResult(0, `1: lo inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global lo\n`), + ], + ], + ]); try { const prepared = preparePortableExperimentalHost( { NEMOCLAW_EXPERIMENTAL_PROFILE: "portable" }, @@ -190,9 +214,10 @@ function proveAdmission( return result; }, ip: (args) => { - assert.deepEqual(args, ["-o", "-4", "address", "show"]); - effects.push("portable host gateway address inspection"); - return commandResult(0, `1: lo inet ${PORTABLE_HOST_GATEWAY_IP}/32 scope global lo\n`); + const result = ipResults.get(JSON.stringify(args)); + assert.ok(result, `Unexpected host address proof command: ${args.join(" ")}`); + effects.push(result[0]); + return result[1]; }, sudo: () => assert.fail("Existing portable host gateway address must not require sudo."), }, diff --git a/test/e2e/support/podman-cpu-proof-workflow.test.ts b/test/e2e/support/podman-cpu-proof-workflow.test.ts index f5cd942fd71..821bc7ea438 100644 --- a/test/e2e/support/podman-cpu-proof-workflow.test.ts +++ b/test/e2e/support/podman-cpu-proof-workflow.test.ts @@ -946,7 +946,7 @@ describe("native Podman CPU proof workflow", () => { expect(fs.readFileSync(githubEnv, "utf8")).toBe(""); const cleanup = namedStep("Clean up rootless Podman runtime").run ?? ""; - const gatewayCleanupStart = cleanup.indexOf('portable_host_gateway_ip=""'); + const gatewayCleanupStart = cleanup.indexOf("# gateway-alias-cleanup"); expect(gatewayCleanupStart).toBeGreaterThanOrEqual(0); const gatewayCleanup = cleanup.slice(gatewayCleanupStart); const runCleanup = async (env: NodeJS.ProcessEnv) => { @@ -958,7 +958,7 @@ describe("native Podman CPU proof workflow", () => { clearTimeout(timer); resolve(true); }); - timer = setTimeout(() => resolve(false), 1_000); + timer = setTimeout(() => resolve(false), 10_000); }); const result = run(gatewayCleanup, { ...env,