Cloud Networking··2 min read

Building a Zero-Trust Multi-Cloud Mesh Network with Self-Hosted Headscale WireGuard and Caddy

Shafikul Islam

Shafikul Islam

Backend & Cloud Infrastructure Engineer · Infrastructure & Cloud Team Lead

Building a Zero-Trust Multi-Cloud Mesh Network with Self-Hosted Headscale WireGuard and Caddy

Why Publicly Exposed Infrastructure Ports Fail Security Audits

When engineering teams run hybrid workloads across multiple cloud providers (for example, AWS EC2 application nodes communicating with dedicated bare-metal database or observability nodes), networking quickly becomes messy. Opening ports 5432 (PostgreSQL), 6379 (Redis), or 9090 (Prometheus) to public IPv4 interfaces with brittle firewall whitelists invites brute-force scans and misconfiguration leaks.

To unify our distributed Linux nodes into a single encrypted private LAN without per-user SaaS VPN licensing fees, we deployed a self-hosted Headscale control plane managing kernel-space WireGuard tunnels.


1. Self-Hosted Headscale Control Plane + Kernel WireGuard Data Plane

Headscale is an open-source, self-hosted implementation of the Tailscale control server. Importantly, the Headscale server never touches application traffic:

  • Control Plane (Headscale + Caddy TLS): Exchanges public WireGuard keys, assigns deterministic 100.64.0.x CGNAT private mesh IPs, and distributes ACL firewall policies.
  • Data Plane (Peer-to-Peer Kernel WireGuard): Encrypted UDP packets flow directly point-to-point between nodes using ChaCha20-Poly1305 encryption in the Linux kernel with sub-millisecond overhead.

2. Enforcing Least-Privilege Mesh ACLs (HuJSON)

Joining the WireGuard mesh does not grant blanket network access. Headscale enforces strict tag-based Access Control Lists (ACLs) at the packet filter level on every node:

{
  "tagOwners": {
    "tag:k3s-worker": ["autogroup:admin"],
    "tag:db-primary": ["autogroup:admin"],
    "tag:monitoring": ["autogroup:admin"]
  },
  "acls": [
    {
      "action": "accept",
      "src": ["tag:k3s-worker"],
      "dst": ["tag:db-primary:5432", "tag:db-primary:6379"]
    },
    {
      "action": "accept",
      "src": ["tag:monitoring"],
      "dst": ["tag:k3s-worker:9100", "tag:db-primary:9187"]
    }
  ]
}

With this policy active, application workers can reach PostgreSQL (5432) and Redis (6379) on the database node, but cannot SSH (22) into the database node, and public internet scanners see zero open ports on eth0.

Infrastructure & PostgreSQL Advisory

Scaling Infrastructure or Diagnosing P95 Latency?

I help engineering teams diagnose PostgreSQL indexing bottlenecks, concurrency limits, and K3s/Docker deployments. Book a 20-minute call with me to review your setup.

Related Technical Articles