Skip to content

Milestone 1: first-run setup, administrator accounts, sessions, and password recovery #4

Closed

Description

@TusanHomichi

Problem or outcome

The operable shell (#2, PR #1) serves health but has no way to initialize an installation or authenticate anyone. Implement the Milestone 1 authentication scope from docs/architecture.md: first-run setup with a short-lived setup code, local administrator creation in a single transaction, Argon2id password hashes, opaque server-side sessions in HttpOnly cookies, administrator-issued password reset codes, and sole-administrator recovery via OS access to the data directory. No email, no OIDC, no external services.

Scope

In scope:

  • Migration 0002: agency (single row), user, capability_grant, session, setup_code, password_reset_code, audit_event (append-only, trigger-enforced)
  • Capability-based authorization from the start (manage_users gates user administration); the Administrator role is a named grant bundle, per the domain model — no role-name comparisons
  • Setup: uninitialized installations emit a hashed, short-lived setup code at serve startup (plus a setup-code command); POST /api/setup creates agency settings + first administrator + grants and consumes the code in one transaction; setup is unavailable after initialization
  • Sessions: POST /api/auth/login, POST /api/auth/logout, GET /api/auth/session; cryptographically random opaque tokens stored hashed at rest, HttpOnly + SameSite cookies, expiration and immediate revocation
  • Reset: POST /api/auth/reset-codes (requires manage_users) issues a short-lived single-use code; POST /api/auth/reset forces a new password, revokes all sessions, and records an audit event
  • Recovery: consolebook recover --username ... (OS access to the data directory) issues a reset code for an administrator and records an explicit recovery audit event
  • Audit events for authentication actions (login, logout, setup, reset issued/used, recovery), content-free per the logging rule
  • ADR 0004 documenting the authentication decisions
  • Integration tests for every flow, including failure paths

Out of scope:

  • SvelteKit shell (separate slice)
  • OIDC, SMTP (held until justified per roadmap)
  • Coordinator/Trainer/Trainee capabilities beyond schema support (Milestone 3)
  • Rate limiting / lockout policy (needs its own decision; noted in ADR)

Acceptance criteria

  • An empty installation initializes end-to-end: setup code → POST /api/setup → login → authenticated session
  • Setup code is single-use, expires, and is refused after initialization
  • Session tokens are opaque, hashed at rest, expire, and revoke immediately on logout and password reset
  • Reset codes are single-use, short-lived, admin-issued (capability-checked), and using one revokes all sessions
  • recover works without any valid credentials but requires data-directory access, and records an audit event
  • audit_event rejects UPDATE and DELETE at the database level
  • All repository gates pass

Expected proof

  • cargo fmt --check && cargo clippy --workspace --all-targets -- -D warnings && cargo test --workspace
  • pr-gate green on the PR

Related roadmap, decisions, or issues

Activity

  1. added a commit that references this issue on Aug 28, 2026
    a412173
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions