openclaw icon indicating copy to clipboard operation
openclaw copied to clipboard

[Bug]: Docker install/onboarding stuck: CLI can’t connect to gateway (1006/1008), token mismatch due to OPENCLAW_GATEWAY_TOKEN override + confusing pairing flow/docs

Open MohamedAbdelwahab24 opened this issue 10 months ago • 10 comments

Summary

Docker installation and onboarding are very hard to complete due to unclear gateway authentication and pairing behavior.

The CLI frequently fails to connect to the gateway with errors such as 1006 / 1008, token missing, token mismatch, or pairing required. This happens mainly because:

  • The CLI defaults to connecting to ws://127.0.0.1 inside a container
  • OPENCLAW_GATEWAY_TOKEN silently overrides gateway.auth.token from config
  • The pairing flow is undocumented and unclear in Docker setups

As a result, a fresh Docker install often feels “stuck” with no clear next step unless you debug deeply.


Steps to Reproduce

  1. Follow the Docker install guide: docs/install/docker

  2. Start the gateway:

    docker compose up -d openclaw-gateway
    
  3. Run any CLI command from Docker:

    docker compose run --rm openclaw-cli health
    

    or

    docker compose run --rm openclaw-cli devices list
    

Observed Errors

CLI output may show one of the following:

gateway closed (1006 abnormal closure)
unauthorized: gateway token missing
unauthorized: gateway token mismatch
pairing required

Even after setting matching tokens in ~/.openclaw/openclaw.json, the errors persist if:

  • The CLI connects to 127.0.0.1 instead of openclaw-gateway
  • OPENCLAW_GATEWAY_TOKEN differs from gateway.auth.token

Expected Behavior

  • Docker install should work out-of-the-box

  • CLI should connect to the gateway using the Docker service hostname

  • CLI should clearly indicate which token source is used (env vs config)

  • Pairing flow should be:

    • documented
    • discoverable via CLI
  • No silent overrides that cause endless authentication failures


Actual Behavior

  • CLI connects to ws://127.0.0.1:18789 inside the container → connection fails (1006)

  • Authentication fails with misleading errors even when config looks correct

  • OPENCLAW_GATEWAY_TOKEN silently overrides config, causing token_mismatch

  • Pairing is required, but there is no documented Docker-friendly way to:

    • list pending pairing requests
    • approve them using the CLI

Onboarding feels blocked with no clear guidance.


Environment

  • OpenClaw version: 2026.2.3

  • OS: Linux (server)

  • Install method: Docker Compose

  • Gateway auth mode: token

  • CLI execution:

    docker compose run --rm openclaw-cli
    

Logs

CLI Errors

gateway closed (1006 abnormal closure (no close frame))
unauthorized: gateway token missing
unauthorized: gateway token mismatch
pairing required

Gateway Logs

[ws] unauthorized ... reason=token_mismatch
[ws] closed before connect ... reason=pairing required

Root Cause (Found)

OPENCLAW_GATEWAY_TOKEN != gateway.auth.token

The environment variable silently overrides the config token, causing authentication to fail.


Workaround That Fixed It

docker-compose.override.yml

services:
  openclaw-cli:
    network_mode: "service:openclaw-gateway"
    environment:
      OPENCLAW_GATEWAY_TOKEN: "<same token as gateway.auth.token>"

Approving the pending device from inside the gateway container

docker compose exec -T \
  -e OPENCLAW_GATEWAY_TOKEN=<token> \
  openclaw-gateway \
  node dist/index.js devices approve <REQUEST_ID>

After this, the CLI works normally.


Suggested Improvements

  • Warn when OPENCLAW_GATEWAY_TOKEN overrides the config token

  • Default Docker CLI connection to:

    ws://openclaw-gateway:18789
    
  • Clearly document the Docker pairing flow:

    • list pending requests
    • approve requests
  • Improve error messages to clearly distinguish:

    • token missing
    • token mismatch
    • pairing required

MohamedAbdelwahab24 avatar Feb 04 '26 19:02 MohamedAbdelwahab24

I am also getting the same error:

Gateway: not detected (gateway closed (1006 abnormal closure (no close frame)): no close reason)

CaptSolo avatar Feb 06 '26 22:02 CaptSolo

Bug: gateway.auth.token from config file not used by gateway process - requires OPENCLAW_GATEWAY_TOKEN env var

Environment

  • OpenClaw version: 2026.1.30 (76b5208)
  • OS: Debian 12 (VPS), Docker container fourplayers/openclaw:latest
  • Docker networking: --network host
  • Reverse proxy: nginx (Plesk-managed) + Cloudflare DNS proxy
  • Node: v24.13.0

Description

The gateway process does not reliably load gateway.auth.token from the config file (~/.openclaw/openclaw.json). When a Control UI client sends the correct token in the WebSocket connect request, the server responds with:

disconnected (1008): unauthorized: gateway token mismatch

Setting the same token as OPENCLAW_GATEWAY_TOKEN environment variable immediately fixes the issue.

Steps to Reproduce

  1. Set a gateway token via CLI:

    openclaw config set gateway.auth.token "my-secret-token"
    
  2. Verify the token is stored:

    openclaw config get gateway.auth.token
    # Output: my-secret-token
    
  3. Restart the gateway (or container).

  4. Connect to the Control UI with ?token=my-secret-token:

    http://localhost:18789/?token=my-secret-token
    
  5. Result: disconnected (1008): unauthorized: gateway token mismatch

  6. Now set the same token as env var:

    export OPENCLAW_GATEWAY_TOKEN="my-secret-token"
    
  7. Restart the gateway.

  8. Connect again with the same URL.

  9. Result: Connection succeeds (hello-ok).

Root Cause Analysis

I traced the issue to dist/gateway/auth.js:

export function resolveGatewayAuth(params) {
    const authConfig = params.authConfig ?? {};
    const env = params.env ?? process.env;
    const token = authConfig.token          // <-- Priority 1: from authConfig param
        ?? env.OPENCLAW_GATEWAY_TOKEN        // <-- Priority 2: env var
        ?? env.CLAWDBOT_GATEWAY_TOKEN        // <-- Priority 3: legacy env var
        ?? undefined;
    // ...
}

authConfig.token has highest priority, but the object passed to resolveGatewayAuth() at gateway startup does not contain the token from the config file. So authConfig.token is undefined, and the function falls through to env.OPENCLAW_GATEWAY_TOKEN.

Without the env var set, auth.token resolves to undefined, and authorizeGatewayConnect() returns { ok: false, reason: "token_missing_config" } - but the error message shown to the user says "token_mismatch" instead of indicating that no token was configured on the server side.

Proof via Manual WebSocket Test

I confirmed this by connecting from localhost with a Python WebSocket client:

# With OPENCLAW_GATEWAY_TOKEN=testtoken123 as env var:
# Sending auth.token="testtoken123" → ok: true
# Sending auth.token="<config-file-token>" → ok: false, token_mismatch

# Without any env var:
# Sending auth.token="<config-file-token>" → ok: false, token_mismatch
# (even though openclaw config get gateway.auth.token returns the exact same value)

Additional Context

This issue is related to #9028 (Docker token mismatch) and compounds with:

  • #7384 (trustedProxies not honored for WebSocket)
  • #1679 (allowInsecureAuth not bypassing device pairing)
  • #6959 (Docker pairing issues)

In Docker reverse proxy setups, the combination of device identity issues and this token bug makes remote Control UI access extremely difficult to debug. The misleading "token_mismatch" error (instead of "token_missing_config") adds to the confusion.

Workaround

Set the token explicitly as an environment variable:

docker run -d --name openclaw \
  -e OPENCLAW_GATEWAY_TOKEN="your-token-here" \
  fourplayers/openclaw:latest

Expected Behavior

  • gateway.auth.token from the config file should be passed to resolveGatewayAuth() as authConfig.token
  • If no token is configured anywhere (neither config nor env var), the error should say "token_missing_config", not "token_mismatch"
  • openclaw doctor should detect when the config file token doesn't match what the gateway actually uses

Labels

bug, gateway, auth, docker

GuideThomas avatar Feb 09 '26 07:02 GuideThomas

Just hit this exact issue following the Hetzner install guide (docs/install/hetzner).

Step 9 says "Navigate to http://127.0.0.1:18789/ and enter your gateway token" — but there's no token input field anywhere in the UI. The dashboard just shows "disconnected (1008): unauthorized: gateway token missing (open the dashboard URL and paste the token in Control UI settings)" in a loop.

Had to discover devices list / devices approve entirely on my own (and through issue #4531). The onboarding docs don't mention device pairing at all — this is really confusing for new users.

+1 for documenting the pairing flow clearly, especially for Docker setups.

bibblebabl avatar Feb 13 '26 17:02 bibblebabl

Closing as duplicate of #5559. If this is incorrect, please contact us.

sebslight avatar Feb 13 '26 21:02 sebslight

Suggestion: add a Devices submenu in the Control UI to list and approve node pairing requests, so users don’t need the CLI (or docker exec) to fix "pairing required". Idea and rationale are in this discussion: https://github.com/openclaw/openclaw/discussions/15876. I can take this idea and implement it (e.g. PR) if the maintainers are open to it.

Darius-Vallejo avatar Feb 14 '26 00:02 Darius-Vallejo

Is there a way to do this in docker? As far as I can tell, I can't use command lines.

sedetweiler avatar Feb 16 '26 19:02 sedetweiler

Is there a way to do this in docker? As far as I can tell, I can't use command lines.

I don't think through the official way of the CLI container. But I was able to get started by using the workaround of pairing through the gateway container:

docker compose exec openclaw-gateway node dist/index.js devices list

This should be the same as

docker compose run --rm openclaw-cli devices list

and it actually worked on my Docker installation.

stefanthoss avatar Feb 16 '26 22:02 stefanthoss

This is such a blocker. I can't even get the device list without an error. I don't know how to get past this until we have some docker support. Thanks for trying to help.

$ docker compose exec openclaw-gateway node dist/index.js devices list

🦞 OpenClaw 2026.2.16 (unknown) — Give me a workspace and I'll give you fewer tabs, fewer toggles, and more oxygen.

│
gateway connect failed: Error: unauthorized: device token mismatch (rotate/reissue device token)
◇
[openclaw] CLI failed: Error: gateway closed (1008): unauthorized: device token mismatch (rotate/reissue device token)
Gateway target: ws://127.0.0.1:18789
Source: local loopback
Config: /home/node/.openclaw/openclaw.json
Bind: loopback
    at Object.onClose (file:///app/dist/call-h-GQmjfc.js:266:10)
    at WebSocket.<anonymous> (file:///app/dist/client-BYp4h1Ri.js:1530:23)
    at WebSocket.emit (node:events:519:28)
    at WebSocket.emitClose (/app/node_modules/.pnpm/[email protected]/node_modules/ws/lib/websocket.js:273:10)
    at Socket.socketOnClose (/app/node_modules/.pnpm/[email protected]/node_modules/ws/lib/websocket.js:1346:15)
    at Socket.emit (node:events:519:28)
    at TCP.<anonymous> (node:net:346:12)

sedetweiler avatar Feb 17 '26 13:02 sedetweiler

I was able to get docker to work (v2026.2.15) but it required working around several overlapping issues.

The first is mismatched tokens (described above). The solution for me was to generate the token in advance, before running the setup script: export OPENCLAW_GATEWAY_TOKEN=$(openssl rand -hex 32) && echo $OPENCLAW_GATEWAY_TOKEN. You must paste in this token during onboarding and also during pairing (below).

The second issue is that you need to bind the gateway to LAN, but the CLI container does not use the docker bridge network by default, so it cannot connect to the gateway. The original poster fixed this by forcing the CLI container to use the same network as the gateway with loopback. I went a different direction and forced the CLI to use wss://openclaw-gateway:18789 as the remote websocket URL.

The final issue is that because the gateway is bound to LAN, it will never see loopback traffic inside the container, which means all connections will refuse to work without pairing. This causes a catch-22 where you can't approve the CLI using the Control UI admin page, and you can't approve the Control UI admin page using the CLI. The solution is to temporarily set gateway.controlUi.allowInsecureAuth to true, which bypasses the pairing requirement for the Control UI. Connect to the Control UI using the same token generated before. Now you can approve the CLI pairing request. Remove the allowInsecureAuth setting and restart the gateway. Now you can use the CLI to approve the pairing request for the Control UI.

weevilgenius avatar Feb 17 '26 20:02 weevilgenius

There are currently two sources of truth for what should be a single token.

OPENCLAW_GATEWAY_TOKEN ( gets generated during initialization ) https://github.com/openclaw/openclaw/blob/e67da1538cfac574ec20a99d26ad2141ea4c2c16/docker-setup.sh#L40 , and then can later be inspected by entering the running container and typing env , that variable persists on future environment recreation due to the creation of an .env file https://github.com/openclaw/openclaw/blob/e67da1538cfac574ec20a99d26ad2141ea4c2c16/docker-setup.sh#L129 during setup.

and the second one is part of the openclaw.json configuration, and can be found in gateway.auth.token .

I am unsure as to how many times that token can be generated but the current process is not keeping them in sync causes some issues, when commands require certain level of auth like openclaw devices list --json

miggu avatar Feb 18 '26 21:02 miggu