Networking

avocado has no inbound ports open to the internet. Two overlays provide access instead: Tailscale for private/admin reach, and a Cloudflare Tunnel for public services. The host firewall stays on throughout.

The firewall

networking.firewall.enable = true in base.nix; each module opens only the ports it needs:

Port(s) Opened by For
22/tcp ssh.nix (openFirewall) SSH (key-only)
5201/tcp + 5201/udp iperf.nix iperf3 server (LAN + tailnet throughput tests)
5353/udp avahi.nix (openFirewall) mDNS — publishing <hostname>.local
6443/tcp k3s.nix Kubernetes API
2379, 2380/tcp k3s.nix etcd client / peer (only matters with >1 server)
10250/tcp k3s.nix kubelet
8472/udp k3s.nix flannel VXLAN

The k3s ports are opened on avocado only. Node-to-node cluster traffic (node IPs, flannel VXLAN) runs over tailscale0, a trusted interface, so the agents (g8way, headless) open nothing for k3s.

Tailscale adds tailscale0 as a trusted interface and sets reverse-path filtering to loose, so tailnet traffic bypasses these rules.

k3s LoadBalancer ports bypass this table. klipper ServiceLB publishes a type: LoadBalancer Service as hostPorts. The CNI DNATs those before the NixOS INPUT chain, so they are reachable on the LAN and tailnet without an allowedTCPPorts entry. Current ones: Traefik 80/443 and Mailpit 1025 (SMTP) / 8025 (inbox). The box sits behind NAT, so none of these reach the internet directly.

mDNS (avocado.local)

modules/avahi.nix runs an Avahi responder that publishes the host’s addresses for avocado.local on the LAN interface (enp2s0). This is the only name that resolves the box from the LAN — avocado is MagicDNS and works inside the tailnet only.

iperf3 -c avocado.local      # from any Mac/iPhone/Android/Linux box on the LAN
ssh rithviknishad@avocado.local

This resolves the host name only. mDNS has no subdomain delegation, so grafana.avocado.local and the other *.avocado.local ingress hosts are not covered by Avahi — they still need LAN DNS, a MagicDNS search domain, or /etc/hosts (see below). Multicast also does not cross Tailscale, so .local works on the LAN only; from the tailnet use avocado.

Known issue: avocado currently registers as avocado-2.local. Something else on the LAN already claims avocado.local, so Avahi’s conflict handling renamed the box. Until that’s tracked down (not yet investigated), avocado.local may reach the other device. Use avocado-2.local or the tailnet name.

Other hosts

The same module runs on every host, each publishing on its own LAN NIC (set in hosts/<host>/default.nix). The new nodes answer to:

Name Host NIC Status
g8way.local NUC jumpbox / k3s agent enp0s25 published since the NixOS install (was Mint nuc.local)
headless.local disposable laptop k3s agent enp1s0 published since the NixOS install (was Mint minty.local)

The LAN has no DHCP reservations. If a name stops resolving, find the host by its MAC (see Cluster nodes).

Tailscale (private mesh)

modules/tailscale.nix runs Tailscale fully declaratively:

  • Auto-authenticates from the sops-managed tailscale/auth-key (a reusable/ephemeral key). Until a real key is present, the autoconnect unit just fails harmlessly.
  • useRoutingFeatures = "both" (can advertise and accept routes).
  • Trusts tailscale0 in the firewall; checkReversePath = "loose".
  • Version bridge. The package is the newer of our nixpkgs’ tailscale and the one from the nixpkgs-tailscale flake input, a nixpkgs master commit pinned only for this. It was added on 2026-11-04 because the admin console flagged versions below 1.104.5 as vulnerable. nixos-unstable only had 1.104.4, and 1.104.5 needs Go 1.27, which our nixpkgs pin lacks, so a simple src override wasn’t possible. The master build comes straight from cache.nixos.org. Once just update nixpkgs brings a tailscale that’s at least as new, the version check picks it automatically. Then remove the input (flake.nix, modules/tailscale.nix) and this bullet. For a future advisory, bump the bridge with just update nixpkgs-tailscale after changing its pinned rev, then check that the build is cached. Check what’s running with tailscale version on each host.

The box is reachable at the MagicDNS name avocado, which is what the justfile and the k3s --tls-san use — stable across DHCP/IP changes. This is the recommended path for kubectl, Lens, SSH, and hitting internal-only services.

Tailnet-only HTTPS (tailscale serve)

Two services are published to the tailnet with a real Let’s Encrypt certificate instead of through Traefik/the tunnel. Each is a systemd oneshot re-asserting tailscale serve --bg, terminating TLS on the box’s MagicDNS name and proxying to a pinned k8s NodePort:

URL → NodePort Service Module
https://avocado.<tailnet>.ts.net:8443 30080 Zerodha Kite MCP modules/zerodha-kite.nix
https://avocado.<tailnet>.ts.net:10000 30800 Settle Up MCP modules/settle-up-mcp.nix

Both stay private: the MagicDNS name resolves only inside the tailnet, and the NodePort range is deliberately not in allowedTCPPorts above, so the backends are unreachable from the LAN/WAN.

The two oneshots are ordered (settle-up’s runs After= zerodha-kite’s). They read-modify-write tailscaled’s one serve config, and starting them together (at boot, or in a deploy that restarts tailscaled) failed one with Preconditions failed: etag mismatch. A future third writer needs the same ordering.

These two ports are the whole budget. tailscale serve only allows HTTPS on 443, 8443, and 10000 — and :443 is already taken by k3s’s klipper svclb for Traefik. A third tailnet HTTPS service must share an existing port via path-based serve routes.

Tailscale Services sidestep that budget. A Service gets its own VIP and MagicDNS name, so its :443 doesn’t collide with the host’s. The Raspberry Pi lumine publishes CARE that way, as svc:care-box at https://care-box.orthrus-bass.ts.net (hosts must be tagged; see CARE in a box → Tailnet).

Cloudflare Tunnel (public access)

modules/cloudflared.nix runs a named tunnel (41180798-4793-474b-847e-3ad36a30df2f) with credentials from a sops binary secret. cloudflared dials out to Cloudflare, so nothing is exposed on the box.

flowchart LR
    subgraph internet[Public internet]
        user[Browser]
    end
    subgraph cf[Cloudflare edge]
        tls[TLS termination]
    end
    subgraph box[avocado]
        cd[cloudflared]
        traefik[Traefik :80]
        subgraph k8s[k3s services]
            hello[hello]
            immich[immich-server]
            grafana[grafana]
            gatus[gatus]
            kite[kite]
            care[care + teleicu]
            suchi[suchi]
            mailpit[mailpit]
            apps[homepage]
        end
    end

    user -->|https| tls --> cd
    cd -->|http localhost:80 + Host header| traefik
    traefik -->|hello.rithviknishad.dev| hello
    traefik -->|photos.rithviknishad.dev| immich
    traefik -->|grafana.rithviknishad.dev| grafana
    traefik -->|status.rithviknishad.dev| gatus
    traefik -->|kite.rithviknishad.dev| kite
    traefik -->|care*.rithviknishad.dev x5| care
    traefik -->|suchi.rithviknishad.dev| suchi
    traefik -->|mailpit.rithviknishad.dev| mailpit
    traefik -->|apps.rithviknishad.dev| apps

Public routing table

Every hostname below is mapped by the tunnel to http://localhost:80, where Traefik routes by Host header to the matching k8s Ingress. Anything not matched returns http_status:404.

Hostname Ingress → Service Page
hello.rithviknishad.dev sample hello Kubernetes
photos.rithviknishad.dev Immich immich-server Kubernetes
grafana.rithviknishad.dev grafana Monitoring
status.rithviknishad.dev Gatus gatus Monitoring
kite.rithviknishad.dev Kite kite Kite
care.rithviknishad.dev CARE app origin, path-routed: /api -> care-backend, /mfe-plugs/abdm -> care-abdm-fe, /care-uploads + /care-facility -> versitygw, / -> care-fe CARE
care-api.rithviknishad.dev CARE care-backend CARE
care-teleicu-gateway.rithviknishad.dev TeleICU reverse-proxy CARE
care-teleicu-devices.rithviknishad.dev TeleICU teleicu-devices-fe CARE
mock-ptz-camera.rithviknishad.dev TeleICU mock-ptz-camera (mock UI, admin/admin) CARE
care-plugs-relative-remote-entry.rithviknishad.dev THROWAWAY care-plugs-test: /api -> care-backend, /plugs/care_flappy_filly -> care-flappy-filly-fe, / -> care-fe CARE
suchi.rithviknishad.dev suchi suchi (own account auth) suchi
mailpit.rithviknishad.dev Mailpit mailpit web inbox (own basic auth; SMTP not routed) Mailpit
apps.rithviknishad.dev Homepage homepage app gallery (no auth by design) App gallery

Notes:

  • TLS terminates at Cloudflare’s edge — no cert-manager on the box.
  • Grafana is public with only its own login (sops-managed admin password) — it is deliberately not behind Cloudflare Access; see Monitoring.
  • Kite carries its own GitHub OAuth login (full cluster-admin console), so it does not need Cloudflare Access in front despite being cluster-admin; see Kite.
  • suchi gates everything with its own accounts (first admin via a one-time setup token; /metrics admin-only) and is used by the Companion mobile app over its API, so it does not sit behind Cloudflare Access either. Create the admin right after the first deploy; see suchi.
  • Mailpit’s inbox is public with only its own basic auth (no Cloudflare Access) because it holds test mail only. Its SMTP port cannot ride the tunnel; it is reachable on the tailnet/LAN via klipper. See Mailpit.
  • The metrics/logs databases (VMSingle, VictoriaLogs) are deliberately not exposed through the tunnel — reach them over Tailscale.
  • The app gallery is public with no auth at all. It lists every host in this table (including the Access-gated ONVIF console) and shows host and cluster stats. See App gallery for exactly what that discloses.
  • care-box.rithviknishad.dev is not on this tunnel. It’s served by the Raspberry Pi lumine through its own tunnel lumine (1e284975-…, lumine/cloudflared/config.yml), so avocado being down doesn’t take it offline. Its DNS route was still created from avocado, which holds the Cloudflare login cert. See CARE in a box.

Adding a public service

  1. Add the ingress host to the ingress map in modules/cloudflared.nix and just deploy.
  2. Create the DNS route once: cloudflared tunnel route dns avocado <host>.rithviknishad.dev.
  3. Add a matching k8s Ingress with that host (Traefik does the final hop).
  4. Add gethomepage.dev/* annotations to that Ingress so the app gets a tile on apps.rithviknishad.dev (see App gallery).

Troubleshooting: Cloudflare Error 1033

Error 1033 on every public host means the edge has no connector registered for the tunnel — i.e. cloudflared on the box is not running. Check it first:

just logs cloudflared-tunnel-41180798-4793-474b-847e-3ad36a30df2f

The usual cause is DNS, not Cloudflare. cloudflared resolves argotunnel.com at startup and exits immediately if that fails:

ERR Failed to fetch features ... lookup cfd-features.argotunnel.com on 100.100.100.100:53: no such host
Couldn't resolve SRV record ... region1.v2.argotunnel.com: no such host

100.100.100.100 is Tailscale MagicDNS. The box has no static nameservers — MagicDNS forwards to whatever upstream resolvers DHCP hands out, so if that lease blips, tailscaled logs no upstream resolvers set, returning SERVFAIL and every public lookup on the box fails. k3s image pulls from ghcr.io failing in the same window is a good confirming signal:

just logs tailscaled

The unit is configured to retry forever (RestartSec=10, startLimitIntervalSec=0 in modules/cloudflared.nix), so it should heal itself once DNS returns. On an older generation that predates that hardening the unit is instead stuck in failed (Result: start-limit-hit) and needs a manual kick:

ssh root@avocado systemctl reset-failed cloudflared-tunnel-41180798-4793-474b-847e-3ad36a30df2f
ssh root@avocado systemctl start cloudflared-tunnel-41180798-4793-474b-847e-3ad36a30df2f

A healthy tunnel logs Registered tunnel connection (usually four of them).

Reaching internal services over Tailscale

Because Traefik routes purely by Host header, you can hit any ingress without Cloudflare by supplying the header directly to the box on the tailnet:

curl -H "Host: grafana.rithviknishad.dev" http://avocado

The manifests also define *.avocado.local hosts (e.g. grafana.avocado.local) for the same purpose.