Skip to content

Writing auditd rules that survive an audit

A starter set of auditd rules for tracking privileged actions, file integrity, and syscall-level events on Linux — with retention and rotation that actually work.

auditd is the Linux kernel’s audit subsystem in userland — the canonical way to know who ran which syscall against which file when. Most distros enable it but ship no operational rules, so it sits at idle producing nothing useful. This article gives a starter set of rules tuned for production: enough coverage to satisfy a Center for Internet Security review, not so verbose that the log eats the disk.

How to verify

Confirm the daemon is running, the rules are loaded, and the log is rotating:

sudo systemctl status auditd
sudo auditctl -l
sudo auditctl -s
sudo ausearch -k privileged --start today
sudo aureport --summary
ls -lh /var/log/audit/

auditctl -l lists every active rule. auditctl -s shows the daemon state, including the backlog (unwritten events queued in kernel buffers) — a non-zero backlog under load means the rules are too expensive or the log disk is too slow.

What’s happening

auditd reads rules from /etc/audit/rules.d/*.rules at boot and compiles them into kernel filters via the audit netlink interface. The kernel writes matching events to /var/log/audit/audit.log. Rules come in three flavours: file-watches (-w /etc/passwd -p wa -k passwd_changes), syscall rules (-a always,exit -F arch=b64 -S execve), and control rules (buffer sizes, failure mode). The -k key tags events for later filtering with ausearch -k.

The danger is over-collection. A rule that watches every read syscall in production buries the signal in noise and may push events faster than the kernel can drain them — auditd’s default failure=1 (printk warning) then escalates to failure=2 (panic) if you set it. The right strategy is to watch specific privileged actions, integrity-sensitive paths, and the syscalls associated with privilege escalation, not “everything”.

CIS and STIG benchmarks ship recommended rule sets. The audit-rules package on Debian/Ubuntu and audit on RHEL family include 30-stig.rules.disabled and similar — rename to enable.

The procedure

  1. Increase the kernel buffer for high-throughput hosts. Edit /etc/audit/rules.d/00-control.rules: -b 16384 (default is 8192) and -f 1 (printk on failure, not panic). Reload with sudo augenrules --load.
  2. Drop in the bundled hardening rules. sudo cp /usr/share/doc/auditd/examples/rules/30-stig.rules /etc/audit/rules.d/ (path varies by distro). Review before loading — some rules reference paths that may not exist on your host.
  3. Watch privilege escalation. -a always,exit -F arch=b64 -S execve -F uid!=0 -F euid=0 -k root_exec catches every binary executed where the real UID was non-root but the effective UID is root — typically sudo-mediated privilege escalation.
  4. File integrity for the paths that matter. -w /etc/passwd -p wa -k identity, -w /etc/shadow -p wa -k identity, -w /etc/sudoers -p wa -k identity, -w /etc/sudoers.d/ -p wa -k identity. The wa permission set covers writes and attribute changes.
  5. Capture loadable kernel modules. -w /sbin/insmod -p x -k modules, -w /sbin/rmmod -p x -k modules, -w /sbin/modprobe -p x -k modules, -a always,exit -F arch=b64 -S init_module,delete_module -k modules.
  6. Apply and verify. sudo augenrules --load then sudo auditctl -l | wc -l to confirm rules are in the kernel. Trigger an event (sudo touch /etc/passwd-test && sudo rm /etc/passwd-test) and sudo ausearch -k identity --start recent to confirm it logged.
  7. Configure retention. /etc/audit/auditd.conf controls log rotation: max_log_file = 50 (MB), num_logs = 10, max_log_file_action = ROTATE, space_left = 1000, space_left_action = SYSLOG, admin_space_left_action = SUSPEND. The SUSPEND action stops auditing rather than overwriting — appropriate for a compliance posture.
  8. Forward events to a SIEM. audisp-syslog (or audisp-remote) plugs into the audit dispatcher and ships every event to a remote syslog. Configure under /etc/audit/plugins.d/syslog.conf.

Common pitfalls

  • The -a always,exit clause is required for syscall rules to produce events. Bare -S execve without the action does nothing.
  • A rule on arch=b64 only matches 64-bit syscalls. On a host that runs 32-bit binaries (some legacy CI), you need both arch=b32 and arch=b64 versions.
  • -w file watches use inotify under the hood — they fire on the path, not the inode. A file replaced atomically (write-then-rename) is seen as a new watch target and the old watch loses scope. ausearch -k plus a key on the parent directory is more reliable for some patterns.
  • Keys are advisory, not enforced. Reusing a key across many rules makes ausearch more useful but loses the per-rule attribution. Use distinct keys for distinct intents.
  • The audit package on RHEL family installs auditd as a non-systemd-managed daemon for historical reasons — systemctl restart auditd works but systemctl reload auditd does not. Use service auditd restart or apply rules with augenrules --load.

In the engagements we run, auditd rules are part of the standard build and the events stream to a SIEM that the security team owns. The retention, forwarding, and rotation pieces live in Managed Operations — auditing without retention is theatre.