Audit log retention: how long to keep auth events and why
Two forces pull your audit-log retention in opposite directions. Auditors want you to keep enough history to reconstruct what happened long after it happened—SOC 2 reviewers routinely ask for a year, some HIPAA interpretations push toward six, PCI expects a year with the recent months instantly available. Your finance team, meanwhile, is looking at a storage line item that grows every month and asking why you're paying to keep the record of a password-reset email from 2023. Set retention too short and you fail an audit or lose the forensic trail; set it uniformly long and you burn money storing low-value events and expand the amount of personal data you're liable for. The answer is not one number. It's a policy that treats different event classes differently.
Not all auth events are worth the same
Lump everything into "audit logs" and you're forced to apply your strictest requirement to your highest-volume, lowest-value events. Separate them by what they're for:
- Security-sensitive events — logins, MFA challenges, failed authentications, privilege changes, API key and credential lifecycle, admin actions. These are the forensic backbone. Keep them long.
- Compliance-mandated events — whatever a framework you're certified against explicitly names. Retention here is dictated, not chosen.
- Operational/debug events — token refreshes, routine reads, health checks that happen to flow through the auth layer. High volume, low forensic value, short retention.
Once events carry a class, retention becomes a lookup table rather than a single global knob.
What the frameworks actually require
SOC 2
SOC 2 is principles-based, not prescriptive—it doesn't name a number. In practice, because a Type II audit covers an observation period (commonly 6 or 12 months), you need logs spanning at least that window plus margin, and auditors overwhelmingly expect to see a year. The real requirement is that you have a documented retention policy and demonstrably follow it; an inconsistency between your stated policy and your actual deletion behavior is itself a finding.
PCI DSS
PCI is specific: retain audit history for at least one year, with a minimum of the most recent three months immediately available for analysis. That "immediately available" clause is a design constraint—it legitimizes a tiered approach where recent logs sit in hot, queryable storage and older ones move to cheaper archival tiers, as long as the archive can be restored.
HIPAA
HIPAA's six-year retention requirement applies to its required documentation—policies, procedures, risk analyses—and that long clock is often applied to security-relevant access logs touching protected health information as well. If you process PHI, treat your access logs as potentially falling under the six-year horizon and confirm the scope with your compliance counsel rather than guessing.
Retention is a floor and a ceiling. Privacy regimes like GDPR say you must not keep personal data longer than necessary for its stated purpose. So "keep everything forever" isn't the safe conservative choice people assume—it can be a violation in its own right, and it enlarges what you must disclose in a breach. The target is a defensible window, not the maximum one.
Encoding the policy
A retention policy that lives in a wiki page gets ignored. Encode it as data the system enforces. A small table mapping event class to a retention period is enough to drive automated expiry.
CREATE TABLE retention_policy (
event_class text PRIMARY KEY,
retain_days integer NOT NULL,
tier_after_days integer, -- move to cold storage after this
legal_hold boolean NOT NULL DEFAULT false
);
INSERT INTO retention_policy (event_class, retain_days, tier_after_days) VALUES
('auth.login', 395, 90), -- ~13 months hot-ish, cold after 90d
('auth.mfa', 395, 90),
('auth.privilege', 2200, 365), -- ~6y for sensitive admin/PHI-adjacent
('auth.token_refresh', 30, NULL), -- high volume, low value
('auth.read', 14, NULL);A scheduled job then enforces it—tiering first, deleting only past the retention horizon, and always skipping anything under legal hold.
-- nightly expiry, respecting legal holds
DELETE FROM audit_log a
USING retention_policy p
WHERE a.event_class = p.event_class
AND p.legal_hold = false
AND a.created_at < now() - make_interval(days => p.retain_days)
AND NOT EXISTS (
SELECT 1 FROM legal_hold h WHERE h.subject_id = a.subject_id
);Legal hold overrides everything. The moment litigation or an investigation is reasonably anticipated, retention clocks for the affected records must stop—deleting on schedule during a hold is spoliation. Build the hold as a hard gate in the expiry job, not a manual "remember to pause the cron" step. Record who placed each hold and when.
Prove it, don't just do it
An auditor's question is rarely "how long do you keep logs" in the abstract—it's "show me your policy, then show me the system doing what the policy says." The gap between the two is where findings live. Keep the policy, the enforcement code, and the deletion records in sync, and be able to point at the expiry job's own audit trail (yes, log the deletions) to demonstrate the control runs.
Retention is one of those decisions that's far easier to get right when the log is yours to shape—when you can add an event class, change a horizon, or place a legal hold without filing a request with a vendor whose log schema you don't control and whose export you pay for. Owning your identity layer means retention is your policy to encode and enforce; Bastionary lets you set per-event-class retention and tiering directly, so the system does what your compliance doc promises.
Run it yourself
Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.