feat(server): add audit event schema and JSONL sink - #24
Merged
Conversation
The guard hides bugs from the MCP client by design; the audit stream is the operator's own record of what was asked and what the guard decided. This adds the self-contained module: strict TOML configuration (fail mode, fsync, size rotation, suppressed-id elision), the versioned closed-struct JSONL event schema (tool_call / initialize / audit_gap), and an append-only sink with 0600 files, gap records for lost events, torn-line self-healing, and file-order == seq-order under one lock. Wiring into the request path follows separately; nothing is exposed through any MCP surface. examples/audit.toml documents every knob; 28 unit tests pin the wire format, rotation bounds, permissions, gap semantics, and the canary that the Bugzilla API key can never reach a record (I12).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A new self-contained
auditmodule in thebugwardencrate: strict TOML configuration, the versioned closed-struct JSONL event schema (tool_call/initialize/audit_gap), and an append-onlyAuditSink(0600 files, 0700 parent, size rotation, gap records for lost events, torn-line self-healing, file-order == seq-order under one lock). Plus a fully commentedexamples/audit.tomland 28 unit tests. Deliberately not wired into the request path yet — server integration (--audit-config, fail-mode enforcement, per-tool recording) is the next PR, so each stays reviewable on its own.Why
The guard's design goal is that the MCP client cannot tell a hidden bug from a nonexistent one (I2), never sees filtered counts (I3), and never learns rule names (I1). The operator needs exactly that record: what was asked, what the guard decided, and what was withheld. The audit stream carries those server-side-only facts, which is why it goes to an operator-owned local file and is never exposed through any MCP surface, never mixed into stderr diagnostics.
Invariants touched: I12 — the schema has no field that could carry the API key (plus a canary regression test); I1/I2/I3 motivate the boundary (operator file only). Client-visible behavior is unchanged by this PR — nothing is wired.
Verification
cargo fmt --check,cargo clippy --workspace --all-targets --locked -- -D warnings,cargo test --workspace --all-targets --locked(195 → 223 tests),cargo deny check,typos— all green.\nheals the stream after a partial write),rotate_keepcapped at 10000, docs corrected to state exactly what is enforced. The formerly-surviving mutations were then independently re-applied and are now killed (weakened rotation bound → 4 tests fail; zeroed open-time size → dedicated test fails).fsync = truea sync failure after a successful write can leave a duplicate seq on disk and over-report the gap (conservative: over-report, never under-report); at most one torn line per outage, and parsers skip empty lines; exactly one live sink per path (concurrent sinks corrupt rotation).