skip to content

Your OpenClaw Gateway on a VPS, set up with the Docker flow, turns up in an internet scan on port 18789; why did that happen, and what do you change?

level: seniorimportance: should knowfreq 6%

answer

  1. the container default is not loopback
  2. a published port on every host interface
  3. host firewall rules Docker bypasses
  4. the token is the last barrier
  5. close the port, tunnel in, rotate

basics

~20 s

OpenClaw's Docker setup binds the Gateway to lan and publishes 18789 on the host, where Docker forwarding can bypass UFW, leaving the token as the main barrier. Close 18789 at the provider firewall, tunnel in over SSH or Tailscale, and rotate the token.

solid answer

~40 s

Inside a container, loopback would be unreachable, so OpenClaw's Docker setup defaults `OPENCLAW_GATEWAY_BIND=lan` and the compose file publishes `18789`, which Docker exposes on every host interface. Published container ports pass through Docker's forwarding chains, so UFW rules on `INPUT` may not stop them. Startup refused an unauthenticated wide bind, so the scanner found a token-protected Gateway: the page and health probes answer, and the shared token, backed by failed-auth throttling, is the main barrier; whoever holds it has operator-level HTTP API access. Fix the network first: remove any inbound rule for `18789` at the provider firewall (or filter in `DOCKER-USER`), reach the Control UI with `ssh -N -L 18789:127.0.0.1:18789`, or use Tailscale. Then rotate the token, look for `AUTH_RATE_LIMITED` in the logs, verify with an external port scan, and re-run `openclaw security audit --deep`.

code

bash · 5 lines
bash
# from your laptop: owner access without a public port
ssh -N -L 18789:127.0.0.1:18789 [email protected]

# on the VPS, after closing the port and rotating the token
openclaw security audit --deep --token "$OPENCLAW_GATEWAY_TOKEN"

go deeper

for a junior

Recall that the container setup binds the Gateway to lan, so on a VPS the provider firewall, not the bind, has to keep port 18789 private.

for a middle

Explain why Docker-published ports can bypass UFW INPUT rules, and how the SSH tunnel reaches a Gateway whose host port is closed.

for a senior

Run the response in order: close the port, restore owner access, rotate the token, read the rate-limit logs, verify externally, re-audit.

for a principal

Turn this into a deployment rule: no public inbound rule for the Gateway port on any server, checked by an external scan and a deep audit after changes.

## How a careful install still ends up in a scan On a laptop, OpenClaw's Gateway binds to `127.0.0.1:18789` and nothing outside the machine can reach it. A VPS running OpenClaw in Docker is different, through three ordinary steps, none of them a bug: 1. **The container bind is `lan`.** Inside a container, `127.0.0.1` is the container's own network namespace, so a loopback-bound Gateway would be unreachable from the host. OpenClaw's Docker setup therefore defaults `OPENCLAW_GATEWAY_BIND=lan`, and the security overview says container images default to an exposed bind that must be paired with auth. 2. **The port is published on the host.** The compose file maps `18789` on the host to the container. Docker publishes a mapped port on every host interface unless told otherwise, so the public IP answers. 3. **The host firewall may not apply.** Published container ports are routed through Docker's forwarding chains, not only the host `INPUT` rules that UFW manages. A `ufw deny 18789` can look correct and still let traffic through; OpenClaw's network-exposure page shows the rules belonging in the `DOCKER-USER` chain instead. ## What the scanner actually found Because startup refuses a non-loopback bind without a token or password, the exposed Gateway is **authenticated**, not open. But consider what is reachable: - the HTTP surface answers: the Control UI page loads and the aggregate health probes respond without auth; - the main barrier is the **shared token**, and shared-secret bearer auth on the HTTP API is full operator access to the agent, its channels and its tools; - failed authentication is throttled per IP (by default 10 failures per 60 seconds, then a 5-minute lockout), which slows guessing but does not make a public port safe. A long random token makes a break-in unlikely. The point is that the install now leans on one secret instead of the layers the docs recommend: no network path for strangers first, auth second. ## The fix, in order | Step | Action | Why | |---|---|---| | 1 | Remove any public inbound rule for `18789` at the provider firewall; allow SSH from your admin network | Stops exposure regardless of Docker's forwarding | | 2 | If you rely on UFW, add a `DOCKER-USER` policy (and the IPv6 equivalent) | Host-level filtering that Docker actually honours | | 3 | Reach the Gateway with `ssh -N -L 18789:127.0.0.1:18789 user@host`, or via Tailscale | Owner access without a public port | | 4 | Rotate the Gateway token and update clients | The secret was exposed to the internet | | 5 | Check Gateway logs for repeated `AUTH_RATE_LIMITED` | Evidence someone was guessing | | 6 | Scan the public IP from outside, then run `openclaw security audit --deep` | Confirm only intended ports remain | Two tempting fixes that do not work: - **Setting `gateway.bind` to `"loopback"` inside the container.** It closes the Gateway even to the host, so the tunnel stops working too. Leave the container on `lan` and make the host port private. - **Turning on Tailscale Funnel to "put it behind Tailscale".** Funnel is public HTTPS; it only starts with password auth and the audit reports it as critical. ## Verifying the result A firewall change is only done when it is observed from outside. OpenClaw's network-exposure page suggests reloading UFW, listing the `DOCKER-USER` rules for both IPv4 and IPv6, and port-scanning the public IP: ```bash ufw reload iptables -S DOCKER-USER ip6tables -S DOCKER-USER nmap -sT -p 1-65535 <public-ip> --open ``` The expected result is only what you intended, typically SSH. Two details from the same page are easy to miss: - IPv6 has separate tables, so an IPv4-only rule can leave the port open over IPv6 when Docker IPv6 is enabled. - Rules keyed on an interface name such as `eth0` can silently miss on images that name it differently. ## What it does not touch This is network exposure only. Who can message the bot through WhatsApp or Telegram is governed by DM and group policies, and what a message can make the agent do is governed by the sandbox and tool policy; both deserve their own review once the port is closed, but neither would have stopped a scanner reaching port `18789`.

  • Why not simply set `gateway.bind` to loopback inside the OpenClaw container?
    Inside a container, loopback is the container's own network namespace, so a loopback-bound Gateway cannot be reached from the host at all, through a published port or an SSH tunnel to the host. The docs keep `lan` as the normal container setting and make the published host port private with the cloud firewall instead.
  • What should you look for in OpenClaw's Gateway logs after this exposure?
    Repeated `AUTH_RATE_LIMITED` entries, which mean a client kept presenting wrong credentials until the failed-auth limiter locked it out. Their presence says someone was guessing; their absence does not prove the token stayed secret, so rotate it either way and re-run the deep audit.

  • The Gateway was open to anyone because Docker disables its auth.
  • A UFW deny rule on 18789 is enough to hide a Docker-published port.
  • Binding loopback inside the container fixes it and keeps the tunnel working.
  • Enabling Tailscale Funnel moves the Gateway off the public internet.
  • With a long token the open port needs no further action.