Verify Group Who Owns the rsyslog Work Directory

Description

The rsyslog work directory /var/lib/rsyslog should be group-owned by root.

Rationale

The work directory holds the rsyslog queue files and state, which contain log messages not yet written or forwarded. Other users must not read or alter them.

Remediation

Shell script

The following script can be run on the host to remediate the issue.

#!/bin/bash

# Remediation is applicable only in certain platforms
if rpm --quiet -q kernel-core && rpm --quiet -q rsyslog; then

newgroup=""
if getent group "0" >/dev/null 2>&1; then
  newgroup="0"
fi

if [[ -z "${newgroup}" ]]; then
  >&2 echo "0 is not a defined group on the system"
else
find -P /var/lib/rsyslog/ -maxdepth 0 -type d  ! -group 0 -exec chgrp --no-dereference "$newgroup" {} \;

fi

else
    >&2 echo 'Remediation is not applicable, nothing was done'
fi

Ansible playbook

The following playbook can be run with Ansible to remediate the issue.

- name: Gather the package facts
  package_facts:
    manager: auto
  tags:
  - CCE-87857-9
  - configure_strategy
  - directory_groupowner_var_lib_rsyslog
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set the directory_groupowner_var_lib_rsyslog_newgroup variable if represented
    by gid
  ansible.builtin.set_fact:
    directory_groupowner_var_lib_rsyslog_newgroup: '0'
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87857-9
  - configure_strategy
  - directory_groupowner_var_lib_rsyslog
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Ensure group owner on /var/lib/rsyslog/
  ansible.builtin.file:
    path: /var/lib/rsyslog/
    follow: false
    state: directory
    group: '{{ directory_groupowner_var_lib_rsyslog_newgroup }}'
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87857-9
  - configure_strategy
  - directory_groupowner_var_lib_rsyslog
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed