Verify Permissions on the rsyslog Drop-In Directory

Description

The /etc/rsyslog.d directory should have mode 0755 or less permissive.

Rationale

A user who can write to the drop-in directory can add a configuration file that rsyslog loads at its next start.

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 /etc/rsyslog.d/ -maxdepth 0 -perm /u+s,g+ws,o+wt -type d -exec chmod u-s,g-ws,o-wt {} \;

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-87850-4
  - configure_strategy
  - directory_permissions_etc_rsyslog_d
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Find /etc/rsyslog.d/ file(s)
  ansible.builtin.command: 'find -P /etc/rsyslog.d/ -maxdepth 0 -perm /u+s,g+ws,o+wt  -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-87850-4
  - configure_strategy
  - directory_permissions_etc_rsyslog_d
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set permissions for /etc/rsyslog.d/ file(s)
  ansible.builtin.file:
    path: '{{ item }}'
    mode: u-s,g-ws,o-wt
    state: directory
  with_items:
  - '{{ files_found.stdout_lines }}'
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87850-4
  - configure_strategy
  - directory_permissions_etc_rsyslog_d
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed