The ability to thoroughly investigate security incidents or misconduct starts with reliable audit logs. In this advanced practical guide I show how to set up Auditd — the Linux-audit subsystem — with actionable rules, robust rotation tuning, secure central analysis and operational runbooks. The emphasis is on operation, risks, troubleshooting and a pragmatic fallback strategy.
Setting up Auditd: objectives and operational guardrails
Setting up Auditd is not just about enabling it, but about trustworthiness: which events will later answer questions of responsibility, timing and scope of an action? Operationally this means: design rules so they are forensically meaningful without overloading the system. A good baseline includes authentications, critical file changes, execve events for privileged UIDs and kernel module operations.
Robust rotation and archiving strategy
Audit logs grow quickly. Rotation is not just file management but part of the availability and evidentiary strategy. Key decisions:
- How many rotation levels to keep locally (num_logs) and when to archive?
- How to ensure integrity of the archives (hashes, signatures)?
- What happens when local partitions are full (disk_full_action)?
Common practice: a small local retention layer (e.g. 20 files) for short-term analysis and quick troubleshooting; a timely push strategy to a central, write-protected archive (WORM-like) that is covered with checksums.
Rotation and archive pipeline (example workflow)
- auditd rotates locally based on size/number.
- A local agent or cronjob hashes the file and moves it to a staging directory.
- Staging places the file + .sha256 via mTLS to a central archive endpoint (scp/HTTPS-API/Storage-Backend).
- Central system verifies the hash, indexes the file and tags it with metadata (host, time, rule-set version).
Practical hash and upload script
#!/bin/bash
# /usr/local/sbin/audit-archive-upload.sh
set -euo pipefail
FILE="$1"
ARCHIVE_HOST="archive.corp.example"
ARCHIVE_PATH="/archive/hosts/$(hostname)/"
sha256sum "$FILE" > "$FILE.sha256"
# Beispiel: curl-Upload mit Client-Zertifikat
curl --cert /etc/pki/client.crt --key /etc/pki/client.key --cacert /etc/pki/ca.crt
-F "file=@${FILE}" -F "sha=@${FILE}.sha256"
https://${ARCHIVE_HOST}/api/upload
Why this way? Hashes allow later integrity verification; mTLS ensures only authorized hosts may archive. Pay attention to secure key rotation and retention policies for the certificates.
Central forwarding: rsyslog + TLS example and Beats comparison
For forwarding, two classes of collectors are recommended: classic syslog pipelines (rsyslog/ syslog-ng) or modern agents (Auditbeat/Filebeat). Both have advantages and disadvantages:
- rsyslog: stable, fewer dependencies, native TLS support, suitable for central syslog ingests.
- Beats (Auditbeat/Filebeat): direct integration with Elasticsearch/Logstash, better field extraction and backpressure handling.
rsyslog TLS example (simplified snippet):
# /etc/rsyslog.d/90-audit-tls.conf
$DefaultNetstreamDriverCAFile /etc/pki/ca.crt
$DefaultNetstreamDriverCertFile /etc/pki/client.crt
$DefaultNetstreamDriverKeyFile /etc/pki/client.key
$ActionSendStreamDriverMode 1
$ActionSendStreamDriverAuthMode x509/name
$ActionSendStreamDriverPermittedPeer "logs.corp.example"
module(load="imfile")
input(type="imfile" File="/var/log/audit/audit.log" Tag="audit" Severity="info" Facility="local6")
# Remote TLS target
action(type="omfwd" Target="logs.corp.example" Port="6514" Protocol="tcp"
StreamDriver="gtls" StreamDriverMode="1" StreamDriverAuthMode="x509/name")Important: Test certificate chains, CN/SAN settings and allow reverse-DNS/name matching if your security policy requires it. Under high load, check rsyslog queue parameters (DiskQueueSize, QueueMaxFileSize).
Auditbeat DaemonSet for Kubernetes: Best Practices
In Kubernetes, host events and container contexts run separately. A DaemonSet running Auditbeat or Filebeat with a specialized processor is ideal. Critical points:
- Mounts: /var/log/audit and /var/run/docker.sock or CRI sockets require correct hostPath mounts.
- RBAC: The collector may need access to the Kubernetes API to obtain ContainerID→Pod mapping.
- Mapping layer: Enrich events with pod and namespace metadata before the event leaves the cluster.
Minimal DaemonSet excerpt (Auditbeat example)
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: auditbeat
namespace: kube-system
spec:
selector:
matchLabels:
app: auditbeat
template:
metadata:
labels:
app: auditbeat
spec:
hostPID: true
hostNetwork: true
containers:
- name: auditbeat
image: docker.elastic.co/beats/auditbeat:8.0.0
securityContext:
privileged: true
volumeMounts:
- name: auditlog
mountPath: /var/log/audit
- name: dockersock
mountPath: /var/run/docker.sock
volumes:
- name: auditlog
hostPath:
path: /var/log/audit
- name: dockersock
hostPath:
path: /var/run/docker.sock
Extend the collector with a process plugin that extracts the container ID and enriches it with pod metadata via API lookup. Without this mapping you lose context in forensic cases as to whether a process ran inside a container or on the host.
Capacity planning and performance tests
Plan capacity based on realistic usage scenarios: simulate load with tools that emulate execve or file operations, and measure event rate, auditd CPU usage, disk I/O and forwarder queue.
Test script: load simulation (conceptual)
#!/bin/bash
# Simpler load-generator: wiederholtes Ausführen von Binaries
for i in $(seq 1 1000); do
/bin/echo "$i" >/tmp/audit-test-$i
/bin/ls -l /tmp/audit-test-$i >/dev/null
rm /tmp/audit-test-$i
done
Then observe aureport/auditctl and system metrics. Evaluate whether rules are too broad and generate unnecessary volume.
Fallback strategy and emergency procedure
If a rule causes unexpected load or interferes with applications, you need a clear rollback path. Recommended procedure:
- Identify the problematic rule file in /etc/audit/rules.d.
- Move the file to a quarantine directory (do not delete) and document the action.
- Reload/RESTart auditd and validate.
- If RESTart is not possible: stop auditd only in an emergency and create a forensic note.
Concrete commands for quick rollback
# Move the rules file
sudo mv /etc/audit/rules.d/50-problem.rules /root/quarantine/
# Reload rules
sudo augenrules --load # for auditd on systemd distributions
# or
sudo systemctl RESTart auditd
# Check
sudo auditctl -l
# Only if unavoidable
sudo systemctl stop auditd
Important: Document every action and the reasons. Stopping auditd should only be a last resort and require management/security approval, as it creates forensic gaps.
Security hardening, SELinux/AppArmor and permissions
Auditd itself requires elevated privileges; therefore set strict file permissions on /var/log/audit and RESTrict access to forwarder configurations. Review SELinux or AppArmor policies: container collectors require appropriate policy exceptions for host mounts.
Operationalization: runbook structure and check intervals
A runbook should include:
- Initial checks (auditd status, rule list, recent event sample).
- Forwarder health (TLS handshake, queue lengths, processed events/min).
- Archive integrity checks (hash comparison, alerting on mismatch).
- Rollback quick-reference with exact commands and instructions for applying quarantine rules.
Run daily health checks automatically and perform a full integrity check of the archives quarterly.
Final recommendations
Setting up auditd is an iterative process: start small, measure, expand selectively. Automate rule deployments via configuration management (Ansible, Puppet) with a validation step before activation. Ensure end-to-end security: mTLS, hash integrity and role-based access control for archives. In Kubernetes a well-configured DaemonSet with automatic pod mapping is mandatory, otherwise you lose context during incident investigations.
Summary
With a considered rule base, robust rotation settings, integrity-secured archiving and secure forwarding you establish a reliable foundation for forensic analysis. Test every change, monitor metrics and prepare clear rollback steps. Only this way does Auditd remain maintainable in daily operation and meaningful in an incident.
Checklist: immediate actions after rollout
- Monitor baseline metrics (event rate, disk usage, forwarder queues) — intensively for the first 72 hours.
- Verify the integrity upload of the first rotation using the hash.
- Check Kubernetes DaemonSet logs and verify container→pod mapping.
- Communicate the runbook for emergencies to the incident team.
Setting up auditd: architectural decisions, reliability and compliance
This section supplements the previous guidance with architectural decisions, operational metrics, compliance-relevant aspects and concrete test scripts. The goal is that you not only activate auditd but integrate it into a resilient, scalable pipeline—with a traceable chain of evidence, test and rollback processes.
Architectural principles and flexible buffering
Decide early where primary persistence should reside: direct push into a SIEM/ELK cluster, buffering in a broker (e.g. Kafka) or first object-based archive (S3-compatible). A typical robust architecture combines local short-term retention, a resilient forwarder with persistent queue and a central, write-protected archive. This keeps short-term analysis possible locally while long-term retention remains tamper-evident.
Important operational metrics and alert thresholds
- Events/sec (per host): fundamental for capacity planning and detecting anomalously high activity.
- Forwarder queue length and Disk-Queue-Size: warning before the forwarder starts dropping events.
- Kernel/Lost-Events (auditd/auditctl statistics): critical indicator that the subsystem is falling behind.
- Disk usage on /var/log/audit and staging paths: alerts at 70/85/95 %.
Concrete alert triggers: events/sec 3× baseline over 5 minutes, queue length > 80 % of configured capacity, or lost events > 0 within 30 minutes — immediate escalation to Incident-Response.
Check whether the kernel is dropping events
# Overview of the audit subsystem
sudo auditctl -s
# Set backlog limit (temporary)
sudo auditctl -b 8192
# Inspect auditd statistics (interpret example output)</nsudo ausearch -m ADT_ANOMALY --start recent || true
auditctl -s shows, among other things, backlog_limit, status and, if applicable, lost/warn_counts. A non-zero value for lost is a serious signal: rules are too broad or system resources are insufficient.
Capacity planning: simple estimation
Use a formula instead of guesses: event rate × average event size × retention period. Example script:
#!/bin/bash
# Simple sizing: events/sec, bytes/event, days
events_per_sec=50
bytes_per_event=400
days=30
bytes_needed=$(( events_per_sec * bytes_per_event * 86400 * days ))
echo "Required bytes: $bytes_needed"
# in GB
awk -v b=$bytes_needed 'BEGIN{printf "%.2f GBn", b/1024/1024/1024}'
Increase buffers for peaks (e.g. factor 3) and plan separate capacity for indexing/metadata in your SIEM.
Integrity and chain-of-custody measures
For forensic suitability, hashes, timestamps from a reliable source and access control are essential. Follow these rules:
- Generate SHA-256 hashes when archiving; store hash + metadata separate from the log.
- Use a trusted time source (chrony with NTP authentication or GPS-PTP in critical environments) and validate clock drift regularly.
- Configure archive storage as append-only (WORM options or object store policy); perform regular hash revalidations.
Rule deployment, testing and canary strategy
Rules must not be uploaded as files into production. Use a git-based change management with automated tests and canary rollout:
- Linting/parsing of rule files (syntax validation, detect redundant rules).
- Staging apply on canary hosts including load simulation.
- Analyze metrics; only on green tests perform gradual rollout (e.g. 5/20/100 % hosts) via Ansible/Orchestrator.
Automated check scripts for runbooks
#!/bin/bash
# runbook-check.sh - Quick healthchecks
set -e
sudo auditctl -s | egrep "enabled|backlog_limit|lost"
df -h /var/log/audit
# Forwarder health: Beispiel mit rsyslog-Queue-Check (falls verfügbar)
sudo systemctl status rsyslog | head -n 20
Automate this script as a cronjob/health check in your monitoring system; manage alerts and automatic ticket creation per policy.
Concluding notes
Auditd is only one component in a forensically sound infrastructure. What matters are planning, measurability and processes: clear capacity figures, canary tests before rollout, integrity checks and a documented Chain-of-Custody. This makes Auditd an operational part of your security and compliance architecture — integrable with SIEMs, object archives and incident response processes for custom enterprise software and digital business solutions.
Setting up Auditd: integration and operational risks
When setting up Auditd, responsibility does not end with collecting events — rather, integration and operational risks begin that can threaten forensic integrity and system stability. Checkpoints often overlooked:
- Schema and mapping incompatibilities: SIEMs or indexers expect structured fields. Ensure that collector-processors store raw log and parsed fields in parallel, otherwise you lose forensic context during re-indexing.
- Backpressure strategy: If forwarders (rsyslog/Beats) fall behind, a persistent broker (z. B. Kafka) or a disk queue must be available — consciously decide between at-least-once and exactly-once consequences.
- Tamper-evident archives and access: Keep archive files, hash manifests and access logs separate; role-based access control on the archive with auditing via its own logs.
- Compliance and retention requirements: Legal requirements (e.g. deletion deadlines) affect retention policies; plan automatic expiry cycles and chains of evidence that demonstrate deletion.
Practical verification step: during RESTore tests, regularly verify that archive hashes still match:
# Verifiziert gespeicherten Hash
sha256sum -c /archive/hosts/host1/audit.log.sha256
Document every RESTore validation and integrate certificate and key rotation into change processes. Only in this way does Auditd remain resilient and verifiable in complex environments such as Kubernetes, hybrid SIEMs and custom enterprise software landscapes.
Auditd rules and Auditd rotation are also important for this topic. This article places these aspects in context and shows what matters in day-to-day operations.