Uh oh!
There was an error while loading. Please reload this page.
auth(setup): first-run setup, sessions, and password recovery - #5
Merged
Conversation
Implement the Milestone 1 authentication scope (docs/architecture.md): - migration 0002: agency, user, capability_grant, session, setup_code, password_reset_code, and audit_event (append-only via triggers) - capability-based authorization from the start; the Administrator role is a grant bundle applied at creation, never a name checked at decision time - first-run setup: short-lived hashed setup code emitted by serve and the setup-code command; POST /api/setup creates agency, first administrator, and grants and consumes the code in one transaction; unavailable after initialization - sessions: 256-bit opaque tokens stored as SHA-256 digests, HttpOnly SameSite=Strict cookies, 12-hour absolute expiry, immediate revocation on logout and password reset; login timing equalized for unknown usernames and failure responses identical - passwords: Argon2id PHC strings, 12-512 byte policy shared by setup and reset - reset: manage_users-gated code issuance over the API; using a code rotates the password, revokes all sessions, and audits, atomically - recovery: consolebook recover --username issues a reset code for an administrator with OS access to the data directory only, refusing non-administrator targets, with a distinct audit event - doctor reports initialization state and administrator count - 15 new integration tests covering the flows and their failure paths - ADR 0004 records the decisions and the deliberate gaps (no rate limiting yet, Secure cookie flag deferred to deployment hardening) Closes#4
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Primary Issue
Closes#4
Problem And Outcome
The operable shell had no way to initialize an installation or authenticate anyone. After merge, an empty installation completes the full Milestone 1 authentication lifecycle with no external services: setup code → first administrator → cookie session → administrator-issued reset → offline sole-administrator recovery.
Changes
agency,user,capability_grant,session,setup_code,password_reset_code,audit_event(append-only, enforced by database triggers)manage_usersgates reset-code issuance; the Administrator role is a grant bundle applied at creation (manage_users,manage_programs,assign_training,export_records), never a name compared at decision timeserveon start and byconsolebook setup-code;POST /api/setupcreates agency + administrator + grants and consumes the code in one transaction; 409 after initializationHttpOnlySameSite=Strictcookies, 12-hour absolute expiry, immediate revocation on logout and reset; login timing equalized against a dummy hash and identical failure bodies so responses don't reveal account existencePOST /api/auth/reset-codes(capability-checked) →POST /api/auth/resetrotates the password, marks the code used, revokes all sessions, and audits — one transactionconsolebook recover --username ...requires OS access to the data directory, refuses non-administrator targets, records a distinct audit eventdoctornow reports initialization state and administrator countSecurecookie flag deferred to deployment hardening — both flagged for pre-pilot work)Scope
Verification
Review And Merge Notes
setup.rs/users.rs(atomicity claims), and ADR 0004's deliberate gapssetup-code,recover)