# Compliance Logging

> Implement compliance-grade logging: audit trails with auditd, systemd journal capture, logrotate policies, and immutable log shipping. Use when working with auditd, journal rotation, api or when the user mentions auditd, journal rotation, api.

- Skill: `opknock/compliance-logging` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/compliance-logging`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/compliance-logging/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/compliance-logging

---


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 `knowledge` and `prerequisites: 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 doctor` patterns for your inputs

### 3. Act — execute with `compliance-logging` tools
- Tools: `Glob`, `Grep`, `Read`, `Auditctl`, `Ausearch` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for 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

```bash
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

```bash
ausearch -k identity -i
ausearch -ts today -k api-config -i | tail -20
```

## systemd Journal

```bash
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
}
```

```bash
logrotate -d /etc/logrotate.d/api
```

## Testing

```bash
# 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 audit
- `key` (string): Audit rule key such as identity or api-config

**Commands:**
- `auditctl -l`
- `auditctl -w /etc/passwd -p wa -k identity`
- `auditctl -a always,exit -F arch=b64 -S execve -k process-exec`
- `ausearch -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.service
- `vacuum_size` (string): Journal size limit such as 500M

**Commands:**
- `journalctl -u api.service`
- `journalctl -u api.service --since "1 hour ago"`
- `journalctl --disk-usage`
- `journalctl --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

## References
- [Linux auditd documentation](https://linux-audit.com/)
- [logrotate man page](https://man7.org/linux/man-pages/man5/logrotate.conf.5.html)

