Skip to content

Commit feefedf

Browse files
fix: allow docker cli container to connect to gateway (openclaw#12504)
* Docker: route CLI through gateway network namespace * Tests: assert Docker Compose CLI namespace wiring * Changelog: add Docker Compose CLI connectivity fix * Docker: pin docker setup gateway mode and bind * Tests: cover docker setup mode and bind sync * Docs: clarify Docker LAN vs loopback gateway targeting * Changelog: expand Docker openclaw#12504 targeting note * Docker: default optional CLAUDE compose vars to empty * Docs(Docker): document non-interactive compose runs * Changelog: note docker compose env-noise reduction * Docker: restore onboarding Tailscale guidance * Docker: simplify onboarding output and clarify Tailscale * Docker: harden shared-namespace CLI container * Docs(Docker): document shared-namespace trust boundary * Changelog: note docker shared-namespace hardening --------- Co-authored-by: Vincent Koc <[email protected]>
1 parent 710004e commit feefedf

File tree

5 files changed

+90
-14
lines changed

5 files changed

+90
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Docs: https://docs.openclaw.ai
129129
- Doctor/macOS state-dir safety: warn when OpenClaw state resolves inside iCloud Drive (`~/Library/Mobile Documents/com~apple~CloudDocs/...`) or `~/Library/CloudStorage/...`, because sync-backed paths can cause slower I/O and lock/sync races. (#31004) Thanks @vincentkoc.
130130
- Doctor/Linux state-dir safety: warn when OpenClaw state resolves to an `mmcblk*` mount source (SD or eMMC), because random I/O can be slower and media wear can increase under session and credential writes. (#31033) Thanks @vincentkoc.
131131
- CLI/Startup follow-up: add root `--help` fast-path bootstrap bypass with strict root-only matching, lazily resolve CLI channel options only when commands need them, merge build-time startup metadata (`dist/cli-startup-metadata.json`) with runtime catalog discovery so dynamic catalogs are preserved, and add low-power Linux doctor hints for compile-cache placement and respawn tuning. (#30975) Thanks @vincentkoc.
132+
- Docker/Compose gateway targeting: run `openclaw-cli` in the `openclaw-gateway` service network namespace, require gateway startup ordering, pin Docker setup to `gateway.mode=local`, sync `gateway.bind` from `OPENCLAW_GATEWAY_BIND`, default optional `CLAUDE_*` compose vars to empty values to reduce automation warning noise, and harden `openclaw-cli` with `cap_drop` (`NET_RAW`, `NET_ADMIN`) + `no-new-privileges`. Docs now call out the shared trust boundary explicitly. (#12504) Thanks @bvanderdrift and @vincentkoc.
132133
- Telegram/Outbound API proxy env: keep the Node 22 `autoSelectFamily` global-dispatcher workaround while restoring env-proxy support by using `EnvHttpProxyAgent` so `HTTP_PROXY`/`HTTPS_PROXY` continue to apply to outbound requests. (#26207) Thanks @qsysbio-cjw for reporting and @rylena and @vincentkoc for work.
133134
- Browser/Security: fail closed on browser-control auth bootstrap errors; if auto-auth setup fails and no explicit token/password exists, browser control server startup now aborts instead of starting unauthenticated. This ships in the next npm release. Thanks @ijxpwastaken.
134135
- Sandbox/noVNC hardening: increase observer password entropy, shorten observer token lifetime, and replace noVNC token redirect with a bootstrap page that keeps credentials out of `Location` query strings and adds strict no-cache/no-referrer headers.

docker-compose.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ services:
55
HOME: /home/node
66
TERM: xterm-256color
77
OPENCLAW_GATEWAY_TOKEN: ${OPENCLAW_GATEWAY_TOKEN}
8-
CLAUDE_AI_SESSION_KEY: ${CLAUDE_AI_SESSION_KEY}
9-
CLAUDE_WEB_SESSION_KEY: ${CLAUDE_WEB_SESSION_KEY}
10-
CLAUDE_WEB_COOKIE: ${CLAUDE_WEB_COOKIE}
8+
CLAUDE_AI_SESSION_KEY: ${CLAUDE_AI_SESSION_KEY:-}
9+
CLAUDE_WEB_SESSION_KEY: ${CLAUDE_WEB_SESSION_KEY:-}
10+
CLAUDE_WEB_COOKIE: ${CLAUDE_WEB_COOKIE:-}
1111
volumes:
1212
- ${OPENCLAW_CONFIG_DIR}:/home/node/.openclaw
1313
- ${OPENCLAW_WORKSPACE_DIR}:/home/node/.openclaw/workspace
@@ -29,18 +29,26 @@ services:
2929

3030
openclaw-cli:
3131
image: ${OPENCLAW_IMAGE:-openclaw:local}
32+
network_mode: "service:openclaw-gateway"
33+
cap_drop:
34+
- NET_RAW
35+
- NET_ADMIN
36+
security_opt:
37+
- no-new-privileges:true
3238
environment:
3339
HOME: /home/node
3440
TERM: xterm-256color
3541
OPENCLAW_GATEWAY_TOKEN: ${OPENCLAW_GATEWAY_TOKEN}
3642
BROWSER: echo
37-
CLAUDE_AI_SESSION_KEY: ${CLAUDE_AI_SESSION_KEY}
38-
CLAUDE_WEB_SESSION_KEY: ${CLAUDE_WEB_SESSION_KEY}
39-
CLAUDE_WEB_COOKIE: ${CLAUDE_WEB_COOKIE}
43+
CLAUDE_AI_SESSION_KEY: ${CLAUDE_AI_SESSION_KEY:-}
44+
CLAUDE_WEB_SESSION_KEY: ${CLAUDE_WEB_SESSION_KEY:-}
45+
CLAUDE_WEB_COOKIE: ${CLAUDE_WEB_COOKIE:-}
4046
volumes:
4147
- ${OPENCLAW_CONFIG_DIR}:/home/node/.openclaw
4248
- ${OPENCLAW_WORKSPACE_DIR}:/home/node/.openclaw/workspace
4349
stdin_open: true
4450
tty: true
4551
init: true
4652
entrypoint: ["node", "dist/index.js"]
53+
depends_on:
54+
- openclaw-gateway

docker-setup.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ ensure_control_ui_allowed_origins() {
9292
echo "Set gateway.controlUi.allowedOrigins to $allowed_origin_json for non-loopback bind."
9393
}
9494

95+
sync_gateway_mode_and_bind() {
96+
docker compose "${COMPOSE_ARGS[@]}" run --rm openclaw-cli \
97+
config set gateway.mode local >/dev/null
98+
docker compose "${COMPOSE_ARGS[@]}" run --rm openclaw-cli \
99+
config set gateway.bind "$OPENCLAW_GATEWAY_BIND" >/dev/null
100+
echo "Pinned gateway.mode=local and gateway.bind=$OPENCLAW_GATEWAY_BIND for Docker setup."
101+
}
102+
95103
contains_disallowed_chars() {
96104
local value="$1"
97105
[[ "$value" == *$'\n'* || "$value" == *$'\r'* || "$value" == *$'\t'* ]]
@@ -340,14 +348,18 @@ fi
340348

341349
echo ""
342350
echo "==> Onboarding (interactive)"
343-
echo "When prompted:"
344-
echo " - Gateway bind: lan"
345-
echo " - Gateway auth: token"
346-
echo " - Gateway token: $OPENCLAW_GATEWAY_TOKEN"
347-
echo " - Tailscale exposure: Off"
348-
echo " - Install Gateway daemon: No"
351+
echo "Docker setup pins Gateway mode to local."
352+
echo "Gateway runtime bind comes from OPENCLAW_GATEWAY_BIND (default: lan)."
353+
echo "Current runtime bind: $OPENCLAW_GATEWAY_BIND"
354+
echo "Gateway token: $OPENCLAW_GATEWAY_TOKEN"
355+
echo "Tailscale exposure: Off (use host-level tailnet/Tailscale setup separately)."
356+
echo "Install Gateway daemon: No (managed by Docker Compose)"
357+
echo ""
358+
docker compose "${COMPOSE_ARGS[@]}" run --rm openclaw-cli onboard --mode local --no-install-daemon
359+
349360
echo ""
350-
docker compose "${COMPOSE_ARGS[@]}" run --rm openclaw-cli onboard --no-install-daemon
361+
echo "==> Docker gateway defaults"
362+
sync_gateway_mode_and_bind
351363

352364
echo ""
353365
echo "==> Control UI origin allowlist"

docs/install/docker.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,31 @@ After it finishes:
5959
- Paste the token into the Control UI (Settings → token).
6060
- Need the URL again? Run `docker compose run --rm openclaw-cli dashboard --no-open`.
6161

62+
### Automation/CI (non-interactive, no TTY noise)
63+
64+
For scripts and CI, disable Compose pseudo-TTY allocation with `-T`:
65+
66+
```bash
67+
docker compose run -T --rm openclaw-cli gateway probe
68+
docker compose run -T --rm openclaw-cli devices list --json
69+
```
70+
71+
If your automation exports no Claude session vars, leaving them unset now resolves to
72+
empty values by default in `docker-compose.yml` to avoid repeated "variable is not set"
73+
warnings.
74+
75+
### Shared-network security note (CLI + gateway)
76+
77+
`openclaw-cli` uses `network_mode: "service:openclaw-gateway"` so CLI commands can
78+
reliably reach the gateway over `127.0.0.1` in Docker.
79+
80+
Treat this as a shared trust boundary: loopback binding is not isolation between these two
81+
containers. If you need stronger separation, run commands from a separate container/host
82+
network path instead of the bundled `openclaw-cli` service.
83+
84+
To reduce impact if the CLI process is compromised, the compose config drops
85+
`NET_RAW`/`NET_ADMIN` and enables `no-new-privileges` on `openclaw-cli`.
86+
6287
It writes config/workspace on the host:
6388

6489
- `~/.openclaw/`
@@ -322,9 +347,30 @@ scripts/e2e/onboard-docker.sh
322347
pnpm test:docker:qr
323348
```
324349

350+
### LAN vs loopback (Docker Compose)
351+
352+
`docker-setup.sh` defaults `OPENCLAW_GATEWAY_BIND=lan` so host access to
353+
`http://127.0.0.1:18789` works with Docker port publishing.
354+
355+
- `lan` (default): host browser + host CLI can reach the published gateway port.
356+
- `loopback`: only processes inside the container network namespace can reach
357+
the gateway directly; host-published port access may fail.
358+
359+
The setup script also pins `gateway.mode=local` after onboarding so Docker CLI
360+
commands default to local loopback targeting.
361+
362+
If you see `Gateway target: ws://172.x.x.x:18789` or repeated `pairing required`
363+
errors from Docker CLI commands, run:
364+
365+
```bash
366+
docker compose run --rm openclaw-cli config set gateway.mode local
367+
docker compose run --rm openclaw-cli config set gateway.bind lan
368+
docker compose run --rm openclaw-cli devices list --url ws://127.0.0.1:18789
369+
```
370+
325371
### Notes
326372

327-
- Gateway bind defaults to `lan` for container use.
373+
- Gateway bind defaults to `lan` for container use (`OPENCLAW_GATEWAY_BIND`).
328374
- Dockerfile CMD uses `--allow-unconfigured`; mounted config with `gateway.mode` not `local` will still start. Override CMD to enforce the guard.
329375
- The gateway container is the source of truth for sessions (`~/.openclaw/agents/<agentId>/sessions/`).
330376

src/docker-setup.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ describe("docker-setup.sh", () => {
151151
expect(extraCompose).toContain("openclaw-home:");
152152
const log = await readFile(activeSandbox.logPath, "utf8");
153153
expect(log).toContain("--build-arg OPENCLAW_DOCKER_APT_PACKAGES=ffmpeg build-essential");
154+
expect(log).toContain("run --rm openclaw-cli onboard --mode local --no-install-daemon");
155+
expect(log).toContain("run --rm openclaw-cli config set gateway.mode local");
156+
expect(log).toContain("run --rm openclaw-cli config set gateway.bind lan");
154157
});
155158

156159
it("precreates config identity dir for CLI device auth writes", async () => {
@@ -253,4 +256,10 @@ describe("docker-setup.sh", () => {
253256
expect(compose).not.toContain("gateway-daemon");
254257
expect(compose).toContain('"gateway"');
255258
});
259+
260+
it("keeps docker-compose CLI network namespace settings in sync", async () => {
261+
const compose = await readFile(join(repoRoot, "docker-compose.yml"), "utf8");
262+
expect(compose).toContain('network_mode: "service:openclaw-gateway"');
263+
expect(compose).toContain("depends_on:\n - openclaw-gateway");
264+
});
256265
});

0 commit comments

Comments
 (0)