Skip to content

Private Mesh Networking

Connect servers and operator devices across different networks using WireGuard, encrypted peer-to-peer communication, and private service discovery.

Connect servers and operator devices across different networks using WireGuard, encrypted peer-to-peer communication (100.64.0.0/10), and built-in private service discovery (MagicDNS).

Zero-Config Peer-to-Peer WireGuard Overlay

On first startup, each flarelensd daemon generates an asymmetric Curve25519 keypair locally—the private key is stored 0600 on the host and never leaves the machine—and receives a deterministic CGNAT address in 100.64.0.0/10.

The Control Plane distributes peer public keys and endpoints inside the 15-second heartbeat envelope so nodes form direct ChaCha20-Poly1305 UDP tunnels:

  • Zero Public Database Ports: Keep PostgreSQL (5432) and Redis (6379) completely unexposed on public interfaces; bind them strictly to private interfaces and the WireGuard mesh.
  • Overlay Service Router (<overlay_ip>:<mesh_port>): Deterministic private listeners forward mesh traffic with zero-copy io.Copy round-robin across healthy local Blue/Green slots and remote peers.
  • Cross-Node Ingress Load Balancing: Edge Traefik instances automatically balance HTTP requests across healthy container replicas on peer nodes via remote_upstreams.

Split-Horizon MagicDNS (<service>.<env>.mesh)

flarelensd embeds a dual-stack UDP + TCP DNS server bound strictly to <overlay_ip>:53 (avoiding conflicts with host systemd-resolved on 127.0.0.53:53) and wires it into managed containers via Docker HostConfig.DNS:

Container environment service discoveryini
DATABASE_URL=postgres://app:secret@postgres.prod.mesh:5432/core?sslmode=require
REDIS_URL=redis://cache.prod.mesh:6379/0
BILLING_INTERNAL_URL=http://billing-api.prod.mesh:8080
  • TTL = 5s Round-Robin Failover: Queries for <service>.<env>.mesh return lock-free round-robin A-records of healthy replicas with a 5-second TTL and RFC 4074 NODATA on TypeAAAA—so cross-host failovers propagate within seconds.
  • Strict Environment Isolation: uat and prod DNS zones remain isolated (postgres.uat.mesh vs postgres.prod.mesh), and single-label misses return instant in-memory NXDOMAIN so internal names never leak upstream.
  • ExtraHosts Shadowing Guard: When <overlay_ip>:53 is active, static 100.64.0.0/10 entries are stripped from /etc/hosts so Linux files dns lookup order never shadows live TTL 5s failover, while retaining /etc/hosts fallback on non-WireGuard hosts.

Operator Workstation Access

Join the private mesh temporarily from macOS or Linux workstations without SSH bastions or per-seat VPN SaaS:

Authenticate operator workstation onto the meshbash
# First-time enrollment via browser SSO (Cloudflare Access):
sudo flarelensd login --control https://ops.example.com

# Connect directly to private mesh services:
psql postgres://readonly@postgres.uat.mesh:5432/app

# Instant zero-browser reconnect after laptop sleep or WSL2 reboot (<200ms):
sudo flarelensd up

# Disconnect interface temporarily (keeps keys) or log out & revoke session:
sudo flarelensd down
sudo flarelensd logout

Public HTTPS Localhost Funnel (flarelensd http)

Expose a local development server (localhost:3000, localhost:8080, Vite, Next.js, or webhook receiver) on a temporary public HTTPS URL—like ngrok or Tailscale Funnel, at $0/mo with zero third-party tunnel SaaS:

Expose localhost:3000 on a public HTTPS subdomainbash
# 1. Authenticate onto the mesh once (if not already connected)
sudo flarelensd login --control https://ops.example.com

# 2. Open a public HTTPS tunnel -> http://127.0.0.1:3000
flarelensd http 3000 --subdomain stripe-webhooks

# 3. Enable the local Webhook Request Inspector & 1-click replay UI on http://127.0.0.1:4040
flarelensd http 3000 --subdomain stripe-webhooks --inspect

# Optional: protect public preview with HTTP Basic Auth
flarelensd http 5173 --subdomain ui-preview --auth demo:s3cr3t

# Optional: explicitly choose Direct Cloudflare Edge QUIC (`edge`) vs Sovereign WireGuard + Traefik (`mesh`)
flarelensd http 5173 --subdomain ui-preview --mode edge
  • Dual-Mode Transport (--mode auto|edge|mesh): When CF_EDGE_API_TOKEN and CF_ACCOUNT_ID are configured on the Control Plane, flarelensd http automatically connects directly from your workstation to the nearest local Cloudflare Edge POP over QUIC (~5–15 ms local latency, zero server bandwidth, and zero Worker request quotas); otherwise it transparently routes over the private WireGuard mesh to your gateway node’s Traefik edge.
  • Zero LAN Exposure: flarelensd http binds its local HTTP + WebSocket reverse proxy strictly on loopback (127.0.0.1) or your workstation’s 100.64.0.x WireGuard interface—never 0.0.0.0—and rewrites Host: localhost:<port> automatically while setting X-Forwarded-Host and X-Forwarded-Proto: https.
  • Local Webhook Inspector & 1-Click Replay (--inspect): Pass --inspect (or --inspect-addr 127.0.0.1:4040) to launch a zero-dependency local inspector UI on http://127.0.0.1:4040 with live SSE streaming, automatic Stripe / Paystack / GitHub / Svix event detection, byte-exact HMAC-preserving 1-click webhook replay (even if your local server was down with 502 or returned 500 on initial delivery), editable payload replay, and reproducible curl export.
  • Keyless Ed25519 Ownership & Collision Guards: Requests are signed with your workstation’s ~/.flarelens/id_ed25519 key (flarelens-mesh-tunnel:<action>:<wg_pub>:<ts>). Active Fleet service domains and existing permanent DNS records cannot be overwritten (409 Conflict).
  • Automatic Cleanup: Pressing Ctrl+C immediately deletes the D1 lease and removes the temporary Cloudflare Edge CNAME/tunnel (or gateway funnel-<id>.yaml Traefik route); if a laptop disconnects abruptly, the 1-minute Control Plane cron reaps expired leases automatically.

Type to search…

↑↓ navigate↵ selectEsc close