Skip to content

fix(governance): fail-closed audit for destructive ops (F2) - #88

Merged
sandstream merged 1 commit into
feat/audit-tamper-evidentfrom
fix/governance-audit-failclosed
Jun 24, 2026
Merged

sandstream merged 1 commit into
feat/audit-tamper-evidentfrom
fix/governance-audit-failclosed

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Closes the F2 finding (#81): withGovernance's allow-path was fail-OPEN on audit logging — a destructive op ran (success logged only AFTER execution), so a failed audit append left the op executed-but-unlogged. Only deny paths failed closed, despite the "fails closed" framing.

  • logAuditEvent now returns a boolean (true on local-append success, true when audit disabled, false on write failure). Backward-compatible — existing callers ignore it.
  • withGovernance 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 / disabled). Full suite 1451/0.

⚠️ Stacked on #86 (base = feat/audit-tamper-evident).


Generated by Claude Code

`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.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg
@sandstream
sandstream merged commit 6a60c44 into feat/audit-tamper-evident Jun 24, 2026
2 checks passed
@sandstream
sandstream deleted the fix/governance-audit-failclosed branch June 24, 2026 04:13
sandstream added a commit that referenced this pull request Jun 24, 2026
…#86)

* feat(audit): tamper-evident hash-chained audit log + `kit audit verify`

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

* fix(governance): fail-closed audit for destructive ops (#81 F2) (#88)

`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>

---------

Co-authored-by: Claude <noreply@anthropic.com>
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