Verify Permissions on the rsyslog Work Directory

Description

The rsyslog work directory /var/lib/rsyslog should have mode 0700 or less permissive.

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

find -H /var/lib/rsyslog/ -maxdepth 0 -perm /u+s,g+xwrs,o+xwrt -type d -exec chmod u-s,g-xwrs,o-xwrt {} \;

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-87860-3
  - configure_strategy
  - directory_permissions_var_lib_rsyslog
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Find /var/lib/rsyslog/ file(s)
  ansible.builtin.command: 'find -P /var/lib/rsyslog/ -maxdepth 0 -perm /u+s,g+xwrs,o+xwrt  -type
    d '
  register: files_found
  changed_when: false
  failed_when: false
  check_mode: false
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87860-3
  - configure_strategy
  - directory_permissions_var_lib_rsyslog
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set permissions for /var/lib/rsyslog/ file(s)
  ansible.builtin.file:
    path: '{{ item }}'
    mode: u-s,g-xwrs,o-xwrt
    state: directory
  with_items:
  - '{{ files_found.stdout_lines }}'
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87860-3
  - configure_strategy
  - directory_permissions_var_lib_rsyslog
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed