Docs v2.0 · October 2026

Architecture & Operations Handbook

Home-Server Architecture

A Docker-based home server with no inbound ports open to the Internet. Public traffic arrives only through an outbound Cloudflare Tunnel, Traefik routes it to containers, and administration runs over a private Tailscale mesh.

Designed, built and operated end to end by Rocco Ferrari: architecture, networking, security, automation and monitoring.

0inbound ports exposed
1public entry point
15 smetrics resolution
7 daysoffsite backup retention

Tunnel-only ingress

cloudflared opens outbound connections to Cloudflare. No port forwarding, and the home IP never appears in DNS.

Zero-trust admin plane

SSH and Portainer are reachable only over the WireGuard-based Tailscale mesh. Admin panels sit behind Cloudflare Access.

Zero-touch DNS

Proxied wildcard records plus wildcard Let's Encrypt certificates mean a new service needs only Docker labels.

Everything as code

Docker Compose for services, Terraform for Cloudflare, and one start.sh script to bring it all up.

01Access & Security

Access and connectivity

The node is reachable for administration only through Tailscale, which gives it a static private address (<tailnet-ip>). No administrative port is reachable from the Internet. Web panels published through the tunnel (Traefik dashboard and Grafana) are protected by Cloudflare Access, which authenticates the administrator at the edge before any request reaches the server.

InterfaceReachable fromPortAuthentication
SSHTailscale only (tailscale0)<ssh-port>Key pairs only, passwords disabled
PortainerTailscale only<portainer-port>HTTPS + Portainer login
Traefik dashboardCloudflare Tunnel—Cloudflare Access (OTP) + Basic Auth
GrafanaCloudflare Tunnel—Cloudflare Access (OTP) + Grafana login
Public servicesCloudflare Tunnel—Per application

A local SSH alias keeps the custom port, user and key out of muscle memory, so a session starts with ssh homeserver:

Host homeserver
    HostName     <tailnet-ip>
    User         <admin-user>
    Port         <ssh-port>
    IdentityFile ~/.ssh/<private-key>

Hardening and perimeter defence

  1. No exposed surface. Public traffic reaches the server only through the Cloudflare Tunnel. The router has no port-forwarding rules and the home IP is in no DNS record, so it can be neither discovered from the domains nor contacted directly.
  2. UFW, default deny. The only exception is SSH, and only on the VPN interface.
  3. Fail2Ban. Watches system logs and bans source IPs after repeated failed attempts.
sudo ufw default deny incoming
sudo ufw allow in on tailscale0 to any port <ssh-port> proto tcp
Never publish container ports. Ports 80 and 443 are no longer opened or published. Docker writes published ports straight into iptables, which bypasses UFW and would expose the home IP again.

02Network & DNS

How DNS evolved

v0 · retired

Registrar CNAME → DuckDNS

DuckDNS answered ACME queries unreliably (SERVFAIL, CAA/AAAA timeouts), so Let's Encrypt certificates could not be issued.

v1 · retired

Cloudflare DNS Only + DDNS + port forwarding

A wildcard pointed at an anchor record updated by cloudflare-ddns. This exposed the home IP to anyone querying DNS, tied it to the domains through the certificate on 443, and was blocked by corporate firewalls that score residential IPs.

v2 · current

Cloudflare Tunnel

Each zone has a proxied wildcard (*.example.com) and optionally the apex, both CNAMEs to <id>.cfargotunnel.com. Clients resolve Cloudflare anycast addresses. No record contains the home IP, and DDNS is no longer needed.

One subdomain level only. Cloudflare's free Universal SSL certificate covers the apex and one subdomain level. Use names like app-api.example.com, never api.app.example.com.

Inbound traffic flow

  1. Resolve. A client asks for app.example.com. Cloudflare answers with its own anycast addresses.
  2. Edge. TLS ends at the nearest Cloudflare node with the zone's edge certificate. Managed WAF, DDoS mitigation, the HTTPS redirect and, for admin panels, Cloudflare Access apply here.
  3. Tunnel. Cloudflare forwards the request through the tunnel. cloudflared opened it outbound (QUIC on 7844, falling back to HTTP/2 on 443), so the router needs no forwarding rules.
  4. Route. cloudflared hands the request to https://traefik:443 on traefik-public and verifies Traefik's wildcard certificate. Traefik matches the Host header against Docker labels. The real visitor IP arrives in CF-Connecting-IP.
Architecture diagram: visitor to Cloudflare edge, through an outbound tunnel to cloudflared, then Traefik, then services and isolated databases. The admin laptop reaches SSH and Portainer over Tailscale. Monitoring alerts go to Telegram and backups go to encrypted cloud storage.
Figure 1: Public ingress over Cloudflare Tunnel, administration over Tailscale, and Docker network isolation.

03Docker Infrastructure

Layers and responsibilities

Edge

cloudflared keeps the tunnel up. Traefik routes, terminates TLS and renews certificates through ACME DNS-01. Cloudflare itself is defined in Terraform under cloudflare/.

Business services

Isolated containers reachable only through the reverse proxy, with no direct path to the outside.

Virtual network topology

NetworkMembersPurpose
traefik-publiccloudflared, Traefik, exposed services, GrafanaShared bridge for anything that must be routed
per-stack internalBackend services, databasesData stores are never attached to traefik-public
monitoring_internalPrometheus, Node Exporter, AlertmanagerKeeps metrics inside the Docker daemon
tunnel_metricscloudflared, PrometheusCreated by cloudflared, declared external by monitoring
# One-time: create the shared proxy network
docker network create traefik-public

tunnel_metrics is external to the monitoring stack, so cloudflared must start first. start.sh guarantees this through its alphabetical start order.

Certificates and key material

Traefik gets Let's Encrypt certificates through the DNS-01 challenge. It creates a temporary TXT record through the Cloudflare API with a token (CF_DNS_API_TOKEN) limited to Zone:DNS:Edit on the managed zones. Unlike the old TLS-ALPN-01 challenge, port 443 does not need to be reachable, and wildcards are possible. One certificate per zone covers the apex and *.zone, which also keeps service names out of public Certificate Transparency logs.

chmod 600 acme.json   # done automatically by start.sh on creation
ls -l acme.json       # must show -rw-------

04Operations

Shutdown and maintenance

Use sudo shutdown now for a full stop. Containers get proper termination signals, and restart policies bring them back on boot. To pause a single service, stop it from its own directory:

cd ~/homeserver-config/services/<service>
docker compose stop

Infrastructure as code

The whole infrastructure lives in the homeserver-config Git repository. start.sh walks services/, loads each .env and creates or updates the containers.

./start.sh                      # everything
./start.sh -c traefik <service> # only selected containers
./start.sh -c monitoring        # only the observability stack
./start.sh -s backups           # only the backup scripts

Moving the server

Neither ingress (outbound tunnel) nor administration (Tailscale) depends on the local or public IP, so the server only needs Internet access. After a move, cloudflared and Tailscale reconnect on their own. When switching from Wi-Fi to Ethernet, eth0 gets a new DHCP lease with no side effects. Disable the radio to avoid routing ambiguity with sudo nmcli radio wifi off. If the new network blocks QUIC, cloudflared falls back to HTTP/2 over 443.

Headless laptop tuning

Ignore the lid switch

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
# may drop the current SSH session
sudo systemctl restart systemd-logind

Cap charge at 80%

@reboot echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold
START_CHARGE_THRESH_BAT0=75
STOP_CHARGE_THRESH_BAT0=80

05Guidelines for New Services

Rules

  • No ports: mappings, ever. Traefik follows this rule too: the tunnel is the only public entry point.
  • Attach the container to the external traefik-public network.
  • Declare all routing with Traefik Docker labels.
  • Use a first-level subdomain (app.example.com or app-api.example.com).
  • Read the visitor IP from CF-Connecting-IP. The last X-Forwarded-For hop is cloudflared.
  • Keep the service's .env out of version control.

Zero-touch deployment

  1. Create services/<service>/ with a git-ignored .env.
  2. Write docker-compose.yml joined to traefik-public with a Host() label.
  3. Run ./start.sh -c <service>. Traefik picks up the route and serves it with the zone's wildcard certificate from acme.json. No DNS or Terraform change is needed.
  4. Admin panels only: add the hostname to Terraform's protected_hosts so Cloudflare Access protects it.
services:
  my-new-api:
    image: my-api-image
    networks:
      - web_public            # proxy network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.my-api.rule=Host(`api2.example.com`)"
      - "traefik.http.routers.my-api.entrypoints=websecure"
      - "traefik.http.routers.my-api.tls.certresolver=myresolver"

networks:
  web_public:
    external: true
    name: traefik-public      # pre-existing network

06Design Principles

Zero-trust networking

No actor is implicitly trusted. The server accepts no inbound connections. Public traffic arrives over the outbound tunnel, and admin traffic over Tailscale.

Explicit segmentation

Containers can only talk when they are declared on the same network.

End-to-end encryption

Edge certificate to Cloudflare, encrypted tunnel, then verified HTTPS from cloudflared to Traefik (SSL Full (strict)). Apps listen in plain HTTP on internal ports such as 8080.

Declarative and lean

YAML and Terraform rule out configuration drift, and the environment rebuilds in minutes. Multi-stage images are often under 20 MB.

07Backup & Disaster Recovery

EngineRclone to encrypted offsite cloud storage
ScheduleDaily at 03:00 via cron
ScopeDatabase volumes, every .env, Terraform secrets in cloudflare/ (.env, terraform.tfvars, backend.hcl), acme.json, SSH public keys, UFW rules, Fail2Ban config
Not includedTerraform state, which already lives in a private R2 bucket
RetentionRemote archives older than 7 days are purged automatically
./scripts/backups/init.sh backup    # on-demand restore point
./scripts/backups/init.sh restore   # interactive: pick an archive

Restore downloads the chosen archive into an isolated temporary directory, then puts back only the relevant application data. It never overwrites sensitive system files.

08Monitoring & Alerts

The old Python-plus-CSV cron script has been replaced by a containerised observability stack:

ComponentRoleNetwork
Node ExporterHost metrics from the kernelmonitoring_internal
PrometheusTime-series DB, 15 s scrape interval, rule evaluationmonitoring_internal, tunnel_metrics
GrafanaDashboards for CPU, RAM, temperatures and volumestraefik-public (behind Cloudflare Access)
AlertmanagerDeduplicates alerts and routes them to Telegrammonitoring_internal

Alert rules

AlertConditionForSeverity
HighCpuLoadCPU > 90%5mwarning
HighTemperaturesensor > 85 °C3mcritical
LowAvailableMemoryavailable RAM < 10%5mwarning
LowDiskSpacefree space on / < 15%10mcritical
InstanceDownup == 03mcritical
CloudflareTunnelDowncloudflared_tunnel_ha_connections < 12mcritical
Show the full rules file
groups:
  - name: HardwareAlerts
    rules:
      - alert: HighCpuLoad
        expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 90
        for: 5m
        labels: { severity: warning }
      - alert: HighTemperature
        expr: node_hwmon_temp_celsius > 85
        for: 3m
        labels: { severity: critical }
      - alert: LowAvailableMemory
        expr: (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100 < 10
        for: 5m
        labels: { severity: warning }
      - alert: LowDiskSpace
        expr: (node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}) * 100 < 15
        for: 10m
        labels: { severity: critical }
      - alert: InstanceDown
        expr: up == 0
        for: 3m
        labels: { severity: critical }
  - name: TunnelAlerts
    rules:
      - alert: CloudflareTunnelDown
        expr: cloudflared_tunnel_ha_connections < 1
        for: 2m
        labels: { severity: critical }
Secrets stay local. The Telegram bot token and chat ID live in protected, git-ignored files, together with every .env.

09Core Components

Tailscale: private zero-trust network

A WireGuard-based mesh overlay that gives the server a static tailnet IP and serves as the only channel for administration. SSH (allowed by UFW only on tailscale0) and Portainer are unreachable from the Internet.

Traefik: edge routing and reverse proxy

Traefik receives traffic from cloudflared and routes it by Host header and Docker labels. It terminates TLS and gets per-zone wildcard certificates through DNS-01, which cloudflared then verifies. It publishes no host ports, mounts the Docker socket read-only and runs with no-new-privileges. During the tunnel migration, a temporary, untracked docker-compose.override.yml republished 80/443 (see cloudflare/README.md).

Show the Traefik compose file
services:
  traefik:
    image: traefik:v3.7
    container_name: traefik
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    # No published ports: traffic arrives only from cloudflared on traefik-public.
    # (Docker-published ports would bypass UFW and re-expose the home IP.)
    environment:
      CF_DNS_API_TOKEN: ${CF_DNS_API_TOKEN}   # Zone:DNS:Edit only, for DNS-01
    networks:
      - traefik-public
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./acme.json:/acme.json
    command:
      - "--api.dashboard=true"
      - "--log.level=INFO"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.docker.network=traefik-public"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entryPoint.scheme=https"
      - "--certificatesresolvers.myresolver.acme.dnschallenge=true"
      - "--certificatesresolvers.myresolver.acme.dnschallenge.provider=cloudflare"
      - "--certificatesresolvers.myresolver.acme.dnschallenge.resolvers=1.1.1.1:53,1.0.0.1:53"
      - "--certificatesresolvers.myresolver.acme.email=${ACME_EMAIL}"
      - "--certificatesresolvers.myresolver.acme.storage=/acme.json"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.dashboard.rule=Host(`traefik.${DOMAIN}`)"
      - "traefik.http.routers.dashboard.service=api@internal"
      - "traefik.http.routers.dashboard.entrypoints=websecure"
      - "traefik.http.routers.dashboard.tls.certresolver=myresolver"
      # Wildcard certs (apex + one level) for both zones; also the name cloudflared verifies
      - "traefik.http.routers.dashboard.tls.domains[0].main=${DOMAIN}"
      - "traefik.http.routers.dashboard.tls.domains[0].sans=*.${DOMAIN}"
      - "traefik.http.routers.dashboard.tls.domains[1].main=${SECOND_DOMAIN}"
      - "traefik.http.routers.dashboard.tls.domains[1].sans=*.${SECOND_DOMAIN}"
      - "traefik.http.middlewares.auth.basicauth.users=${TRAEFIK_DASHBOARD_CREDENTIALS}"
      - "traefik.http.routers.dashboard.middlewares=auth"

networks:
  traefik-public:
    external: true

Portainer: visual management

Complements the IaC workflow with live container status, logs, resource usage and network inspection. It is reachable only over HTTPS on the tailnet IP (<portainer-port>).

Cloudflare: DNS, tunnel and edge security

Cloudflare is the authoritative DNS provider and the only public entry point. Every public record is proxied (orange cloud), which hides the origin and enables caching, DDoS mitigation and the WAF. Zone settings: SSL Full (strict), forced HTTPS, minimum TLS 1.2, TLS 1.3, HTTP/3 and HSTS. An edge rate-limiting rule protects a public GraphQL endpoint alongside the application's own limit. Bot Fight Mode stays off because it would block legitimate API clients.

Tunnel

Remotely managed: ingress rules live in Terraform and the container gets only TUNNEL_TOKEN. The apex and wildcard of each zone go to https://traefik:443 with originServerName set to the zone. Anything else gets a 404.

Access

Free Zero Trust plan. Only admin email addresses get in, verified by a one-time PIN, with 24 h sessions. Traefik's Basic Auth stays on as a second layer.

Terraform

Tunnel, DNS, zone settings, rate limiting and Access live in cloudflare/. State is in a private R2 bucket. ./tf.sh plan|apply runs a pinned Terraform container. Rollback: origin_mode = "direct".

services:
  cloudflared:
    image: cloudflare/cloudflared:2026.9.3
    container_name: cloudflared
    restart: unless-stopped
    read_only: true
    security_opt:
      - no-new-privileges:true
    command: ["tunnel", "--no-autoupdate", "--metrics=0.0.0.0:2000", "run"]
    environment:
      TUNNEL_TOKEN: ${TUNNEL_TOKEN}
    networks:
      - traefik-public
      - tunnel_metrics

The cloudflare-ddns container has been removed: with the tunnel, no record depends on the public IP.