Commit Graph

226 Commits

Author SHA1 Message Date
5f8ebab5b2 T13.9 follow-up 2: name PEM keys, forgive missing braces and double encoding, give a length hint (D23) 2026-10-16 16:24:05 -07:00
5cf6355a01 T13.9 follow-up: forgive paste damage in OKTA_SYNC_PRIVATE_KEY and name the failing step (D23) 2026-10-16 16:04:52 -07:00
d137d690f9 T13.9: sign in to the Okta Management API as an OAuth service app, private_key_jwt (D23) 2026-10-16 15:29:32 -07:00
ad1b8273c0 T13.8: run the stack in Docker on a PC, local compose override and steps (D22); log BL-070 2026-10-16 15:08:01 -07:00
bcef0e8145 T13.7: dry run for the Okta sync, OKTA_SYNC_DRY_RUN (D22) 2026-10-16 14:53:05 -07:00
2d4e96d668 T13.6: record full-suite result on the release tree (D18) 2026-10-16 14:17:39 -07:00
493ead725d Release: wave 11 + T13.2-T13.5 (D18 Okta sync), T13.1 held back until T14.1; mobile roadmap docs (BL-062..BL-069) 2026-10-16 14:03:33 -07:00
2abd55c745 T13.4 follow-up: make the sync's log lines visible under gunicorn (D18)
Nothing configures Python logging and gunicorn only configures its own loggers,
so INFO lines from wpsuite.* were dropped: with the production launch command a
healthy start printed no Okta lines, and an operator could not tell the sync was
off from on-and-quiet. okta_sync's logger now has its own stderr handler, only
when the root logger has none. Verified with real gunicorn, 2 workers, with and
without a token. Other modules' output is unchanged.
2026-10-16 13:30:47 -07:00
bbfa403117 D18 docs: admin instructions for accounts the Okta sync disabled (T13.6)
New DEPLOYMENT.md section: how to see what the sync did, how to re-enable a
person (fix Okta first, then Enable in the User Directory), who may do it
(admin; super user only for exclusive-scope accounts), the host CLI when no
admin can sign in, and how to turn the sync off if it disabled the wrong people.
2026-10-16 12:05:03 -07:00
253886923c T13.6 (part): test T13.1's sliding session, and record what it found
T13.1 shipped with its done-when list unchecked and no test of its own. Adds
tests/session_idle_check.py (28 checks): continuous activity survives 30 minutes
but not the ceiling, an idle session gets 401, the cookie is not rewritten per
request, a pre-D18 token still gets a ceiling via iat, identity carries forward,
both variables are documented. Mutation-tested (no throttle, no ceiling, a fresh
ceiling for legacy tokens each fail it).

Notes in wave-13.md: /api/auth/* is exempt from the refresh, and the wave exit
criteria say AUTH_SESSION_HOURS 2 while T13.1 and the code say 8.
2026-10-16 11:41:29 -07:00
763ab8d98d T13.5: verify an auto-disable reads clearly in the admin console (D18)
No UI change. The existing Activity log card already renders a sync disable
legibly: system:okta_sync / user deprovisioned by sync / user / <name> /
okta_status: SUSPENDED|MISSING. tests/okta_sync_ui_check.py runs the real sync
on a throwaway database and reads the real page at 1440px and 390px (28/28):
rows, search, filter, no sideways scroll, no JS errors, and the disabled
account refused on its next request. Does not depend on CR-019's usage card.
2026-10-16 11:36:38 -07:00
f30989d4b8 T13.4: run the Okta sync on a schedule (D18)
A daemon timer thread starts from a new lifespan hook in app.py and calls the
T13.3 sync every OKTA_SYNC_INTERVAL_SECONDS (default 900, minimum 300). With no
OKTA_API_TOKEN it starts nothing and the startup log says so.

The api runs 2 gunicorn workers, so each starts its own timer. A single atomic
conditional UPDATE on one app_settings row (key okta_sync) is the gate: exactly
one worker wins each cycle, on SQLite and Postgres, with no lock held. The row
survives a restart, so a restart inside the interval starts no second run. A
fetch is now capped at 120 s in total, so a run is always shorter than the
minimum interval and cannot overlap the next. No migration needed.

docker-compose.yml passes OKTA_API_TOKEN, OKTA_ORG_URL,
OKTA_SYNC_PROFILE_ATTRIBUTE and OKTA_SYNC_INTERVAL_SECONDS to the api service.

tests/okta_sync_schedule_check.py: 38 checks including an 8-worker race on a
file database (exactly one winner, 16 rounds) and fail-closed through the
scheduled path. okta_auth_check.py still 22/22.
2026-10-16 11:34:13 -07:00
103e4d40ee T13.3: Okta deprovisioning sync job, fail closed (D18)
run_sync() compares the Okta user list (T13.2) to active local accounts and
disables the ones Okta no longer vouches for. One AuditLog row per change,
actor system:okta_sync, action user_deprovisioned_by_sync.

Fail closed: any exception from the fetch, an empty or untrusted answer, or a
failed save changes nothing and writes nothing. The fetch runs before the
database is read, so a failed fetch has no path to a change. It only ever
disables; an already-disabled account is untouched and gets no new row.

Decided with Matt 2026-10-16: disable on missing, SUSPENDED or DEPROVISIONED.
PASSWORD_EXPIRED, LOCKED_OUT and RECOVERY do not disable (the job never
re-enables, so a literal "not ACTIVE" would lock people out for good).
Added a guard: no match between any active local account and any Okta user is
refused as a wrong identity attribute, not read as a mass offboarding.

tests/okta_sync_job_check.py: 71 checks; removing the fail-closed branch and the
guard fails 28 of them. BL-069 logs the missing per-run cap.
2026-10-16 11:31:39 -07:00
2f7de6e33b T13.2: Okta Management API client (D18)
New server/okta_sync.py: lists every Okta user and status with its own
read-only credential (OKTA_API_TOKEN, SSWS), separate from the OIDC client.
Follows pagination. Every failure raises OktaSyncError; an error is never an
empty list, because T13.3 reads an empty list as "nobody is active".

Also refuses: a next-page link to another host (token never leaves the org),
a redirect, a chain over 50 pages (a cut-off list looks like missing users),
a bad item among good ones (never skipped), and an empty list.

tests/okta_sync_check.py: 52 checks, self-contained (httpx MockTransport).
Not wired into app.py yet. T13.3 uses it; T13.4 starts it on a schedule.
2026-10-16 11:28:57 -07:00
d42ae0c65b Merge pull request 'feat/wave-12-bulk-users' (#4) from feat/wave-12-bulk-users into main
Reviewed-on: #4
2026-10-06 22:41:38 +00:00
9fc2d307bb Merge pull request 'feat/wave-16-on-main' (#3) from feat/wave-16-on-main into main
Reviewed-on: #3
2026-10-06 22:40:22 +00:00
e50a05a1e0 T12.6: wave 12 closed - browser_check passes after the re-point
Matt reran tests/browser_check.py on the re-pointed probe: all
passed. Every T12 done-when and every wave 12 exit criterion is now
checked in wave-12.md.
2026-10-06 14:05:43 -07:00
b2b3774dea T16.4: security_check skips the D18 refresh check where D18 is absent
Wave 16 rebuilt on main (feat/wave-16-on-main, 2026-10-06) so it can
ship without wave 11 and T13.1. main has no sliding refresh, so the one
D18 check now runs only when auth.maybe_refresh_token exists; on main
it instead proves a valid token near its expiry is still accepted.
security_check 36/36 on this branch; smoke 27/27.
2026-10-06 13:28:22 -07:00
cfecdca3f7 T16.4: record the production check for D20 (no duplicate complete SOPs)
(cherry picked from commit 2420c73de4)
2026-10-06 13:27:50 -07:00
be3157baf2 T16.4: browser probes pass; cdp.py starts from an elevated shell
files_check.py 36/36 (T16.2), sample_check.py 10/10 and
critical_reopen_check.py 11/11 (T16.3), run on Matt's machine with
Edge 154. T16.2 and T16.3 done; wave 16 verification complete.

tests/cdp.py: every probe first failed 'exited rc=0 without binding
the port'. The shell was elevated; Edge and Chrome de-elevate by
relaunching through Explorer and the relaunch drops the debugging
port ('Edge is running elevated: 1' in the browser log). Adds
--do-not-de-elevate on Windows and a 15 s grace for the port after an
rc=0 exit. Both inert on a normal shell and off Windows.

(cherry picked from commit f752ae3677)
2026-10-06 13:27:50 -07:00
0157b4b325 T16.4: wave 16 verification record
security_check.py 36/36 (da1325c: 20/36, the 16 failures are the
findings). sec_probe.py: only S3 and S12 change. equivalence_check
IDENTICAL vs da1325c (canonical SOP id in the scenario). Smoke test
27/27. pip-audit clean.

Open: files_check.py (T16.2), sample_check.py and
critical_reopen_check.py (T16.3) need a machine with Edge; those two
tasks stay not-done until they pass.

(cherry picked from commit f0750212ca)
2026-10-06 13:27:49 -07:00
c0b736e503 T16.3: D20 one SOP per project
- A SOP posted with no id lands on sop__<project_id>, the id pushSOP
  has always used. Creating (or moving in) a SOP under any other id on
  a project is refused with 400.
- While a project has a complete SOP, writing another complete one
  needs Project Admin (the existing rule only checked the posted row).
- New project_baseline_sop(): canonical row when complete, else the
  latest complete (pre-D20 rows). Used by /api/sops/latest with
  complete=true&project_id, project_summary, project_sop_team and
  project_qa_group, so a rogue row made before the fix cannot stay
  the baseline or the mail routing.
- Existing rows under other ids stay and keep their old rules.

Security review SEC-02 (a project_user took over the baseline and the
PM/CM/QA mail routing with one POST).

security_check.py: 36/36 with D19-D21. Against da1325c: 7 D20 checks
fail (the findings). Smoke test 27/27; seed_demo writes the canonical
id.

(cherry picked from commit 7bd5ab104d)
2026-10-06 13:27:48 -07:00
f4d74879cc T16.2: D19 uploaded files download safely
New server/files_http.py; get_wp_file uses it.
- PDF and raster images (png, jpeg, gif, webp, bmp, avif) open inline,
  as before; Cache-Control unchanged for the offline drawing cache.
- Every other type, SVG included, downloads as an attachment with
  Content-Security-Policy: sandbox; default-src 'none'.
- SVG uploads stay accepted (decided 2026-10-02: accept, download only).
- Content-Disposition: ASCII fallback + RFC 5987 filename*, control
  characters and quotes replaced. nosniff from the API too.

Security review SEC-01 (stored XSS through an SVG drawing) and SEC-15e
(non-Latin-1 names gave 500; CR/LF reached the header).

security_check.py D19: 20/20 total with D21. Against da1325c: 6 fails
(the findings); every inline/cache/access check passes on both.

(cherry picked from commit 14ecb75c88)
2026-10-06 13:27:48 -07:00
d962ab2381 T16.1: D21 session decode fails closed; PyJWT 2.15.1
decode_token treats any decode failure, and any cookie over 4096 chars,
as not signed in, and requires exp and sub. PyJWT 2.13.0 -> 2.15.1
(pip-audit: 13 advisories -> none).

Security review SEC-07: a crafted 1.6 KB cookie with no account gave
500 + stack trace; now 401.

New tests/security_check.py (no browser): D21 section 6/6. Against
da1325c with PyJWT 2.13.0 it fails 3 checks (crafted cookie 500,
token with no exp accepted, old pin) - the findings. The over-long
cookie and the two still-works checks pass on both.
Smoke test 27/27.

(cherry picked from commit 01ce7e941c)
2026-10-06 13:27:47 -07:00
8dd0afaba4 wave 16: planning docs for D19, D20, D21
D19 - uploaded files download safely (SEC-01, SEC-15e)
D20 - one SOP per project (SEC-02)
D21 - session decode fails closed, PyJWT 2.15.1 (SEC-07)

From the security review of 2026-10-01. Decision record and task
breakdown only in this commit - no code yet.

(cherry picked from commit 1c221a122e)
2026-10-06 13:27:46 -07:00
912cf75027 T12.6: browser results, screenshots, browser_check re-pointed
Matt's run (Edge/Chrome, one at a time): bulk_users_ui_check 19/19,
console_dialogs_check 16/16, mobile_check 24/24, a11y_check 22/22.

browser_check 67/71: its four failures asserted column POSITIONS
(9 columns; r.cells[3]/[4] for Permissions/Project role). CR-020's
selection column comes first, so those read Username and Email. The
probe now expects 10 columns with the selection column first, finds
the cells by header name, and checks your own row has no selection
box. Verified on the real page in the DOM harness; rerun to close.

After-screenshots committed in docs/reference/baseline/wave-12/.
BL-061 logged: the pre-existing sync badge covers a control for ~2 s
after load (pointer-events:none, so never blocks a click); belongs
with wave 14's badge work.
2026-10-06 11:18:39 -07:00
d04a0ff414 T12.6: wave 12 verification record, browser probe, BL-060
- tests/bulk_users_ui_check.py (new): selection, keyboard Space on a
  row box, toolbar role change, super-user CSV with good and bad lines,
  add-to-project with a role, typed DELETE, all end to end against a
  real server; 390px bar layout; writes after-screenshots to
  docs/reference/baseline/wave-12/. Needs a browser: to be run on
  Matt's machine.
- tests/cdp.py: --do-not-de-elevate and the rc=0 grace, the same
  change as wave 16 T16.4 (identical content, merges cleanly), so the
  probes start from an elevated shell on this branch too.
- Verification record in wave-12.md: bulk_users_check 61/61 (main
  7/18), single-user routes identical before/after on 16 calls, DOM
  harness 48/48, jsdom against a real server 13/13, smoke 27/27,
  seed_demo OK. Server-checkable done-when boxes ticked; the browser,
  screenshot and full-suite boxes stay open until run on Edge.
- BL-060 logged: a super user's refusal reason promises a project
  access change neither the dialog nor the bulk route allows. Needs
  Nick; not fixed here (scope).
- file-map.md: wave 12's two new checks.
2026-10-06 11:08:03 -07:00
1c4d1bbccb T12.5: CR-020 bulk delete with typed confirmation
'Delete selected…' in the bulk bar. The dialog lists every affected
username (scrolling inside the dialog for a long list), says the
delete cannot be undone and offers disable instead, and sends nothing
until the word DELETE is typed in capitals, whatever the count
(confirmed 2026-10-06). Wrong words keep the dialog open with the
reason; cancel sends nothing.

Your own account cannot be selected; if it ever reached the request,
the server refuses that row and the report names it with the reason.

The bulk delete is a prompt-style dialog, so it is covered in
tests/console_dialogs_check.py (its docstring asks for exactly this):
new section 4 drives it in the browser with native dialogs poisoned.
DOM harness: 48/48.
2026-10-06 11:05:01 -07:00
74d3bc4af7 T12.4: CR-020 CSV upload (usernames only)
POST /api/auth/bulk-users/resolve reads a list of usernames (first
column; comma, semicolon or tab; header skipped) and answers line by
line, the CR-005 validate-and-report pattern. A line is rejected, with
its number and reason, when it names nobody the caller can see ('User
not found', as everywhere else), an account they may not change (the
single route's own reason), their own account, or a username already
listed (duplicate of line N). An email address resolves only when
exactly one account has it. Nothing is changed by this route.

The console's 'Select from CSV' turns the accepted accounts into the
ordinary selection (filter reset so every selected row is visible) and
lists every rejected line. The action, confirm and per-row report are
the checkbox ones, through the same T12.1 routes, which re-check each
row: a CSV cannot reach an account a checkbox could not.
Usernames only, action in the toolbar (decided 2026-10-06). Files over
1 MB are refused before upload; FileReader fallback for browsers
without Blob.text().

bulk_users_check.py: 61/61. DOM harness: 40/40.
2026-10-06 11:04:01 -07:00
681048197a T12.3: CR-020 bulk-action toolbar
Role change, enable/disable, and project add/remove on the selected
rows, wired to the T12.1 endpoints. Delete is T12.5.

- The toolbar offers only what the caller may do: grantable roles,
  managed projects (archived last, marked), grantable per-project roles.
- Every action confirms through wpConfirmDialog naming the exact count
  (and for projects, the project and role) before anything is sent.
- The result lists every failed row with the server's reason, plus the
  changed / already-set counts; a partial failure is a warning, an
  all-failed batch an alert, a server error says nothing was changed.
  Never a blanket success. Announced through the live-region banner.
- The directory reloads afterwards, which clears the selection.

DOM harness (jsdom, real page and scripts, mocked API): 30/30 with
T12.2.
2026-10-06 11:02:09 -07:00
cf46b3ce42 T12.2: CR-020 row selection in the User Directory
- A checkbox per row the caller may change; select-all covers only the
  rows the current filter and search show, and is indeterminate on a
  partial selection.
- Your own row and rows you cannot change show a disabled box whose
  label gives the reason.
- Changing the filter or the search clears the selection and says so
  in a live region (decided 2026-10-06), so no hidden row stays
  selected.
- The bulk bar appears at one or more selected rows and is hidden (out
  of the tab order) at zero. Actions arrive in T12.3.
- Selection is updated in place, not by re-rendering, so focus stays on
  the checkbox just used. One delegated listener; no ids in inline
  handlers.
- The email-width rule now targets td.ell, not nth-child(3), which the
  new column would have shifted.

Checked in a DOM harness (jsdom) against the real page and scripts:
14/14; against main the selection checks fail. Browser probe at
390px/1440px follows in T12.6.
2026-10-06 11:01:02 -07:00
0e79e17a57 T12.1: CR-020 bulk user endpoints
POST /api/auth/bulk-users/{active,role,projects,delete} take a list of
user ids (max 500) and run each row through the same guards and audit
as the single-user route: the rules now live once, in guard_target and
apply_user_{active,role,delete,projects}, which the single-user routes
call too.

- A refused row is reported with its reason; the rest still run; the
  response counts ok / unchanged / failed. Never a blanket success.
- The caller's own account is refused only on its own row.
- One AuditLog row per changed account, same action and shape as the
  single route. A row already in the requested state is 'unchanged'
  and writes no audit row.
- Project assignment is add/remove to ONE project with a per-project
  role (confirmed 2026-10-06); roles on the user's other projects are
  carried over as stored.
- Routes sit under /api/auth/bulk-users/ because /api/auth/users/bulk/
  would match {user_id}='bulk'.

New tests/bulk_users_check.py (no browser): 47/47. Against main: the
7 single-route checks pass, every bulk check fails.
Single-user routes compared before/after on 16 calls (200/400/403/404):
identical responses, audit rows and memberships. Smoke test 27/27.
2026-10-06 10:57:48 -07:00
286e629782 wave 12: plan for CR-020 on a branch from main; details confirmed
Brings docs/waves/wave-12.md and decisions-2026-09-17.md across from
feat/waves-11-13 (planning docs only, no wave 11 or 13 code), so the
PR into main is wave 12 alone.

Confirmed 2026-10-06 by Matt Mabrey: typed DELETE for bulk delete;
project assignment is add/remove per project; changing the filter
clears the selection; the CSV holds usernames only.
2026-10-06 10:53:29 -07:00
da1325c8a1 T11.7: full verification pass - wave 11 closed out 2026-09-24 16:40:03 -07:00
4f3a94bd06 T11.6 follow-up: fix autosave_check.py regression from the retired tracker
Found running the full tests/*_check.py suite as part of a deployability
check on feat/waves-11-13: autosave_check.py's "section 7" asserted that
calling trackStepDwell() still wrote an event into wp-usage.js's
localStorage log (wp_suite_analytics_v1). That assertion predates CR-019
and was checking that the autosave guard hadn't accidentally clobbered
the pre-existing analytics dwell listener - a real concern at the time.

T11.6 (previous commit b2a083a) retired that listener on purpose: track()
is now a documented no-op and wp-usage.js is gone, so the localStorage key
is never written to any more. The test was still asserting the old
behavior, so it now correctly failed (0 -> 0) - this was a gap in T11.6's
own verification (only tests/baseline_shots.py was run for it at the
time; the full suite wasn't).

Fix: rewrote section 7 to check what's actually still true - autosave's
own registration (WPAutosave / sopDraftId), and that the retired
trackStepDwell() is a harmless no-op (exists, doesn't throw) rather than
missing or broken - instead of asserting it still records anywhere.

Verified: tests/autosave_check.py now passes 33/33 (was 33/34, exit 1).
Also ran the complete tests/*_check.py suite (39 scripts) as a
deployability check for the whole feat/waves-11-13 branch:
  - 38/39 exit 0 after this fix
  - token_check.py exits 2 when run with no arguments by design (it needs
    --out or --compare) - a harness-invocation detail, not a test failure;
    already confirmed non-regression in wave 10
  - generalinfo_check.py has one known pre-existing failure (a raw colour
    literal check against html/wp-creation-styles.css, a file untouched by
    any wave 11/13 work) - already diagnosed as pre-existing in wave 10,
    unrelated to CR-019/D18
Also re-verified the usage_events migration (T11.1) round-trips cleanly
on SQLite (upgrade/downgrade/upgrade) and renders clean, valid DDL for
Postgres via `alembic upgrade ... --sql` (TIMESTAMP WITH TIME ZONE / JSON,
no SQLite-only syntax) - no BL-027-class defect.
Backend smoke test (27/27) and seed_demo.py still pass.
2026-09-24 16:38:55 -07:00
2842ec996c Add session notes for 2026-09-23 (CR-019 / D18 work) 2026-09-23 15:06:02 -07:00
b2a083ac7c T11.6: retire the per-browser Usage report (CR-019)
Removes the old "Usage logs" card from admin.html/admin.js (the
usage-admin panel + loadUsage(), D5/T7.10) now that T11.5's real,
server-side Activity & usage card exists and reads real per-user data
instead of per-browser localStorage.

wp-usage.js is deleted outright, along with its three <script> includes
(admin.html, wp-creation-index.html, work-package-suite.html) - it had
no reader left once the panel above it was removed (the "download the
full event log" button lived only in that panel), and per the original
CR-019 decision record it was never reliably tied to a real identity,
so it was never a candidate data source for the new report either.

Its two call sites (wp-creation-app.js, work-package-suite-app.js) keep
a local track() function as a documented no-op rather than having each
of their ~45 individual track('event', ...) call sites deleted one at a
time - that would be a much larger, riskier diff for the same outcome
(no data is recorded either way), and each call site still marks what
was worth recording if usage analytics are ever rebuilt server-side.
work-package-suite-app.js's dwell-timer plumbing (_stepEnter /
trackStepDwell), which only ever fed track(), was left in place for the
same reason: inert, not broken.

Also removes tests/usage_check.py, which tested exactly the retired
feature, and updates its line in docs/reference/file-map.md to point at
the 2026-09-17 decision record instead.

Verified:
  - grep across the whole repo for WPUsage / wp-usage.js / usage-admin /
    usage_check: no live references remain, only explanatory comments
    and planning docs (decisions-2026-09-17.md, wave-11.md) that
    describe the removal itself
  - node --check on all three touched .js files: no syntax errors
  - full backend smoke test (27/27) and seed_demo.py still pass
  - tests/baseline_shots.py --pages admin,creator,sop at 390px/1440px,
    run locally: all three pages render with no new JS errors (the one
    "beforeunload" log line on sop/creator at 1440px is pre-existing
    harness noise from wp-autosave.js's unsaved-work guard, unrelated
    to this change) and no horizontal overflow; refreshed baseline
    screenshots committed alongside this change
2026-09-23 14:46:32 -07:00
0b5ab59518 T11.5: verify Activity & usage card at 390px/1440px 2026-09-23 14:40:30 -07:00
a6c3fbfe50 T11.5: admin console Activity & usage card (CR-019)
New card in admin.html/admin.js, above the old per-browser Usage logs
card (which T11.6 retires next). Filters (date range, project, user,
tool) drive GET /api/usage/summary; two export buttons call
GET /api/usage/export (raw / sanitized) and save the CSV via a Blob,
same download pattern wp-usage.js already uses.

Access: the card lives inside admin.html, already gated admin-only
client-side by gateByRole() (unchanged) - a non-admin never sees the
card. The underlying API is gated server-side by require_user_manager
regardless (admin or project_super_user on >=1 project), independent
of and stricter than the client-side gate, so a non-admin request is
refused even if someone reached the endpoint directly.

Accessibility (C1): every control is a real <input>/<select>/<button>,
keyboard-operable. Status/export banners use the existing '.banner' /
'*-banner' id convention, which console-util.js's MutationObserver
already turns into aria-live (role=status, or role=alert on a '.bad'
banner) - no new announcement plumbing needed. No new CSS: reuses
.toolbar/.banner/.card/.row/.kv/.users, so nothing here adds a second
token source (the token rule).

Verified so far:
  - node --check html/admin.js: no syntax errors
  - every id admin.js's new code references exists in admin.html
    (scripted diff against the full getElementById/id= sets)
  - live-server check: GET /api/usage/summary with the exact
    (possibly-empty) query string _activityFilters() builds returns
    the {active_users, per_user_last_active, by_tool, event_count}
    shape renderActivity() expects; project_id filter narrows
    correctly; GET /api/usage/export?sanitize=true returns
    text/csv with the expected header row
  - full smoke test + seed_demo.py still pass

NOT yet verified: rendering at 390px/1440px with before/after
screenshots (CLAUDE.md verification step). This sandbox has no
headless-capable browser (no chromium/msedge on PATH) and the
playwright/chromium download is blocked by this environment's
network allowlist, so tests/cdp.py's harness can't run here. Deferred
to T11.7, same as wave 10's browser checks — flagging rather than
skipping silently.
2026-09-23 12:31:55 -07:00
2de76d52e6 T11.4: usage export endpoint (raw + sanitized CSV)
CR-019 / wave 11. Adds GET /api/usage/export, reusing _usage_query()'s
scoped filters (from/to/project_id/username/tool) and the same
require_user_manager gate as /api/usage/summary. Two modes:

- raw (default): real usernames, for internal admin use.
- sanitize=true: usernames replaced with an HMAC-SHA256 pseudonym
  (keyed with auth.SECRET_KEY, 16 hex chars, 'u_' prefix) so the file
  can be fed into PowerBI or another external reporting tool without
  carrying real identities. HMAC chosen over a plain hash since the
  username space is small enough to brute-force a bare digest.

Both modes emit at, username, project_id, tool, event as columns and
deliberately omit the detail JSON column in both modes to avoid an
identity leak riding along inside free-form detail data. Response is
returned with a Content-Disposition: attachment header and a filename
that encodes mode + date.

Verified locally against a throwaway SQLite DB with two seeded users
and four seeded UsageEvent rows:
  - raw export contains the real usernames and matches the summary
    endpoint's event_count for the same session state
  - sanitized export contains no real username or email anywhere in
    the file body, across two independently-issued export calls
  - the same real user maps to the same pseudonym both within one
    export and across the two separate export calls
  - raw and sanitized rows line up 1:1 on at/tool/event for the same
    filter set
  - the tool= filter narrows the export the same way it narrows the
    summary
  - a plain project_user is refused with 403; an unauthenticated
    request is refused with 401
  - full smoke test (27/27) and seed_demo.py both still pass
2026-09-23 12:25:05 -07:00
8e863ae7d0 T11.3: usage aggregation endpoint with filters (CR-019)
GET /api/usage/summary: active-user counts by day/week/month, per-user
last-active, per-tool breakdown. Filters (from/to/project_id/username/
tool) combine. Gated by require_user_manager - same boundary as the User
Directory. A project_super_user is scoped to events tied to projects
they manage plus their own activity (managed_project_ids), never another
user's suite-wide activity outside that; an app admin sees everything.

_usage_query() factored out so T11.4's export can never disagree with
what this endpoint counted - same filtered row set, not two derivations.

Verified: admin sees all seeded events; a project_super_user scoped to
one of two projects correctly sees only that project's events plus their
own account-wide activity, and specifically does NOT see the admin's
other-project or no-project activity; date/tool/project filters each
narrow results correctly and combine.
2026-09-23 12:19:14 -07:00
6cde6e3f60 T13.1: idle timeout + absolute ceiling (D18)
Sessions now slide on activity (AUTH_IDLE_MINUTES, default 30) capped by
a hard ceiling from original sign-in (AUTH_SESSION_HOURS, meaning changed,
default 12 -> proposed 8). login_at carried across reissues so the ceiling
survives refreshes; pre-D18 tokens with no login_at fall back to iat.
Refresh is throttled (~IDLE_MINUTES/3) so the cookie isn't rewritten on
every request. Wired into auth_gate (server/app.py) - no DB hit, reads
only the already-validated claims.

Verified: 7 unit-level checks (fresh-token expiry, past-ceiling refusal,
throttling, mid-session extension, legacy-token fallback both live and
expired, idle cutoff itself) all pass, plus the full 27-check smoke
suite still passes end to end through the new middleware path.
2026-09-23 11:40:59 -07:00
358469531c D18: revise T13.1 to idle timeout + absolute ceiling
Matt asked whether idle time would be a better fit than a flat session
length. It is, but idle-alone weakens D18's own purpose - a continuously
active session would never force a fresh Okta recheck on its own. Decided:
both. AUTH_IDLE_MINUTES (new, default 30) slides the session on activity;
AUTH_SESSION_HOURS (existing var, meaning changes to an absolute ceiling,
default 12 -> proposed 8) caps it regardless of activity.

Docs only in this commit - implementation is T13.1, next.
2026-09-23 11:38:37 -07:00
850b78972b T11.2: capture usage events (CR-019)
POST /api/usage/ping writes one page_open UsageEvent per authenticated
page load, identity from the session (get_current_user), never from the
client. Wired from exactly one place - auth-guard.js's proceed(), after
wp-auth-ready - so this can't drift into six separate per-page copies.

okta_callback now also writes one login event per sign-in.

Verified locally: unauthenticated ping -> 401; a real fake-Okta sign-in
writes exactly one login row and one page_open row, no duplicates.
2026-09-23 11:24:49 -07:00
0652fa732d T11.1: UsageEvent model + migration (CR-019)
New usage_events table, separate from audit_log - see the model docstring
for why. Verified: applies and downgrades cleanly on SQLite, and the
postgresql-dialect --sql render has no risky defaults (the BL-027 class
of defect). No app wiring yet - that's T11.2.
2026-09-23 11:23:14 -07:00
75ac930d0c waves 11-13: planning docs for CR-019, CR-020, D18
CR-019 - usage/activity metrics (admin console), wave 11
CR-020 - bulk editing of users, wave 12
D18    - Okta/AD deprovisioning detection and auto-disable, wave 13

Raised by Matt Mabrey 2026-09-17. Decision record and task breakdowns
only in this commit - no feature code yet.
2026-09-18 09:21:29 -07:00
df20b8f18d wave-10: close out claim mapping and redirect URI, live in production
Confirmed by an actual live Okta sign-in after main (cc64c88) deployed: preferred_username is the right identity claim, and the redirect URI works. Matt matched his existing pre-Okta admin account rather than getting JIT-provisioned as a duplicate. Two deploy-time snags recorded, both Case B (config, not data): OKTA_CLIENT_ID/SECRET/ISSUER left empty in Portainer at first (caught cleanly by is_configured()), then OKTA_ISSUER missing its https:// scheme (surfaced as httpx.UnsupportedProtocol, not a deliberate app error - BL-028 still stands). Neither needed the backup. BTG pilot group now includes Cody and Cameron, awaiting Adrian.
2026-09-09 13:34:32 -07:00
cc64c88c3e T10.10: audit manage_users.py promote
cmd_promote() changed a user's role with no audit trail, unlike the
identical change from the web Admin Console (set_user_role() ->
log_event(), action "role_changed"). Not a new privilege - anyone
with container-exec access already has DB access directly, D16's own
trust-tier reasoning - but there was no record of who ran it or what
changed.

Now writes an AuditLog row matching set_user_role()'s shape, tagged
via:cli (mirrors JIT provisioning's via:okta_jit) since a container
shell exec carries no signed-in identity to attribute the change to.

Verified against a scratch SQLite db: audit row lands correctly, role
change persists, the no-such-user refusal still exits 1 clean.
2026-09-03 16:27:13 -07:00
dc13f9b0e3 T10.8: verification (390px/1440px, full suite, per-task done-when)
Walked T10.1-T10.5's claims against the actual code (env vars, routes,
JIT provisioning, the password-removal sweep, login.html) rather than
re-trusting this file's own prose. No drift found.

Full suite via the Docker runner: 39/41 files clean. token_check.py's
exit 2 is a harness mismatch (needs --out/--compare, not a bare run),
not a failure. generalinfo_check.py is 48/49 - the one failure is a
pre-existing rgba() shadow literal from the D11 Micron-assets merge,
confirmed via git show HEAD to predate this wave; logged as BL-031,
not fixed here. okta_auth_check.py re-run fresh: 22/22.

390px/1440px: baseline_shots.py captured all fourteen shots. Visually
confirmed login.html and users.html show the Okta-only sign-in and the
password-free admin UI at both widths.

Wave 10 complete.
2026-09-03 15:22:03 -07:00
d6eae0d846 T10.9: rollback-aware deploy runbook for the Okta cutover
New DEPLOY-runbook-2026-09-03.md, separate from the 2026-08-04 runbook.
Names the five new OKTA_* env vars, treats the pre-deploy backup as the
only way back once 1d60a608bb51 (drop_local_password) commits since its
downgrade() restores the column but not the data, and splits Rollback
into the fixable case (Okta app integration misconfigured, fix and
redeploy api, no data at risk) versus the severe case (abandoning Okta
for local-password code, which only a destructive backup restore can
reach). States D16's no-break-glass posture plainly.

D17 records the decision and why: staged-deploy-sequence docs and
backlog-only were both considered and declined in favor of the runbook.

Logged to backlog.md rather than fixed here: okta_auth.describe() has
no caller (BL-028), users.failed_attempts/locked_until are vestigial
(BL-029), DEPLOY-login-portal.md is fully stale (BL-030).
2026-09-03 14:25:18 -07:00