🚧 FastCMS is under active development — not ready for production use. APIs and features may change without notice.
FastCMS
Security

Audit Logging

Comprehensive security event tracking — logins, 2FA changes, API key operations, admin actions, and suspicious activity.

Audit Logging

FastCMS includes a comprehensive audit logging system for tracking security-relevant events.

What Gets Logged

  • Authentication — login, logout, failed attempts, token refresh
  • 2FA — setup, enable, disable, verification, backup code usage
  • API Keys — create, update, delete, revoke
  • Security — rate limiting, suspicious activity
  • Admin Actions — settings changes, backups

Event Types

Event TypeDescription
authAuthentication-related events
userUser management
api_keyAPI key operations
two_factor2FA/TOTP events
collectionCollection operations
recordRecord operations
fileFile operations
adminAdministrative actions
systemSystem events
securitySecurity-related events

Severity Levels

LevelUse Case
infoSuccessful logins, standard actions
warningFailed logins, configuration changes
criticalSuspicious activity, access denied

API Endpoints

All endpoints require admin authentication.

List Audit Logs

GET /api/v1/audit
Authorization: Bearer {admin_token}

Query Parameters:

ParameterDescription
limitMax results (1-1000, default: 100)
offsetSkip results
event_typeFilter by event type
severityFilter by severity
user_idFilter by user ID
ip_addressFilter by IP
from_dateFilter from date
to_dateFilter to date

Response:

{
  "items": [
    {
      "id": "550e8400-...",
      "event_type": "auth",
      "event_action": "login",
      "severity": "info",
      "user_email": "user@example.com",
      "ip_address": "192.168.1.100",
      "description": "User logged in via password",
      "outcome": "success",
      "created": "2025-01-15T10:30:00"
    }
  ],
  "total": 1
}

Get Security Events

GET /api/v1/audit/security?severity=critical
Authorization: Bearer {admin_token}

Get Failed Logins

GET /api/v1/audit/failed-logins?ip_address=10.0.0.1
Authorization: Bearer {admin_token}

Get Statistics

GET /api/v1/audit/statistics
Authorization: Bearer {admin_token}
{
  "by_event_type": {"auth": 150, "api_key": 25},
  "by_severity": {"info": 160, "warning": 20, "critical": 5},
  "by_outcome": {"success": 175, "failure": 10},
  "total": 185
}

Cleanup Old Logs

DELETE /api/v1/audit/cleanup?retention_days=90
Authorization: Bearer {admin_token}

Programmatic Usage

from app.services.audit_service import (
    AuditService, EventType, EventAction, Severity
)

async def log_custom_event(db):
    service = AuditService(db)

    await service.log(
        event_type=EventType.ADMIN,
        event_action=EventAction.SETTINGS_CHANGE,
        description="System settings updated",
        user_id="admin-123",
        user_email="admin@example.com",
        ip_address="192.168.1.1",
        details={"setting": "rate_limit", "old": 100, "new": 200},
        severity=Severity.WARNING,
    )

Best Practices

What to Always Log

  • Login attempts (success and failure)
  • Password changes
  • 2FA configuration changes
  • API key operations
  • Administrative actions
  • Access to sensitive data

What to Avoid Logging

  • Sensitive data content (passwords, tokens)
  • High-frequency read operations
  • Internal system calls

Retention

  • Default: 90 days
  • Minimum recommended: 30 days
  • Check compliance requirements (GDPR, SOC2)

Monitoring Alerts

Set up alerts for:

  • Multiple failed logins from same IP
  • 2FA disabled on admin accounts
  • Critical severity events
  • API key revocations

On this page