Working with Audit Logging

1. Understanding Audit Logging Requirements

DriverDetail
ComplianceSOC 2, ISO 27001, HIPAA, PCI DSS
ForensicsReconstruct incidents
AccountabilityWho did what, when, where
DetectionSIEM correlation

2. Logging Authentication Events

EventDetail
login.successuser_id, method, ip, ua, mfa_used
login.failureemail_hash, reason, ip, ua
logoutuser_id, session_id
mfa.challengemethod, outcome
password.changeuser_id, actor

3. Tracking Authorization Decisions

FieldDetail
subjectUser/service
actionOperation
resourceObject + id
decisionpermit / deny
policyRule that matched

4. Implementing User Activity Logging

TypeDetail
Admin actionsAll changes (config, users, roles)
Data accessSensitive resource reads
Data modificationCRUD with before/after
ExportsVolume + destination

5. Using Tamper-Proof Logs

MechanismDetail
Append-onlyWORM storage (S3 Object Lock)
Hash chainingEach entry includes prev hash
SignedHSM-signed log batches
RemoteForward to SIEM in real time

6. Implementing Structured Logging

Example: JSON log entry

{
  "ts": "2026-05-18T18:00:00.123Z",
  "level": "info",
  "event": "login.success",
  "user_id": "u_1",
  "session_id": "s_abc",
  "ip": "1.2.3.4",
  "ua": "Mozilla/...",
  "mfa": "webauthn",
  "trace_id": "01HK..."
}

7. Handling Sensitive Data in Logs

FieldTreatment
PasswordNEVER log (even in errors)
TokensLog truncated prefix only
PII (email)Hash or pseudonymize for compliance
PAN/SSNMask or omit

8. Implementing Log Retention Policies

RegulationPeriod
SOX7 years
PCI DSS1 year (3 months online)
HIPAA6 years
GDPRMinimize — no longer than necessary

9. Using Centralized Logging

StackDetail
ELK / OpenSearchElasticsearch + Logstash + Kibana
SplunkCommercial SIEM
Datadog, SumoSaaS
LokiGrafana — cheap log aggregation

10. Implementing Real-Time Alerting

TriggerAction
5+ failed logins / 5 minAlert + temp lockout
Login from new countryNotify user
Admin role assignedPage security
Privilege escalationImmediate Slack/PagerDuty

11. Handling Compliance Requirements

  • Log all access to ePHI (HIPAA §164.312(b))
  • Audit trail integrity (SOX §404)
  • Retain authentication logs (PCI DSS 10.7)
  • User notification of data breaches (GDPR 72-hour rule)