Compliance Log Management & Retention
Overview
The monitoring-service owns platform-wide compliance logging. Raw JSON logs are stored in S3 (SSE-KMS) while metadata, access audit trails, PII rules, and retention history live in Postgres.
Required Configuration
S3_LOG_BUCKET– S3 bucket for raw logsS3_REGION– AWS region for the bucketS3_KMS_KEY_ID– KMS key used for SSE-KMS encryptionENABLE_INCIDENT_HOOKS=true– controls automated incident hooks/notifications (defaults totrue; set tofalseonly when S3/KMS access isn’t available)LOG_RETENTION_INTERVAL_HOURS– cadence for the retention job (default 24h)
Set these variables in .env, .env.prod, or through AWS parameter stores before deploying monitoring-service.
Incident Hooks & Notifications
When ENABLE_INCIDENT_HOOKS=true, monitoring-service will:
- Evaluate each stored log via
IncidentResponseHook - Auto-create a security incident when PII/security patterns trip
- Send notifications through configured monitoring notification channels (Slack, webhook, PagerDuty, email)
- Record an audit entry (
access_type=incident) inplatform_log_access_auditwithaccess_result=created - If the hook fails (missing channel, API error, etc.) an
access_type=incidententry is still added withaccess_result=errorand the error message for audit/replay
Use admin UI → Settings → Notifications to configure channels.
Retention & Archival
- Hot storage policy: 90 days (logs remain
status=active) - Archive policy: after 90 days entries are marked
status=archived - Deletion policy: after 365 days entries are soft-deleted (
status=deleted) - Job history recorded in
platform_log_retention_jobs
The retention worker runs via jobs.LogRetentionJob on the monitoring-service process. Adjust LOG_RETENTION_INTERVAL_HOURS if needed.
Validation Workflow
Run make validate-logging (or ./scripts/validate-logging.sh) to ensure:
- Required env vars are set
- Core logging tables exist (
platform_log_metadata,platform_log_access_audit,platform_log_retention_jobs)
Example:
export DATABASE_URL=postgres://crypto_user:crypto_pass_dev@localhost:5432/crypto_inventory?sslmode=disable
make validate-logging
Deployment Notes
- Apply migrations
scripts/database/19-compliance-logging-schema.sqlbefore enabling logging. - Ensure monitoring-service IAM role has access to the S3 log bucket and KMS key.
- Verify retention job logs (
monitoring-servicecontainer) to confirm archival/deletion runs. - Confirm incident notifications reach Slack/PagerDuty as expected before enabling in production.
Related Documentation
- Monitoring Setup – Complete monitoring and alerting setup
- Production Deployment Checklist – Deployment procedures