Verify Permissions on /var/log/*.journal(~) Files

Description

To properly set the permissions of the journal files under /var/log, *.journal and *.journal~, run the command:

$ sudo find /var/log -type f \( -name '*.journal' -o -name '*.journal~' \) -exec chmod 0640 {} +

Rationale

The /var/log/*.journal(~) files are system logs managed by the “systemd” service.

Remediation

Shell script

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

#!/bin/bash

find -P /var/log/  -perm /u+xs,g+xws,o+xwrt  -type f -regextype posix-extended -regex '^.*\.journal~?$' -exec chmod u-xs,g-xws,o-xwrt {} \;

Ansible playbook

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

- name: Find /var/log/ file(s) recursively
  ansible.builtin.command: find -P /var/log/  -perm /u+xs,g+xws,o+xwrt  -type f -regextype
    posix-extended -regex "^.*\.journal~?$"
  register: files_found
  changed_when: false
  failed_when: false
  check_mode: false
  tags:
  - configure_strategy
  - file_permissions_var_log_journal
  - 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-xwrt
    state: file
  with_items:
  - '{{ files_found.stdout_lines }}'
  tags:
  - configure_strategy
  - file_permissions_var_log_journal
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed