Verify Permissions on the DNF Log Files

Description

To properly set the permissions of /var/log/dnf.* /var/log/hawkey.log* /var/log/yum.log*, run the command:

$ sudo chmod 0644 /var/log/dnf.* /var/log/hawkey.log* /var/log/yum.log*

Rationale

The /var/log/dnf.*, /var/log/hawkey.log and /var/log/yum.log files record the packages the package manager installs and removes, and should only be modified by authorized personnel.

Remediation

Shell script

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

#!/bin/bash

find -P /var/log/ -maxdepth 1 -perm /u+xs,g+xws,o+xwt  -type f -regextype posix-extended -regex '^(.*/)?(dnf[0-9]*\.|hawkey\.log|yum\.log)[^/]*$' -exec chmod u-xs,g-xws,o-xwt {} \;

Ansible playbook

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

- name: Find /var/log/ file(s)
  ansible.builtin.command: find -P /var/log/ -maxdepth 1 -perm /u+xs,g+xws,o+xwt  -type
    f -regextype posix-extended -regex "^(.*/)?(dnf[0-9]*\.|hawkey\.log|yum\.log)[^/]*$"
  register: files_found
  changed_when: false
  failed_when: false
  check_mode: false
  tags:
  - CCE-88635-8
  - configure_strategy
  - file_permissions_var_log_dnf
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set permissions for /var/log/ file(s)
  ansible.builtin.file:
    path: '{{ item }}'
    mode: u-xs,g-xws,o-xwt
    state: file
  with_items:
  - '{{ files_found.stdout_lines }}'
  tags:
  - CCE-88635-8
  - configure_strategy
  - file_permissions_var_log_dnf
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed