Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5cef290
fix(security): keep API keys out of curl probe argv
laitingsheng Jun 29, 2026
d0a16da
Merge remote-tracking branch 'origin/main' into fix/curl-probe-no-bea…
laitingsheng Jun 30, 2026
53fffa8
refactor(inference): apply PR review feedback for curl auth-config
laitingsheng Jun 30, 2026
d214d8a
style(inference): biome import sort
laitingsheng Jun 30, 2026
f3077d5
ci(vitest): bump spawned child heap to 4 GiB
laitingsheng Jun 30, 2026
f84290e
ci(pr): bump cli-test-shards timeout to 15 min
laitingsheng Jun 30, 2026
db72076
Revert "ci(pr): bump cli-test-shards timeout to 15 min"
laitingsheng Jun 30, 2026
854cfc8
Revert "ci(vitest): bump spawned child heap to 4 GiB"
laitingsheng Jun 30, 2026
4b1d749
ci(vitest): clear NODE_V8_COVERAGE for spawned children
laitingsheng Jun 30, 2026
956564b
ci(pr): bump cli-test-shards timeout to 15 min
laitingsheng Jun 30, 2026
00d65eb
ci(vitest): serialize integration project to single fork
laitingsheng Jun 30, 2026
1b23e35
revert: roll back CI workarounds for shard 1 OOM
laitingsheng Jun 30, 2026
a2ee4d0
Merge branch 'main' into fix/curl-probe-no-bearer-in-argv
laitingsheng Jun 30, 2026
fcce3d4
refactor(inference): scrub credential env, extract Anthropic probe, a…
laitingsheng Jul 1, 2026
39f875d
test(probe): centralize env restore and output-body write
laitingsheng Jul 1, 2026
d1ec667
fix(inference): route ollama auth-proxy token through trusted curl co…
laitingsheng Jul 1, 2026
75f57a3
fix(security): scrub credential-shaped opts.env entries for curl probes
laitingsheng Jul 1, 2026
7d04b23
refactor(inference): drop unused curl auth-config bindings
laitingsheng Jul 1, 2026
6b27752
Merge branch 'main' into fix/curl-probe-no-bearer-in-argv
laitingsheng Jul 1, 2026
7d5cb81
fix(security): scrub curl probe child env unconditionally
laitingsheng Jul 1, 2026
ce016ff
test: drop PR-added curl-probe tests to isolate shard-1 timeout
laitingsheng Jul 1, 2026
7a6ca48
test: drop integration fileParallelism:false to restore parallel shar…
laitingsheng Jul 1, 2026
a664175
test: restore curl-probe test coverage
laitingsheng Jul 1, 2026
17b2a7f
ci: shard cli coverage into 10 lanes to fit worker heap
laitingsheng Jul 1, 2026
9a46498
ci: sync 10-shard coverage config, workflow contract, and probe env test
laitingsheng Jul 1, 2026
8a8ca45
ci: use 7 cli coverage shards to balance heap and hook budget
laitingsheng Jul 1, 2026
38e14cf
Merge branch 'main' into fix/curl-probe-no-bearer-in-argv
laitingsheng Jul 1, 2026
079bc7d
ci: run cli coverage in 10 shards with 20s cli test and hook timeouts
laitingsheng Jul 1, 2026
32becc2
Merge branch 'main' into fix/curl-probe-no-bearer-in-argv
laitingsheng Jul 1, 2026
52bbe34
ci: raise vitest cli/integration fork heap to 8GB for coverage runs
laitingsheng Jul 1, 2026
4f9f685
ci: raise cli shard worker heap via NODE_OPTIONS (vitest 4 dropped po…
laitingsheng Jul 1, 2026
2c4a525
ci: run integration project in parallel with capped workers under rai…
laitingsheng Jul 1, 2026
47d2842
Merge branch 'main' into fix/curl-probe-no-bearer-in-argv
laitingsheng Jul 1, 2026
df789b8
test(onboard-selection): read probe auth from curl --config tmpfile i…
laitingsheng Jul 1, 2026
aefde33
ci: restore original 5-shard cli coverage config
laitingsheng Jul 1, 2026
f5ee355
test(onboard-selection): read probe auth from curl --config without g…
laitingsheng Jul 1, 2026
b65619f
fix(ollama): reject path traversal in registry manifest model refs
laitingsheng Jul 1, 2026
a22b7c1
fix(inference): report probe credential-setup failures as unhealthy
laitingsheng Jul 1, 2026
bb98915
test(http): cover auth-config fs failures and probe env-leak boundary
laitingsheng Jul 1, 2026
53b1b0b
test(inference): prove probe secrets absent via ps auxww and cover au…
laitingsheng Jul 1, 2026
aaf26ec
refactor(security): extract shared credential-env scrubbing and test …
laitingsheng Jul 1, 2026
e605c64
test(security): keep credential-env env restore branch in shared helper
laitingsheng Jul 1, 2026
32e923b
fix(security): widen credential-shaped name pattern; ESM-ify anthropi…
laitingsheng Jul 1, 2026
b81c983
fix(security): scrub credential-shaped vars from curl probe replaceme…
laitingsheng Jul 1, 2026
8510512
test(inference): extract shared fake-curl harness to cut onboard-prob…
prekshivyas Jul 1, 2026
d39e2c6
Merge branch 'main' into fix/curl-probe-no-bearer-in-argv
prekshivyas Jul 1, 2026
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
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ jobs:
needs: changes
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
Expand Down
41 changes: 41 additions & 0 deletions src/lib/adapters/http/auth-config-test-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
// Shared assertions for tests that inspect the curl --config tmpfile route
// introduced in PR #5975. Extracted from src/lib/inference/onboard-probes.test.ts
// and src/lib/inference/provider-models.test.ts so the assertion shape stays
// in one place. See PR #5975 review notes PRA-9 (Nemotron) and PRA-CR
// (CodeRabbit "assert --config has a path value").

import fs from "node:fs";

import { expect } from "vitest";

export function captureAuthConfigPath(argv: readonly string[]): string {
const index = argv.indexOf("--config");
expect(index).toBeGreaterThanOrEqual(0);
const configPath = argv[index + 1];
expect(configPath).toBeTruthy();
expect(typeof configPath).toBe("string");
return configPath;
}

export function readAuthConfigContents(argv: readonly string[]): string {
const configPath = captureAuthConfigPath(argv);
// Single readFileSync, no existsSync precheck: readFileSync throws ENOENT
// synchronously if the file is missing, which is what the assertion wants
// anyway, and avoids the "check then use" filesystem race that CodeQL
// flagged in PR #5975 review.
const contents = fs.readFileSync(configPath, "utf8");
const stat = fs.statSync(configPath);
expect(stat.mode & 0o777).toBe(0o600);
return contents;
}

export function expectTrustedConfig(
argv: readonly string[],
opts: { trustedConfigFiles?: readonly string[] } | undefined,
): void {
const configPath = captureAuthConfigPath(argv);
expect(opts?.trustedConfigFiles ?? []).toContain(configPath);
}
116 changes: 116 additions & 0 deletions src/lib/adapters/http/auth-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import fs from "node:fs";

import { describe, expect, it } from "vitest";

import {
createBearerAuthConfig,
createCurlAuthConfig,
createOpenAiLikeAuthConfig,
createQueryParamAuthConfig,
createXApiKeyAuthConfig,
} from "./auth-config";

describe("curl auth config helper", () => {
it("returns an empty config when no entries are provided", () => {
const config = createCurlAuthConfig([]);
expect(config.args).toEqual([]);
expect(config.trustedConfigFiles).toEqual([]);
expect(() => config.cleanup()).not.toThrow();
});

it("writes a 0600 curl config tmpfile with a header entry and removes it on cleanup", () => {
const config = createBearerAuthConfig("nvapi-test-1234");
const configPath = config.args[1];
try {
expect(config.args[0]).toBe("--config");
expect(typeof configPath).toBe("string");
// Single readFileSync — readFileSync throws ENOENT synchronously if
// the file is missing, which is what we want anyway, and avoids the
// "check then use" race CodeQL flagged in PR #5975 review.
const contents = fs.readFileSync(configPath, "utf8");
const stat = fs.statSync(configPath);
expect(stat.mode & 0o777).toBe(0o600);
expect(contents).toContain('header = "Authorization: Bearer nvapi-test-1234"');
expect(config.trustedConfigFiles).toContain(configPath);
} finally {
config.cleanup();
}
expect(() => fs.statSync(configPath)).toThrow(/ENOENT/);
});

it("writes a url-query entry instead of a header for query-param auth", () => {
const config = createQueryParamAuthConfig("key", "AIzaFakeKey123");
try {
const contents = fs.readFileSync(config.args[1], "utf8");
expect(contents).toContain('url-query = "key=AIzaFakeKey123"');
} finally {
config.cleanup();
}
});

it("escapes embedded quotes, backslashes, and newlines in entry values", () => {
const config = createCurlAuthConfig([
{ kind: "header", value: 'Authorization: Bearer evil"\\\nvalue' },
]);
try {
const contents = fs.readFileSync(config.args[1], "utf8");
expect(contents).toContain('header = "Authorization: Bearer evil\\"\\\\ value"');
expect(contents).not.toContain("\nvalue");
} finally {
config.cleanup();
}
});

it("emits an x-api-key header entry for Anthropic-style auth", () => {
const config = createXApiKeyAuthConfig("sk-ant-secret");
try {
const contents = fs.readFileSync(config.args[1], "utf8");
expect(contents).toContain('header = "x-api-key: sk-ant-secret"');
} finally {
config.cleanup();
}
});

it("routes the OpenAI-like helper through Bearer auth by default and emits no url-query entry", () => {
const config = createOpenAiLikeAuthConfig("sk-test");
try {
const contents = fs.readFileSync(config.args[1], "utf8");
expect(contents).toContain('header = "Authorization: Bearer sk-test"');
expect(contents).not.toContain("url-query =");
} finally {
config.cleanup();
}
});

it("routes the OpenAI-like helper through query-param auth when requested and emits no Authorization header", () => {
const config = createOpenAiLikeAuthConfig("AIzaFakeKey123", "query-param");
try {
const contents = fs.readFileSync(config.args[1], "utf8");
expect(contents).toContain('url-query = "key=AIzaFakeKey123"');
expect(contents).not.toContain('header = "Authorization');
} finally {
config.cleanup();
}
});

it("honours a caller-supplied tmpfile prefix so health probes are identifiable in /proc", () => {
const config = createBearerAuthConfig("nvapi-test", { prefix: "nemoclaw-kimi-health-curl" });
try {
expect(config.args[1]).toContain("nemoclaw-kimi-health-curl-");
} finally {
config.cleanup();
}
});

it("rejects an invalid prefix value to keep tmpfile paths predictable", () => {
expect(() => createBearerAuthConfig("nvapi-test", { prefix: "../escape" })).toThrow(
/invalid curl auth config prefix/,
);
expect(() => createBearerAuthConfig("nvapi-test", { prefix: "" })).toThrow(
/invalid curl auth config prefix/,
);
});
});
142 changes: 142 additions & 0 deletions src/lib/adapters/http/auth-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import fs from "node:fs";
import os from "node:os";
import path from "node:path";

const CURL_AUTH_CONFIG_PREFIX = "nemoclaw-curl-auth";
const CURL_AUTH_CONFIG_NAME_PATTERN = /^[a-zA-Z][a-zA-Z0-9._-]{0,127}$/;

function resolveCurlAuthConfigPrefix(prefix: string | undefined): string {
if (prefix === undefined) return CURL_AUTH_CONFIG_PREFIX;
if (!CURL_AUTH_CONFIG_NAME_PATTERN.test(prefix)) {
throw new Error(`invalid curl auth config prefix: ${prefix}`);
}
return prefix;
}

export type CurlAuthConfigEntry =
| { kind: "header"; value: string }
| { kind: "url-query"; name: string; value: string };

export interface CurlAuthConfig {
args: readonly string[];
trustedConfigFiles: readonly string[];
cleanup(): void;
}

const EMPTY_CURL_AUTH_CONFIG: CurlAuthConfig = {
args: [],
trustedConfigFiles: [],
cleanup() {
/* no-op */
},
};

function quoteCurlConfigValue(value: string): string {
return value
.replace(/\\/g, "\\\\")
.replace(/"/g, '\\"')
.replace(/[\r\n]+/g, " ");
}

function formatCurlConfigEntry(entry: CurlAuthConfigEntry): string {
if (entry.kind === "header") {
return `header = "${quoteCurlConfigValue(entry.value)}"`;
}
return `url-query = "${quoteCurlConfigValue(`${entry.name}=${entry.value}`)}"`;
}

function isInsideOwnTempDir(configPath: string, prefix: string): boolean {
const dir = path.dirname(configPath);
const tempRoot = path.resolve(os.tmpdir());
const parentDir = path.resolve(dir);
const relativeParent = path.relative(tempRoot, parentDir);
const inside =
relativeParent !== "" && !relativeParent.startsWith("..") && !path.isAbsolute(relativeParent);
return inside && path.basename(parentDir).startsWith(`${prefix}-`);
}

export interface CreateCurlAuthConfigOptions {
/**
* Filename prefix for the per-call tmpfile directory. Defaults to
* `nemoclaw-curl-auth`. Callers that want their tmpfile to be
* recognizable in `ps`/`/proc` (e.g. the Kimi health probe) can supply a
* narrower prefix; the cleanup contract still enforces it.
*/
prefix?: string;
}

export function createCurlAuthConfig(
entries: readonly CurlAuthConfigEntry[],
options: CreateCurlAuthConfigOptions = {},
): CurlAuthConfig {
if (entries.length === 0) return EMPTY_CURL_AUTH_CONFIG;
const prefix = resolveCurlAuthConfigPrefix(options.prefix);
const dir = fs.mkdtempSync(path.join(os.tmpdir(), `${prefix}-`));
let succeeded = false;
try {
fs.chmodSync(dir, 0o700);
const configPath = path.join(dir, "auth.conf");
const body = `${entries.map(formatCurlConfigEntry).join("\n")}\n`;
fs.writeFileSync(configPath, body, { mode: 0o600, encoding: "utf8" });
const config: CurlAuthConfig = {
args: ["--config", configPath],
trustedConfigFiles: [configPath],
cleanup() {
if (isInsideOwnTempDir(configPath, prefix)) {
fs.rmSync(path.dirname(configPath), { recursive: true, force: true });
}
},
};
succeeded = true;
return config;
} finally {
if (!succeeded) {
fs.rmSync(dir, { recursive: true, force: true });
}
}
}

export function createBearerAuthConfig(
token: string,
options: CreateCurlAuthConfigOptions = {},
): CurlAuthConfig {
if (!token) return EMPTY_CURL_AUTH_CONFIG;
return createCurlAuthConfig(
[{ kind: "header", value: `Authorization: Bearer ${token}` }],
options,
);
}

export function createXApiKeyAuthConfig(
token: string,
options: CreateCurlAuthConfigOptions = {},
): CurlAuthConfig {
if (!token) return EMPTY_CURL_AUTH_CONFIG;
return createCurlAuthConfig([{ kind: "header", value: `x-api-key: ${token}` }], options);
}

export function createQueryParamAuthConfig(
name: string,
value: string,
options: CreateCurlAuthConfigOptions = {},
): CurlAuthConfig {
if (!value) return EMPTY_CURL_AUTH_CONFIG;
return createCurlAuthConfig([{ kind: "url-query", name, value }], options);
}

export type OpenAiLikeAuthMode = "bearer" | "query-param";

export function createOpenAiLikeAuthConfig(
apiKey: string,
authMode?: OpenAiLikeAuthMode,
options: CreateCurlAuthConfigOptions = {},
): CurlAuthConfig {
if (!apiKey) return EMPTY_CURL_AUTH_CONFIG;
if (authMode === "query-param") {
return createQueryParamAuthConfig("key", apiKey, options);
}
return createBearerAuthConfig(apiKey, options);
}
Loading
Loading