Verify Permissions on the GRUB2 Configuration Files in /boot/grub2

Description

The GRUB2 configuration files in /boot/grub2 and its subdirectories, which are the files whose names start with grub, such as grub.cfg and grubenv, and the files named user.cfg, should have mode 0600 or stricter. To set their mode, run the command:

$ sudo find /boot/grub2 -type f \( -name 'grub*' -o -name user.cfg \) -exec chmod u-x,go-rwx {} +

Rationale

These files hold the boot parameters and the boot loader password hashes. A user who can read them learns the boot settings, which can reveal weaknesses to exploit at boot.

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 grub2-common && rpm --quiet -q kernel-core ) && { ( ! ( [ -f /.dockerenv ] || [ -f /run/.containerenv ] ) ); }; then

find -P /boot/grub2/  -perm /u+xs,g+xwrs,o+xwrt  -type f -regextype posix-extended -regex '^(.*/)?(grub[^/]*|user\.cfg)$' -exec chmod u-xs,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-88601-0
  - configure_strategy
  - file_permissions_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Find /boot/grub2/ file(s) recursively
  ansible.builtin.command: find -P /boot/grub2/  -perm /u+xs,g+xwrs,o+xwrt  -type
    f -regextype posix-extended -regex "^(.*/)?(grub[^/]*|user\.cfg)$"
  register: files_found
  changed_when: false
  failed_when: false
  check_mode: false
  when:
  - ( "grub2-common" in ansible_facts.packages and "kernel-core" in ansible_facts.packages
    )
  - not ( ansible_virtualization_type in ["docker", "lxc", "openvz", "podman", "container"]
    )
  tags:
  - CCE-88601-0
  - configure_strategy
  - file_permissions_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set permissions for /boot/grub2/ file(s)
  ansible.builtin.file:
    path: '{{ item }}'
    mode: u-xs,g-xwrs,o-xwrt
    state: file
  with_items:
  - '{{ files_found.stdout_lines }}'
  when:
  - ( "grub2-common" in ansible_facts.packages and "kernel-core" in ansible_facts.packages
    )
  - not ( ansible_virtualization_type in ["docker", "lxc", "openvz", "podman", "container"]
    )
  tags:
  - CCE-88601-0
  - configure_strategy
  - file_permissions_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed