From adad6afb70171539b4b272f89d926f7f1dc738e3 Mon Sep 17 00:00:00 2001 From: zyang-dev <267119621+zyang-dev@users.noreply.github.com> Date: Fri, 17 Apr 2026 13:49:38 -0700 Subject: [PATCH 1/4] fix: prompt for NGC API key when pulling local NIM images Signed-off-by: zyang-dev <267119621+zyang-dev@users.noreply.github.com> --- src/lib/nim.ts | 22 ++++++++++++++++++++++ src/lib/onboard.ts | 22 ++++++++++++++++++++++ test/onboard-selection.test.ts | 1 + 3 files changed, 45 insertions(+) diff --git a/src/lib/nim.ts b/src/lib/nim.ts index d30db81fa42..2675ac8c95d 100644 --- a/src/lib/nim.ts +++ b/src/lib/nim.ts @@ -176,6 +176,28 @@ export function detectGpu(): GpuDetection | null { return null; } +export function isNgcLoggedIn(): boolean { + try { + const os = require("os"); + const fs = require("fs"); + const config = os.homedir() + "/.docker/config.json"; + const data = fs.readFileSync(config, "utf-8"); + return data.includes("nvcr.io"); + } catch { + return false; + } +} + +export function dockerLoginNgc(apiKey: string): boolean { + const { spawnSync } = require("child_process"); + const result = spawnSync("docker", ["login", "nvcr.io", "-u", "$oauthtoken", "--password-stdin"], { + input: apiKey, + encoding: "utf-8", + stdio: ["pipe", "pipe", "pipe"], + }); + return result.status === 0; +} + export function pullNimImage(model: string): string { const image = getImageForModel(model); if (!image) { diff --git a/src/lib/onboard.ts b/src/lib/onboard.ts index a8221aa687e..2172b11240f 100644 --- a/src/lib/onboard.ts +++ b/src/lib/onboard.ts @@ -3955,6 +3955,28 @@ async function setupNim(gpu) { } model = sel.name; + // Ensure Docker is logged in to NGC registry before pulling NIM images. + if (!nim.isNgcLoggedIn()) { + console.log(""); + console.log(" NGC API Key required to pull NIM images."); + console.log(" Get one from: https://org.ngc.nvidia.com/setup/api-key"); + console.log(""); + let ngcKey = await prompt(" NGC API Key: ", { secret: true }); + if (!ngcKey) { + console.error(" NGC API Key is required for Local NIM."); + process.exit(1); + } + if (!nim.dockerLoginNgc(ngcKey)) { + console.error(" Failed to login to NGC registry. Check your API key and try again."); + console.log(""); + ngcKey = await prompt(" NGC API Key: ", { secret: true }); + if (!ngcKey || !nim.dockerLoginNgc(ngcKey)) { + console.error(" NGC login failed. Cannot pull NIM images."); + process.exit(1); + } + } + } + console.log(` Pulling NIM image for ${model}...`); nim.pullNimImage(model); diff --git a/test/onboard-selection.test.ts b/test/onboard-selection.test.ts index 04305e33c10..bd078f9c2ff 100644 --- a/test/onboard-selection.test.ts +++ b/test/onboard-selection.test.ts @@ -3066,6 +3066,7 @@ nimMod.pullNimImage = () => {}; nimMod.containerName = () => "nemoclaw-nim-test"; nimMod.startNimContainerByName = () => "container-123"; nimMod.waitForNimHealth = () => true; +nimMod.isNgcLoggedIn = () => true; // Select option 7 (nim-local), then model 1 const answers = ["7", "1"]; From 7b175f6da7e8751f2d5ab564cfac97f6157adedd Mon Sep 17 00:00:00 2001 From: zyang-dev <267119621+zyang-dev@users.noreply.github.com> Date: Fri, 17 Apr 2026 16:05:45 -0700 Subject: [PATCH 2/4] fix: stricter NGC auth check, non-interactive guard, and credential normalization Signed-off-by: zyang-dev <267119621+zyang-dev@users.noreply.github.com> --- src/lib/nim.ts | 9 +++++++-- src/lib/onboard.ts | 10 ++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/lib/nim.ts b/src/lib/nim.ts index 2675ac8c95d..22ed0f1f2fb 100644 --- a/src/lib/nim.ts +++ b/src/lib/nim.ts @@ -180,9 +180,14 @@ export function isNgcLoggedIn(): boolean { try { const os = require("os"); const fs = require("fs"); - const config = os.homedir() + "/.docker/config.json"; + const path = require("path"); + const config = path.join(os.homedir(), ".docker", "config.json"); const data = fs.readFileSync(config, "utf-8"); - return data.includes("nvcr.io"); + const parsed = JSON.parse(data); + if (parsed?.credHelpers?.["nvcr.io"]) return true; + const auths = parsed?.auths || {}; + const entry = auths["nvcr.io"] || auths["https://nvcr.io"]; + return Boolean(entry && (entry.auth || entry.token)); } catch { return false; } diff --git a/src/lib/onboard.ts b/src/lib/onboard.ts index 2172b11240f..eb0c17ff923 100644 --- a/src/lib/onboard.ts +++ b/src/lib/onboard.ts @@ -3957,11 +3957,17 @@ async function setupNim(gpu) { // Ensure Docker is logged in to NGC registry before pulling NIM images. if (!nim.isNgcLoggedIn()) { + if (isNonInteractive()) { + console.error( + " Docker is not logged in to nvcr.io. In non-interactive mode, run `docker login nvcr.io` first and retry.", + ); + process.exit(1); + } console.log(""); console.log(" NGC API Key required to pull NIM images."); console.log(" Get one from: https://org.ngc.nvidia.com/setup/api-key"); console.log(""); - let ngcKey = await prompt(" NGC API Key: ", { secret: true }); + let ngcKey = normalizeCredentialValue(await prompt(" NGC API Key: ", { secret: true })); if (!ngcKey) { console.error(" NGC API Key is required for Local NIM."); process.exit(1); @@ -3969,7 +3975,7 @@ async function setupNim(gpu) { if (!nim.dockerLoginNgc(ngcKey)) { console.error(" Failed to login to NGC registry. Check your API key and try again."); console.log(""); - ngcKey = await prompt(" NGC API Key: ", { secret: true }); + ngcKey = normalizeCredentialValue(await prompt(" NGC API Key: ", { secret: true })); if (!ngcKey || !nim.dockerLoginNgc(ngcKey)) { console.error(" NGC login failed. Cannot pull NIM images."); process.exit(1); From 6f584fea7f5f7c7f7746e0318a72f6d607183409 Mon Sep 17 00:00:00 2001 From: zyang-dev <267119621+zyang-dev@users.noreply.github.com> Date: Fri, 17 Apr 2026 17:10:02 -0700 Subject: [PATCH 3/4] fix: address review feedback for NGC login Signed-off-by: zyang-dev <267119621+zyang-dev@users.noreply.github.com> --- src/lib/nim.test.ts | 86 +++++++++++++++++++++++++++++++++++++++++++++ src/lib/nim.ts | 12 +++++++ 2 files changed, 98 insertions(+) diff --git a/src/lib/nim.test.ts b/src/lib/nim.test.ts index fa251765334..bdacee8b5a3 100644 --- a/src/lib/nim.test.ts +++ b/src/lib/nim.test.ts @@ -268,4 +268,90 @@ describe("nim", () => { } }); }); + + describe("isNgcLoggedIn", () => { + const fs = require("fs"); + const os = require("os"); + + function mockDockerConfig(config: string | null) { + const origReadFileSync = fs.readFileSync; + const origHomedir = os.homedir; + os.homedir = () => "/mock-home"; + if (config === null) { + fs.readFileSync = () => { throw new Error("ENOENT"); }; + } else { + fs.readFileSync = (p: string, ...args: unknown[]) => { + if (typeof p === "string" && p.includes(".docker/config.json")) return config; + return origReadFileSync(p, ...args); + }; + } + return () => { + fs.readFileSync = origReadFileSync; + os.homedir = origHomedir; + }; + } + + it("returns true when credHelpers has nvcr.io", () => { + const restore = mockDockerConfig(JSON.stringify({ credHelpers: { "nvcr.io": "secretservice" } })); + try { + expect(nim.isNgcLoggedIn()).toBe(true); + } finally { + restore(); + } + }); + + it("returns true when auths has nvcr.io with auth field", () => { + const restore = mockDockerConfig(JSON.stringify({ auths: { "nvcr.io": { auth: "dXNlcjpwYXNz" } } })); + try { + expect(nim.isNgcLoggedIn()).toBe(true); + } finally { + restore(); + } + }); + + it("returns true when auths has https://nvcr.io with token field", () => { + const restore = mockDockerConfig(JSON.stringify({ auths: { "https://nvcr.io": { token: "abc123" } } })); + try { + expect(nim.isNgcLoggedIn()).toBe(true); + } finally { + restore(); + } + }); + + it("returns false when auths has nvcr.io but empty entry", () => { + const restore = mockDockerConfig(JSON.stringify({ auths: { "nvcr.io": {} } })); + try { + expect(nim.isNgcLoggedIn()).toBe(false); + } finally { + restore(); + } + }); + + it("returns false when config file is missing", () => { + const restore = mockDockerConfig(null); + try { + expect(nim.isNgcLoggedIn()).toBe(false); + } finally { + restore(); + } + }); + + it("returns false when config has malformed JSON", () => { + const restore = mockDockerConfig("not json"); + try { + expect(nim.isNgcLoggedIn()).toBe(false); + } finally { + restore(); + } + }); + + it("returns false when auths is empty and no credHelpers", () => { + const restore = mockDockerConfig(JSON.stringify({ auths: {} })); + try { + expect(nim.isNgcLoggedIn()).toBe(false); + } finally { + restore(); + } + }); + }); }); diff --git a/src/lib/nim.ts b/src/lib/nim.ts index 22ed0f1f2fb..ca4f0962143 100644 --- a/src/lib/nim.ts +++ b/src/lib/nim.ts @@ -176,6 +176,10 @@ export function detectGpu(): GpuDetection | null { return null; } +// Check if Docker has stored credentials for nvcr.io. +// When credsStore is set (e.g., Docker Desktop), credentials are in the OS +// keychain and not visible in config.json. Returns false in that case, +// causing a redundant but harmless re-prompt. export function isNgcLoggedIn(): boolean { try { const os = require("os"); @@ -193,6 +197,7 @@ export function isNgcLoggedIn(): boolean { } } +// NGC expects literal "$oauthtoken" as the username for API key authentication. export function dockerLoginNgc(apiKey: string): boolean { const { spawnSync } = require("child_process"); const result = spawnSync("docker", ["login", "nvcr.io", "-u", "$oauthtoken", "--password-stdin"], { @@ -200,6 +205,13 @@ export function dockerLoginNgc(apiKey: string): boolean { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"], }); + if (result.error) { + console.error(` Docker error: ${result.error.message}`); + return false; + } + if (result.status !== 0 && result.stderr) { + console.error(` Docker login error: ${result.stderr.trim()}`); + } return result.status === 0; } From 5c43718874338ab5ac2b6f2bacb1cec81deeb0a4 Mon Sep 17 00:00:00 2001 From: zyang-dev <267119621+zyang-dev@users.noreply.github.com> Date: Fri, 17 Apr 2026 18:20:48 -0700 Subject: [PATCH 4/4] fix(nim): detect NGC login on Docker Desktop via credsStore marker Docker Desktop writes an empty auths marker after login; creds live in the OS keychain. Treat marker + credsStore as logged in. Signed-off-by: zyang-dev <267119621+zyang-dev@users.noreply.github.com> --- src/lib/nim.test.ts | 37 +++++++++++++++++++++++++++++++++++-- src/lib/nim.ts | 10 ++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/lib/nim.test.ts b/src/lib/nim.test.ts index bdacee8b5a3..77219e12565 100644 --- a/src/lib/nim.test.ts +++ b/src/lib/nim.test.ts @@ -309,8 +309,10 @@ describe("nim", () => { } }); - it("returns true when auths has https://nvcr.io with token field", () => { - const restore = mockDockerConfig(JSON.stringify({ auths: { "https://nvcr.io": { token: "abc123" } } })); + it("returns true when auths has https://nvcr.io with auth field", () => { + const restore = mockDockerConfig( + JSON.stringify({ auths: { "https://nvcr.io": { auth: "dXNlcjpwYXNz" } } }), + ); try { expect(nim.isNgcLoggedIn()).toBe(true); } finally { @@ -353,5 +355,36 @@ describe("nim", () => { restore(); } }); + + it("returns true when empty nvcr.io marker exists and credsStore is set (Docker Desktop)", () => { + const restore = mockDockerConfig( + JSON.stringify({ credsStore: "desktop", auths: { "nvcr.io": {} } }), + ); + try { + expect(nim.isNgcLoggedIn()).toBe(true); + } finally { + restore(); + } + }); + + it("returns false when credsStore is set but no nvcr.io marker (not logged in)", () => { + const restore = mockDockerConfig( + JSON.stringify({ credsStore: "desktop", auths: {} }), + ); + try { + expect(nim.isNgcLoggedIn()).toBe(false); + } finally { + restore(); + } + }); + + it("returns false when empty nvcr.io marker exists but no credsStore", () => { + const restore = mockDockerConfig(JSON.stringify({ auths: { "nvcr.io": {} } })); + try { + expect(nim.isNgcLoggedIn()).toBe(false); + } finally { + restore(); + } + }); }); }); diff --git a/src/lib/nim.ts b/src/lib/nim.ts index ca4f0962143..d83e6399d26 100644 --- a/src/lib/nim.ts +++ b/src/lib/nim.ts @@ -177,9 +177,9 @@ export function detectGpu(): GpuDetection | null { } // Check if Docker has stored credentials for nvcr.io. -// When credsStore is set (e.g., Docker Desktop), credentials are in the OS -// keychain and not visible in config.json. Returns false in that case, -// causing a redundant but harmless re-prompt. +// Docker Desktop (macOS/Windows/WSL) stores creds in the OS keychain and +// leaves an empty marker entry { "nvcr.io": {} } in auths after a successful +// login. That marker plus a global credsStore is treated as logged in. export function isNgcLoggedIn(): boolean { try { const os = require("os"); @@ -191,7 +191,9 @@ export function isNgcLoggedIn(): boolean { if (parsed?.credHelpers?.["nvcr.io"]) return true; const auths = parsed?.auths || {}; const entry = auths["nvcr.io"] || auths["https://nvcr.io"]; - return Boolean(entry && (entry.auth || entry.token)); + if (entry?.auth) return true; + if (entry && parsed?.credsStore) return true; + return false; } catch { return false; }