Seven-layer defense-in-depth strategy for OpenClaw agents on Hostinger VPS. Built around
Cloudflare Tunnel + Access as the primary access layer — port 18789 is never exposed to the internet.
Internet → Cloudflare Edge
├── Cloudflare Access (identity check — blocked if unauthenticated)
└── Cloudflare Tunnel (outbound-only from VPS)
└── localhost:18789 (OpenClaw — loopback only)
└── OpenClaw token auth (second factor)
Internet → port 2222 (SSH — key-only, fail2ban)
Internet → port 18789 ✗ (denied by UFW — invisible to port scan)
With Cloudflare active: the VPS has one open port (SSH). Everything else is invisible.
Use the openclaw-vps-deploy skill. Get the agent running before hardening.
Use the cloudflare-agent-tunnel skill. Verify the agent is accessible at https://agent.yourdomain.com before closing port 18789.
# Copy script to VPS
scp scripts/harden.sh root@SERVER_IP:/tmp/harden.sh
# Dry run first — see what will change
ssh root@SERVER_IP "bash /tmp/harden.sh --dry-run"
# Apply (opens new terminal first to test SSH on new port)
ssh root@SERVER_IP "bash /tmp/harden.sh --ssh-port 2222"
# In a NEW terminal — verify SSH works on new port BEFORE closing old session
ssh -p 2222 root@SERVER_IP "echo OK"
# If that works, close old session. If it fails, revert:
# ssh root@SERVER_IP "cp /etc/ssh/sshd_config.bak.YYYYMMDD /etc/ssh/sshd_config && systemctl reload sshd"
PermitRootLogin no)PasswordAuthentication no)gateway.bind from "lan" to "loopback"127.0.0.1 — unreachable from outside VPS~/.openclaw/ → mode 700openclaw.json, secrets.json → mode 600~/.cloudflared/ → mode 700, credentials → mode 600See references/cloudflare-access.md for full setup walkthrough including phone app service token configuration.
For a native mobile app connecting directly to agents without browser-based login:
```
CF-Access-Client-Id:
CF-Access-Client-Secret:
```
See references/cloudflare-access.md → Phone App Integration for full details.
bash harden.sh [options]
--ssh-port 2222 SSH port to open (default: 2222)
--openclaw-user koda Service user for OpenClaw (default: koda)
--openclaw-dir /path OpenClaw config directory (default: /root/.openclaw)
--dry-run Print changes without applying
--skip-ufw Skip UFW configuration
--skip-ssh Skip SSH hardening
--skip-fail2ban Skip Fail2Ban installation
--skip-upgrades Skip unattended upgrades
Wrong order = lockout. Always:
openclaw-vps-deploy)See references/threat-model.md for full attack surface analysis, what each layer defends against, and residual risks.
Security posture after hardening: A-
One open port (SSH). Agents invisible to port scan. Identity gate on every connection. TLS everywhere. Brute-force protection. Auto-patched OS.
共 1 个版本