Skip to content

feat(audit): add versioned integrity format - #75

Open
P4ST4S wants to merge 1 commit into
feat/audit-operation-lifecyclefrom
feat/audit-integrity-v2
Open

feat(audit): add versioned integrity format#75
P4ST4S wants to merge 1 commit into
feat/audit-operation-lifecyclefrom
feat/audit-integrity-v2

Conversation

@P4ST4S

@P4ST4S P4ST4S commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Summary

Add Integrity v2 as an additive, versioned HMAC-SHA256 format that authenticates the complete critical audit record through RFC 8785 JSON Canonicalization Scheme.

Legacy signature generation and verification remain unchanged so existing audit logs and consumers continue to work.

Context

Closes #73.

Stacked on #74, which introduces audit_operation_id and terminal outcome fields included in the v2 protected payload.

Approach

  • canonicalize an explicit Integrity v2 payload with RFC 8785 JCS
  • protect identity, request, response, error, direction, duration, operation, and outcome fields
  • reject duplicate JSON object keys and unsafe JCS integer values instead of signing ambiguous input
  • store version, algorithm, key ID, and hexadecimal signature in an additive integrity object
  • preserve the legacy signature field set and add legacy verification coverage
  • persist Integrity v2 metadata through JSONL and additive SQLite migration
  • add audit.signing.key_id, defaulting to default

The new github.com/gowebpki/jcs dependency is used because RFC 8785 requires ECMAScript-compatible number serialization, UTF-16 property ordering, duplicate-key rejection, and strict string handling. Reimplementing those security-sensitive rules with encoding/json would not be standards-compliant. The dependency is Apache-2.0, has no runtime dependencies, and supports Go 1.15+.

Test plan

  • go test -race ./internal/audit/... ./internal/proxy/... ./cmd/mcp-audit
  • go test -race ./...
  • go build ./...
  • go vet ./...

All commands pass.

Regression coverage mutates every protected field individually, verifies object-order and whitespace invariance, rejects duplicate keys and unsupported versions, and round-trips metadata through JSONL and SQLite.

Stability impact

Adds the optional integrity audit object and the additive audit.signing.key_id configuration key. Existing audit fields, config keys, and legacy signature semantics are unchanged.

Integrity v2 is itself contract-stable: its algorithm and protected field set are documented in docs/AUDIT_INTEGRITY.md.

Notes for reviewer

This PR intentionally does not fail startup for a missing secret. That behavior remains isolated in the next stacked PR for #67.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 68.49315% with 46 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/mcp-audit/main.go 25.00% 12 Missing ⚠️
internal/audit/integrity/signer.go 75.00% 6 Missing and 6 partials ⚠️
internal/audit/storage/sqlite.go 65.00% 4 Missing and 3 partials ⚠️
internal/audit/signer.go 40.00% 3 Missing and 3 partials ⚠️
internal/audit/logger.go 86.84% 4 Missing and 1 partial ⚠️
internal/audit/integrity/canonical.go 71.42% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

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