Implement audit logging for security and compliance#310
Draft
Implement audit logging for security and compliance#310
Conversation
Co-authored-by: rrobetti <7221783+rrobetti@users.noreply.github.com>
Co-authored-by: rrobetti <7221783+rrobetti@users.noreply.github.com>
Co-authored-by: rrobetti <7221783+rrobetti@users.noreply.github.com>
Co-authored-by: rrobetti <7221783+rrobetti@users.noreply.github.com>
Co-authored-by: rrobetti <7221783+rrobetti@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add comprehensive audit logging functionality for OJP server
Implement audit logging for security and compliance
Jan 24, 2026
Contributor
|
@copilot produce comprehensive documentation about this implementation. Find appropriated places to do so. |
Co-authored-by: rrobetti <7221783+rrobetti@users.noreply.github.com>
Contributor
Author
I've created comprehensive documentation for the audit logging implementation in commit c493d00: Documentation Added:
The documentation covers configuration, usage, compliance requirements, performance impact, troubleshooting, and integration with monitoring tools. |
Contributor
|
Need to finish review of the code before merging, probably after release 0.4.0-beta. |
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.
Audit Logging Feature Implementation - COMPLETE ✅
Phase 1: Core Audit Infrastructure ✅
org.openjproxy.grpc.server.audit)AuditEvent.java- Event model/enumerationAuditConfiguration.java- Configuration holder for audit settingsAuditLogFormatter.java- Formats audit events consistentlyAuditLogger.java- Core audit logging implementation with async supportPhase 2: Configuration Integration ✅
ServerConfiguration.javaPhase 3: Integration Points ✅
SessionManagerImpl.javafor connection eventsStatementServiceImpl.javafor query eventsIpWhitelistingInterceptor.javafor auth eventsGrpcServer.javaon server startupPhase 4: Testing ✅
Phase 5: Documentation ✅
Phase 6: Build & Verification ✅
Implementation Complete! 🎉
All requirements from the problem statement have been implemented, tested, and documented.
Original prompt
Implement Audit Logging Features
Overview
Implement comprehensive audit logging functionality for the OJP (Open J Proxy) server as described in Chapter 11 - Security, Audit Logging section of the ebook. This feature will provide security and compliance capabilities by logging connections, queries, and authentication events.
Context
OJP is a JDBC Type 3 driver and Layer 7 Proxy Server that acts as an intelligent intermediary between applications and databases. The audit logging feature will track all significant security-related events passing through the proxy to support:
Security monitoring and incident response
Compliance requirements (PCI-DSS, HIPAA, GDPR)
Performance analysis and troubleshooting
Forensic analysis of database access patterns
Requirements
Add support for the following configuration properties (following the existing pattern in ServerConfiguration.java):
Enable/disable audit logging globally
ojp.server.audit.enabled=true
Path to audit log file (supports absolute and relative paths)
ojp.server.audit.log.path=/var/log/ojp/audit.log
Log all connection events (connect, disconnect, connection errors)
ojp.server.audit.log.connections=true
Log all queries (WARNING: High performance impact - use with caution)
Should log: SQL statement, execution time, result set size, parameters
ojp.server.audit.log.queries=false
Log authentication events (login attempts, failures, certificate validation)
ojp.server.audit.log.auth=true
2. Audit Log Format
The audit log should follow a structured format for easy parsing and analysis:
[TIMESTAMP] [LEVEL] [EVENT_TYPE] [SESSION_ID] [CLIENT_IP] [USER] - [MESSAGE] - [METADATA_JSON]
Example log entries:
[2026-01-24T21:25:22.587Z] [INFO] [CONNECTION] [sess-12345] [192.168.1.100] [app-user-1] - Connection established - {"database":"postgresql","host":"db-server-1","port":5432}
[2026-01-24T21:25:23.120Z] [INFO] [AUTH] [sess-12345] [192.168.1.100] [app-user-1] - Authentication successful - {"method":"password","database":"mydb"}
[2026-01-24T21:25:24.567Z] [INFO] [QUERY] [sess-12345] [192.168.1.100] [app-user-1] - Query executed - {"sql":"SELECT * FROM users WHERE id = ?","params":["123"],"executionTimeMs":45,"rowCount":1}
[2026-01-24T21:25:30.890Z] [WARN] [AUTH] [sess-67890] [10.0.0.50] [unknown] - Authentication failed - {"reason":"invalid_credentials","attempts":3}
[2026-01-24T21:26:15.234Z] [INFO] [CONNECTION] [sess-12345] [192.168.1.100] [app-user-1] - Connection closed - {"durationSeconds":53,"queryCount":15}
3. Event Types to Log
CONNECTION Events (when ojp.server.audit.log.connections=true)
Connection Established: Log when a new connection/session is created
Capture: session ID, client IP, target database, timestamp, connection parameters
Connection Closed: Log when a connection/session is terminated
Capture: session ID, duration, number of queries executed, reason (normal/error/timeout)
Connection Error: Log connection failures
Capture: error type, client IP, target database, error message
QUERY Events (when ojp.server.audit.log.queries=true)
Query Executed: Log each SQL statement execution
Capture: session ID, SQL statement, parameters (sanitized), execution time, row count
WARNING: Add prominent logging warning that this has significant performance impact
Consider: Sampling mode (log 1 in N queries) or threshold-based logging (only log slow queries)
Query Error: Log failed query executions
Capture: SQL statement, error message, error code
AUTH Events (when ojp.server.audit.log.auth=true)
Authentication Success: Log successful authentication
Capture: user/principal, authentication method, client IP, timestamp
Authentication Failure: Log failed authentication attempts
Capture: attempted user/principal, failure reason, client IP, timestamp, attempt count
Certificate Validation: Log mTLS certificate validation (when mTLS is enabled)
Capture: certificate subject, issuer, validation result, client IP
4. Implementation Guidelines
4.1 Code Structure
Create a new package: org.openjproxy.grpc.server.audit
Main classes:
AuditLogger.java - Core audit logging implementation
AuditEvent.java - Event model/enumeration
AuditConfiguration.java - Configuration holder for audit settings
AuditLogFormatter.java - Formats audit events consistently
4.2 Integration Points
Integrate audit logging at these key points in the existing codebase:
Session Management (SessionManagerImpl.java)
Log connection established in createSession() or equivalent
Log connection closed in session cleanup/termination
Statement Execution (StatementServiceImpl.java)
Log query execution (when enabled)
Use existing query timing mechanisms if available
Authentication (IP whitelist validation, any auth mechanisms)
Log authentication events in IpWhitelistValidator.java or similar
If mTLS is implemented, add logging there
gRPC Server (GrpcServer.java)
Initialize audit logging system on server startup
Log audit system status (enabled/disabled, configuration)
4.3 P...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.