6.3.4.4 Ensure audit log files group owner is configured

Information

Audit log files contain information about the system and system activity.

Access to audit records can reveal system and configuration data to attackers, potentially compromising its confidentiality.

Solution

Note The following scripts will set the group to either audit or root based on the existence of the group audit If the group audit doesn't exist, or the log_group parameter is already set to root the appropriate group is determined to be the group root

Run the following script to configure the audit log files to be owned by appropriate group:

#!/usr/bin/env bash

{
l_group=""; grep -Pq '^audit:' /etc/group && l_group="audit"
[ -z "$l_group" ] || [ "$(awk -F= '$1~/^\s*log_group\s*$/{print $2}' /etc/audit/auditd.conf | xargs)" = root ] && l_group="root"
find $(dirname $(awk -F"=" '/^\s*log_file\s*=\s*/ {print $2}' /etc/audit/auditd.conf | xargs)) -type f \( ! -group root -a ! -group audit \) -exec chgrp "$l_group" {} +
}

Run the following script to configure the audit log files to be owned by the audit appropriate group:

#!/usr/bin/env bash

{
l_group=""; grep -Pq '^audit:' /etc/group && l_group="audit"
[ -z "$l_group" ] || [ "$(awk -F= '$1~/^\s*log_group\s*$/{print $2}' /etc/audit/auditd.conf | xargs)" = root ] && l_group="root"
chgrp "$l_group" /var/log/audit/
}

Run the following script to set the log_group parameter in the audit configuration file to log_group = <appropriate_group> :

#!/usr/bin/env bash

{
l_group=""; grep -Pq '^audit:' /etc/group && l_group="audit"
[ -z "$l_group" ] || [ "$(awk -F= '$1~/^\s*log_group\s*$/{print $2}' /etc/audit/auditd.conf | xargs)" = root ] && l_group="root"
sed -ri 's/^\s*#?\s*log_group\s*=\s*\S+(\s*#.*)?.*$/log_group = '"$l_group"'\1/' /etc/audit/auditd.conf
}

Run the following command to restart the audit daemon to reload the configuration file:

# systemctl restart auditd

See Also

https://workbench.cisecurity.org/benchmarks/21095