⚠️ Porta is in beta — APIs and features may change before v1.0
Skip to content

Audit Log API

View the audit trail of administrative and security events.

Base path: /api/admin/audit

List Audit Events

http
GET /api/admin/audit

Query parameters:

ParameterTypeDescription
pageintegerPage number (default: 1)
pageSizeintegerItems per page (default: 20)
actionstringFilter by action type
entity_typestringFilter by entity type
entity_iduuidFilter by entity ID
actor_iduuidFilter by actor (who performed the action)
organization_iduuidFilter by organization
fromISO 8601Start date/time
toISO 8601End date/time

Response: 200 OK

json
{
  "data": [
    {
      "id": "event-uuid",
      "action": "organization.created",
      "entityType": "organization",
      "entityId": "org-uuid",
      "actorId": "user-uuid",
      "actorEmail": "admin@example.com",
      "organizationId": "org-uuid",
      "metadata": {
        "name": "Acme Corp",
        "slug": "acme-corp"
      },
      "createdAt": "2024-01-15T10:30:00.000Z"
    }
  ],
  "pagination": {
    "total": 156,
    "page": 1,
    "pageSize": 20,
    "totalPages": 8
  }
}

Audit Event Types

Organization Events

ActionDescription
organization.createdNew organization created
organization.updatedOrganization details updated
organization.suspendedOrganization suspended
organization.activatedOrganization reactivated
organization.archivedOrganization archived
organization.branding_updatedBranding settings changed

User Events

ActionDescription
user.createdNew user created
user.invitedUser invitation sent
user.updatedUser profile updated
user.suspendedUser suspended
user.activatedUser activated
user.lockedUser locked (security)
user.unlockedUser unlocked
user.archivedUser archived
user.password_changedPassword changed
user.login_successSuccessful login
user.login_failureFailed login attempt

Client Events

ActionDescription
client.createdNew OIDC client created
client.updatedClient configuration updated
client.revokedClient revoked
client.secret_generatedNew client secret generated
client.secret_revokedClient secret revoked

RBAC Events

ActionDescription
role.createdNew role created
role.updatedRole updated
role.archivedRole archived
role.permission_assignedPermission assigned to role
role.permission_removedPermission removed from role
user.role_assignedRole assigned to user
user.role_removedRole removed from user

Security Events

ActionDescription
security.login_method_disabledAttempted login via disabled method
security.2fa_enabled2FA enabled for user
security.2fa_disabled2FA disabled for user
security.rate_limitedRate limit triggered

GDPR Events

ActionDescription
user.data_exportedUser data exported (GDPR Article 20)
user.data_purgedUser data purged (GDPR Article 17)

Account Lockout Events

ActionDescription
user.auto_lockedAccount auto-locked after failed login threshold
user.auto_unlockedAccount auto-unlocked after cooldown expired

INFO

Audit events are fire-and-forget — they are written asynchronously to avoid impacting request latency. All events include the actor (who), the entity (what), and metadata (details). If an audit write fails, a WARN-level log entry is emitted.

Audit Retention & Cleanup

Porta supports configurable audit log retention with automatic cleanup of old entries.

Configure Retention

The retention period is managed via the audit_retention_days system configuration key:

bash
# Set retention to 365 days
porta config set --key audit_retention_days --value 365

Cleanup Old Entries

http
DELETE /api/admin/audit/cleanup

Deletes audit log entries older than the configured audit_retention_days value.

Response: 200 OK

json
{
  "deleted": 1542,
  "retentionDays": 365,
  "cutoffDate": "2025-04-21T00:00:00.000Z"
}

WARNING

Audit cleanup is irreversible. Ensure your retention period meets your compliance requirements before running cleanup. Consider exporting old audit data to cold storage before purging.

Released under the MIT License.