Demo 17 — `audit-chain` plugin
Demo 17 — audit-chain plugin
Module brief: §Module 17
UVP
Hash-chained tamper-evident audit log. Every record embeds the SHA-256 of the previous; modifying any entry breaks the chain. Real cryptography via
env.sha256_hex(was a placeholder in v0.3.x).
Use cases
- SOC 2 / ISO 27001 evidence. Auditor walks the chain; unbroken = no tampering since boot.
- Forensic incident response. When a breach is suspected, chain breakage points to which records were modified and when.
- Regulatory query log. PCI / HIPAA require immutable query records; hash chain + S3 object lock satisfies both.
What this demo shows
- Run 5 queries — each appends to the chain.
- Dump the chain via
/admin/kv/audit-chain/record:N. - Walk the chain — every
prev_hashmatches the previous record’s SHA-256. - Tamper with
record:2(modifyelapsed_us). - Re-run the verifier → reports broken link at
record:3because itsprev_hashno longer matches the (modified)record:2.
Run it
cd demos/v0.4.0/17-audit-chain./demo.shOutput:
=== audit-chain demo ===[1/5] Running 5 queries[2/5] Dumping chain: seq=0 prev=GENESIS hash=cab07e7b... seq=1 prev=cab07e7b... hash=58df8a91... seq=2 prev=58df8a91... hash=a1c93e7f... seq=3 prev=a1c93e7f... hash=2e8b7d44... seq=4 prev=2e8b7d44... hash=ff301aa2...[3/5] verify_chain → OK (5 records, no broken links)[4/5] Tampering with seq=2 (elapsed_us 100 → 999)[5/5] verify_chain → FAILED at index 3 (prev_hash mismatch)Implementation pointer
HDB-HeliosDB-Proxy-Plugins/audit-chain/src/lib.rs. record_hash
verify_chainare pure functions;build_recordshapes the record from aPostQueryEnvelope. Thesha256_hexhelper delegates toenv.sha256_hexonwasm32(production) and falls back to a deterministic FNV mixer on host targets (so unit tests don’t need wasmtime).
HeliosDB compatibility
Backend-agnostic.