feat(dashboard): add username and password login
SA
10d ago+2590+2590+0123456789012345678901234567890123456789-81-81-01234567890123456789
Description
Closes #1611.
Setting DASHBOARD_PASSWORD (admin.password) turns on a username and password login for the dashboard. DASHBOARD_USERNAME (admin.username) defaults to admin. The login is off by default.
- Signing in starts a 24-hour session in an
HttpOnly,SameSite=Strictcookie, which/admin/*and the playground's model calls accept in place of a bearer token. The auth dialog asks for username and password, with a link to use an API key instead; the sidebar shows who is signed in and a sign-out button. - With a password set, the admin API requires a credential even without a master key, instead of staying open.
- Model API access does not change: the master key and managed keys work as before, and a gateway with neither still serves model requests without a credential.
The issue left these open; this is what the PR does:
- Sessions are stateless. The cookie is signed with a key derived (Argon2id) from the username and password, so replicas agree without shared storage and changing either value ends every session. The lifetime is fixed at 24 hours, with no setting.
- Guessing: ten failed sign-ins from one client address (an IPv6 /64) lock it out for up to 15 minutes. Counted in memory, per replica.
- CSRF: besides
SameSite=Strict, the session cookie and the sign-in are refused on requests a browser marks as coming from another origin. - Privileges: a session can do what a managed key with dashboard access and no user path can, so it cannot add secret references while a master key is configured.
- Password storage: plain text in the configuration, like the master key;
${file:...}references work, and an unset${VAR}inadmin.passwordstops startup. There is no hashed-password format. - Sign-ins and sign-outs are recorded in the request log.
New routes, registered only when the login is on: GET, POST and DELETE /admin/session.
Generated by Claude Code
Summary by CodeRabbit
- New Features
- Added optional dashboard sign-in with a username and password alongside API-key authentication.
- Successful sign-in creates a 24-hour browser session for the dashboard and admin endpoints. The dashboard displays the signed-in username and provides a sign-out option.
- Repeated failed sign-in attempts are temporarily blocked. Model API authentication remains unchanged.
- Documentation
- Documented dashboard login configuration, session behavior, security limits, and session endpoints.