1) PII catalog (what’s in logs, where, why, and how it’s handled)
Goal: maintain an authoritative, queryable inventory of all log fields/events that may contain PII or sensitive data, with an explicit handling rule per field.
Recommended catalog schema (minimum):
- Producer: service/app, version, environment (prod/stage)
- Log type: request logs, auth logs, app events, DB audit, WAF/CDN, etc.
- Field path: e.g.,
user.email, http.headers.authorization, request.body.ssn
- Data classification: Public / Internal / Confidential / Restricted (PII/PHI/PCI/secrets)
- PII category: identifier (email/phone), government ID, financial, auth secret, health, location, biometric, etc.
- Purpose: debugging, security audit, fraud, compliance
- Handling rule: drop / mask / tokenize / encrypt / allow
- Retention class: hot/warm/cold, duration, and storage locations
- Deletion requirements: user-scoped deletion? time-based TTL only?
- Access policy: roles allowed, break-glass process
- Owner: team + on-call
How to build/keep it current:
- Schema-first logging (structured logs) + field allowlist per event type.
- Automated DLP scanning on samples of ingested logs to detect drift (new fields, accidental payload dumps).
- CI checks: block merges that add disallowed fields (e.g., headers/body dumps) without catalog entries.
- Quarterly review with Security/Privacy.
Common “must-not-log” list (typically Restricted):
- Passwords, auth tokens, session cookies, API keys, OAuth codes, private keys
- Full payment card data (PAN), CVV (never), bank creds
- Full government IDs unless absolutely required (and then tokenize/encrypt)
2) Redaction & tokenization (make logs useful without retaining raw PII)
Principle: redact/tokenize at the source (application/logger) whenever possible; treat downstream redaction as a safety net, not the primary control.
Handling options (and when to use them)
- Drop
- Best for: secrets, request bodies, high-risk identifiers not needed for ops.
- Example: drop
Authorization header entirely; drop request.body.
- Mask (irreversible partial)
- Best for: human debugging where partial visibility helps.
- Example: email
j***@example.com, phone ***-***-1234.
- Risk: still PII; treat as Restricted unless truly anonymized.
- Tokenize (reversible via secure mapping)
- Best for: correlating events for the same user across systems without exposing raw identifiers.
- Implement via:
- Deterministic tokenization service (returns stable token per input)
- Store mapping in a separate, locked-down vault (HSM/KMS-backed), with strict audit logs
- Good for:
user_id, email, account_id when you need joinability.
- Keyed hashing (HMAC) (usually irreversible in practice)
- Best for: correlation without any re-identification requirement.
- Use HMAC-SHA256(key, value) (not plain hash) to prevent rainbow-table attacks.
- Rotate keys with versioning; store key material in KMS/HSM.
- Caveat: if you must support “delete user from logs,” you need a way to locate entries (see deletion section).
- Encrypt field-level
- Best for: rare cases where raw value is needed later under strict access.
- Higher operational burden; still counts as personal data for many regimes.
Where to apply redaction
- In-app logger middleware: sanitize structured fields (preferred).
- Ingress pipeline (e.g., Fluent Bit/Logstash/Vector): regex + schema-based redaction as defense-in-depth.
- Storage/query layer: avoid relying on this; it’s too late for access/exfil risk.
Quality controls
- Unit tests for redaction (“golden log lines”).
- Continuous DLP scan alerts (e.g., patterns for emails, PAN, tokens).
- “Accidental payload dump” guardrail: cap max size and denylist keys like
password, token, secret, cookie, authorization.
3) Sampling (reduce volume without losing security/compliance signal)
Principles
- Sampling happens after redaction.
- Never sample away: security-relevant and compliance/audit logs (auth events, privilege changes, admin actions, payment events, data export events).
- Prefer event-type-based sampling, not global sampling.
Recommended approach
- Tier 0 (no sampling): security/audit logs, incidents, access logs needed for forensics.
- Tier 1 (tail-based / error-biased): keep 100% of errors (5xx), exceptions, latency outliers; sample successes.
- Tier 2 (probabilistic): high-volume debug/trace events, keep 0.1–5% depending on volume.
Avoid common failure modes
- Sampling that breaks correlation: ensure every event has a stable correlation id (request_id/trace_id) and consider “keep entire trace if any span is an error.”
- Biased sampling: don’t sample solely by endpoint if it hides rare failure modes; use dynamic sampling keyed by (service, endpoint, status).
4) Retention & deletion SLAs (time-based TTL + user-scoped deletion)
You generally need two retention constructs:
-
Time-based retention (TTL)
Straightforward: logs expire by age, enforced in every storage tier (hot/warm/cold).
-
User-scoped deletion (e.g., GDPR/CCPA deletion requests)
Harder: you must be able to find and purge (or render inaccessible) all log entries linked to a user.
Recommended retention tiers (typical starting point; adjust to your regulatory needs)
- Hot (searchable, full-fidelity): 7–30 days
- Warm (cheaper, slower search): 30–90 days
- Cold/archive (compressed, restricted access): 90–365 days (or longer if required for security/SOX)
- Aggregated metrics (non-PII): keep longer (1–3+ years), ensure aggregation is non-identifying
Deletion mechanisms
- Primary stores (Elasticsearch/Splunk/ClickHouse/etc.):
- Partition by time + TTL.
- For user deletions: index a deletion key (e.g.,
user_token), enabling targeted delete-by-query.
- Object storage archives (S3/GCS):
- Prefer time-partitioned objects so deletion is coarse-grained by time.
- For user deletion, consider crypto-shredding: encrypt partitions with per-partition keys; deleting keys makes data effectively irretrievable.
- Backups / immutable snapshots:
- Document the constraint: if backups are immutable, user deletion may be satisfied by key destruction or by letting backups expire within a defined window.
- Keep backup retention minimal and explicit.
5) Deletion SLAs (define what “deleted” means, and by when)
Define SLAs per storage layer and for:
- Standard TTL expiry
- User deletion request (DSAR)
- Incident/legal hold exception
Example SLA matrix (customize):
| Data location | TTL enforcement | User deletion (render inaccessible) | Hard delete completion |
|---|
| Hot searchable store | automatic daily | 7 days | 14 days |
| Warm store | automatic weekly | 14 days | 30 days |
| Cold archive | lifecycle policy | 30 days (key shred) | 90 days (expiry) |
| Backups/snapshots | lifecycle policy | 30 days (key shred or exclude from restore) | 90–180 days (expiry) |
Key definitions to write into the policy
- “Render inaccessible”: data cannot be retrieved through normal tooling; access requires extraordinary measures (and is blocked by deleted keys/controls).
- Legal hold: documented exception path with approvals, scope limitation, and expiry.
6) Practical implementation checklist
If you share (1) your log stack (e.g., ELK/Splunk/Datadog/S3 lake), (2) main regulatory drivers (GDPR/CCPA/PCI/HIPAA/SOX), and (3) whether you need re-identification for support/security, I can propose a concrete retention schedule + tokenization design and the exact deletion workflow per storage layer.