Skip to content

Commit 21cc648

Browse files
committed
fix: bind gateway to 0.0.0.0 and document remote dashboard access (Fixes #20)
- Set gateway.bind to lan in sandbox so port-forward works; optional GATEWAY_BIND env. - Extract gateway config to write-openclaw-gateway-config.py for tests. - Add Remote dashboard access section to deploy-to-remote-gpu.md. - Add test/gateway-config.test.js for bind and allowedOrigins. - Address CodeRabbit review: console fences, active voice, JSON error handling, temp cleanup. Fixes #20 Signed-off-by: Deepak Jain <[email protected]> Made-with: Cursor
1 parent 1dbf82f commit 21cc648

4 files changed

Lines changed: 133 additions & 1 deletion

File tree

‎docs/deployment/deploy-to-remote-gpu.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ To reconnect after closing the session, run the deploy command again:
5959
$ nemoclaw deploy <instance-name>
6060
```
6161

62+
## Remote dashboard access
63+
64+
When you access the dashboard from your laptop via SSH port-forward, set `CHAT_UI_URL` to the URL your browser uses.
65+
This ensures the gateway allows that origin and websocket connections succeed.
66+
67+
The gateway inside the sandbox binds to all interfaces (`0.0.0.0`) by default so that port-forwarding works.
68+
The sandbox Control UI disables device auth; use the token in the dashboard URL to authenticate.
69+
70+
1. On the remote host, ensure the sandbox is started with the origin you use in the browser, for example:
71+
```console
72+
$ export CHAT_UI_URL="http://YOUR_HOST_IP_OR_NAME:18789"
73+
```
74+
2. From your laptop, forward the dashboard port to the remote host:
75+
```console
76+
$ ssh -L 18789:localhost:18789 <instance-name>
77+
```
78+
3. Open `http://127.0.0.1:18789/` (or the URL shown after sandbox start, including the `#token=...` fragment) in your browser.
79+
80+
To bind the gateway to loopback only (e.g. when not using remote access), set `GATEWAY_BIND=loopback` in the sandbox environment.
81+
6282
## Monitor the Remote Sandbox
6383

6484
SSH to the instance and run the OpenShell TUI to monitor activity and approve network requests:

‎scripts/nemoclaw-start.sh‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@
77
#
88
# Optional env:
99
# NVIDIA_API_KEY API key for NVIDIA-hosted inference
10-
# CHAT_UI_URL Browser origin that will access the forwarded dashboard
10+
# CHAT_UI_URL Browser origin that will access the forwarded dashboard (e.g. http://your-host:18789 for SSH port-forward)
11+
# GATEWAY_BIND Gateway bind mode: 'lan' (0.0.0.0, default for remote access) or 'loopback' (127.0.0.1 only)
1112

1213
set -euo pipefail
1314

1415
NEMOCLAW_CMD=("$@")
1516
CHAT_UI_URL="${CHAT_UI_URL:-http://127.0.0.1:18789}"
1617
PUBLIC_PORT=18789
1718

19+
fix_openclaw_config() {
20+
SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd)"
21+
python3 "${SCRIPTS_DIR}/write-openclaw-gateway-config.py"
22+
}
23+
1824
write_auth_profile() {
1925
if [ -z "${NVIDIA_API_KEY:-}" ]; then
2026
return
@@ -131,6 +137,8 @@ echo 'Setting up NemoClaw...'
131137
# (Dockerfile Step 28). At runtime they fail with EPERM against the locked
132138
# /sandbox/.openclaw directory and accomplish nothing.
133139
write_auth_profile
140+
export CHAT_UI_URL PUBLIC_PORT
141+
fix_openclaw_config
134142

135143
if [ ${#NEMOCLAW_CMD[@]} -gt 0 ]; then
136144
exec "${NEMOCLAW_CMD[@]}"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Writes/updates OpenClaw gateway and model config (bind, controlUi, trustedProxies, default model).
6+
# Used by nemoclaw-start.sh and by tests. Set OPENCLAW_JSON_PATH to override config path (for tests).
7+
8+
import json
9+
import os
10+
from urllib.parse import urlparse
11+
12+
def main():
13+
config_path = os.environ.get('OPENCLAW_JSON_PATH')
14+
if not config_path:
15+
home = os.environ.get('HOME', '/sandbox')
16+
config_path = os.path.join(home, '.openclaw', 'openclaw.json')
17+
os.makedirs(os.path.dirname(config_path), exist_ok=True)
18+
19+
cfg = {}
20+
if os.path.exists(config_path):
21+
try:
22+
with open(config_path) as f:
23+
cfg = json.load(f)
24+
except (json.JSONDecodeError, ValueError):
25+
cfg = {}
26+
27+
default_model = os.environ.get('NEMOCLAW_MODEL')
28+
if default_model:
29+
cfg.setdefault('agents', {}).setdefault('defaults', {}).setdefault('model', {})['primary'] = default_model
30+
31+
chat_ui_url = os.environ.get('CHAT_UI_URL', 'http://127.0.0.1:18789')
32+
parsed = urlparse(chat_ui_url)
33+
chat_origin = f"{parsed.scheme}://{parsed.netloc}" if parsed.scheme and parsed.netloc else 'http://127.0.0.1:18789'
34+
local_origin = f'http://127.0.0.1:{os.environ.get("PUBLIC_PORT", "18789")}'
35+
origins = [local_origin]
36+
if chat_origin not in origins:
37+
origins.append(chat_origin)
38+
39+
gateway = cfg.setdefault('gateway', {})
40+
gateway['mode'] = 'local'
41+
gateway['bind'] = os.environ.get('GATEWAY_BIND', 'lan')
42+
# Sandbox defaults intentionally replace any preexisting controlUi settings.
43+
gateway['controlUi'] = {
44+
'allowInsecureAuth': True,
45+
'dangerouslyDisableDeviceAuth': True,
46+
'allowedOrigins': origins,
47+
}
48+
gateway['trustedProxies'] = ['127.0.0.1', '::1']
49+
50+
with open(config_path, 'w') as f:
51+
json.dump(cfg, f, indent=2)
52+
os.chmod(config_path, 0o600)
53+
54+
if __name__ == '__main__':
55+
main()

‎test/gateway-config.test.js‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
const { describe, it } = require("node:test");
5+
const assert = require("node:assert/strict");
6+
const fs = require("node:fs");
7+
const os = require("node:os");
8+
const path = require("node:path");
9+
const { execSync } = require("node:child_process");
10+
11+
const SCRIPTS_DIR = path.join(__dirname, "..", "scripts");
12+
const PYTHON_SCRIPT = path.join(SCRIPTS_DIR, "write-openclaw-gateway-config.py");
13+
14+
function runGatewayConfigScript(env = {}) {
15+
const configDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-gateway-config-"));
16+
const configPath = path.join(configDir, "openclaw.json");
17+
const fullEnv = { ...process.env, OPENCLAW_JSON_PATH: configPath, ...env };
18+
execSync(`python3 "${PYTHON_SCRIPT}"`, { env: fullEnv, encoding: "utf-8" });
19+
const content = fs.readFileSync(configPath, "utf-8");
20+
fs.rmSync(configDir, { recursive: true, force: true });
21+
return { config: JSON.parse(content), configPath };
22+
}
23+
24+
describe("write-openclaw-gateway-config.py (remote dashboard bind)", () => {
25+
it("sets gateway.bind to lan by default for remote access", () => {
26+
const { config } = runGatewayConfigScript();
27+
assert.equal(config.gateway?.bind, "lan");
28+
});
29+
30+
it("honors GATEWAY_BIND=loopback", () => {
31+
const { config } = runGatewayConfigScript({ GATEWAY_BIND: "loopback" });
32+
assert.equal(config.gateway?.bind, "loopback");
33+
});
34+
35+
it("includes local and CHAT_UI_URL origins in allowedOrigins", () => {
36+
const { config } = runGatewayConfigScript({
37+
CHAT_UI_URL: "http://my-host:18789",
38+
PUBLIC_PORT: "18789",
39+
});
40+
const origins = config.gateway?.controlUi?.allowedOrigins ?? [];
41+
assert.ok(origins.includes("http://127.0.0.1:18789"), "local origin present");
42+
assert.ok(origins.includes("http://my-host:18789"), "remote CHAT_UI_URL origin present");
43+
});
44+
45+
it("sets dangerouslyDisableDeviceAuth for sandbox so websocket works over port-forward", () => {
46+
const { config } = runGatewayConfigScript();
47+
assert.equal(config.gateway?.controlUi?.dangerouslyDisableDeviceAuth, true);
48+
});
49+
});

0 commit comments

Comments
 (0)