Audit Service Configuration

Architecture, endpoints, middleware setup, and troubleshooting for the centralized audit-service

This document describes how the audit logging architecture works in MQUAD and how services are configured to send audit logs to the centralized audit-service.

Audit Service API Endpoints

The audit-service provides endpoints under base path /api/v1:

Health Endpoints

MethodEndpointDescription
GET/healthBasic health check
GET/health/readyReadiness check
GET/health/liveLiveness check

Audit Logs Endpoints

MethodEndpointDescription
POST/audit/logsIngest a new audit log entry
GET/audit/logsList audit logs with filtering/pagination
GET/audit/logs/systemSystem-wide audit logs (super:admin only)
GET/audit/logs/{log_id}Get a specific audit log by ID
GET/audit/chain/verifyVerify integrity of audit log chain

Compliance Endpoints

MethodEndpointDescription
GET/audit/compliance/gdpr/data-access/{user_id}GDPR data access report
POST/audit/compliance/consentRecord/update user consent
GET/audit/compliance/consent/{user_id}Get all consent records for user

Export Endpoints

MethodEndpointDescription
POST/audit/exportExport audit logs (json/csv)

Service Configuration

Each microservice must include AUDIT_SERVICE_URL in its configuration:

audit_service_url: str = os.getenv("AUDIT_SERVICE_URL", "http://audit-service:8013")

All configured services:

ServiceConfig File
backendbackend/api/core/config.py
survey-servicesurvey-service/api/core/config.py
workspace-serviceworkspace-service/api/core/config.py
data-servicedata-service/api/core/config.py
sync-servicesync-service/api/core/config.py
analytics-serviceanalytics-service/api/core/config.py
webhook-servicewebhook-service/api/core/config.py
notification-servicenotification-service/api/core/config.py
media-servicemedia-service/api/core/config.py
form-serviceform-service/api/core/config.py
feature-flags-servicefeature-flags-service/api/core/config.py

Middleware Implementation

Each service implements AuditWriteMiddleware that captures write operations (POST, PUT, PATCH, DELETE) and sends them to the audit-service.

Middleware Files by Service

ServiceMiddleware File
backendbackend/api/interfaces/middlewares/audit_logs_write_middleware.py
survey-servicesurvey-service/api/common/audit_middleware.py
workspace-serviceworkspace-service/api/common/audit_middleware.py
data-servicedata-service/api/common/audit_middleware.py
sync-servicesync-service/api/common/audit_middleware.py
analytics-serviceanalytics-service/api/common/audit_middleware.py
webhook-servicewebhook-service/api/common/audit_middleware.py

Endpoint Used

All services send audit logs to: POST http://audit-service:8013/api/v1/audit/logs

Middleware Behavior

  1. Intercepts all POST, PUT, PATCH, DELETE requests
  2. Extracts entity type and resource ID from the request path
  3. Captures the request body (sanitized for sensitive fields)
  4. Sends the audit log asynchronously to the audit-service
  5. Falls back to local file logging (/tmp/audit_logs_*.jsonl) if the audit-service is unavailable

Verification

To verify audit logging is working:

  1. Check that the service has AUDIT_SERVICE_URL configured
  2. Verify the middleware is added to the FastAPI app
  3. Check the audit-service logs for incoming requests
  4. Query the audit logs endpoint: GET /api/v1/audit/logs

Troubleshooting

Logs Not Appearing

  1. Verify AUDIT_SERVICE_URL is set in the service's environment
  2. Check that the audit-service is running and accessible
  3. Review service logs for errors connecting to audit-service
  4. Check local backup logs in /tmp/audit_logs_*.jsonl

Connection Errors

If "Error connecting to audit service" appears in logs:

  • Verify network connectivity between services
  • Check that audit-service is healthy: GET /api/v1/health
  • Verify the correct endpoint URL is configured