Skip to main content

Module audit

Module audit 

Source
Available on crate feature audit only.
Expand description

An audit trail, as a Hook.

A REST service that does not record its authorization decisions is a liability: when someone asks who deleted a row, “the logs” has to be an answer rather than a shrug. This module makes that answer a two-line registration.

It is deliberately not a second interception mechanism. An audit record is exactly an after hook — it observes an operation and its outcome, and cannot change either — so it is built on the same Hooks every other cross-cutting concern uses. Metrics and tracing will be the same shape.

ⓘ
use ash_jsonapi::audit::Audit;
use ash_jsonapi::crud::Validators;
use ash_jsonapi::hook::Hooks;

let hooks = Hooks::new().with(Audit::new(logger));

impl Validators for App {
    fn hooks(&self) -> Option<&Hooks> {
        Some(&self.hooks)
    }
}

§What is recorded

One event per operation, carrying the correlation id, the principal, the resource and operation, and the outcome. The record is written after the operation, so it states what actually happened rather than what was attempted.

Attribute values are never recorded. An audit trail says that alice@example.com updated todo/t_1 and that it succeeded; what she changed it to is the row’s business, and a log that copies request bodies is a second place for personal data to leak from.

Structs§

Audit
Records every operation to an ash-log Logger.