Skip to content

Commit 9936c52

Browse files
committed
fix(security): stop leaking API keys in process args visible via ps aux
Pass credential env var names to openshell instead of KEY=VALUE pairs. OpenShell reads the actual value from the environment, keeping it out of the process argument list. Closes #325
1 parent 4a1b749 commit 9936c52

3 files changed

Lines changed: 96 additions & 6 deletions

File tree

‎bin/lib/onboard.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ async function setupInference(sandboxName, model, provider) {
808808
// Create nvidia-nim provider
809809
run(
810810
`openshell provider create --name nvidia-nim --type openai ` +
811-
`--credential ${shellQuote("NVIDIA_API_KEY=" + process.env.NVIDIA_API_KEY)} ` +
811+
`--credential ${shellQuote("NVIDIA_API_KEY")} ` +
812812
`--config "OPENAI_BASE_URL=https://integrate.api.nvidia.com/v1" 2>&1 || true`,
813813
{ ignoreError: true }
814814
);
@@ -824,10 +824,12 @@ async function setupInference(sandboxName, model, provider) {
824824
}
825825
const baseUrl = getLocalProviderBaseUrl(provider);
826826
run(
827+
`OPENAI_API_KEY=dummy ` +
827828
`openshell provider create --name vllm-local --type openai ` +
828-
`--credential "OPENAI_API_KEY=dummy" ` +
829+
`--credential "OPENAI_API_KEY" ` +
829830
`--config "OPENAI_BASE_URL=${baseUrl}" 2>&1 || ` +
830-
`openshell provider update vllm-local --credential "OPENAI_API_KEY=dummy" ` +
831+
`OPENAI_API_KEY=dummy ` +
832+
`openshell provider update vllm-local --credential "OPENAI_API_KEY" ` +
831833
`--config "OPENAI_BASE_URL=${baseUrl}" 2>&1 || true`,
832834
{ ignoreError: true }
833835
);
@@ -844,10 +846,12 @@ async function setupInference(sandboxName, model, provider) {
844846
}
845847
const baseUrl = getLocalProviderBaseUrl(provider);
846848
run(
849+
`OPENAI_API_KEY=ollama ` +
847850
`openshell provider create --name ollama-local --type openai ` +
848-
`--credential "OPENAI_API_KEY=ollama" ` +
851+
`--credential "OPENAI_API_KEY" ` +
849852
`--config "OPENAI_BASE_URL=${baseUrl}" 2>&1 || ` +
850-
`openshell provider update ollama-local --credential "OPENAI_API_KEY=ollama" ` +
853+
`OPENAI_API_KEY=ollama ` +
854+
`openshell provider update ollama-local --credential "OPENAI_API_KEY" ` +
851855
`--config "OPENAI_BASE_URL=${baseUrl}" 2>&1 || true`,
852856
{ ignoreError: true }
853857
);

‎nemoclaw-blueprint/orchestrator/runner.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ def action_apply(
209209
"--type",
210210
provider_type,
211211
]
212+
target_cred_env = "OPENAI_API_KEY"
212213
if credential:
213-
provider_args.extend(["--credential", f"OPENAI_API_KEY={credential}"])
214+
os.environ[target_cred_env] = credential
215+
provider_args.extend(["--credential", target_cred_env])
214216
if endpoint:
215217
provider_args.extend(["--config", f"OPENAI_BASE_URL={endpoint}"])
216218

‎test/credential-exposure.test.js‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
// Security regression test: credential values must never appear in --credential
5+
// CLI arguments. OpenShell reads credential values from the environment when
6+
// only the env-var name is passed (e.g. --credential "NVIDIA_API_KEY"), so
7+
// there is no reason to pass the secret itself on the command line where it
8+
// would be visible in `ps aux` output.
9+
10+
"use strict";
11+
12+
const fs = require("node:fs");
13+
const path = require("node:path");
14+
15+
const ONBOARD_JS = path.join(__dirname, "..", "bin", "lib", "onboard.js");
16+
const RUNNER_PY = path.join(
17+
__dirname,
18+
"..",
19+
"nemoclaw-blueprint",
20+
"orchestrator",
21+
"runner.py",
22+
);
23+
24+
// Matches --credential followed by a value containing "=" (i.e. KEY=VALUE).
25+
// This catches patterns like:
26+
// --credential "NVIDIA_API_KEY=" + process.env.NVIDIA_API_KEY
27+
// --credential "OPENAI_API_KEY=somevalue"
28+
// --credential f"OPENAI_API_KEY={credential}"
29+
const JS_EXPOSURE_RE = /--credential\s+[^"]*"[A-Z_]+=/;
30+
const JS_CREDENTIAL_CONCAT_RE = /--credential.*=.*process\.env\./;
31+
const PY_EXPOSURE_RE = /--credential.*=.*\{/;
32+
33+
describe("credential exposure in process arguments", () => {
34+
it("onboard.js must not pass KEY=VALUE to --credential", () => {
35+
const src = fs.readFileSync(ONBOARD_JS, "utf-8");
36+
const lines = src.split("\n");
37+
38+
const violations = lines.filter(
39+
(line, i) =>
40+
(JS_EXPOSURE_RE.test(line) || JS_CREDENTIAL_CONCAT_RE.test(line)) &&
41+
// Allow comments that describe the old pattern
42+
!line.trimStart().startsWith("//"),
43+
);
44+
45+
expect(violations).toEqual([]);
46+
});
47+
48+
it("runner.py must not pass KEY=VALUE to --credential", () => {
49+
const src = fs.readFileSync(RUNNER_PY, "utf-8");
50+
const lines = src.split("\n");
51+
52+
const violations = lines.filter(
53+
(line) =>
54+
PY_EXPOSURE_RE.test(line) &&
55+
line.includes("--credential") &&
56+
!line.trimStart().startsWith("#"),
57+
);
58+
59+
expect(violations).toEqual([]);
60+
});
61+
62+
it("onboard.js --credential flags pass env var names only", () => {
63+
const src = fs.readFileSync(ONBOARD_JS, "utf-8");
64+
65+
// Find all --credential arguments and verify they contain only a key name
66+
// (no "=" sign in the credential value)
67+
const credentialArgs = src.match(/--credential\s+"([^"]+)"/g) || [];
68+
const credentialShellQuote =
69+
src.match(/--credential\s+\$\{shellQuote\("([^"]+)"\)\}/g) || [];
70+
71+
const allArgs = [...credentialArgs, ...credentialShellQuote];
72+
expect(allArgs.length).toBeGreaterThan(0);
73+
74+
for (const arg of allArgs) {
75+
// Extract the credential value from the match
76+
const valueMatch =
77+
arg.match(/--credential\s+"([^"]+)"/) ||
78+
arg.match(/--credential\s+\$\{shellQuote\("([^"]+)"\)\}/);
79+
if (valueMatch) {
80+
expect(valueMatch[1]).not.toContain("=");
81+
}
82+
}
83+
});
84+
});

0 commit comments

Comments
 (0)