0010 — Panel TLS and authentication
Status: accepted · Date: 2026-11-20 (proposed), 2026-11-21 (accepted)
Context. M2 exposes the first real attack surface: the panel, its first run, sign-in, sessions and API tokens. The maintainer decided (Q2) that the panel is reached over HTTPS on the server IP with a self-signed certificate whose fingerprint the console prints, that a panel domain can be added later, and that the IP redirects to the domain once the domain has a valid certificate. The maintainer also decided (Q8) that API tokens can't run destructive, sensitive or session-only actions, and can never manage tokens, auth settings or users. The threat model (docs/security.md Draft 2) listed gaps G2–G10 for M2. ADR 0009 already separated the hub CA from the panel.
Decision.
- Panel transport. The embedded Caddy serves the panel on
:443with a self-signed ECDSA P-256 leaf of its own atDATA/pki/panel.pem(0600), with a publicDATA/pki/panel.fingerprint. It is never issued by the hub CA. Its SANs arelocalhost,127.0.0.1,::1, the host's addresses at creation and any--panel-hostnames. The TLS connection policy setsdefault_sniandfallback_snitolocalhost, so the leaf is served for handshakes without SNI (IP literals) and for any unknown name. It is valid for 825 days and regenerated at start when fewer than 60 days remain, when missing or invalid, or when the--panel-hostset changes; each regeneration logs a warning with the new fingerprint. The fingerprint is logged at every start and shown on Settings › Security, never on an unauthenticated page.:80answers only308to HTTPS, using the port of--https-listen. Users are never told to install a CA. - Panel domain (M4). M2 has no panel-domain setting. M4 adds the setting, ACME, the IP → domain redirect once the domain certificate is valid, HSTS and a break-glass option to keep the IP panel (G15). M2 only accepts extra names through
--panel-host. - Control plane on a unix socket. No TCP listener. Caddy reaches it on
DATA/run/cp.sock(0600 in a 0700 directory owned by the service user, 256 connections).X-Forwarded-Foris trusted only on that socket and only as a single value; Caddy has notrusted_proxies, so it replaces client values. Loopback is trusted for nothing. - Host and Origin. Accepted
Host: an IP literal,localhost, or a--panel-hostname; otherwise 421. On every unsafe request, anOriginthat is present must equalhttps://+Host; cookie-authenticated unsafe requests and WebSocket upgrades must carry it. Every APIPOSTmust beapplication/json. - Credentials. Each route declares its kind, and only that kind's credential is read: none for public and setup routes, the pending cookie for the 2FA route, the session cookie for session routes, and for session-or-token routes
Authorizationfirst (cookies then ignored) or else the session cookie. An unknown, expired or revoked session cookie counts as none and is cleared. Unsafe session requests need theX-SD-CSRFheader (an HMAC of the session secret) and a matchingOrigin. Tokens and session ids are never accepted from URLs; session ids are only created by the server. - Auth state machine. "An admin exists" means a user with a password and a confirmed TOTP. Setup needs the console setup token (256 bits, hashed, 1 h, written to
DATA/setup-token0600 at every start while no admin exists; only the path is logged). Completion checks the token, the enrolment and a code from the server-generated pending seed before hashing the password, then in one transaction consumes the token (compare-and-delete) and writes the admin, seed and recovery codes. A correct password yields a pending-2FA token (hashed, 5 min, 5 tries, at most 5 per user), never a session. A session is minted only after the second factor, and an older session presented at login is revoked. Password or TOTP changes revoke every session and, by default, every token. Five failed step-up codes revoke the session. If an auth event's audit intent can't be written (it waits about 2 s), nothing is minted (503). Actions that only remove access (logout, revoke session, revoke token) always run, and flag the gap (audit: "unrecorded", an ERROR in the log). - Secrets and parameters. Passwords: argon2id (19 MiB, t = 2, p = 1), one hash at a time, at most 4 waiters, 2 s wait, then a fast 503; all request checks run before hashing. TOTP: RFC 6238, SHA-1, 6 digits, ±1 step, counters never reused; seeds stored with AES-256-GCM (secretbox) under
DATA/keys/master.keywith table/row/column as AAD. The server refuses to start if the key is missing while ciphertexts exist or whilemeta.secretbox_key_idis recorded (even when no ciphertexts exist), if the key file is unreadable, or if its id differs from the recorded one;admin resetclears the encrypted admin data andmeta.secretbox_key_idin one transaction and creates a key. Recovery codes: 10 × 80 bits, SHA-256, single use. Session, pending, setup and token secrets: 256 bits, SHA-256.DATAmust be 0700; umask 0077. Startup takes the data-directory lock before writing anything underDATA. - Login protection without lockout. Four independent exponential back-offs, all checked before hashing: per client IP (IPv4 or IPv6 /64), per IPv6 /48, per account for passwords (one shared bucket for all non-existent names), and per account for second factors (cap 1 h). Blocked keys are never evicted; unblocked keys are evicted oldest-first; a full map of blocked keys refuses new keys, except IPs that completed a full login in the last 30 days, which also skip the per-account password back-off. Remaining risk: back-off state resets on restart; a distributed attacker can keep the hash slot busy; a password holder can delay the admin's second factor by up to 1 h; a flood can block sign-in from a new network. Failed second factors after a correct password are shown at the next sign-in. Accepted: the shared
<unknown>bucket lets a multi-IP attacker tell whether a user name exists (saturate<unknown>from many IPs, then a probe for a name that does not exist is refused 429 while an existing name still gets 401). Single clients see identical answers and timing. The user name is not a secret, the password and TOTP still guard the account, and per-name buckets would undo the map-filling protection. - API tokens.
sd_+ 256 bits, hashed, scopedread<write<admin, required expiry (default 90 days, at most 365), accepted only fromAuthorization: Bearer, created only from a session with fresh 2FA, audited. The registry denies tokens every sensitive, destructive, session-only and console-only action; token, auth and user management are session-only. - Recovery.
serverdock admin resetruns only as the uid that ownsDATA(root against another owner is refused), takes the data-directory lock (the server must be stopped), runs pending migrations, and runs the console-only actionauth.admin_reset, which exists only in that process's registry. It clears the password, TOTP and recovery codes, deletes sessions, revokes tokens, clearsmeta.secretbox_key_idin the same transaction as the ciphertexts, and creates a missing master key; the next server start writes a new setup token.
Consequences.
- The panel works on a fresh server with no domain, at the cost of a browser warning on first use. The first-run on-path risk remains for users who skip both the SSH tunnel and the fingerprint check; this is accepted, and M4 recommends re-enrolling TOTP once the domain has a valid certificate.
- Cookies are host-scoped, not port-scoped: on IP and tunnel access, another HTTPS service on the same host name could receive them.
SameSite=Strict,HttpOnlyand fresh 2FA limit the impact; M3a warns about services published on the panel IP; M4's domain removes the overlap. - Login can be delayed, but not taken over, by a distributed attacker or a password holder. Existing sessions keep working, and the console can recover.
- A server running more than 60 days without a restart can end up serving an expired self-signed leaf; Settings › Security warns, and a restart renews it.
- Behind Docker port mapping, the
:80redirect points at the in-container HTTPS port. - Losing
master.keymakes encrypted admin data unreadable and requiresadmin reset; losingpanel.pemchanges the fingerprint. - Development and the bench reach the control plane through the socket, and
--internalis gone. - Idle cost: Caddy's TLS server on
:443. No new timers or goroutines.
Acceptance (2026-11-21). security reviewed the design before M2 and each implementation step (1 to 13) against it, and approved the result; the maintainer's answers (QM2-1 to QM2-3) are in plan 0003. The decisions above stand as written. What changed while building them, all recorded in plan 0003 (on GitHub) and security.md:
- Decision 1: the fingerprint is on Settings › Security and in the log, never on an unauthenticated page; the setup page shows the token's real path and the SSH-tunnel hint instead.
- Decision 5: the 401 reason codes (
idle_expired,absolute_expired,revoked) reach the Signed-out screen, and a shown-once token or recovery-code list stays on screen until the user hides it or leaves (accepted by the maintainer, oversecurity's suggestion of an automatic clear, so that switching apps to paste it on a phone cannot destroy it). - Decision 8: the
<unknown>bucket's multi-IP enumeration is accepted and pinned by a test (TestUnknownBucketRevealsExistenceToAMultiIPAttacker). - Verification found two defects the design did not predict, both fixed: Caddy's DEBUG log printed the
X-SD-CSRFheader (the proxy's log encoder now redacts it), and SvelteKit's route announcer used an inline style the CSP blocks (a build plugin replaces it). - The Playwright suite does not use a test-only server flag: state-changing tests start a fresh binary and edit its temporary database; WebSocket routes do not exist yet and must pass the same rules when they arrive.