Skip to content

feat(audit): coverage policy, space-scoped visibility, retention enforcement (#151) - #155

Draft
LeoStehlik wants to merge 1 commit into
masterfrom
audit/151-audit-review
Draft

LeoStehlik wants to merge 1 commit into
masterfrom
audit/151-audit-review

Conversation

@LeoStehlik

@LeoStehlik LeoStehlik commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Review status: held from deployment. The proposed automatic deletion of audit records is outside this data-preserving update. Space-scoped queries must honour restricted-page access before expanding audit visibility. Missing event coverage and fire-and-forget delivery also remain unresolved; #151 must stay open.

Refs #151 (audit-log reliability and access scoping; incomplete)

Kept separate from the smaller #148/#149/#150 fixes as requested. This is the reliability + server-side-scoping subset of the broader #151 review; the full coverage matrix and recording policy are documented so the log is never mistaken for a complete activity record.

What changed

  • Coverage matrix & policy — new docs/audit-coverage.md: per-action recording matrix across UI/API/MCP/background paths, explicit policy for reads / exports / denied attempts / failures, reliability model, and an explicit list of remaining gaps.
  • Server-side visibility scoping (core/audit):
    • Workspace owners/admins keep workspace-wide access.
    • Space administrators (direct or via group) now see only events whose spaceId is a space they administer — enforced inside the SQL query, so filters, pagination cursors and a chosen spaceId can never widen the scope; a spaceId outside scope is rejected. Workspace-level events (no spaceId) are excluded from space scope.
    • Everyone else gets 403. The actor join is constrained to the event's workspace.
    • New POST /audit/access returns the server's decision; the client sidebar shows the Audit log entry from that response instead of a client-side role guess.
  • Actor accuracy: public login routes now set the audit actor explicitly, so user.login no longer stores a NULL actor.
  • Retention: workspaces.auditRetentionDays is now enforced by a daily cleanup job (previously stored/displayed but never applied → unbounded table). Added a (workspace_id, created_at desc) index to support the deletes and time filters. Retention changes are themselves audited (audit.retention_updated).
  • Reliability visibility: DatabaseAuditService logs a warning when an event is dropped for missing request context instead of dropping silently.

Tests

  • New specs: visibility resolution (workspace / space / none), query always workspace-constrained, space scope applied with other filters, out-of-scope spaceId rejected, retention cleanup honours per-workspace days and skips unset, DatabaseAuditService context/exclusion/drop-warning behaviour, login sets actor. Full server suite: 33 suites / 235 tests pass; server tsc clean.
  • Browser E2E on a disposable stack with three users:
    • Space admin (Francis): sees his space's activity, blind to another space's activity and to workspace-level events.
    • Ordinary member: no Audit nav entry, no rows (403).
    • Workspace owner (Leo): sees everything.

Remaining limitations (documented in docs/audit-coverage.md, not closed here)

Denied attempts other than MFA challenges, failed logins, human collab edits, scheduled trash purge, zip-import per-page outcomes, AI admin and untracked settings changes are not recorded; reads are excluded by policy; HTTP-path writes are fire-and-forget with no retry/outbox; ipAddress is header-derived. These are listed explicitly rather than presented as covered.

No cross-workspace disclosure was established before this change; the scoping above is a hardening requirement from #151, now enforced server-side and tested.

…rcement

Audit-log reliability review for #151:

- Publish docs/audit-coverage.md: coverage matrix across UI/API/MCP/
  background paths, explicit policy for reads, exports, denied attempts
  and failures, reliability model and remaining limitations.
- Enforce audit visibility server-side: workspace owners/admins keep
  workspace-wide access; space administrators (direct or via group) now
  see only events scoped to spaces they administer, applied inside the
  SQL query so filters, pagination and spaceId selection cannot widen
  the scope; everyone else is rejected. Actor join is constrained to
  the event workspace.
- Add POST /audit/access so the client shows the Audit log entry based
  on the server-side decision instead of a client role guess.
- Record the actual actor on public login routes (user.login previously
  stored a NULL actor).
- Record audit.retention_updated when retention changes.
- Enforce workspaces.auditRetentionDays with a daily cleanup job and a
  (workspace_id, created_at) index; previously the setting was stored
  but never applied.
- DatabaseAuditService logs a warning when an event is dropped for
  missing request context instead of dropping it silently.

Refs #151

Signed-off-by: Leo Stehlik <[email protected]>
@LeoStehlik
LeoStehlik marked this pull request as draft November 21, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant