Phase 1: identity, sessions, audit, frontend shell

AD sign-in over LDAPS (search with the service account, bind as the user,
nested groups through LDAP_MATCHING_RULE_IN_CHAIN, disabled accounts refused),
roles as the union of PS-* groups mapped by a table derived from the seeded
departments. Server-side sessions with idle, lock and absolute timeouts, Origin
and X-Requested-With check, step-up unlock. Optional Argon2id PIN set with the
domain password; PIN sign-in by employee ID on registered devices only; five
wrong attempts disable the PIN, three wrong at unlock or signature end the
session. Rate limits per account and per address before any bind. Devices,
signatures table and sign helper, audit rows for every identity event, SSE over
LISTEN/NOTIFY with presence. Account settings and Admin APIs and screens
(AD view, devices, PIN clearing, group map with missing-group flags, refresh
from AD now). CLI ad-groups --list and ad-refresh. Migration 0002.

Frontend: real sign-in (password tab, PIN keypad on registered devices), lock
screen, role switcher, Account settings, Admin shell, screen placeholders.

CI: Samba AD DC container (PSTEST.LOCAL) with a generated CA, 49 of the 50
groups plus one extra, 17 test users; wired into the CI compose overlay and
the Gitea workflow; Playwright sign-in scenario.

Verified on docker-1: 171 server tests green inside the CI stack against
PostgreSQL and the Samba DC, 48 frontend tests, 8 Playwright scenarios against
the live stack (password and PIN sign-in, lock and unlock, Admin group map).
Findings recorded in the docs: the DC needs CAP_SYS_ADMIN, a hidden tab locks
only after a minute as the old build did,
and the app uses the alias ps-app for Playwright because "app" is on
Chromium's HSTS preload list.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
2026-10-16 07:40:29 -06:00
co-authored by Claude Fable 5.1
parent 0b663bb2b2
commit 97b0973130
95 changed files with 9609 additions and 183 deletions
+65
View File
@@ -0,0 +1,65 @@
// Typed calls for the phase 1 endpoints. Paths and shapes follow the design contract.
import { api } from "../api/client";
import type {
AccessLogRow,
AccountInfo,
AdLookup,
AdRefreshResult,
AdminDevice,
AdminUser,
AdminUserDetail,
AuthContextInfo,
Department,
DeviceRef,
Factor,
GroupMap,
Me,
PinState,
SessionRow,
SigninAttempt,
} from "./types";
const enc = encodeURIComponent;
export const authApi = {
context: (signal?: AbortSignal) => api.get<AuthContextInfo>("/api/auth/context", signal),
me: (signal?: AbortSignal) => api.get<Me>("/api/auth/me", signal),
signInPassword: (login: string, password: string) =>
api.post<Me>("/api/auth/signin/password", { login, password }),
signInPin: (emp_no: string, pin: string) => api.post<Me>("/api/auth/signin/pin", { emp_no, pin }),
signOut: () => api.post<null>("/api/auth/signout"),
lock: () => api.post<null>("/api/auth/lock"),
visibility: (hidden: boolean) => api.post<null>("/api/auth/visibility", { hidden }),
unlock: (factor: Factor, secret: string) => api.post<Me>("/api/auth/unlock", { factor, secret }),
};
export const accountApi = {
get: (signal?: AbortSignal) => api.get<AccountInfo>("/api/account", signal),
setPin: (password: string, pin: string) =>
api.post<{ pin: PinState }>("/api/account/pin", { password, pin }),
sessions: (signal?: AbortSignal) => api.get<SessionRow[]>("/api/account/sessions", signal),
signOutOthers: () => api.post<{ revoked: number }>("/api/account/sessions/signout-others"),
accessLog: (limit = 50, signal?: AbortSignal) =>
api.get<AccessLogRow[]>(`/api/account/access-log?limit=${limit}`, signal),
registerDevice: (name: string) => api.post<{ device: DeviceRef }>("/api/account/device", { name }),
};
export const adminApi = {
users: (q: string, signal?: AbortSignal) =>
api.get<AdminUser[]>(q ? `/api/admin/users?q=${enc(q)}` : "/api/admin/users", signal),
user: (id: string, signal?: AbortSignal) => api.get<AdminUserDetail>(`/api/admin/users/${enc(id)}`, signal),
lookup: (login: string, signal?: AbortSignal) =>
api.get<AdLookup>(`/api/admin/ad/lookup?login=${enc(login)}`, signal),
clearPin: (id: string, reason: string) =>
api.delWithBody<null>(`/api/admin/users/${enc(id)}/pin`, { reason }),
devices: (signal?: AbortSignal) => api.get<AdminDevice[]>("/api/admin/devices", signal),
revokeDevice: (id: string) => api.del<null>(`/api/admin/devices/${enc(id)}`),
groups: (signal?: AbortSignal) => api.get<GroupMap>("/api/admin/groups", signal),
refresh: () => api.post<AdRefreshResult>("/api/admin/ad/refresh"),
signinAttempts: (limit = 100, signal?: AbortSignal) =>
api.get<SigninAttempt[]>(`/api/admin/signin-attempts?limit=${limit}`, signal),
};
export const departmentsApi = {
list: (signal?: AbortSignal) => api.get<Department[]>("/api/departments", signal),
};