---
title: Verify Permissions on the sudo Configuration Snippets
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > OOTB Rules > Verify Permissions on the sudo
  Configuration Snippets
---

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

# Verify Permissions on the sudo Configuration Snippets
 
## Description{% #description %}

To properly set the permissions of files in `/etc/sudoers.d`, run the command:

```
find -H /etc/sudoers.d -type f -exec chmod 0440 {} \;
```

## Rationale{% #rationale %}

sudo reads every snippet in /etc/sudoers.d as part of its policy. A snippet that other users can write lets them grant themselves root, and one they can read shows them who may run which commands.

## 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 kernel-core && { rpm --quiet -q sudo; }; then

find -P /etc/sudoers.d/ -maxdepth 1 -perm /u+xws,g+xws,o+xwrt  -type f -regextype posix-extended -regex '^.*$' -exec chmod u-xws,g-xws,o-xwrt {} \;

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.

```go
- name: Gather the package facts
  package_facts:
    manager: auto
  tags:
  - CCE-89421-2
  - configure_strategy
  - file_permissions_sudoers_drop_in_config
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Find /etc/sudoers.d/ file(s)
  ansible.builtin.command: find -P /etc/sudoers.d/ -maxdepth 1 -perm /u+xws,g+xws,o+xwrt  -type
    f -regextype posix-extended -regex "^.*$"
  register: files_found
  changed_when: false
  failed_when: false
  check_mode: false
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"sudo" in ansible_facts.packages'
  tags:
  - CCE-89421-2
  - configure_strategy
  - file_permissions_sudoers_drop_in_config
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set permissions for /etc/sudoers.d/ file(s)
  ansible.builtin.file:
    path: '{{ item }}'
    mode: u-xws,g-xws,o-xwrt
    state: file
  with_items:
  - '{{ files_found.stdout_lines }}'
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"sudo" in ansible_facts.packages'
  tags:
  - CCE-89421-2
  - configure_strategy
  - file_permissions_sudoers_drop_in_config
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
```
