Skip to content

feat: require sign-in or an API token for the web UI and API - #60

Merged
MaxAnderson95 merged 2 commits into
mainfrom
feat/http-auth
Oct 9, 2026
Merged

MaxAnderson95 merged 2 commits into
mainfrom
feat/http-auth

Conversation

@MaxAnderson95

@MaxAnderson95 MaxAnderson95 commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Tally's web UI and REST API answered anyone who could reach its port: GET /api/v1/status returned 200 with no credentials. That was tolerable behind a tailnet, but Max is moving personal services to OpenTunnel, which publishes the port on a public https://<route>.<id>.opentunnel.xyz hostname. Tally now requires app-level authentication the same way keep does (keep ADR 0005): a browser password, passkeys added after sign-in, and a bearer token for scripts.

What changed

  • Server (Sources/TallyHTTP/Auth.swift): every route except the SPA shell, static assets, and /api/v1/auth/* sign-in routes needs a tally_session cookie or Authorization: Bearer <TALLY_SERVE_TOKEN>, loopback included, because OpenTunnel's local client also connects from 127.0.0.1. Sessions are stateless HMAC-SHA256 cookies (30 days, HttpOnly, SameSite=Strict) signed with a persistent key. The key, WebAuthn user handle, and passkeys live in ~/Library/Application Support/Tally/serve-state.json (mode 0600). Cookie mutations also need a same-origin Origin or Sec-Fetch-Site; bearer requests skip that check. The existing Host/Origin allowlists and JSON-only mutations still apply to everything. Tally refuses to serve with neither secret, and token-only disables password sign-in. Passkeys use swift-server/webauthn-swift pinned to the 1.0.0-beta.1 revision.
  • Deliberate difference from keep: keep derives the WebAuthn origin scheme and the cookie Secure flag from r.TLS or a loopback X-Forwarded-Proto. OpenTunnel ends TLS in its local client and forwards raw TCP (anomalyco/opentunnel crates/opentunnel/src/tunnel.rs), so that would yield an http:// relying-party origin and break passkeys. Tally decides from the allowlisted Host: the configured HTTPS origin's Host is HTTPS; localhost:<port> is plain HTTP.
  • Secrets (Sources/TallyApp/ServeSecrets.swift, Settings): Tally launches from Finder and login items with no shell environment, so the password and token are stored in the login Keychain under the names TALLY_SERVE_PASSWORD and TALLY_SERVE_TOKEN and edited in native Settings > Web access. Startup errors such as a missing secret appear in the popover immediately.
  • Web: a sign-in page (passkey and password) and a Settings > Sign-in section to add, list, and remove passkeys and to sign out, using @simplewebauthn/browser 13.3.0. A 401 on the dashboard poll returns to sign-in. Sign-out switches to the sign-in page only after Tally confirms it; a failed request leaves the page signed in with a retryable error.
  • Consumers: the companion sends TALLY_SERVE_TOKEN from the OpenCode service environment and reports unauthorized with a fix when it is missing or wrong. The tally skill's curl helper passes the bearer header on stdin so the token stays out of process arguments.
  • Docs: ADR 0002 (including the quit-delete-relaunch order for revoking every session), plus SPEC section 9 (which previously said there was no login or bearer token), INSTALLATION, README, and the companion README.

Verification

  • Swift tests: 103 passed, run with SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk bash scripts/test-swift.sh --build-system native. A new test drives a software ES256 authenticator through password, bearer, cookie flags, cross-origin rejection, and passkey register and sign-in on both localhost and a tunnel Host, including rejection of an assertion made for the other origin.
  • Web tests 21 passed and the web build succeeded; companion tests 17 passed.
  • A throwaway local server driven by Playwright with Chromium's virtual WebAuthn authenticator completed password sign-in, passkey registration, sign-out, and passkey sign-in on http://localhost, and a restart kept the session valid.
  • Not verified: Face ID or Touch ID on real hardware, a real HTTPS OpenTunnel route, and the packaged app's Keychain read and write.

Originally created in OpenCode session ID: ses_edde72b75ffenF4F0i3R02Dlpd using model: anthropic/claude-opus-5-5

Tally's web UI and REST API answered anyone who could reach the port, which is unsafe once the port is published on a public OpenTunnel hostname. Every route except the SPA shell, static assets, and sign-in endpoints now requires a browser session from password or passkey sign-in, or a bearer token, with no loopback exemption, modeled on keep's ADR 0005. The password and token live in the login Keychain as TALLY_SERVE_PASSWORD and TALLY_SERVE_TOKEN and are edited in native Settings; Tally serves nothing until one is set. Sessions are 30-day signed SameSite=Strict cookies, and the signing key and passkeys persist in Application Support. Unlike keep, the WebAuthn origin and Secure flag come from the configured HTTPS origin's Host, because OpenTunnel forwards plain HTTP with no forwarding header. The web app gains a sign-in page and a Sign-in settings section for passkeys, the companion and tally skill send TALLY_SERVE_TOKEN, and ADR 0002 records the decision.

OpenCode session ID: ses_edde72b75ffenF4F0i3R02Dlpd using model: anthropic/claude-opus-5-5

@MaxAnderson95 MaxAnderson95 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review by OpenCode using GPT-6 Astra

Pull Request Review

Reviewed all 22 changed files at 46c05d5 against the originating request, repository instructions, SPEC, and ADRs. Inspected the keep reference implementation and the pinned webauthn-swift implementation for ceremony verification. Two P2 findings concern sign-out and session revocation: a failed logout is presented as successful, and the documented state-file deletion procedure leaves the running server authenticated and can restore the deleted state.

Validation: SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX26.sdk bash scripts/test-swift.sh --build-system native passed 103 tests; npm --prefix web test passed 21; npm --prefix companion test passed 17. A separate synthetic execution of the actual SignInPreferences click handler, with fetch rejecting before a server response, confirmed that it still invokes signedOut. The state-file finding follows the initialization and persistence paths in Auth.swift; no real credentials or auth state were changed. Packaged Keychain behavior, hardware authenticators, and a live OpenTunnel route were not exercised in this review.

Confidence Score: 3/5

Originally created in OpenCode session ID: ses_eddbf762fffeUwLbcxEIVzpAgy using model: openai/gpt-6-astra

Comment thread web/src/auth.tsx Outdated
<button type="submit" className="primary-button" disabled={busy}>Add passkey</button>
</form>
: <p className="fine-print">Passkeys need an HTTPS address or localhost, not an IP address.</p>}
<button className="quiet-button sign-out" disabled={busy} onClick={() => { void signOut().catch(() => undefined).finally(signedOut) }}>Sign out</button>

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review by OpenCode using GPT-6 Astra

P2: Keep logout failures visible instead of claiming sign-out

If the tunnel disconnects, the Mac goes offline, or /auth/logout returns an error, this catch suppresses the failure and finally(signedOut) still replaces the dashboard with the login screen. The HttpOnly 30-day cookie remains in the browser because no successful logout response cleared it; reloading when connectivity returns authenticates the browser again without a password. I reproduced the callback with the actual component and a fetch stub rejecting before any response. Invoke signedOut only after logout succeeds, and show a retryable error on failure so someone leaving a shared browser knows it is still authenticated.

Originally created in OpenCode session ID: ses_eddbf762fffeUwLbcxEIVzpAgy using model: openai/gpt-6-astra

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up by OpenCode using Claude Opus 5.5

Accepted: fixed in 8e3fe1a. SignInPreferences now calls signedOut only after POST /auth/logout succeeds. On any failure it keeps the dashboard, re-enables the button, and shows "This browser is still signed in. Try again when Tally is reachable." I dropped the 401 special case because the logout route needs no session and never answers 401.

Originally created in OpenCode session ID: ses_edde72b75ffenF4F0i3R02Dlpd using model: anthropic/claude-opus-5-5

Comment thread docs/INSTALLATION.md Outdated
- **Scripts and the companion:** send `Authorization: Bearer $TALLY_SERVE_TOKEN`.

On Max's Mac, the rootless Tailscale CLI uses `--socket="$HOME/.config/tailscale/tailscaled.sock"`. Inspect existing exposure with `tailscale --socket="$HOME/.config/tailscale/tailscaled.sock" serve status --json`. Adding a new service can reset approval for other services on this node, so configure and approve Tally as a separate operational task. The installation verification found no existing Tally exposure and changed no tailnet service.
Sessions are signed with a key in `~/Library/Application Support/Tally/serve-state.json`, which also holds the passkeys. Changing the password or token does not sign browsers out. Delete that file to end every session; it also removes every passkey. Tally is ad-hoc signed, so a rebuilt app can ask once to read its Keychain items; choose Always Allow.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review by OpenCode using GPT-6 Astra

P2: Stop Tally before deleting the session-revocation state

Deleting this file while Tally runs does not end any session: HTTPAuth.init copies its signing key into codec, and AuthState keeps the passkeys in memory for the listener's lifetime. A subsequent passkey login calls state.used, which persists the old key and all passkeys back to the deleted path, so even a later restart can retain the credentials the operator intended to revoke. This is the only documented way to revoke a leaked session. Specify the complete order: quit Tally, delete serve-state.json, then relaunch; update the corresponding ADR consequence too.

Originally created in OpenCode session ID: ses_eddbf762fffeUwLbcxEIVzpAgy using model: openai/gpt-6-astra

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up by OpenCode using Claude Opus 5.5

Accepted: fixed in 8e3fe1a. Confirmed against Auth.swift: HTTPAuth.init copies the signing key into codec, and AuthState.used persists the in-memory file on the next passkey sign-in. docs/INSTALLATION.md now says to quit Tally, delete serve-state.json, then reopen Tally, and explains why deleting it while Tally runs revokes nothing. The ADR 0002 consequence now says the same. I left the code path alone, matching keep's documented lever, because a revoke-without-restart control would expand scope.

Originally created in OpenCode session ID: ses_edde72b75ffenF4F0i3R02Dlpd using model: anthropic/claude-opus-5-5

A failed logout request left the 30-day HttpOnly cookie in place but still switched the web app to the sign-in screen, so a reload re-authenticated the browser. Sign-out now leaves the page signed in and shows a retryable error unless Tally confirms the logout. The installation guide and ADR 0002 now say to quit Tally before deleting serve-state.json, because a running server keeps the signing key and passkeys in memory and writes them back on the next passkey sign-in.

OpenCode session ID: ses_edde72b75ffenF4F0i3R02Dlpd using model: anthropic/claude-opus-5-5
@MaxAnderson95

Copy link
Copy Markdown
Owner Author

Review Follow-up

Follow-up by OpenCode using Claude Opus 5.5

Reviewed 2 findings from #60 (review): 2 accepted, 0 rejected, 0 deferred.

  • P2 failed logout shown as signed out: web/src/auth.tsx SignInPreferences now signs out only after POST /api/v1/auth/logout succeeds and otherwise shows a retryable error (8e3fe1a).
  • P2 revocation order: docs/INSTALLATION.md and docs/adr/0002-app-level-http-auth.md now say to quit Tally, delete serve-state.json, then reopen it, and explain why deleting it while Tally runs revokes nothing (8e3fe1a).

Validation: web build (tsc + vite) and npm --prefix web test (21 passed). No Swift code changed.

Originally created in OpenCode session ID: ses_edde72b75ffenF4F0i3R02Dlpd using model: anthropic/claude-opus-5-5

@MaxAnderson95 MaxAnderson95 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review by OpenCode using GPT-6 Astra

Follow-up Review

Reviewed the complete three-file diff from 46c05d5 to 8e3fe1a and the author's responses. Both prior P2 findings are resolved. No new actionable findings.

  • Failed logout: leave() invokes signedOut only after the logout request succeeds. Network and HTTP failures keep the session UI, display a retryable error, and re-enable the button. Synthetic execution of the actual component handler passed all four cases: network rejection, HTTP 503, HTTP 401, and successful logout.
  • Session revocation: INSTALLATION and ADR 0002 now specify quit, delete serve-state.json, then relaunch, and explain the running server's in-memory state. This resolves the documentation finding without changing the auth-state implementation.

npm --prefix web test passed all 21 tests. web/node_modules/.bin/tsc --noEmit --project web/tsconfig.json passed. Swift and companion code are unchanged from the previously reviewed SHA, where their suites passed. Hardware authenticators, packaged Keychain behavior, and a live OpenTunnel route remain outside the runtime verification performed here. The author's worktree remains clean.

Confidence Score: 4/5

Originally created in OpenCode session ID: ses_eddbf762fffeUwLbcxEIVzpAgy using model: openai/gpt-6-astra

@MaxAnderson95
MaxAnderson95 merged commit 79c6376 into main Oct 9, 2026
5 checks passed
@MaxAnderson95
MaxAnderson95 deleted the feat/http-auth branch October 9, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant