identity_audit_events, a table with three properties most
application tables do not have.
So is every change to the organization’s plan. A subscription bought,
upgraded, downgraded, cancelled or lapsed is recorded as
subscription.changed, with the new plan, its status and the payment
provider, whether the change arrived by the provider’s webhook or by the
hourly reconciliation that catches a webhook that never came. No human acted,
so the actor is system: the trail says the provider reported it rather
than inventing a person. A duplicate or unmatched provider event writes
nothing.
Append-only, at the database level
A trigger rejectsUPDATE unconditionally, and rejects DELETE of any row
whose organization still exists: the one lawful exception is the cascade
that runs when the organization itself is deleted (see
Delete an organization below), which the
trigger recognizes because the parent row is already gone by the time it
fires. This is not enforced by the API or the service layer (those never
expose an edit or delete path either): it is enforced by PostgreSQL itself,
so a bug, a support script or an operator with a psql prompt cannot quietly
rewrite or remove a live tenant’s history.
Hash-chained, so a rewrite is detectable
Each row carrieschain_seq (a per-tenant sequence) and entry_hash, a
SHA-256 digest of the row’s own fields and the previous row’s hash,
computed by the same trigger that enforces append-only. Deleting or editing a
row at the database level (the one thing the trigger cannot see, because it
only fires on INSERT) breaks the chain: every row after the gap no longer
hashes forward correctly, and verification reports exactly where.
auditctl verify.
A break reports ok: false, the sequence number where it broke, and why. The
one lawful way rows leave the chain is organization deletion, which leaves a
tombstone recording how many rows were erased and the chain head at the
moment of erasure: an operator (or an auditor) can tell “erased because the
tenant closed its account” apart from “someone made rows disappear.”
The chain is computed and verified inside the database with an unkeyed
digest: it detects accidental and most unprivileged tampering, but a database
owner able to disable the trigger and recompute every hash could produce an
internally-consistent forged chain that verifies.
The control against that is a signed checkpoint.
auditctl checkpoint exports the head
of every chain, signed with HMAC-SHA256 under a key the database never holds,
and auditctl verify --checkpoint proves that history up to that checkpoint
is what was signed. The worker can take one on a schedule (daily by default)
when you set AUDIT_CHECKPOINT_DIR and AUDIT_CHECKPOINT_KEY
(Scheduled checkpoints); nothing
takes one otherwise, and one kept on the database host beside its key proves
nothing. Without a checkpoint
stored elsewhere, describe the chain as tamper-evident against everything
short of a database owner, not as tamper-proof.
The other chained tables
Four more tables carry the same kind of chain, verified by the same command:
The first three differ from the administrative trail in one way that matters:
rows leave them lawfully. Retention deletes old finding history and agent
actions, deleting a finding or a scan removes its events and verdicts, and
deleting a user or an API key clears the actor column that named it. So:
- A deleted row leaves a removal record holding its sequence number and digest, when it was removed, and whether the retention sweep removed it. Verification accepts a gap only when every missing row has one.
- An actor or scan reference is sealed as a digest. Verification accepts the original value or an empty one (the referent was deleted), never a different one: attribution can be lost, it cannot be reassigned.
auditctl counts
them, and they are outside what the chain proves.
When an action is refused because it cannot be recorded
Most audit writes are best effort: the action happens, and a failure to record it is logged at error level and counted in thetrustowl_audit_write_failures_total metric. That is deliberate for anything
that removes access. An audit outage must never be the reason a revoked
key keeps working or a departed member keeps their seat.
Four actions fail closed instead. They hand out a standing credential or
somebody else’s data, and they can be refused without leaving anything
half-done:
The response is
503 with "code": "audit_unavailable". Nothing was changed
and the request is safe to retry.
Changes made in place (a role, an identity provider, a policy) are still best
effort. The change and its audit entry are not yet written in one transaction,
so refusing after the fact would report a failure for a change that had
happened. Alert on the metric above to catch a gap.
What every row carries
Action, resource, and actor, attributed three ways at once when it applies: the human who delegated (actor_user_id), the non-human principal
that acted (actor_workload_id), and the process name, so “a workload acted
under this person’s authority” is one row, not two that have to be joined by
guessing. And where it came from: the client address (as
TRUSTED_PROXIES resolves it, see Deployment),
the User-Agent, and the request ID that joins the row to the access log.
Retention
Audit rows are never deleted by the retention job, at any age, regardless of plan.finding history and usage metering expire on a plan’s window;
identity_audit_events does not (finding history and agent actions that
expire leave a removal record, see above), because the schema’s append-only trigger
would refuse the delete in any case, and because a compliance evidence trail
that quietly aged out would be a second, worse surprise. There is currently
no separate configurable retention window for the audit trail beyond “kept
for the life of the tenant”. If your framework requires a documented,
shorter retention with destruction, that is a data-handling policy to state
in your own documentation, not a knob TRUSTIVAN exposes today.
Getting it out: pull, or subscribe
Pull.GET /api/v1/audit/export?format=jsonl|csv streams the trail,
filtered by since/until, with the chain verified fail-closed before
the first byte is written: if verification cannot complete, the export is
refused rather than shipped with an unverified chain header. Requires
identity:read and the audit_export entitlement. See
API reference.
Subscribe. audit.recorded is a webhook event (see
Webhooks) that fires once per appended row, for a
SIEM or log pipeline that wants the trail pushed rather than polled. It uses
the same entitlement as the pull export, and it is deliberately narrower:
no actor identity (only a kind: user, api_key, workload, system,
scim, idp or staff), and none of the row’s free-form detail/before/after fields,
which have carried policy bodies and credential names. What travels is enough
to correlate “what happened, from where, and does it match this access-log
line”. A receiver that needs the acting identity for one event pulls that
row from the export using the delivery’s chain_seq.
See also
- Compliance evidence: the audit trail is one of the capabilities several framework controls cite as evidence.
- Webhooks
- Delete an organization: what happens to the trail when a tenant is erased.