Course map

Topic 171 / Advanced

Audit logging and compliance (PCI DSS as the payments example)

Chapter 10.6 · Privacy, Compliance, and the Secure Lifecycle

What and why

Topic 163 named privilege escalation prevention as requiring that admin actions be audited; this topic is that audit trail, and the compliance posture it supports. An audit log records who did what, to which resource, and when, for sensitive or privileged actions — a distinct purpose from an observability log (→ 201), which exists to debug the system, not to prove what happened to an auditor. PCI DSS is used here as the worked compliance example: its core technique, scope minimization through tokenization, generalizes well beyond payments. Builds on: → 163 (RBAC and ABAC — privilege escalation prevention requires audited admin actions).

Diagram

Audit log Observability log (→ 201)
Purpose Prove who did what, when Debug and understand system behavior
Mutability Append-only, tamper-evident Often rotated, overwritten, or sampled
Retention Often long, set by compliance need Often short, set by debugging need
Audience Auditors, security, compliance Engineers

How it works

  1. Record who, what, to which resource, and when for every sensitive or privileged action — role changes, data exports, access to sensitive records, administrative overrides.
  2. Make the log append-only and tamper-evident — an attacker who gains admin access must not be able to erase their own trail.
  3. Set audit-log retention independently of observability-log retention; compliance needs often require holding records far longer than debugging ever would.
  4. Apply PCI DSS's scope-minimization technique as the worked example: the fewer systems that touch raw sensitive data (here, card data), the smaller the set of systems that must meet the full compliance standard.
  5. Tokenize: replace the sensitive value with a reference token everywhere outside the minimal scope, so the rest of the system — reporting, order history, refunds — never handles the raw value at all.
  6. Treat compliance as an ongoing posture, periodically audited — not a one-time checkbox at launch.

Practical example

(illustrative). In Project 8 (payment processing), a tokenization service sits inside the minimal PCI-scoped boundary and is the only component that ever touches a raw card number; it returns a reference token. Every other system — order history, reporting, refunds — stores and handles only that token. Because those systems never touch the raw card number, they fall outside PCI DSS's scope entirely, shrinking the set of systems that must meet the full standard to one.

When to use it

  • Use audit logging for every privileged action a system allows — role changes, exports, access to sensitive records, admin overrides.
  • Use PCI-style scope minimization whenever a sensitive data type (payment, health, government ID) can be isolated behind a narrow boundary and referenced by a token everywhere else.
  • Avoid logging the sensitive value itself into the audit log — log the action and a reference to the object, never the card number or equivalent raw value.
  • Failure scenarios: a mutable audit log that an attacker with admin access can edit or delete, erasing their own trail; compliance scope creep, where "just one more service" starts touching raw sensitive data and pulls itself into full scope; audit and observability logs merged into one stream, so the audit trail is lost in debug noise or purged by a short observability retention policy.
  • Simpler alternative: for a system with no regulated data and no privileged roles beyond a single owner, a lightweight action log is enough — full compliance tooling is disproportionate until there's regulated data or multiple privileged roles.

Practice

(Process kind — fill the template on a small real system; 20–30 min, lab: Postgres). Design an append-only audit_log table (actor, action, resource, timestamp, and a before/after reference — never a raw sensitive value) for Project 3's role-change action. Insert a few sample rows, then show the design structurally resists tampering — for example, by granting the application's database role INSERT only, with no UPDATE or DELETE on that table. Done when a role change produces a row that can be inserted but not altered or removed through that role.

Shared lab setup

Key takeaway

An audit log proves who did what and when, kept separate from debugging logs and made tamper-evident; PCI DSS shows that the cheapest path to compliance is often shrinking the scope that needs it, not auditing everything equally. Done when you can: design an audit log for a privileged action and explain how tokenization would shrink a system's compliance scope. Used next in → 172 (compliance gates become checks in the pipeline); Project 8.

References

PCI Security Standards Council (PCI DSS) — see references.md.

Source directory

Search the guide