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
| Method | Endpoint | Description |
|---|---|---|
| GET | /health | Basic health check |
| GET | /health/ready | Readiness check |
| GET | /health/live | Liveness check |
Audit Logs Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /audit/logs | Ingest a new audit log entry |
| GET | /audit/logs | List audit logs with filtering/pagination |
| GET | /audit/logs/system | System-wide audit logs (super:admin only) |
| GET | /audit/logs/{log_id} | Get a specific audit log by ID |
| GET | /audit/chain/verify | Verify integrity of audit log chain |
Compliance Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /audit/compliance/gdpr/data-access/{user_id} | GDPR data access report |
| POST | /audit/compliance/consent | Record/update user consent |
| GET | /audit/compliance/consent/{user_id} | Get all consent records for user |
Export Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /audit/export | Export 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:
| Service | Config File |
|---|---|
| backend | backend/api/core/config.py |
| survey-service | survey-service/api/core/config.py |
| workspace-service | workspace-service/api/core/config.py |
| data-service | data-service/api/core/config.py |
| sync-service | sync-service/api/core/config.py |
| analytics-service | analytics-service/api/core/config.py |
| webhook-service | webhook-service/api/core/config.py |
| notification-service | notification-service/api/core/config.py |
| media-service | media-service/api/core/config.py |
| form-service | form-service/api/core/config.py |
| feature-flags-service | feature-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
| Service | Middleware File |
|---|---|
| backend | backend/api/interfaces/middlewares/audit_logs_write_middleware.py |
| survey-service | survey-service/api/common/audit_middleware.py |
| workspace-service | workspace-service/api/common/audit_middleware.py |
| data-service | data-service/api/common/audit_middleware.py |
| sync-service | sync-service/api/common/audit_middleware.py |
| analytics-service | analytics-service/api/common/audit_middleware.py |
| webhook-service | webhook-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
- Intercepts all POST, PUT, PATCH, DELETE requests
- Extracts entity type and resource ID from the request path
- Captures the request body (sanitized for sensitive fields)
- Sends the audit log asynchronously to the audit-service
- Falls back to local file logging (
/tmp/audit_logs_*.jsonl) if the audit-service is unavailable
Verification
To verify audit logging is working:
- Check that the service has
AUDIT_SERVICE_URLconfigured - Verify the middleware is added to the FastAPI app
- Check the audit-service logs for incoming requests
- Query the audit logs endpoint:
GET /api/v1/audit/logs
Troubleshooting
Logs Not Appearing
- Verify
AUDIT_SERVICE_URLis set in the service's environment - Check that the audit-service is running and accessible
- Review service logs for errors connecting to audit-service
- 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
