Appearance
Networking and the firewall
There are three layers, from the outside in.
1. Cloudflare
Every public hostname is a proxied Cloudflare record. Visitors reach Cloudflare, and Cloudflare reaches the server. Admin hostnames also have Cloudflare Access in front of them (see Cloudflare).
2. ufw on the host
default deny incoming, allow outgoing
22/tcp allow (ssh)
80/tcp allow (http)
443/tcp allow (https)3. The DOCKER-USER chain
Docker publishes container ports by writing its own iptables rules, and those bypass ufw. Coolify publishes several (its UI on 8000, realtime on 6001–6002, Traefik's dashboard on 8080), so ufw alone would leave them open to the internet.
/etc/ufw/after.rules and after6.rules add rules to the DOCKER-USER chain, which Docker consults before its own rules:
- Return for established and related traffic.
- Return for anything that isn't arriving on
eth0, i.e. container-to-container traffic. - Return for traffic to ports 80/443 (TCP, plus UDP 443) only when it comes from a Cloudflare IP range.
- Drop everything else arriving on
eth0.
The original destination port is matched with conntrack --ctorigdstport, because by the time the packet reaches DOCKER-USER, Docker has already rewritten the address.
The rules are generated by /usr/local/sbin/cf-origin-lock (box/cf-origin-lock.sh in the repo). It downloads Cloudflare's current IPv4 and IPv6 lists, rebuilds that block and reloads ufw. /etc/cron.weekly/cf-origin-lock runs it every week. If the download fails or looks wrong, it changes nothing.
What this gives you
| From the internet | Result |
|---|---|
https://app.stu-bot.uk via Cloudflare | works |
| The server's IP directly, on any web port | dropped |
| Coolify's 8000 / 6001 / 6002, Traefik's 8080 | dropped |
| SSH on 22 | open, key only |
To check it from outside:
sh
nc -z -G 3 <server-ip> 8000 # should fail
curl --resolve n8n.stu-bot.uk:443:<server-ip> https://n8n.stu-bot.uk # should time outInside the server
Containers share the coolify Docker network and reach each other by name: http://coolify:8080, http://claude-runner:8080, the bus by its internal URL. Nothing internal needs a public address.