The operator’s answer to “is the audit trail intact?”. It walks every hash-chained table for every organization, reports the first broken link in each chain, and can sign the current chain heads so that history can later be proved unchanged by somebody who does not trust the database.
In the image it is installed as /app/auditctl. For what the chains are and what they prove, see Audit trail.

Synopsis

Environment

The application role sees one organization at a time under row-level security, so with it every chain would read as empty and intact. auditctl checks the role before doing any work and refuses to run as one that cannot read tenant tables.
Keep AUDIT_CHECKPOINT_KEY out of the database, out of the deployment’s environment file and off the database host. Its whole value is that a database administrator does not have it. Pass it for the one invocation that needs it, from wherever you keep the checkpoints.

What it checks

  • SEALED is the number of rows whose digest and link were recomputed and matched.
  • REMOVED counts rows that were deleted lawfully (the retention sweep, or a cascade from a deleted finding, scan or agent) and left a removal record. A gap in a chain with no removal record is reported as a break.
  • UNSEALED counts rows written before the table was chained. They are not covered by the chain. A checkpoint records the count, so the set cannot grow unnoticed.
A broken chain reads BROKEN at row N: <reason> and names the first row that does not verify.

Exit codes

1 and 2 are distinct so that a scheduled job can page on 1 and retry on 2.

Checkpoints

The chains use an unkeyed SHA-256 computed inside the database. Somebody who can disable a trigger can rewrite a chain from any row forward, and verify on its own will pass it. A checkpoint is the control against that.
The file holds the head of every chain (sequence number and digest) and an HMAC-SHA256 over the whole document. Rewriting any row at or below a checkpointed head changes that head’s digest, and producing a checkpoint that matches the rewritten chain needs the key.
checkpoint refuses to sign when any chain is broken: a checkpoint of a tampered chain would anchor the tampering.

What a checkpoint does and does not prove

It proves that history up to the moment it was signed is unchanged, to anybody holding the file and the key. It says nothing about rows written afterwards, so take checkpoints on a schedule (below): the interval is the window in which a rewrite by a database administrator would go undetected. It proves nothing if it is stored where the database administrator can replace it and the key. Store checkpoints off the host.

Scheduled checkpoints

The worker takes checkpoints itself when AUDIT_CHECKPOINT_DIR is set: Each run does what auditctl verify --checkpoint <newest file> followed by auditctl checkpoint would: it verifies every chain, proves history up to the newest checkpoint already in the directory, and only then writes a new one. It writes nothing, and logs periodic task failed with the reason, when a chain is broken, when history below the previous checkpoint changed, or when the previous file does not authenticate with the key (it was edited, or the key changed: move the old files aside to start a new series). It runs as the worker’s own database role, one organization at a time, so it needs no migration-owner credentials. The production Compose file mounts a volume, audit_checkpoints, at /audit-checkpoints in the worker, so AUDIT_CHECKPOINT_DIR=/audit-checkpoints is all it needs there; on Kubernetes, mount a volume yourself and name its path. The trade is that the worker holds the key. A checkpoint still proves nothing until it has left the host, so point the directory at storage the database’s administrators cannot write, or at a directory your off-host backup copies, and verify against those copies. If the key cannot live on the worker’s host, run auditctl checkpoint from another host instead. A lawful removal and a removal by somebody who also forged its removal record look the same to verify. The checkpoint comparison reports how many rows were removed since it was signed, so the number can be compared with what your retention settings would remove.

Run it on a deployment

See also