Simple, Secure, Private Hostnames for My Homelab
In my homelab, I wanted a dead simple way to provide secure access to any new app I added. It’d allow me to quickly experiment with new apps without having to worry about much more than getting the app itself running. Routes need to be off the public internet, but easily accessible from my phone or laptop anywhere I happen to be. Hostnames shouldn’t leak publicly, so a wildcard cert keeps individual subdomains out of Certificate Transparency logs. Connections need to be secured with TLS certs from a trusted CA. I didn’t want to have to install my own certs or click past warning screens.
This could be done pretty simply with Tailscale MagicDNS, but I wanted the vanity domain.
The pieces that make it all work:
- Tailscale is the network boundary.
- Nomad orchestrates apps via a simple job description.
- Traefik terminates TLS and routes by Nomad tags.
- Let’s Encrypt provides a wildcard cert for my domain.
- CoreDNS answers for my domain, but only on the tailnet.
Nomad Client Setup
Nomad orchestrates all apps, including Traefik. Traefik will need to bind to
the tailnet so Nomad needs to be configured to make that available. That’s
done with a host_network config in the client stanza.
client {
host_network "tailnet" {
cidr = "100.64.0.0/10"
}
}With that I can have my Traefik job bind to the tailnet:
port "https" {
host_network = "tailnet"
static = 443
}Traefik Certs and Service Discovery
Traefik gets set up to use Let’s Encrypt as the cert resolver and DNS-01 as the challenge. DNS-01 only requires a TXT record, so I don’t have to expose a listener to the open internet.
certificatesResolvers:
letsencrypt:
acme:
storage: /certs/acme.json
dnsChallenge:
provider: route53Traefik then binds an entrypoint to the tailnet port and requests a wildcard cert from that resolver.
entryPoints:
tailnet:
address: ":443"
asDefault: true
http3: {}
http:
tls:
certResolver: letsencrypt
domains:
- main: "*.<domain>"Every app will use this entrypoint by default and can declare its hostname as a subdomain of the wildcard. To do so, Traefik is configured to use Nomad as the service discovery provider.
providers:
nomad:
exposedByDefault: falseGetting a new app set up with a domain is as simple as adding a couple
of tags to the service stanza in the Nomad job spec. This will tell
Traefik to route any request to app.<domain> to this service.
service {
name = "app"
port = "http"
tags = [
"traefik.enable=true",
"traefik.http.routers.app.rule=Host(`app.<domain>`)",
]
}CoreDNS to Resolve App Hostnames
The final piece to tie this all together is a custom DNS resolver using
CoreDNS. Tailscale split DNS sends any lookup for <domain> to the
CoreDNS instance, and those hosts resolve to the Traefik instance.
<domain>:53 {
errors
file local/<domain>.cfg
}$ORIGIN <domain>.
@ IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600
*.<domain>. IN A <traefik tailnet IP>How it fits together
sequenceDiagram autonumber participant D as Laptop / phone participant DNS as CoreDNS (via split DNS) participant T as Traefik (tailnet IP) participant A as App D->>DNS: app.#lt;domain#gt;? DNS-->>D: Traefik's tailnet IP D->>T: HTTPS to app.#lt;domain#gt; over WireGuard T->>A: Host rule → Nomad service A-->>T: response T-->>D: response over TLS (wildcard cert)
With all of that in place, adding a new app is just a Nomad job with two Traefik tags. It gets a real HTTPS hostname that only my devices can reach.