Repository navigation
feat: implement audit log middleware for MCP servers - #551
Merged
Merged
Conversation
JAORMX
force-pushed
the
feat/audit-log-middleware
branch
2 times, most recently
from
June 2, 2025 13:26
3fb9ca0 to
b4a5330
Compare
Collaborator
|
@JAORMX Do we know if this works out of the box for the Kubernetes Operator? |
Collaborator
Author
It should, but it needs to be explicitly enabled. I'm not happy about the logs being shared with the standard logger. We need to come up with something better. I normally have a dedicated container for these logs, but we can brainstorm a little more about this. |
jhrozek
reviewed
Jun 2, 2025
jhrozek
reviewed
Jun 2, 2025
jhrozek
reviewed
Jun 2, 2025
jhrozek
previously approved these changes
Jun 2, 2025
jhrozek
left a comment
Contributor
There was a problem hiding this comment.
I'm not really familiar with thv code, but the audit part seems quite solid to me (the first thing I went looking after was a timestamp in UTC :-))
- Add comprehensive audit logging package with NIST SP 800-53 compliance - Implement HTTP middleware for capturing audit events - Support MCP-specific event types and metadata - Add flexible configuration with event filtering - Integrate audit middleware into runner middleware chain - Include extensive test coverage (45+ tests) - Support privacy-conscious request/response data capture - Add structured JSON output for log aggregation systems Closes #204
- Reference issue #552 for implementing actual MCP method extraction - Current implementation is a stub that returns empty string - Need to parse JSON-RPC messages to get accurate event types
- Add EventTypeMCPRequest and EventTypeHTTPRequest constants - Update validation function to include fallback event types - Replace hardcoded strings with constants in auditor.go - Addresses PR feedback from jhrozek in #551 Fixes the validation issue where mcp_request and http_request event types were not included in the valid event types list, even though they can be emitted by the middleware.
JAORMX
force-pushed
the
feat/audit-log-middleware
branch
from
June 3, 2025 11:36
b4a5330 to
559ef9c
Compare
jhrozek
approved these changes
Jun 3, 2025
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.
Summary
Implements comprehensive audit logging middleware for MCP servers to provide NIST SP 800-53 compliant audit trails.
Changes
📦 New Audit Package (
pkg/audit/)event.go: NIST SP 800-53 compliant audit event structures (adapted from auditevent library)mcp_events.go: MCP protocol-specific event types and constantsconfig.go: Flexible configuration with event filtering capabilitiesauditor.go: HTTP middleware implementation with comprehensive audit logging🔧 Integration
pkg/runner/config.go: Added audit configuration fields to RunConfigpkg/runner/runner.go: Integrated audit middleware into middleware chain (Auth → Authz → Audit → Handler)✅ Key Features
NIST SP 800-53 Compliance:
Flexible Configuration:
MCP Protocol Support:
🧪 Testing
📋 Configuration Example
{ "enabled": true, "component": "my-mcp-server", "event_types": ["mcp_tool_call", "mcp_resource_read"], "exclude_event_types": ["mcp_ping"], "include_request_data": false, "include_response_data": false, "max_data_size": 2048 }📊 Sample Audit Log Output
{ "metadata": { "auditId": "uuid-here", "extra": { "duration_ms": 45, "transport": "sse", "response_size_bytes": 1024 } }, "type": "mcp_tool_call", "loggedAt": "2025-06-02T14:30:00Z", "source": { "type": "network", "value": "192.168.1.100", "extra": { "user_agent": "Claude/1.0", "request_id": "req-123" } }, "outcome": "success", "subjects": { "user": "john.doe", "user_id": "sub123" }, "component": "my-mcp-server", "target": { "endpoint": "/messages", "method": "POST", "type": "tool" } }Known Issues
Testing
Closes #204