# Remote Access Research and decision trail for how AutoButler devices get reached from outside the home network. Spans issues #862, #863, #864, #865, #866, #931, #968 (epic #498, design doc `docs/design/zero-config-remote-access.md`). ## The constraint that shapes everything AutoButler devices sit behind whatever router the user already has — we don't control it, and we can't assume port forwarding, a public IP, or CGNAT-free service. That single fact rules out most of the obvious answers and is why this took seven tickets to settle. ## UX requirements first (#865) Before comparing tech, the UX bar was defined explicitly: - **Zero-touch setup for the common case.** No port forwarding, no router admin, no third-party account, no terminal. One toggle in Settings ("Enable remote access") is the acceptable first-time action. - **One-time device pairing is fine** for a *new* device (phone, laptop) — a QR code or short code, same pattern as 1Password or Tailscale. - **Transparent local/remote switching** — fast path on the home WiFi, tunnel automatically when away, user never picks a mode. - **Graceful offline state** — a clear "your AutoButler isn't reachable" message, not a spinner or a cryptic error. - **Per-device authorization and revocation** — losing a phone means revoking it from another trusted device, immediately. - **No mandatory third-party account** for basic functionality. Everything below was judged against this list. ## Research: how Firewalla does it (#863) First pass concluded Firewalla's remote access was *just* a WireGuard/OpenVPN server on the device — which needs a public IP and port forwarding, and doesn't work behind CGNAT. That would have made Firewalla a non-model for us. **That first pass was wrong.** A follow-up dig into Firewalla's actual open-source code ([firewalla/firewalla](https://github.com/firewalla/firewalla)) found a second, primary mechanism it had missed: - **Cloud relay via `encipher.io`** — the device holds a persistent **outbound** Socket.IO WebSocket to Firewalla's cloud. Outbound-only means it works through CGNAT and any NAT/firewall with zero configuration. End-to-end encrypted with device-generated RSA keys (the relay only ever sees encrypted blobs). This is Layer 1 — what makes the box "just set itself up." - **FRP tunnel relay** — a secondary mechanism (`frpc`/`frpd`) used to expose specific services (their API port, VPN port) through NAT without port forwarding. - **Direct VPN (WireGuard/OpenVPN)** — the *optional* full-tunnel mode, which is the one that does require port forwarding. This is what the first research pass found and mistook for the whole picture. Takeaway: Firewalla's "it just worked" reputation comes from the cloud relay, not the VPN server. The VPN server is the power-user path layered on top. ## Comparing the options (#864) | Approach | CGNAT? | Zero-config? | 3rd-party account? | Infra cost | Self-hostable? | | --- | --- | --- | --- | --- | --- | | Cloud relay (Firewalla model) | ✅ | ✅ | No | Low (one relay) | ✅ | | Tailscale tsnet + Headscale | ✅ (DERP fallback) | ❌ needs a coordination server | No (self-hosted Headscale) | Medium (VPS) | ✅ | | Plain WireGuard | ❌ | ❌ | No | None | ✅ | | ZeroTier | ✅ | Partial | ZeroTier account (or self-hosted controller) | Free tier | Partial | | Cloudflare Tunnel | ✅ | Partial | CF account | Free tier | ❌ — ruled out on privacy principle | Plain WireGuard and Cloudflare Tunnel were both ruled out early: the first doesn't solve CGNAT, the second means all traffic transits Cloudflare's edge, which conflicts with the no-data-leaves-the-house premise. ## Where the recommendation landed — resolved, confirmed against the codebase Two different final recommendations came out of #866, and they disagreed on sequencing: **Recommendation A — Tailscale tsnet + self-hosted Headscale, ship first.** Embed `tsnet` (Tailscale as a Go library, no separate daemon) directly in the AutoButler binary. Run our own Headscale coordination server so users never see a Tailscale account or an auth key. DERP relay (Tailscale's, initially) handles CGNAT transparently. **Recommendation B — lightweight custom relay first, Tailscale later.** Build a small WebSocket relay (control-plane only), mirroring Firewalla's cloud-relay layer more directly, and treat Tailscale/tsnet as a Phase 2 data-plane upgrade. **Confirmed: A is what shipped, and it's the only one that did.** Checked directly against the codebase (2026-08-25) — `go.mod` depends on `tailscale.com v1.102.2` directly (not indirect), and `pkg/util/remoteutil/remoteutil.go` wraps `tsnet.Server` exactly per Recommendation A. There's no custom relay anywhere in the tree. B was superseded, not left open — this page previously said the tension was unreconciled; it wasn't, the commit history just didn't say so explicitly on the issue thread. ## Implementation status — confirmed against the codebase (2026-08-25) `pkg/util/remoteutil/remoteutil.go` is real and in production shape, not a prototype: - `Start(authKey)` boots a `tsnet.Server` with `Hostname: "quark"`, persists its state under `/var/lib/quark/tsnet` (falls back to `~/.config/quark/tsnet` off Linux), and is controlled by the `QUARK_HEADSCALE_URL` env var — **default is already `https://network.quark.org`, already HTTPS.** (The env var and default host were renamed from `AUTOBUTLER_HEADSCALE_URL` / `network.autobutler.org` at some point — `autobutler.org`'s own Terms of Service still references `network.autobutler.org`; worth a look at whether that's stale copy or a second, still -live domain.) The code itself warns loudly at startup if it's ever pointed at a plain-`http://` control URL. - `Stop()` / `IsRunning()` / `RemoteURL()` are implemented and already wired to a real settings API: `GET/POST/DELETE /settings/remote-access` (`internal/server/api/v0/settings/remote_access.go`). POST takes a Tailscale auth key, starts the tsnet node, starts an HTTP reverse proxy (`StartProxy`) on the tailnet listener forwarding to the local server, and persists the enabled state via `settingsutil.SetRemoteAccess`. DELETE tears it down. This is a full, working device-side on/off switch today — see quark#1582, which is about a *client-app* quick-toggle UI for this, not new backend plumbing. - `RemoteURL()` returns `http://:80` (the tsnet-internal listener), proxying to whatever the local server is actually serving — `StartProxy` takes a `localTLS` flag (`serverutil.ServingTLS()`) and skips cert verification on that hop with a code comment explaining why: it's a loopback connection to the same process presenting its own self-signed cert, there's no third party to authenticate. See `Spikes/Encrypt-Data-In-Motion.md` — this confirms Option B (Gin-native TLS) from that spike was the one actually built. Three connectivity scenarios need to keep working (per #931): 1. **AutoButler's own Headscale network** (the default, zero-config path) — implemented, and the TLS gap on the control server that #931 flagged as blocking appears closed (`network.quark.org` is the HTTPS default now). 2. **User's existing Tailscale account** ("bring your own tailnet") — code-level, this should work by setting `QUARK_HEADSCALE_URL=https://controlplane.tailscale.com`, but end-to-end validation (conflict with a system Tailscale daemon already running on the same box, correct surfacing of the resulting `100.x.x.x`/`*.ts.net` address in the UI) wasn't confirmed as tested. 3. **Direct socket / NAT hole-punch, no VPN at all** — not implemented, spike-only. Recommendation was to assess real user demand before building this. ## Mobile embedding (#968) For genuine peer-to-peer performance (vs. routing through a relay), the plan is to compile tsnet into a native `.aar` (Android) / `.xcframework` (iOS) via `gomobile bind` and call it from Flutter over a method channel. - **Android** — needs the `VpnService` permission; one-time system dialog, then fully transparent. Lower complexity, do first. - **iOS** — needs Apple's Network Extension entitlement (Tailscale itself ships this way, so it's known-possible, but expect App Store review scrutiny). - **Desktop** — no special entitlements, simplest of the three. Not started as of the last tracked update. Open questions: `gomobile bind` feasibility against the current tsnet version, and IPA/APK size impact of bundling it. ## Prior art: how openGym handles this [openGym](https://gitlab.com/DuarteSantos8/opengym) — a self-hosted workout tracker — takes the opposite approach worth noting as a contrast, not a recommendation: - **Ships no remote-access mechanism at all.** DNS, TLS, and tunneling are entirely bring-your-own: the README points self-hosters at Cloudflare Tunnel, Caddy (automatic Let's Encrypt), or Traefik/nginx/NPM — pick one, point your own domain at it. - **The reason it needs a real domain isn't a networking design choice — it's WebAuthn.** Passkeys are bound to an exact hostname (`RP_ID`) and only work over HTTPS (with a `localhost` exception), so a plain LAN IP simply can't complete a passkey prompt from another device. Remote reachability is a side effect of the auth method, not a feature they built. AutoButler's WebAuthn spikes (`Spikes/Post-Quantum-Cryptography.md`) will hit the same `RP_ID`/origin binding once passkey login lands — worth keeping in mind for scenario 2 above, since a Headscale-assigned `*.ts.net` hostname changing would invalidate existing passkeys the same way changing `RP_ID` does for openGym. - **No mesh VPN, no coordination server, no relay** — it explicitly suggests layering a VPN or an auth proxy (Authelia, Cloudflare Access) *in front of* whichever reverse proxy you picked, as an optional extra, not something it provides. - **Falls back to a LAN-only "guest mode"** with no passkey and no sync (data stays in that one browser) for people who don't want remote access at all — conceptually adjacent to quark#1581 (local-only file explorer mode, no device required). The takeaway: openGym pushes 100% of the DNS/TLS/tunneling complexity onto the self-hoster, which is a reasonable choice for a project with no dedicated infra budget, but is exactly what the UX requirements in #865 ruled out for AutoButler. It's a useful data point for "what happens if we did nothing," not a design to imitate. ## Open threads - Validate scenario 2 (bring-your-own Tailscale) end-to-end. - Decide whether scenario 3 (VPN-free hole-punch) is worth building at all. - `gomobile bind` mobile embedding (#968) — not started. - **quark#1582** — a fast, prominent on/off toggle for remote access *in the mobile/desktop apps*. The backend API already supports this (`/settings/remote-access`, see above) — the gap is a client-side UI that's reachable in a tap or two, for when a VPN-hostile network (airplane WiFi, some corporate/school networks) makes the tunnel actively harmful rather than just slow. Note this existing API is a whole-device switch (turns tsnet off on the butler itself); once #968 lands a client-embedded tunnel, there may also be a need for a purely local, per-device "don't route through the tunnel right now" toggle that doesn't touch the butler's own tsnet state at all — worth deciding whether #1582 means one, the other, or both. - Confirm whether `network.autobutler.org` (referenced in autobutler.org's Terms of Service) and `network.quark.org` (the code's actual default) are the same infrastructure under two names, or one of them is stale.