magpie serve, magpie web and magpie daemon install take --tls-cert <file>
--tls-key <file> (or MAGPIE_TLS_CERT / MAGPIE_TLS_KEY). The gateway and the
web UI on its listener then serve HTTPS to other computers. Without them
nothing changes.
- Half a pair, a file that doesn't parse, or a flag with no value is
refused at start with a message naming the missing flag.
- The pair is re-read when either file's mtime or size changes (certbot
renewal), with no restart. A renewal that doesn't parse keeps the
certificate already served and is logged once.
- Other computers get HTTPS only. Plain HTTP from them gets net/http's
400 "Client sent an HTTP request to an HTTPS server".
- This computer (loopback, or a peer address equal to the local one) may
still use plain http on the same port. Its connections are sniffed on
their own goroutine (a first byte of 0x16 is TLS) for up to 10s, so a
silent client holds nobody else up. gateway.URL() stays
http://127.0.0.1:<port>, which agents, MCP servers, ServedBy, the
healthcheck and daemon status all use, and no certificate covers
loopback.
- WSL NAT and containers count as other computers.
- ALPN is http/1.1 only (hijacked connections and websockets need it), with
TLS 1.2 as the minimum.
- Printed links, LAN addresses, publicURL, the serve/web banners and
daemon install show https:// for other computers' addresses.
- The DNS-rebinding Host checks (foreignPage, rebound, the MCP
loopbackHost) don't depend on the scheme and are unchanged.
- daemon install carries MAGPIE_TLS_* into the unit or plist. A reinstall
or `daemon web on` that names no certificate keeps the installed pair,
and --no-tls removes it.
- Docs: reference.md gets an HTTPS section that names Caddy as the
alternative, gateway-routing.md gets a TLS row, and docker.html (en,
zh, ja) gets the env rows.
What was run:
- New tests: internal/gateway/tls_test.go (others HTTPS-only, this
computer both, a silent local client holds no other, renewed
certificate served, CheckTLS, addresses, Relisten keeps TLS),
internal/cli/tls_cli_test.go and daemon TestInstallCarriesTLS (linux
and darwin, paths with space, %, & and ").
- Each was broken by hand and went red: no wrap in listen, no reload, a
synchronous sniff, a bad renewal dropping the certificate, http in
publicURL or the pinned LANURLs, the carried entries removed, and
keepTLS as a no-op.
- Real use under a sandbox HOME, with a self-signed pair, on
0.0.0.0:3461:
- Half a pair, a garbage certificate, a flag with no value, and the
env set to half a pair each exit 1 with the message.
- curl -k https://127.0.0.1 and https://<LAN IP>/v1/models with a key:
200. Plain http on loopback: 200.
- The cert files were swapped for a second pair while it ran.
openssl s_client then showed the new CN and serial, and curl
--cacert with the new pair got 200. A junk key file then kept the
second pair, logged once.
- From the Windows box over the LAN: plain http got 400; https with
the key got 200, and without it 401.
- magpie web --addr 0.0.0.0:3462: https network links. From Windows,
http got 400 and https with the key got 303.
- gofmt -l clean. go vet passed on darwin, GOOS=linux -tags nogui and
GOOS=windows.
- go test -tags nogui for ./internal/cli, ./internal/daemon, and the TLS
tests of ./internal/gateway and ./internal/gui: all pass at the rebased
head.
- Two reds in the full suite (`go test -tags nogui ./...`) are the same
on origin/main f074996d9; both are filed:
- TestGatewayHeldByAContainer failed 2 of 5 there (#2107).
- The gateway package runs past go test's default 10m under load:
1208s on main and 1221s here, both passing with -timeout 40m
(#2108).