Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/podman-cpu-proof.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down
17 changes: 17 additions & 0 deletions docs/inference/set-up-openai-compatible-endpoint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<Warning>
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.
</Warning>

The portable profile handles the descriptor as follows:

| Descriptor state | Onboarding result |
Expand Down
133 changes: 117 additions & 16 deletions src/lib/onboard/experimental/portable-host-preparation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" };
Expand Down Expand Up @@ -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");
Expand All @@ -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)",
Expand Down Expand Up @@ -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,
}),
),
Expand All @@ -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();
});

Comment thread
senthilr-nv marked this conversation as resolved.
Resolved
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);
Expand All @@ -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`),
Expand All @@ -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"],
]);
Expand All @@ -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,
}),
),
Expand Down
69 changes: 62 additions & 7 deletions src/lib/onboard/experimental/portable-host-preparation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<string, unknown> {
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 —
Expand Down Expand Up @@ -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<PortableHostPreparationDeps["ip"]>,
): 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 ` +
Expand Down
31 changes: 28 additions & 3 deletions test/e2e/live/portable-cpu-delegation-proof.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,30 @@ function proveAdmission(
commandResult(0, `1 true ${PORTABLE_REGISTRY_IP}`),
],
]);
const ipResults: ReadonlyMap<string, readonly [string, SpawnResult]> = 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`),
],
],
]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
try {
const prepared = preparePortableExperimentalHost(
{ NEMOCLAW_EXPERIMENTAL_PROFILE: "portable" },
Expand Down Expand Up @@ -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."),
},
Expand Down
Loading
Loading