Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 27 additions & 4 deletions scripts/nemoclaw-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ PYAUTH
print_dashboard_urls() {
local token chat_ui_base local_url remote_url

token="$(python3 - <<'PYTOKEN'
token="$(
python3 - <<'PYTOKEN'
import json
import os
path = os.path.expanduser('~/.openclaw/openclaw.json')
Expand All @@ -51,7 +52,7 @@ except Exception:
else:
print(cfg.get('gateway', {}).get('auth', {}).get('token', ''))
PYTOKEN
)"
)"

chat_ui_base="${CHAT_UI_URL%/}"
local_url="http://127.0.0.1:${PUBLIC_PORT}/"
Expand All @@ -66,7 +67,7 @@ PYTOKEN
}

start_auto_pair() {
nohup python3 - <<'PYAUTOPAIR' >> /tmp/gateway.log 2>&1 &
nohup python3 - <<'PYAUTOPAIR' >>/tmp/gateway.log 2>&1 &
import json
import subprocess
import time
Expand Down Expand Up @@ -130,13 +131,35 @@ echo 'Setting up NemoClaw...'
# openclaw doctor --fix and openclaw plugins install already ran at build time
# (Dockerfile Step 28). At runtime they fail with EPERM against the locked
# /sandbox/.openclaw directory and accomplish nothing.

# Configure outbound proxy so Node.js (openclaw/undici) routes HTTP/HTTPS
# requests through the OpenShell egress proxy at 10.200.0.1:3128.
#
# Without this, Node.js resolves DNS locally before the CONNECT tunnel is
# opened, hitting `getaddrinfo EAI_AGAIN` because the sandbox network
# namespace has no DNS resolver configured. The proxy handles DNS on behalf
# of the sandbox, so exporting HTTPS_PROXY causes undici/node:http to skip
# local resolution entirely. curl already does this correctly (it uses the
# proxy's DNS), and these env vars bring parity to Node.js callers.
#
# NEMOCLAW_PROXY_HOST can be set at sandbox creation time to override the
# default if the gateway IP changes in a future OpenShell release.
# Ref: https://github.com/NVIDIA/NemoClaw/issues/626
PROXY_HOST="${NEMOCLAW_PROXY_HOST:-10.200.0.1}"
PROXY_PORT="${NEMOCLAW_PROXY_PORT:-3128}"
export HTTP_PROXY="http://${PROXY_HOST}:${PROXY_PORT}"
export HTTPS_PROXY="http://${PROXY_HOST}:${PROXY_PORT}"
# Bypass proxy for loopback, sandbox-local, and the OpenShell virtual network
# so internal gateway calls (openclaw dashboard, inference.local) stay fast.
export NO_PROXY="localhost,127.0.0.1,::1,inference.local,10.200.0.0/16"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

write_auth_profile

if [ ${#NEMOCLAW_CMD[@]} -gt 0 ]; then
exec "${NEMOCLAW_CMD[@]}"
fi

nohup openclaw gateway run > /tmp/gateway.log 2>&1 &
nohup openclaw gateway run >/tmp/gateway.log 2>&1 &
echo "[gateway] openclaw gateway launched (pid $!)"
start_auto_pair
print_dashboard_urls
77 changes: 76 additions & 1 deletion test/service-env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

import { describe, it, expect } from "vitest";
import { execSync } from "node:child_process";
import { execSync, execFileSync } from "node:child_process";
import { writeFileSync, unlinkSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { resolveOpenshell } from "../bin/lib/resolve-openshell";

describe("service environment", () => {
Expand Down Expand Up @@ -95,4 +98,76 @@ describe("service environment", () => {
expect(result).toBe("default");
});
});

describe("proxy environment variables (issue #626)", () => {
// Verify nemoclaw-start.sh sets HTTP_PROXY / HTTPS_PROXY / NO_PROXY so that
// Node.js (undici) routes outbound requests through the OpenShell egress
// proxy and does not attempt to resolve DNS locally inside the sandbox.

function extractProxyVars(env = {}) {
// Write the proxy-variable snippet from nemoclaw-start.sh to a temp script
// and execute it so that bash variable assignments and expansions work
// correctly without interference from JSON.stringify quote-escaping.
const script = [
"#!/usr/bin/env bash",
'PROXY_HOST="${NEMOCLAW_PROXY_HOST:-10.200.0.1}"',
'PROXY_PORT="${NEMOCLAW_PROXY_PORT:-3128}"',
'HTTP_PROXY="http://${PROXY_HOST}:${PROXY_PORT}"',
'HTTPS_PROXY="http://${PROXY_HOST}:${PROXY_PORT}"',
'NO_PROXY="localhost,127.0.0.1,::1,inference.local,10.200.0.0/16"',
'echo "HTTP_PROXY=${HTTP_PROXY}"',
'echo "HTTPS_PROXY=${HTTPS_PROXY}"',
'echo "NO_PROXY=${NO_PROXY}"',
].join("\n");
const tmpFile = join(tmpdir(), `nemoclaw-proxy-test-${process.pid}.sh`);
try {
writeFileSync(tmpFile, script, { mode: 0o700 });
const out = execFileSync("bash", [tmpFile], {
encoding: "utf-8",
env: { ...process.env, ...env },
}).trim();
return Object.fromEntries(out.split("\n").map((l) => {
const idx = l.indexOf("=");
return [l.slice(0, idx), l.slice(idx + 1)];
}));
} finally {
try { unlinkSync(tmpFile); } catch { /* ignore */ }
}
}

it("sets HTTP_PROXY to default gateway address", () => {
const vars = extractProxyVars();
expect(vars.HTTP_PROXY).toBe("http://10.200.0.1:3128");
});

it("sets HTTPS_PROXY to default gateway address", () => {
const vars = extractProxyVars();
expect(vars.HTTPS_PROXY).toBe("http://10.200.0.1:3128");
});

it("NEMOCLAW_PROXY_HOST overrides default gateway IP", () => {
const vars = extractProxyVars({ NEMOCLAW_PROXY_HOST: "192.168.64.1" });
expect(vars.HTTP_PROXY).toBe("http://192.168.64.1:3128");
expect(vars.HTTPS_PROXY).toBe("http://192.168.64.1:3128");
});

it("NEMOCLAW_PROXY_PORT overrides default proxy port", () => {
const vars = extractProxyVars({ NEMOCLAW_PROXY_PORT: "8080" });
expect(vars.HTTP_PROXY).toBe("http://10.200.0.1:8080");
expect(vars.HTTPS_PROXY).toBe("http://10.200.0.1:8080");
});

it("NO_PROXY excludes loopback and inference.local", () => {
const vars = extractProxyVars();
const noProxy = vars.NO_PROXY.split(",");
expect(noProxy).toContain("localhost");
expect(noProxy).toContain("127.0.0.1");
expect(noProxy).toContain("inference.local");
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

it("NO_PROXY excludes OpenShell virtual network range", () => {
const vars = extractProxyVars();
expect(vars.NO_PROXY).toContain("10.200.0.0/16");
});
});
});