PortGate

Blueprints · Server Hardening

Production 15 min · auditd

auditd file and privilege watch

Watches passwd, shadow, sudoers, and sshd_config, and records execve from uid 0. The package is installed when apt or dnf is available.

Baked-in protections

Step 1 · conf

Rules

/etc/audit/rules.d/portgate.rules

A busy host will grow the audit log. The journald blueprint caps journald, not the audit log. Set max_log_file in auditd.conf for this host.

-w /etc/passwd -p wa -k portgate_identity
-w /etc/shadow -p wa -k portgate_identity
-w /etc/sudoers -p wa -k portgate_identity
-w /etc/sudoers.d -p wa -k portgate_identity
-w /etc/ssh/sshd_config -p wa -k portgate_sshd
-a always,exit -F arch=b64 -S execve -F euid=0 -k portgate_root_exec

Step 2 · bash

Install and load

/root/portgate-blueprints/auditd-apply.sh

augenrules loads the rules. Existing rules are kept.

#!/bin/sh
set -eu
if command -v apt-get >/dev/null 2>&1; then
  apt-get update
  apt-get install -y auditd
elif command -v dnf >/dev/null 2>&1; then
  dnf install -y audit
else
  echo "Install auditd, then copy the rules file."
  exit 0
fi
augenrules --load || true
systemctl enable --now auditd || true