Skip to content

[M2.4a] Scoped audit log reads and JSON Lines export - #123

Merged
samuelmbabhazi merged 5 commits into
mainfrom
feat/m2.4a-audit-query
Nov 5, 2026
Merged

samuelmbabhazi merged 5 commits into
mainfrom
feat/m2.4a-audit-query

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

M2.4a: organization administrators can read and export their audit log.

  • AuditQueries.
    • Both reads recheck the live account (session or scoped token through AccountMutationAuthority.run, with the audit.read command authority) and live audit.read on the organization.
    • page returns 1 to 100 events, newest first, with an exclusive cursor.
    • export returns at most 10,000 events plus a truncated flag.
  • PrismaAuditEventReader. Reads under runTenant, so the M2.3g2 row-level security applies: account and system events and other tenants' events are never returned. Filters are exact action, targetType, targetId and actorId, plus a from (inclusive) and to (exclusive) period.
  • Routes. RequireTenant('audit.read', 'organization') plus AllowApiToken('audit.read'), for SIEM exports with scoped tokens:
    • GET /organizations/{o}/audit-events;
    • GET /organizations/{o}/audit-events/export: application/x-ndjson, Content-Disposition: attachment, X-Shipkeep-Truncated.
  • Query validation. Event-type grammar for action, safe character sets for ids and types, strict ISO 8601 dates.
  • AuditModule. Imports IdentityModule and TenantAccessModule. The SPEC 7 table in the matrix test gains audit.read@organization (owner, admin), and the matrix is regenerated.
  • Docs. The SPEC describes the routes. The PLAN ticks M2.4a and moves the "every command publishes an event" test to a new M2.4c.

Design choices

  • Reads are not audited. SPEC rule 6 covers state changes, and auditing exports would also make the route/role acceptance test's no-write invariant false.
  • Project-level audit reading ("project only" in SPEC 7) needs a project column on audit events, so it is left for later. Today only organization administrators read.

How it was tested

  • New audit-http.integration.spec.ts:
    • only the organization's events, newest first, with no identity.* events and no foreign organization;
    • filters, cursor paging, an empty future period and four invalid queries giving 400;
    • admins allowed; member, project admin, environment admin and outsider get 404;
    • the JSON Lines export works with its headers.
  • The route/role matrix integration test now covers both routes.
  • API (208), web (52) and client tests, builds and the local gate pass.
  • Not run locally: the integration tests (no Docker). They run in CI-1.

Security considerations

Audit data is tenant-confidential, enforced both by the guard and by PostgreSQL row-level security. There is no write path.

@samuelmbabhazi
samuelmbabhazi merged commit 93f35d6 into main Nov 5, 2026
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.4a-audit-query branch November 5, 2026 16:39
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