feat(audit): record entity mutations + auth events (PMS-117) #70

Merged
vas2000-work merged 2 commits from feat/pms-117-audit-log into main 2026-06-05 04:12:26 +02:00
Owner

Implements PMS-117. In-transaction audit_write (before/after via to_jsonb, secrets stripped) + AuditCtx extractor + audit_auth_event. Instrumented contacts/tickets/tenants/credential-vault/user-CRUD + auth login/logout/failed-login. Read API admin-only, tenant-scoped, append-only; 24-month retention documented. tests/audit.rs 4/4 green; no regressions. Billing/contracts audit hooks land in PMS-33/PMS-64.

Implements PMS-117. In-transaction audit_write (before/after via to_jsonb, secrets stripped) + AuditCtx extractor + audit_auth_event. Instrumented contacts/tickets/tenants/credential-vault/user-CRUD + auth login/logout/failed-login. Read API admin-only, tenant-scoped, append-only; 24-month retention documented. tests/audit.rs 4/4 green; no regressions. Billing/contracts audit hooks land in PMS-33/PMS-64.
feat(audit): record entity mutations + auth events in the audit log
All checks were successful
Build OCI container / Build and push mokosh-api image (push) Successful in 3m6s
Check / fmt + clippy + compile + tests (pull_request) Successful in 4m52s
708d32239c
PMS-117: turn the audit_log table into a real, queryable trail. Adds an in-transaction write path so a mutation and its audit row commit or roll back together, capturing actor, ip, user-agent and full before/after JSONB snapshots of the changed row.

New shared helper `audit_write` (generic PgExecutor, so callers pass `&mut *tx`) plus an `AuditCtx` request extractor and an `audit_auth_event` wrapper, all in `src/modules/audit/context.rs`. Row snapshots use Postgres `to_jsonb(t)`; secret columns (credential_vault encrypted blobs, users password_hash/mfa_secret) are stripped from snapshots.

Instrumented mutations: contacts (companies/contacts/sites), tickets, tenants, credential vault, and admin user create/update. Auth records login, logout, and failed-password attempts. The read API (`GET /api/v1/audit-log`) stays admin-only, tenant-scoped, paginated and filterable; it is append-only (no update/delete route) and the module documents a 24-month retention policy.

Integration tests in tests/audit.rs cover the in-transaction before/after write, tenant-scoped reads (cross-tenant rows are not visible), admin-only access, and the login event.

#PMS-117

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Merge remote-tracking branch 'origin/main' into feat/pms-117-audit-log
All checks were successful
Check / fmt + clippy + compile + tests (pull_request) Successful in 2m45s
Build OCI container / Build and push mokosh-api image (push) Successful in 7m43s
Create release / Create release from merged PR (pull_request) Has been skipped
f7f08c1304
# Conflicts:
#	src/modules/contacts/service.rs
vas2000-work deleted branch feat/pms-117-audit-log 2026-06-05 04:12:26 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/mokosh-server!70
No description provided.