Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Security Logging

Security logging is the practice of recording events within a system that are relevant to security, such as authentication attempts, access to sensitive resources, configuration changes, and system errors. These logs provide a traceable record of activity across applications, infrastructure, and services.

Effective security logging is vital to a Security by Design approach because it ensures visibility into how a system is used and how it may be abused. By capturing meaningful and well-structured log data, organisations can detect suspicious behaviour, investigate incidents, and respond in a timely manner.

In addition, security logging supports accountability and continuous improvement. It enables teams to validate security controls, identify weaknesses, and refine defences over time. Without adequate logging, even well-designed systems may fail to detect or respond to security incidents, undermining the overall effectiveness of their security posture.

Essentials

Always implement a dedicated audit logging system separate from operational logs. Audit logs track security-relevant events for:

Key Principles

PrincipleImplementation
No PIIOnly IDs logged, never names/emails
No SecretsTokens, keys, passwords never logged
Trace Correlationtrace_id links to request logs
Structured FormatJSON for machine parsing
ImmutableEvents cannot be modified after creation

Example Event Schema for Audit logging

FieldTypeDescription
timestampstringISO 8601 UTC timestamp
event_idstringUnique event identifier (evt_xxxx)
event_typestringEvent type (see Section 4)
event_categorystringCategory grouping
severitystringinfo, warning, error, critical
actorobjectWho performed the action
resourceobjectWhat was accessed/modified
actionstringcreate, read, update, delete, access, validate
outcomestringsuccess, failure, denied, error
detailsobjectAdditional context (varies by event)
trace_idstringRequest correlation ID
servicestringService that generated the event

Typical Audit Event Types

Authentication Events

Event TypeSeverityDescription
AUTH_SUCCESSinfoJWT token issued successfully
AUTH_FAILUREwarningToken generation failed
AUTH_TOKEN_EXPIREDinfoToken validation - expired
AUTH_TOKEN_INVALIDwarningToken validation - invalid signature

mTLS Events

Event TypeSeverityDescription
MTLS_SUCCESSinfomTLS certificate validated
MTLS_FAILUREwarningmTLS certificate invalid
MTLS_CN_MISMATCHwarningCertificate CN != JWT subject

Authorization Events (RBAC)

Event TypeSeverityDescription
AUTHZ_SUCCESSinfoPermission granted
AUTHZ_FAILUREwarningPermission denied (403)

Security Events

Event TypeSeverityDescription
RATE_LIMIT_EXCEEDEDwarningRate limit triggered

Data Events

Event TypeSeverityDescription
TELEMETRY_CREATEDinfoNew telemetry event ingested
TELEMETRY_DUPLICATEinfoDuplicate event (idempotent)
TELEMETRY_CONFLICTwarningSame ID, different payload
CONTACTS_ACCESSEDinfoContacts data retrieved

OAuth Events

Event TypeSeverityDescription
OAUTH_INITIATEDinfoOAuth flow started
OAUTH_COMPLETEDinfoOAuth tokens received
OAUTH_REVOKEDinfoOAuth tokens revoked
OAUTH_FAILUREwarningOAuth flow failed

System Events

Event TypeSeverityDescription
SERVICE_STARTEDinfoService started
SERVICE_STOPPEDinfoService stopped
CONFIG_CHANGEDwarningConfiguration modified

Compliance

When doing security by design good, security, and audit logging directly meet compliance requirements.

SOC 2 Type II

ControlAudit Support
CC6.1Authentication events logged
CC6.2Authorization failures logged
CC7.2Security incidents traceable
CC8.1Changes logged (CONFIG_CHANGED)

GDPR

RequirementImplementation
Data Access TrackingCONTACTS_ACCESSED events
No PII in LogsOnly IDs, never names/emails
Right to Accesstrace_id enables request tracing

Log Retention

Recommended retention policies:

EnvironmentRetentionRationale
Development7 daysDebugging
Staging30 daysTesting
Production90 daysCompliance (SOC 2)
Archive1 yearLegal/regulatory

Best Practices for Security By Desing

Mind Never ever:

Key Security Considerations:

  1. Access Control: Restrict audit log access to security team

  2. Integrity: Use append-only storage if possible

  3. Encryption: Encrypt audit logs at rest

  4. Backup: Maintain secure backups of audit logs

  5. Log rotation