The default install bias for a self-hosted AI agent is to put a TLS terminator on :443, a hostname in DNS, and call it shipped. That works until you remember that the gateway is reading your inbox, holding your bank’s OAuth refresh token, and running shell commands when a skill decides to — at which point a public ingress that exists at all is the wrong shape. The right shape for OpenClaw is the same as for an SSH bastion or a Kubernetes API: no inbound from the public internet, all access through an authenticated overlay, and a narrow exception only where a third-party platform genuinely needs to deliver a webhook.
This article lays out two overlay choices — Tailscale and Cloudflare Tunnel — and the firewall rules that handle the one case where neither overlay is enough on its own: chat-platform webhooks that arrive from a public IP range you do not control.
What’s happening
OpenClaw’s gateway listens on 127.0.0.1:18789 after a proper install (github.com/openclaw/openclaw, see Deploying OpenClaw on a Virtuozzo Hybrid Server VM). Three classes of traffic want to reach it:
- You. Your phone, your laptop, your iPad — devices that initiate sessions, fetch dashboard pages, or call HTTP endpoints. Always-authenticated, always-yours.
- Third-party chat platforms. Telegram, Slack, Discord, etc. when configured in webhook mode deliver inbound messages by POSTing to a URL the gateway exposes (core.telegram.org — Webhooks, api.slack.com — Events API). These arrive from the platform’s IP ranges and the gateway authenticates them by signature, not by IP.
- The platforms when configured in polling mode. The gateway makes outbound HTTPS to the platform’s API, pulls messages, and acts. No inbound required.
If every channel can run in polling mode, you do not need any inbound exposure at all — the overlay handles you, and polling handles the platforms. Tailscale or Cloudflare Tunnel alone is sufficient. If even one channel is webhook-only or you prefer the lower-latency webhook delivery, you need a public-internet ingress narrow enough to only accept POSTs from that platform’s IP ranges, signature-validated, and rate-limited.
The design below assumes the realistic case: you want the overlay-only setup for your human-facing access, plus a narrow webhook hole for Telegram or Slack if you choose to run those in webhook mode.
Prerequisites
- An OpenClaw VPS already provisioned per Deploying OpenClaw on a small IaaS VPS for 24/7 access or the cloud-init template at A cloud-init template for OpenClaw on a fresh VPS. The gateway is on
127.0.0.1:18789. - A Tailscale account (tailscale.com) or a Cloudflare account (cloudflare.com) — pick one for the overlay.
- A list of which channels you actually use, and whether each one is configured in polling mode or webhook mode.
How to verify
After the architecture is in place, three observations make it verifiably correct:
# 1. The gateway is on loopback only. Public ingress shows no 18789.
ss -lntp | grep 18789
# 127.0.0.1:18789 users:(("node",pid=...))
# 2. From an off-tailnet host, the public IP refuses everything except SSH
# (and the webhook port, if you opened one):
nc -zv <public-ip> 18789
# Connection refused
nc -zv <public-ip> 22
# Connection succeeded
# 3. From a tailnet device (or via the Cloudflare Tunnel), the gateway answers:
curl -fsS http://openclaw-vps:18789/health
# (200 OK or auth challenge — but not a TCP refusal)
If a webhook is configured, the platform’s webhook self-test from its admin panel should hit the gateway and the gateway should log the inbound:
journalctl -u openclaw-gateway.service -f
# expect to see the inbound POST and a 200 response back to the platform
The fix
1. Pick the overlay
Tailscale is the lower-friction option and the right default for personal and small-team OpenClaw. Each device — your VPS, your phone, your laptop — runs the Tailscale client and joins your tailnet. The VPS gets a 100.x.y.z address, MagicDNS resolves openclaw-vps for free, and nothing inbound is opened on the public internet. ACLs are JSON and version-controllable (tailscale.com — ACL Reference).
# On the VPS
curl -fsSL https://tailscale.com/install.sh | sh
sudo tailscale up --hostname=openclaw-vps --ssh --accept-routes=false
# Confirm
tailscale status
tailscale ip -4
The --ssh flag enables Tailscale SSH — your phone can SSH to the VPS through the tailnet without managing keys (tailscale.com — Tailscale SSH). Worth taking.
Lock the tailnet ACL so only the right device tags can reach openclaw-vps:18789:
{
"tagOwners": {
"tag:openclaw-server": ["group:operators"],
"tag:operator": ["group:operators"]
},
"acls": [
{
"action": "accept",
"src": ["tag:operator"],
"dst": ["tag:openclaw-server:18789"]
}
],
"ssh": [
{
"action": "accept",
"src": ["tag:operator"],
"dst": ["tag:openclaw-server"],
"users": ["root"]
}
]
}
Cloudflare Tunnel is the right choice when you want a real public hostname — claw.example.com — without a public IP on the VPS. The cloudflared daemon dials out to Cloudflare; Cloudflare Access enforces SSO in front; the gateway never sees the public internet directly (developers.cloudflare.com — Cloudflare Tunnel).
# Install (Ubuntu)
curl -fsSL https://pkg.cloudflare.com/cloudflared-keyring.gpg \
| sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" \
| sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt-get update && sudo apt-get install -y cloudflared
# Auth + create tunnel
cloudflared tunnel login
cloudflared tunnel create openclaw
cloudflared tunnel route dns openclaw claw.example.com
/etc/cloudflared/config.yml:
tunnel: openclaw
credentials-file: /etc/cloudflared/openclaw.json
ingress:
- hostname: claw.example.com
service: http://127.0.0.1:18789
originRequest:
noTLSVerify: true
connectTimeout: 30s
- service: http_status:404
Run it as a service:
sudo cloudflared service install
sudo systemctl enable --now cloudflared
sudo systemctl status cloudflared
Then enforce SSO in Cloudflare Access — the hostname claw.example.com should require email/SSO/MFA before the request ever reaches the tunnel (developers.cloudflare.com — Cloudflare Access). Without that step, the tunnel just publishes your gateway to anyone with the URL.
Both overlays work; running both at once is reasonable on the same VPS (Tailscale for human access, Cloudflare Tunnel for a public-hostname webhook endpoint if you need one).
2. UFW: only SSH on the public NIC
The base firewall stays narrow. SSH only.
sudo ufw --force reset
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw --force enable
sudo ufw status verbose
If you went the Tailscale route, Tailscale’s interface (tailscale0) is not a public-internet ingress and does not need a UFW rule for the gateway. Tailscale handles overlay routing in userspace.
If you went the Cloudflare Tunnel route, cloudflared makes outbound TCP/443 only — no inbound rule needed. UFW outbound-allow is already in place.
3. The webhook exception, if you need one
If a chat channel runs in webhook mode, you have to accept inbound from the platform’s public IP ranges. The right place to do this is nftables — UFW does not easily express CIDR allow-lists (wiki.nftables.org), but nftables is what UFW writes to under the hood and you can layer your own rules in a separate file.
First, find out the platform’s webhook source IP ranges. The platforms publish them:
- Telegram:
149.154.160.0/20,91.108.4.0/22(core.telegram.org — Webhooks). - Slack: dynamically discoverable via the Events API config; Slack does not commit to a fixed IP range (api.slack.com — Events API delivery). For Slack, prefer a Cloudflare Tunnel + Access policy that validates the Slack signing secret instead of IP-based allowlisting.
- Discord: Discord interactions use a fixed set of IPs documented at (discord.com/developers — Interactions). The verification model is signature-based; IP allowlist is a defense-in-depth measure.
- GitHub webhooks: the meta API publishes the current ranges at api.github.com/meta.
Use the platform’s published ranges as a starting point, and re-pull them periodically — the lists move.
The pattern is: put a reverse proxy on :443 that forwards /webhooks/telegram (and only /webhooks/telegram) to 127.0.0.1:18789, and lock :443 to the platform’s IP ranges at the firewall. Here is the nftables rule set:
sudo tee /etc/nftables-openclaw.conf >/dev/null <<'NFT'
#!/usr/sbin/nft -f
# Custom rules for OpenClaw webhook ingress.
# Loaded by systemd in addition to UFW's rules.
table inet openclaw {
set telegram_v4 {
type ipv4_addr
flags interval
elements = {
149.154.160.0/20,
91.108.4.0/22
}
}
set github_v4 {
type ipv4_addr
flags interval
# refresh from api.github.com/meta periodically
elements = {
140.82.112.0/20,
192.30.252.0/22,
185.199.108.0/22,
143.55.64.0/20
}
}
chain webhook_in {
type filter hook input priority -10; policy accept;
# Drop :443 unless source is in an allow-list
tcp dport 443 ip saddr @telegram_v4 accept
tcp dport 443 ip saddr @github_v4 accept
tcp dport 443 drop
}
}
NFT
# Install a systemd unit that loads the rules after the network is up
sudo tee /etc/systemd/system/nftables-openclaw.service >/dev/null <<'UNIT'
[Unit]
Description=Custom OpenClaw nftables rules
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/nft -f /etc/nftables-openclaw.conf
ExecReload=/usr/sbin/nft -f /etc/nftables-openclaw.conf
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
UNIT
sudo systemctl daemon-reload
sudo systemctl enable --now nftables-openclaw.service
Then open :443 in UFW and put Caddy in front of the gateway for that specific path:
sudo ufw allow 443/tcp
Caddyfile (/etc/caddy/Caddyfile):
claw.example.com {
@telegram path /webhooks/telegram*
handle @telegram {
reverse_proxy 127.0.0.1:18789
}
handle {
respond 404
}
}
The Caddy site config restricts the URL surface to just the webhook path. The nftables rules restrict the source IP. The gateway’s own webhook signature validation closes the loop — neither layer alone is enough, all three layered together is the right shape (caddyserver.com — Caddyfile concepts).
4. Restrict outbound where it matters
OpenClaw is a heavy outbound talker by design — it calls LLM APIs, browses the web, posts to chat APIs. A default allow outgoing is the only practical default. The targeted exception is to block egress to known-bad ranges if your VPS provider’s panel makes that easy, or to put the entire VPS behind an outbound proxy (Squid, mitmproxy in passthrough mode) if you need to audit what model calls and skills are actually making. That is a defensive posture most personal deployments do not need but is worth knowing about for a team install.
Network architecture summary
What you end up with on a fully built-out OpenClaw VPS:
+-----------------------------+
your phone --(tailnet)--+ |
your laptop -(tailnet)--+--> openclaw-vps (100.x.y.z) |
| ├── tailscale0 |
| ├── eth0 (public IP) |
| │ ├── :22 (ufw allow) |
| │ └── :443 (caddy + nft allow-list)
| └── lo |
| └── 127.0.0.1:18789 (openclaw gateway)
+-----------------------------+
^
|
Telegram webhooks (allowlisted CIDR -> :443 -> caddy -> :18789)
Cloudflare Tunnel (cloudflared -> :18789, no public ingress)
Three independent paths, each with its own auth model. The combination is what makes the gateway safe to leave running on the public internet at all.
Common mistakes
Binding the gateway on 0.0.0.0 because the overlay “feels like” the only path. Even with Tailscale in front, if a hostile process inside the VM can reach 0.0.0.0:18789 (or someone scans a panel where the firewall is not what you think it is), the gateway is exposed. Always keep it on 127.0.0.1 and let the overlay or Caddy proxy in.
Trusting IP allowlists alone. Platforms add IPs without warning. IP allowlist is defense-in-depth; signature validation is the actual authentication. The agent rejects unsigned webhooks regardless of where they came from.
Forgetting Cloudflare Access on the Tunnel hostname. A Tunnel without Access is a public, unauthenticated route to the gateway. Always pair them. The setup is documented at developers.cloudflare.com — Self-hosted apps.
Running the channel in polling mode and opening the webhook port “just in case”. Close the port. Polling channels do not need any inbound rule.
Related
- Deploying OpenClaw on a small IaaS VPS for 24/7 access
- Firewall rules for an OpenClaw IaaS deployment
- DNS, TLS, and secure remote access to OpenClaw
Sources
- openclaw.ai
- github.com/openclaw/openclaw
- tailscale.com — ACL Reference
- developers.cloudflare.com — Cloudflare Tunnel
- developers.cloudflare.com — Self-hosted apps
- core.telegram.org — Webhooks
- api.slack.com — Events API
- wiki.nftables.org
- caddyserver.com — Caddyfile concepts
Last verified on OpenClaw current.