Home/Templates/Record what investigations ask first
Record what investigations ask first
auditd rules on Linux for account changes, sudo rights, SSH keys, persistence, kernel modules, and commands people ran as root.
Ansible
Why bother
The first questions on a Linux host are usually these. Who changed an account or gave themselves sudo? Which SSH key was added? What was set to start on its own, and what did someone run as root? The default logs answer few of them. auditd records each one with the account that signed in, even after sudo, when the rules ask for it.
Change a watched file, such as adding a file to /etc/sudoers.d. ausearch -k privilege shows it with the account that did it.
How it works
Set it up
Pick your platform, then open the level you want. Each level is complete on its own. Read the comments in the files as you go. Anything with a real consequence is explained on the line where it happens.
Ansible. auditd rules in /etc/audit/rules.d, loaded with augenrules
What you need first
- An inventory, and an account you can become root with.
- For forwarding (Standard), the host log shipping template or another syslog forwarder on each host.
What it creates
- /etc/audit/rules.d/50-iac.rules: watches on account, sudo, SSH, and persistence files, kernel module loads, and root commands by people
- 32-bit coverage on x86_64, a larger kernel backlog, and PAM and audit configuration watches (Standard)
- The auditd syslog plugin switched on, so records reach the host log forwarder (Standard)
- An optional lock, -e 2, that stops anyone changing the rules until reboot (Standard)
The code
Quick startReady
ansible all -i inventory.ini -m ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini playbook.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini playbook.yml
Makes the change.ansible-playbook -i inventory.ini playbook.yml
Run it once more. The recap should end with changed=0.
No inventory yet? A one-machine inventory.ini:
[all] web-01 ansible_host=10.0.0.11 ansible_user=ubuntu
Syntax passedAnsible lint passed
Last run 2026-10-02.
Open playbook.yml as plain text
StandardReady
ansible all -i inventory.ini -m ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini site.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini site.yml
Makes the change.ansible-playbook -i inventory.ini site.yml
Run it once more. The recap should end with changed=0.
No inventory yet? A one-machine inventory.ini:
[all] web-01 ansible_host=10.0.0.11 ansible_user=ubuntu
Syntax passedAnsible lint passed
Last run 2026-10-02.
Open main.yml as plain text
Open main.yml as plain text
Open main.yml as plain text
Open main.yml as plain text
Open 50-iac.rules.j2 as plain text
Open site.yml as plain text
HardenedReady
ansible all -i inventory.ini -m ping
Proves Ansible can reach every machine before anything changes.ansible-playbook -i inventory.ini site.yml --check --diff
Shows each change it would make, line by line. Changes nothing.ansible-playbook -i inventory.ini site.yml
Makes the change.ansible-playbook -i inventory.ini site.yml
Run it once more. The recap should end with changed=0.
No inventory yet? A one-machine inventory.ini:
[all] web-01 ansible_host=10.0.0.11 ansible_user=ubuntu
Syntax passedAnsible lint passed
Last run 2026-10-02.
Open guard.yml as plain text
Open settings.yml as plain text
Open site.yml as plain text
How to check it worked
sudo touch /etc/sudoers.d/iac-test, then ausearch -k privilege -ts recent. The record shows the file and the account that signed in. Remove the file afterwards.
auditd refuses a plain systemctl restart. The templates load rules with augenrules --load, and Standard restarts the daemon with the service command, which auditd allows.
With the lock on, a later rule change fails the run until the host reboots. Settle the rules first, then turn the lock on.
Commands by every user are far louder than commands run as root. Standard has that switch off by default; turn it on where you can absorb the volume.
How to undo it
Delete /etc/audit/rules.d/50-iac.rules and run augenrules --load. With the lock on, the old rules stay until reboot.
What it costs
None beyond the disk and forwarding volume. Root commands by people are a small share; every user's commands can be large.
Good to know
- Every rule carries a key. ausearch -k <key> finds its records, and the same key is in each record forwarded to your SIEM.
- auid is the account that signed in. It survives sudo, so records show the person behind a root command.