feat(audit): implement audit logging functionality with middleware#88
Open
romariohornburg wants to merge 3 commits intogrid-labs-tech:mainfrom
Open
feat(audit): implement audit logging functionality with middleware#88romariohornburg wants to merge 3 commits intogrid-labs-tech:mainfrom
romariohornburg wants to merge 3 commits intogrid-labs-tech:mainfrom
Conversation
…d configuration options - Added audit logging middleware to the FastAPI application, activated based on configuration. - Enhanced user and token handling in authentication to include audit actor information. - Updated webapp and worker command execution endpoints to capture and log execution details. - Introduced environment variables for audit logging configuration in Docker setup.
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 Logs Implementation (Closes #82)
Summary
This PR implements headless, asynchronous audit logging across the Tron platform. It captures structured events for every significant request and exports them directly to external SIEMs (Elasticsearch, Splunk, Datadog) via HTTP. The design is fail-open and configured exclusively via environment variables (no UI).
Audit Event Structure
Each log entry contains:
anonymousinstances/abc-123,organizations/xyz/members)X-Forwarded-Forbehind proxies)For EXEC events (pod command execution), the following are also included:
Architecture
asyncio.create_task()(non-blocking)request.state.audit_actoron successful authenticationFile Structure
Configuration
Environment variables (add to
.env):AUDIT_LOG_ENABLED(default:false) – enables/disables audit loggingAUDIT_SIEM_URL– SIEM endpoint URL (e.g.,https://logs.example.com/ingest)AUDIT_SIEM_TOKEN(optional) – Bearer token for authenticationAUDIT_SIEM_TIMEOUT(default:5) – HTTP timeout in secondsThe middleware is only registered when
AUDIT_LOG_ENABLED=trueandAUDIT_SIEM_URLis set.Changes
AuditMiddlewareto capture request/response metadataaudit_exec_payloadwith command and outputdocker-compose.yamlto pass audit env vars to the API containerdocker/.env.examplewith audit variablesTests
audit_config,audit_event, andaudit_sender(including fail-open behavior)pytest tests/unitif you want it exact)Compliance