Audit and tamper evidence
Design audit trails that answer who did what, when and from where, and that prove they have not been altered.
15 min readAudit logs are not application logs
Application logs help engineers debug; they are sampled, rotated after days and can be dropped under load. Audit logs are evidence: a complete record of security-relevant actions, kept for years, used by auditors, investigators and sometimes courts. They need different guarantees: no loss, no modification, controlled access, and long retention. Seven years is common for financial records; SOC 2 and PCI DSS require at least a year of searchable history. Design them as a product with their own owner, schema and retention policy.
What to record
Every audit event should answer who, what, when, where and the result, in a consistent schema across services. Use a shared library so every service emits the same schema.
- Actor: user or service identity, plus impersonation if an admin acted as a user
- Action and target: 'refund.created' on order 1234
- Timestamp from a synchronised clock, in UTC
- Source: IP address, user agent, request and trace ID
- Outcome: success or failure, and the reason for denials
- Before and after values for changed settings, avoiding raw secrets and unnecessary personal data
Reliable capture
Write audit events in the same transaction as the change they describe, using the transactional outbox pattern, then relay them to a durable stream such as Kafka. That way an action cannot succeed without its audit record. Consumers write the stream into an append-only store and a search index for investigations. Alert if any producer's audit volume drops to zero unexpectedly; silence is often the first sign of a broken pipeline or an attacker disabling logging. Test the pipeline end to end regularly with synthetic events.
Making tampering evident
Assume a privileged insider or attacker may try to erase their tracks. Hash chaining links each record to the previous one (each entry stores a hash of its contents plus the prior hash), so altering or deleting one breaks the chain. Periodically publish a signed checkpoint of the latest hash, or use a Merkle tree as in Certificate Transparency, to allow efficient verification. Store copies in write-once storage, such as S3 Object Lock in compliance mode, in a separate account that the system's own administrators cannot modify.
Key takeaways
- Audit logs are evidence: complete, immutable, access-controlled and retained for years.
- Record actor, action, target, time, source and outcome in one consistent schema.
- Use the outbox pattern so no action succeeds without its audit record, and alert on silence.
- Hash chains, signed checkpoints and write-once storage in a separate account make tampering evident.
Sign in to track lessons and earn badges.