Login page with accounts stored in the local database #8

Open
opened 2026-11-09 11:40:33 +01:00 by Claude · 0 comments

Problem

The web UI is protected by HTTP Basic auth with a single username and password from the config ([ui] username/password). That works, but:

  • there's no way to log out; the browser keeps sending the credentials until it's closed;
  • the browser's own password prompt can't be styled, works poorly with password managers and gives no feedback;
  • nothing limits repeated guesses;
  • the password sits in plain text in the config file or environment;
  • Basic auth from a reverse proxy clashes with jellymove's own, since a request carries only one Authorization header.

Proposal

Replace Basic auth for the UI with a login page and accounts kept in the agent's SQLite database.

Accounts

  • New migration with a users table: username, password hash, created/last-login times. Append to MIGRATIONS, don't edit existing entries.
  • Hash with Argon2id (the argon2 crate) and a per-user salt. Never store or log plain passwords.
  • Manage accounts from the CLI, which needs shell access to the machine: jellymove user add <name>, jellymove user passwd <name>, jellymove user remove <name>, jellymove user list. Read passwords from a prompt or stdin, never from arguments.
  • No web sign-up and no "first visitor creates the admin" page: on a public VPS, whoever got there first would own it.
  • Upgrade path: if [ui] username/password is set and no users exist, create that user on start-up and log a warning to remove the password from the config.

Sessions

  • POST /api/login checks the password and sets a session cookie: random token, HttpOnly, SameSite=Strict, Secure when served over HTTPS, Path matching where the UI is served. Store only a hash of the token in SQLite, with an expiry (e.g. 30 days, renewed on use).
  • POST /api/logout deletes the session. A "Log out" button in the header.
  • Changing or removing a user's password ends their sessions.
  • /api/* returns 401 without a valid session and the UI shows the login page. Don't send WWW-Authenticate, so the browser doesn't pop up its own prompt.
  • Keep the X-Jellymove CSRF header check on state-changing requests.

Guessing

  • Limit failed logins per IP and per username (e.g. 5 per 15 minutes), with the same "wrong username or password" message either way.
  • Take the client IP from X-Forwarded-For only when a trusted_proxies setting says so, otherwise anyone can pretend to be anyone.

Unchanged

  • /peer/v1/* keeps using the peer token and never needs a login.
  • With no users and no [ui] password, the UI stays open as today, and the Status tab warns that it has no login.

Done when

  • Logging in, logging out and session expiry work, and an e2e test covers: no session → 401, wrong password → 401, right password → cookie → API works, logout → 401, password change ends sessions, peer routes unaffected.
  • The rate limit has a test.
  • A database from v0.2.x upgrades, and a [ui] password becomes the first user.
  • README and config.example.toml describe the jellymove user commands and the upgrade, and CLAUDE.md/ARCHITECTURE.md describe the auth model.

Notes

  • Related to #7: the cookie Path must follow the path the UI is served under.
  • Not in scope: roles/permissions, single sign-on (OIDC), two-factor auth.
## Problem The web UI is protected by HTTP Basic auth with a single username and password from the config (`[ui] username/password`). That works, but: - there's no way to log out; the browser keeps sending the credentials until it's closed; - the browser's own password prompt can't be styled, works poorly with password managers and gives no feedback; - nothing limits repeated guesses; - the password sits in plain text in the config file or environment; - Basic auth from a reverse proxy clashes with jellymove's own, since a request carries only one `Authorization` header. ## Proposal Replace Basic auth for the UI with a login page and accounts kept in the agent's SQLite database. **Accounts** - New migration with a `users` table: username, password hash, created/last-login times. Append to `MIGRATIONS`, don't edit existing entries. - Hash with Argon2id (the `argon2` crate) and a per-user salt. Never store or log plain passwords. - Manage accounts from the CLI, which needs shell access to the machine: `jellymove user add <name>`, `jellymove user passwd <name>`, `jellymove user remove <name>`, `jellymove user list`. Read passwords from a prompt or stdin, never from arguments. - No web sign-up and no "first visitor creates the admin" page: on a public VPS, whoever got there first would own it. - Upgrade path: if `[ui] username/password` is set and no users exist, create that user on start-up and log a warning to remove the password from the config. **Sessions** - `POST /api/login` checks the password and sets a session cookie: random token, `HttpOnly`, `SameSite=Strict`, `Secure` when served over HTTPS, `Path` matching where the UI is served. Store only a hash of the token in SQLite, with an expiry (e.g. 30 days, renewed on use). - `POST /api/logout` deletes the session. A "Log out" button in the header. - Changing or removing a user's password ends their sessions. - `/api/*` returns 401 without a valid session and the UI shows the login page. Don't send `WWW-Authenticate`, so the browser doesn't pop up its own prompt. - Keep the `X-Jellymove` CSRF header check on state-changing requests. **Guessing** - Limit failed logins per IP and per username (e.g. 5 per 15 minutes), with the same "wrong username or password" message either way. - Take the client IP from `X-Forwarded-For` only when a `trusted_proxies` setting says so, otherwise anyone can pretend to be anyone. **Unchanged** - `/peer/v1/*` keeps using the peer token and never needs a login. - With no users and no `[ui]` password, the UI stays open as today, and the Status tab warns that it has no login. ## Done when - Logging in, logging out and session expiry work, and an e2e test covers: no session → 401, wrong password → 401, right password → cookie → API works, logout → 401, password change ends sessions, peer routes unaffected. - The rate limit has a test. - A database from v0.2.x upgrades, and a `[ui]` password becomes the first user. - README and `config.example.toml` describe the `jellymove user` commands and the upgrade, and CLAUDE.md/ARCHITECTURE.md describe the auth model. ## Notes - Related to #7: the cookie `Path` must follow the path the UI is served under. - Not in scope: roles/permissions, single sign-on (OIDC), two-factor auth.
Claude Bot added this to the v0.3.0 milestone 2026-11-09 11:40:33 +01:00
Claude Bot added the Kind/SecurityKind/Feature
Priority
Medium
3
labels 2026-11-09 11:40:33 +01:00
Sign in to join this conversation.