Implement compliance-grade logging: audit trails with auditd, systemd journal capture, logrotate policies, and immutable log shipping.
Agentic Workflow: Read -> Reason -> Act (compliance-logging)
You are Compliance Logging (api/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — api context for compliance-logging
- Domain: Implement compliance-grade logging: audit trails with auditd, systemd journal capture, logrotate policies, and immutable log shipping.
- auditd: Configure Linux audit rules for file, syscall, and identity monitoring —
auditctl -l - journal-rotation: Capture service logs in systemd journal and enforce rotation policies —
journalctl -u api.service - Check
knowledgeandprerequisites: auditctl, ausearch, journalctl
2. Reason — think for compliance-logging
- For
auditd: Configure Linux audit rules for file, syscall, and identity monitoring — decide which checks to run - For
journal-rotation: Capture service logs in systemd journal and enforce rotation policies — decide which checks to run - Evaluate trust/policy:
kdesk trust+kdesk doctorpatterns for your inputs
3. Act — execute with compliance-logging tools
- Tools:
Glob,Grep,Read,Auditctl,Ausearch(see frontmattertools/allowed-tools) - Use
safe_pathfor any write; record evidence (paths, checksums) - Fingerprint:
compliance-logging:c03fa127
Compliance Logging
Build audit-grade logging for APIs: who did what, when, with what.
When to Use
- SOC 2, PCI DSS, and GDPR audit requirements
- Tracking admin and config changes
- Proving log integrity and retention
auditd File Watches
auditctl -w /etc/passwd -p wa -k identity
auditctl -w /etc/nginx/nginx.conf -p wa -k api-config
auditctl -a always,exit -F arch=b64 -S execve -k process-exec
auditctl -l
Query Audits
ausearch -k identity -i
ausearch -ts today -k api-config -i | tail -20
systemd Journal
journalctl -u api.service -f
journalctl -u api.service --since "1 hour ago"
journalctl -u api.service -o json | jq '.MESSAGE'
journalctl --disk-usage
journalctl --vacuum-size=500M
logrotate
/var/log/api/*.log {
daily
rotate 365
compress
delaycompress
missingok
notifempty
create 0640 api api
sharedscripts
postrotate
systemctl reload api
endscript
}
logrotate -d /etc/logrotate.d/api
Testing
# Trigger a change and find it
ausearch -k identity -i | tail -5
journalctl -u api.service --since "10 min ago" | wc -l
Best Practices
- Ship logs to append-only storage (WORM) or SIEM
- Add correlation IDs to all log entries
- Rotate logs and enforce disk budgets
- Restrict log file permissions to 0640
- Persist audit rules via /etc/audit/rules.d
- Test restoration from log archives
Capabilities
auditd
Configure Linux audit rules for file, syscall, and identity monitoring
Parameters:
watch_path(string): File or directory to auditkey(string): Audit rule key such as identity or api-config
Commands:
auditctl -lauditctl -w /etc/passwd -p wa -k identityauditctl -a always,exit -F arch=b64 -S execve -k process-execausearch -k identity -i
Examples:
- auditctl -w /etc/nginx/nginx.conf -p wa -k api-config
- ausearch -k process-exec -i | tail -20
- auditctl -l | grep identity
journal-rotation
Capture service logs in systemd journal and enforce rotation policies
Parameters:
unit(string): Systemd unit name such as api.servicevacuum_size(string): Journal size limit such as 500M
Commands:
journalctl -u api.servicejournalctl -u api.service --since "1 hour ago"journalctl --disk-usagejournalctl --vacuum-size=500M
Examples:
- journalctl -u api.service -f
- journalctl -u api.service --since today -o json | jq '.MESSAGE'
- journalctl --disk-usage && journalctl --vacuum-size=500M