CMP-26Recommended
Write an audit event for every sensitive action
Write one audit event for each action on a fixed list, with who, what, which record, when, from where and the result.
How to do it
The list covers sign-ins, failed sign-ins, two-factor changes, role changes and admin actions. It also covers data exports, deletions, API keys, payout details and security settings. Reading a person's data is covered in the access logging rule. Money movements have their own money audit log and payment ledger. Mark whether the actor is a person, a service or an AI agent. Use UTC times and the request ID. Record "from where" as a shortened IP address or a place, as keep only what you need asks. Store IDs, never the data itself. ISO/IEC 27001:2022 control A.8.15 and SOC 2 criterion CC7.2 both expect this log.
Examples
JavaScript example
export function auditEvent({ actor, actorType, action, target, requestId, sourceIp, outcome }) {
return {
at: new Date().toISOString(),
actor, actor_type: actorType,
action, target,
request_id: requestId, source_ip: sourceIp,
outcome,
};
}
await auditLog.append(auditEvent({ actor: 'u_381', actorType: 'person', action: 'role.grant', target: 'u_902:admin', requestId, sourceIp, outcome: 'success' }));
Python example
from datetime import datetime, timezone
def audit_event(*, actor, actor_type, action, target, request_id, source_ip, outcome) -> dict:
return {
"at": datetime.now(timezone.utc).isoformat(),
"actor": actor, "actor_type": actor_type,
"action": action, "target": target,
"request_id": request_id, "source_ip": source_ip,
"outcome": outcome,
}
audit_log.append(audit_event(actor="u_381", actor_type="person", action="role.grant",
target="u_902:admin", request_id=request_id, source_ip=source_ip, outcome="success"))
How to check
An end-to-end test performs every action on the list. For each, the audit store holds exactly one event with every field filled.
Sources
Related rules
- DAT-76 Keep the history of records that settle disputes in Data and databases
- ACC-33 Let organisation owners sign a member out in Accounts and identity
- ACC-48 Never let admins choose or see a member's password in Accounts and identity
- ACC-50 Check who is asking before support changes an account in Accounts and identity
- ACC-52 Ask business customers before support looks in in Accounts and identity
- DAT-34 Log who reads personal data in Data and databases
- PAY-57 Log every staff action on money in Payments and billing
- PAY-21 Record every money movement in an append-only ledger in Payments and billing
- WEB-212 Keep only what you need and delete it on time in Website
- CMP-63 Take notices about illegal content and answer each one in Compliance and governance
- APP-81 Show who changed a record and when in Web app interface
- TNS-14 Show moderators only what the case needs in Trust and safety
- SUP-9 Tie every support-tool action to a ticket in Customer support
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/compliance/audit-logs-and-access/audit-log-events">Agent Wranglers compliance and governance playbook</a>. In code you write, add a comment next to it with the same link.