Skip to content

2.09 Audit Logging and Tamper Evidence: Exit Evidence

Evidence · Step: 2.09 Audit Logging and Tamper Evidence

Step 2.09 Audit Logging and Tamper Evidence
Date 2026-11-15
Database PostgreSQL 18.6 (postgres:18-alpine) in Docker Desktop on Windows 11; postgres:18-alpine on GitHub’s ubuntu-latest in CI
Decision ADR-0018
Result Passed; the chain head is a throughput bottleneck, recorded for step 3.03
Deliverable Where
Hash chain crates/core/src/chain.rs (what is hashed, byte for byte); crates/engine/src/tamper.rs (appending in the posting transaction, verifying)
Checkpoint signer crates/engine/src/signing.rs (Ed25519); record_checkpoint; mezgeb-cli close-period and POST /v1/periods/close sign one at each close
Audit module audit_events and its chain (tamper.rs); the API’s request middleware (crates/api/src/http/middleware.rs); mezgeb-cli client and credential
Verification mezgeb-cli verify --chain [--checkpoints DIR], mezgeb-cli checkpoint export
API Receipts on every entry; GET /v1/keys, GET /v1/checkpoints, GET /v1/audit-events (audit:read)
Schema Migration 0010: entry_chain, audit_events, checkpoints, signing_keys, chain_heads
Documentation db-schema.md, Tamper evidence; the tamper evidence runbook; docs/api/README.md, Tamper evidence

The work arrived in nine pull requests: ADR-0018 (#98), the chain encoding (#99), the engine (#100), the CLI (#101), the API (#102), the benchmark (#103), the Postman collection (#104), the documentation (#105) and this evidence (#106).

Task Done
audit_events: actor, client, action, target, request ID, outcome, before/after for non-ledger config; append-only Migration 0010, hash-chained on its own head. The API records every request that changes something, every 401 and 403, and every read across clients; details hold the status and error code, and before and after for an account’s status. The CLI records every change to clients and credentials with before and after. Append-only by trigger
A hash chain on journal_entries, computed in the posting transaction, the head row locked; contention measured In its own table, entry_chain, so the hash can cover the lines: the posting’s last step locks the head, hashes the entry, its lines and the previous hash, signs the receipt and moves the head. One call site covers postings, reversals, adjustments, refunds and holds. Contention measured below
Daily signed checkpoints At each period close (the daily close), from the CLI or the API: both chains’ heads, signed with Ed25519
mezgeb-cli verify --chain Recomputes both chains, checks every receipt and checkpoint signature, every checkpoint in the database and every copy kept elsewhere

Also, from spec §7.2 and INV-26: a signed receipt per entry, returned by the API and identical on a retry (T-26a, T-26b: a_clean_ledger_verifies_and_every_receipt_is_signed, receipts_and_checkpoints_verify_end_to_end).

Requirement Test Result
Tampering with any entry, line or audit row, as superuser, is detected by the chain verify tampering_with_entries_lines_or_audit_events_is_found: seven attacks, as the superuser with triggers switched off, each on a fresh copy of the same ledger Each found, with its own finding (table below)
Deleting the last entry is detected via the checkpoint deleting_the_last_entry_is_found_by_the_checkpoint: the last entry, its lines, its idempotency record and its link deleted and the head rewound, so the chain itself is consistent Found by the checkpoint in the database; with that checkpoint deleted too, found by the copy kept outside
Posting throughput with and without the chain mezgeb-bench, before (#99) and after (#103), on the same machine The chain halves throughput between uniform accounts (below); recorded for step 3.03
Attack Finding
A line’s amount changed the entry does not match its hash
An entry’s metadata changed the entry does not match its hash
A line moved to another account the entry does not match its hash
A link deleted from the middle links are missing
An audit event’s outcome changed the event was changed
An entry inserted with no link the entry is not in the chain
A receipt signature forged the signature does not verify

The cost of the chain. 16 workers, 1,000 wallets, 2-line entries, 3 runs of 10 seconds each:

Scenario Before (#99) After (#103)
Uniform accounts 135/s, p99 209 ms 71/s, p99 874 ms
One hot account 52/s 41/s

Why. Every posting holds the chain head from its last step to its commit, so commits no longer share a disk flush (group commit). Docker Desktop’s file system makes that flush slow, which makes the serial step long; a server with fast disks loses less. The machine is noisy (both runs fail the benchmark’s 10% spread check), but the size of the drop is clear.

Not fixed here. As the step asks, the bottleneck is recorded for step 3.03: several chains, or chaining in batches.

  • All planted tampering is detected. Every attack above, plus a forged checkpoint caught three ways by hand: its signature, the chain no longer reaching its position, and the copy kept outside.

  • Every API mutation produces an audit event. every_api_mutation_produces_an_audit_event is generated from the contract: each of its 27 write operations is called by a role allowed to make it, and each request’s ID must appear in the audit log. The test then checks, with outcome and details:

    • a deposit, and a refusal by a rule;
    • a missing scope, and a missing token;
    • a status change, with before and after;
    • a token issued, and a wrong secret, which records the credential tried.

    No event contains a secret.

Where the checkpoint is published is decided (ADR). ADR-0018, decided with the maintainer:

  • To clients. GET /v1/checkpoints, each with a one-line text form to keep.
  • To a file. mezgeb-cli checkpoint export writes the files. The runbook has them copied, after every close, somewhere the database’s administrators cannot write.
  • Crashes do not break the chain. A short chaos run through the API, killing PostgreSQL and then the service under load, with signing on, stayed clean: 438 requests, 0 violations. verify --chain on that database was clean too, with 426 entries and 467 audit events.
  • The roles. The service cannot change a link, a checkpoint or a key (append-only triggers), and an audit event can only be added.

The whole suite. On the final main, cargo test --workspace against PostgreSQL ran 43 test binaries and 297 tests, with 0 failures. CI ran the same on every PR, plus the container and the Postman smoke collection, which checks that a posted entry carries a signed receipt.

What tamper evidence does not prove (ADR-0018)

Section titled “What tamper evidence does not prove (ADR-0018)”
  • An entry deleted after the last checkpoint, with the chain rewritten by someone who also holds the signing key, goes unnoticed until clients compare their receipts.
  • A crash between an API write committing and its audit event being written loses that one event; the entry itself is chained.
  • The chain head bottleneck: step 3.03.
  • The signing key in a key service, not a file: step 3.12.
  • Anchoring checkpoints in a public place (a public repository or write-once storage) beyond the operator’s own copies: possible later, as one more export target.