Skip to content

feat(audit): tamper-evident hash-chained audit log + kit audit verify - #86

Merged
sandstream merged 2 commits into
mainfrom
feat/audit-tamper-evident
Jun 24, 2026
Merged

sandstream merged 2 commits into
mainfrom
feat/audit-tamper-evident

Conversation

@sandstream

Copy link
Copy Markdown
Owner

No-egress roadmap (#80): tamper-evident audit trail.

The audit log was plain JSONL — entries could be altered/deleted/reordered undetectably. Now hash-chained:

  • Each line carries prev (previous hash) + hash (sha256 over the canonical pre-hash JSON). Both append paths use it.
  • verifyAuditChain() (pure, tested) reports the first break — content tamper (hash mismatch) or insert/delete/reorder (prev-link mismatch) — with index.
  • kit audit verify surfaces it (green intact / red BROKEN at N).

Full suite: 1448 pass / 0 fail (audit format gained prev/hash; consumers read by field, unaffected). Cross-process concurrent appends can fork the chain (external tampering still detected); syslog/CEF export is a follow-up. Independent of the air-gap stack (#73/#83/#84/#85).


Generated by Claude Code

The audit log was a plain JSONL append — an attacker (or a careless edit) could
alter, delete, or reorder entries undetectably. For a regulated/air-gapped
enclave the audit trail must be tamper-evident.

- Each appended line now carries `prev` (previous line's hash) and `hash`
  (sha256 over the line's canonical pre-hash JSON), forming a hash chain.
  Both append paths (`appendAuditEventDirect`, `logAuditEvent`) use it.
- `verifyAuditChain()` (pure, exported) re-walks the chain and reports the first
  break: content tamper (hash mismatch) or insertion/deletion/reorder (prev-link
  mismatch), with the 0-based index.
- `kit audit verify` surfaces it on the CLI (green intact / red BROKEN at N).

Tests cover a verified chain, tampered content, a deleted entry, and a legacy
unchained entry. Note: cross-process concurrent appends can fork the chain;
external tampering is still detected. Syslog/CEF export for SIEM is a follow-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

`withGovernance`'s allow-path was fail-OPEN on audit logging: a destructive op
ran (and its success was logged AFTER execution), so if the audit append failed
the op still executed — unlogged. Only the deny paths failed closed, despite the
"fails closed" framing.

- `logAuditEvent` now returns a boolean (true when the local append succeeded,
  true when audit is disabled, false on write failure). Backward-compatible —
  existing callers ignore it.
- `withGovernance` now persists an "authorized" audit entry BEFORE executing a
  `context.destructive` op and refuses (throws fail-closed) if it can't be
  written. Non-destructive ops keep best-effort logging.

Tests cover logAuditEvent's return (success / unwritable path / disabled). Full
suite 1451/0. Stacked on the audit hash-chain branch.


Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg

Co-authored-by: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit 0e444b8 into main Jun 24, 2026
15 checks passed
@sandstream
sandstream deleted the feat/audit-tamper-evident branch June 24, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants