mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-06 04:14:15 +00:00
Storage step of the multi-user work in #790 (phase 2a). Migration 0029_users.sql adds three tables: - users: case-insensitive unique username, display name, optional email, optional bcrypt hash (SSO-only users have none), account source (local now; oidc, saml, ldap, scim later), break-glass flag (local accounts only), disabled, login and update times. - user_identities: links a subject at an identity provider to one user, unique on (provider_id, subject). An identity is never linked by matching email or username. - user_sessions: one row per token id (jti) with expiry, last use, revocation, user agent and client address. The migration seeds the existing ARTEX account as the break-glass local user, so later changes have a row to point to. It does not copy the password hash: login still reads the auth.password_hash setting, and a copy would go stale when the password changes. The change that moves login onto these tables moves the hash with it. An existing ARTEX row is left unchanged. Every CHECK constraint is named, so a later migration can alter it by name. Usernames are at most 128 characters without control characters. Only a local account can have a password (users_password_local_only), so an account from an identity provider cannot gain a second way in. The session user agent is at most 512 bytes and the client address 64; the address is TEXT because the peer is not always an IP address. db/users.go adds the store functions later phases need: create and look up users, set a password, disable a user (which also revokes its sessions), link and resolve identities, and create, read, touch and revoke sessions and delete expired ones. The Go side applies the same limits first (ErrUserInvalid; user agent and address are cut). A session is created only for an existing, enabled user (ErrUserDisabled), is not active and cannot be touched while its user is disabled, and a missing row means no session. DisableUser refuses the last enabled break-glass user (ErrLastBreakGlass), locking the break-glass rows so two concurrent calls cannot disable the last two. Expired sessions are deleted by the database clock, as TouchSession checks expiry. Nothing reads these tables yet. Login still uses the single ARTEX account and the setting, so behaviour does not change.