tilsit.vip Routing and Authenticated Gateway: Design¶
History. Done. The design's recommendations, R3 (one public name) and G2 (Cloudflare Tunnel plus Access), were adopted on 2026-10-22, and #210 was closed that day. The G2 implementation plan carried them out: the tunnel code merged in #225 (2026-10-22) and #230 (2026-11-03), and the gateway has been live since 2026-11-03. #209 was closed on 2026-11-05. For the current setup see Cloudflare Tunnel and Tunnel security layers.
Date: 2026-10-22
Issues: #210 (internal vs external routing), #209 (authenticated gateway).
Affects: #130 and 2026-04-19-caddy-forms-auth.md (see "Consequence for #130").
Goal¶
-
210: one way to reach the home tools that works on and off the home¶
network, without adding a new LAN authentication bypass. -
209: a me-only gateway with a sign-in that 1Password can fill, linked from¶
projectinsomnia.com, with clear trust boundaries, revocation, and failure behavior.
The two issues share one answer, so this document covers both.
Current state (measured on TILSIT, 2026-10-22)¶
Network path¶
Internet ─ 203.0.113.13 ─ 192.168.0.1 (ISP gateway, lighttpd UI)
└─ 192.168.21.1 (LAN router, DHCP)
└─ 192.168.21.10 TILSIT (Caddy :80, :443)
- The network is double-NATed.
tracerouteshows 192.168.21.1, then 192.168.0.1, then the ISP. External access therefore needs a port-forward rule on both routers. Those rules are not visible from the shell. - External clients use
tilsit.vip:24443. This is inferred from theHostheader (tilsit.vip:24443) on every external request in the access log. Caddy listens only on 443, so the routers forward WAN 24443 to TILSIT 443. tilsit.viphas an A record (203.0.113.13, the current public IP) and no AAAA record. TILSIT has no global IPv6 address, only ULA (fd09:…). The record is DNS-only (grey cloud): resolvers return the origin IP.cloudflare-ddns.shupdatescontentonly and keepsproxiedas set.- From TILSIT,
https://tilsit.vip/andhttps://tilsit.vip:24443/both time out. A LAN client cannot reach the public name. The cause may be missing NAT loopback or ISP filtering; the symptom is the same.
DNS on the LAN¶
- DHCP (from 192.168.21.1) hands out two resolvers: 192.168.0.1 and 149.112.112.112 (Quad9).
- 192.168.0.1 returns the public IP for
tilsit.vip. It is the ISP gateway. Whether it can hold a local override record is unknown.
Caddy¶
From app-setup/templates/Caddyfile, as of #220:
| Site | Cert | Auth |
|---|---|---|
:443 catch-all |
— | 403 for unknown host or bare IP |
tilsit.local localhost 192.168.21.10 |
tls internal (clients install caddy-root-ca.crt) |
basic_auth when not LAN |
tilsit.vip |
Let's Encrypt, DNS-01 via Cloudflare (SAN: tilsit.vip only) |
basic_auth when not LAN |
- The LAN/external split is
remote_ip: 192.168.21.0/24, loopback,fe80::/10,fd00::/8. Caddy sees the real client address because nothing proxies in front of it. - Both sites share one listener, and the WAN forward reaches both. Before
#220, the auth matcher also required
host tilsit.vip, so a WAN client that sentHost: tilsit.localreached/transmission/with no password. This was reproduced from a PIA exit IP and fixed on 2026-10-22. /media/*returns 403 to non-LAN clients, on both sites. After #220,basic_authanswers 401 first.- Transmission's RPC has no auth of its own
(
TRANSMISSION_RPC_AUTHENTICATION_REQUIRED=false). Since #220 the container publishes 9091 on127.0.0.1only, so Caddy is the only way in. Before that, gvproxy listened on*:9091(LAN-reachable, not WAN). - Routes: landing page,
/transmission/,/media/(LAN only), and/romanoand/berkswellredirects to Synology QuickConnect. Plex is not behind Caddy; clients use plex.tv.
Usage¶
All retained access logs (2026-07-27 to 2026-10-22) show external traffic on
4 days, from 10 distinct IPs, about 90 requests in total. Almost all of it is
/transmission/. The design should be sized for one person who sometimes
checks downloads away from home.
projectinsomnia.com¶
Netlify hosts it. Its DNS is at name.com, not Cloudflare. gh reports the
repo as smartwatermelon/projectinsomnia; #209 names
twistedmelonman/projectinsomnia. This document does not decide which is
current.
Three traps every option must avoid¶
- A hop in front of Caddy that originates on loopback or the LAN removes
all external auth. If
cloudflared, a local proxy, or any relay connects to Caddy from 127.0.0.1 or 192.168.21.0/24,remote_ipsees a "local" client.basic_authis then skipped and the/media/*guard opens. Any option that adds such a hop must either give that traffic its own site block with no LAN bypass, or move the matchers toclient_ipwithtrusted_proxies. - Split-horizon DNS with a port mismatch. If LAN DNS maps
tilsit.vipto 192.168.21.10, thenhttps://tilsit.vip:24443from the LAN hits a port Caddy does not listen on. One URL for both places needs the WAN forward on 443, or Caddy also listening on 24443. - Auth keyed on the hostname. The client chooses Host and SNI. Any matcher that decides "needs auth" by hostname can be bypassed by asking for a different name on the same listener. This was the #220 bug. Auth decisions must use the source address, or live in a site that only the trusted path can reach.
#210: Routing options¶
R1. Split-horizon DNS¶
LAN resolver answers tilsit.vip → 192.168.21.10. External DNS stays as is.
- For: LAN clients get the Let's Encrypt cert through SNI, so the internal CA
install is no longer needed for that name. DNS-01 renewal does not care
about LAN DNS. The
remote_ipbypass stays exactly as it is today. - Against: three blockers.
- The ISP gateway may not support override records. The alternative is a new resolver (dnsmasq on TILSIT, or Synology DNS Server) and a DHCP change on 192.168.21.1.
- DHCP also hands out Quad9. A client that uses the secondary resolver gets the public IP and times out. Results vary by client and by moment.
- The port mismatch (trap 2) needs a router change too.
R2. IP-aware redirect at projectinsomnia.com¶
A Netlify Edge Function at, for example, projectinsomnia.com/tools
compares the visitor IP with the current tilsit.vip A record (DNS over
HTTPS). A match means "at home": redirect to https://tilsit.local/.
Otherwise, redirect to https://tilsit.vip:24443/.
- For: no change to TILSIT, the routers, or LAN DNS. No new bypass.
- Against: two URLs and two certs stay in use. DDNS lag (up to the update interval after a public IP change) sends a home visitor to the external URL, which times out. It also adds logic to the public site.
R3. One public name in front of Cloudflare¶
Put tilsit.vip behind Cloudflare (tunnel or proxied record; see G2). LAN
clients resolve tilsit.vip to Cloudflare, not to the home IP, so hairpin
and LAN DNS no longer matter. The same URL works everywhere, and the user
signs in everywhere.
- For: one URL, no LAN DNS work, no dependence on NAT loopback.
- Against: home traffic to
tilsit.vipleaves the house and comes back.tilsit.localremains for fast LAN-only use, such as/media/.
Recommendation for #210: R3, done as part of G2. R1 and R2 each fix routing only. R3 comes free with the recommended gateway.
#209: Gateway options¶
All three keep tilsit.local and its LAN bypass unchanged.
G1. Self-hosted form login (caddy-security, the #130 plan)¶
- Sign-in: form plus JWT cookie. 1Password can fill it.
- Exposure: TILSIT stays directly reachable on WAN 24443. Anyone can reach the login page, and a Caddy or plugin bug is exposed to the internet.
- Upkeep: a custom Caddy build with two plugins.
caddy-securitylags Caddy releases. - Revocation: rotate the JWT signing key (logs out every session) or change the password.
- Failure: if the plugin config breaks, Caddy fails to start, and LAN access goes down with it.
-
210: no help. Needs R1 or R2 as well.¶
G2. Cloudflare Tunnel plus Cloudflare Access (recommended)¶
cloudflared on TILSIT makes an outbound connection to Cloudflare.
Cloudflare serves tilsit.vip, applies an Access policy ("allow only these
email addresses"), and sends allowed requests down the tunnel.
- Sign-in: the Access login page, using an identity provider (Google, GitHub, or an email one-time code). 1Password fills an IdP login and stores passkeys.
- Exposure: no inbound port. The 24443 forwards on both routers can be removed. Unauthenticated traffic stops at Cloudflare and never reaches TILSIT.
- Trust boundary: Cloudflare decrypts the traffic at its edge. This is new. The tunnelled traffic is the Transmission UI and the landing page; Plex and the NAS do not pass through it.
- Trap 1 applies.
cloudflaredconnects from loopback. It must target a dedicated Caddy listener bound to loopback only, whose site block has the routes without theremote_ipbypass, and with/media/*denied. - Do not just
import common_configthere. Its auth matcher excludes loopback, so every tunnel request would skipbasic_auth. - Use a site address without a hostname, such as
http://:8080withbind 127.0.0.1. A site address ofhttp://127.0.0.1:8080adds a host matcher, andcloudflaredsendsHost: tilsit.vip, so requests would probably not match (untested). The other way is to set the tunnel'shttpHostHeader. - Keep a
basic_authwith no matcher on that listener as a second layer. It still protects the tools if the Access policy is deleted or misconfigured. - Origin check:
cloudflaredingress can require a valid Access token before it forwards a request (originRequest.accesswithrequired: true,teamName, andaudTag). That closes the gap if the Access application is removed. Verify the option names against currentcloudflareddocs before relying on them. - Upkeep: one more binary (
cloudflared, Homebrew) and one LaunchDaemon. The stock Caddy build is enough; no new plugin. The Let's Encrypt cert fortilsit.vipis no longer needed once the forwards are removed. Cloudflare terminates public TLS. - Revocation: remove the email from the Access policy, or revoke sessions in the Zero Trust dashboard. Session length is a policy setting.
- Failure: Cloudflare or tunnel down means external access is down, with a
Cloudflare error page. LAN access through
tilsit.localis not affected. A watchdog can alert on tunnel health (alert-lib pattern). -
210: solves it (R3).¶
- Cost: Cloudflare offers a free Zero Trust plan. Its user limit and whether it covers this setup need checking at sign-up time.
- Constraint: as far as I can tell, Access and tunnel public hostnames need
the hostname in a Cloudflare zone.
tilsit.vipis already there.tools.projectinsomnia.comis not (name.com), so projectinsomnia.com links totilsit.vipinstead of hosting the tools under its own name. Moving projectinsomnia.com's DNS to Cloudflare would change that. A partial (CNAME) setup for a zone hosted elsewhere is, as far as I recall, a Business-plan feature; check before relying on it.
A proxied record (orange cloud) without a tunnel is a weaker variant. It keeps the inbound forward open, so the origin IP (published by the A record's history) can bypass Access unless Caddy also checks the Access JWT or allows only Cloudflare IP ranges. Cloudflare also proxies only a fixed set of HTTPS ports (443, 2053, 2083, 2087, 2096, 8443), and 24443 is not one of them. The tunnel avoids both problems.
G3. Tailscale (or another mesh VPN)¶
- For: strongest isolation. No public surface at all.
- Against: every device needs the client, and a borrowed browser cannot connect. There is no "public site as entry point", which is the stated goal of #209. Good as an addition, not as the gateway.
Recommendation¶
- G2: Cloudflare Tunnel plus Access in front of
tilsit.vip, with a loopback-only Caddy listener for the tunnel that has no LAN bypass. - This also closes #210 (R3).
- projectinsomnia.com gets a "Tools" link to
https://tilsit.vip/. The change belongs in the projectinsomnia repo.
Consequence for #130¶
G2 replaces the caddy-security plan in 2026-04-19-caddy-forms-auth.md.
If G2 is accepted, close #130 as superseded and mark that plan as such. If G1
is chosen instead, #130 stays, and #210 still needs R1 or R2.
Rollout sketch for G2 (for a later implementation plan)¶
- Create the Access application and policy for
tilsit.vip. - Install
cloudflaredand add a LaunchDaemon. Store the tunnel token in the System keychain, following theCF_API_TOKENpattern. - Add the loopback tunnel listener to the Caddyfile. Validate. Restart Caddy with explicit permission (production).
- Point the tunnel's public hostname at the listener. The A record then
gives way to the tunnel CNAME. Retire
cloudflare-ddnsonly after the cutover works. - Test from outside. The transmission-vpn container's PIA exit is a real outside vantage point; LAN tests of the public name prove nothing, because hairpin times out.
- With no session: the Access page.
- With a session:
/transmission/works;/media/is denied. - Through the old forward, with
Hostset totilsit.vip,tilsit.local,192.168.21.10, andlocalhost: 401 for every one.tests/caddyfile.batsguards the matcher. This checks the deployed result. - Remove the 24443 forwards on both routers. Confirm that
203.0.113.13:24443no longer answers. - Add a tunnel-health watchdog and update
docs/apps/caddy-README.md.
Rollback: re-add the forwards and restore the A record. The existing
tilsit.vip site block stays in the Caddyfile until step 6 is proven.
Open questions for Andrew¶
- Is it acceptable for Cloudflare to terminate TLS for the Transmission UI?
- Which Access sign-in: Google, GitHub, or email one-time code?
- Should the NAS QuickConnect links stay on the landing page? They bypass this gateway completely and use Synology's own login.