---
title: Verify Group Ownership of the GRUB2 Configuration Files
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > OOTB Rules > Verify Group Ownership of the GRUB2
  Configuration Files
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Verify Group Ownership of the GRUB2 Configuration Files
 
## Description{% #description %}

The GRUB2 configuration files in `/boot/grub2` and in `/boot/efi/EFI`, with their subdirectories, which are the files whose names start with `grub`, such as `grub.cfg` and `grubenv`, and the files named `user.cfg`, should be group-owned by the `root` group. To set the group owner of the files in `/boot/grub2`, run the command:

```
$ sudo find /boot/grub2 -type f \( -name 'grub*' -o -name user.cfg \) -exec chgrp root {} +
```

The EFI system partition is a FAT file system, which takes the group of its files from the `gid` mount option: set `gid=0` on the `/boot/efi` entry in `/etc/fstab`.

## Rationale{% #rationale %}

The `root` group is a highly-privileged group, and only root should be able to modify the boot parameters.

## Remediation{% #remediation %}

### Shell script{% #shell-script %}

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

```bash
#!/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

newgroup=""
if getent group "0" >/dev/null 2>&1; then
  newgroup="0"
fi

if [[ -z "${newgroup}" ]]; then
  >&2 echo "0 is not a defined group on the system"
else
find -P /boot/grub2/  -type f  ! -group 0 -regextype posix-extended -regex '^(.*/)?(grub[^/]*|user\.cfg)$' -exec chgrp --no-dereference "$newgroup" {} \;
find -P /boot/efi/EFI/  -type f  ! -group 0 -regextype posix-extended -regex '^(.*/)?(grub[^/]*|user\.cfg)$' -exec chgrp --no-dereference "$newgroup" {} \;

fi

else
    >&2 echo 'Remediation is not applicable, nothing was done'
fi
```

### Ansible playbook{% #ansible-playbook %}

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

```gdscript3
- name: Gather the package facts
  package_facts:
    manager: auto
  tags:
  - CCE-88594-7
  - configure_strategy
  - file_groupowner_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set the file_groupowner_grub2_config_files_newgroup variable if represented
    by gid
  ansible.builtin.set_fact:
    file_groupowner_grub2_config_files_newgroup: '0'
  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-88594-7
  - configure_strategy
  - file_groupowner_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Find /boot/grub2/ file(s) matching ^(.*/)?(grub[^/]*|user\.cfg)$ recursively
  ansible.builtin.command: find -P /boot/grub2/  -type f  ! -group 0 -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-88594-7
  - configure_strategy
  - file_groupowner_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Ensure group owner on /boot/grub2/ file(s) matching ^(.*/)?(grub[^/]*|user\.cfg)$
  ansible.builtin.file:
    path: '{{ item }}'
    follow: false
    group: '{{ file_groupowner_grub2_config_files_newgroup }}'
    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-88594-7
  - configure_strategy
  - file_groupowner_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Find /boot/efi/EFI/ file(s) matching ^(.*/)?(grub[^/]*|user\.cfg)$ recursively
  ansible.builtin.command: find -P /boot/efi/EFI/  -type f  ! -group 0 -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-88594-7
  - configure_strategy
  - file_groupowner_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Ensure group owner on /boot/efi/EFI/ file(s) matching ^(.*/)?(grub[^/]*|user\.cfg)$
  ansible.builtin.file:
    path: '{{ item }}'
    follow: false
    group: '{{ file_groupowner_grub2_config_files_newgroup }}'
    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-88594-7
  - configure_strategy
  - file_groupowner_grub2_config_files
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
```
