feat(audit): emit events for export, purge, reindex#179
Conversation
0fad44f to
538cf2b
Compare
|
@smunini please can I get a review? |
|
| Request | Middleware classifies as | Handler checks | Match? |
|---|---|---|---|
DELETE /Patient/123/$purge |
Delete on Patient | Delete | ✅ |
POST /Patient/$purge |
Create on Patient | Delete | ❌ |
POST /Patient/$reindex |
Create on Patient | Update | ❌ |
POST /$reindex (system) |
None ($-prefix skipped) |
Update on * |
Consequences:
-
Over-restriction for narrow scopes. A token scoped exactly to what the handler documents as sufficient —
patient/Patient.dfor purge,.ufor reindex — is blocked by the middleware'sCreatecheck before the handler runs. Only tokens carrying create/writescope get through, so the documented scope requirement isn't what's enforced end-to-end. (Too strict, not too loose — not a security hole, but it'll surprise least-privilege clients.) -
Mislabeled audit trail.
authz_middlewareemits an AuditEvent readingGranted/Forbidden: Create on Patientfor what is really a destructive purge or a reindex — misleading, and especially so in an audit-focused PR. -
Inconsistent enforcement surface. Instance purge is gated correctly at the middleware, type purge/reindex are misgated as
Create, and system reindex isn't gated at the middleware at all — three behaviors for one feature.
Suggested fix — pick one so middleware and handler agree:
- (a) Teach
extract_operation_for_routingto map.../$purge→Deleteand.../$reindex→Update; or - (b) Return
Nonefor these paths (as it already does for$export, batch, and system$-ops) and rely solely on the handler check, dropping the misleading middleware audit event.
Option (b) is most consistent with the existing batch/bulk-export "defer to handler" pattern. Right now it accidentally does neither and lands on Create.
ea83c79 to
4f1cc42
Compare
Went with (b), I made extract_operation return None for any $-op path so it defers to the handler's SmartScopePolicy::check, and my tests show patient/Patient.d now reaches $purge with no misleading Create on event. |
Summary
AuditEventemission for$purge,$reindex, and bulkexport — closing Persistence-layer audit events for bulk export, purge, and reindex #168.
$purgeand$reindexland as new REST handlers backed by anOperationsBundle,while the bulk-export worker now emits worker-complete / cancelled / failed events
at the actual lifecycle boundary instead of leaving them silent.
end-to-end via a new
InMemoryAuditSinktest fixture.Test plan
cargo fmt --all -- --checkcargo clippy --no-depsonhelios-audit,helios-rest,helios-persistence,helios-hfscargo test -p helios-audit -p helios-rest -p helios-persistence -p helios-hfs(1623 pass, 0 fail)hfsbinary withHFS_AUDIT_BACKEND=file,confirming 11 expected
AuditEventrecords emit across $purge, $reindex, and thefull bulk-export lifecycle (including worker-emitted completion)