---
title: Verify Owner on rsyslog Configuration Files
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > OOTB Rules > Verify Owner on rsyslog Configuration
  Files
---

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

# Verify Owner on rsyslog Configuration Files
 
## Description{% #description %}

The `/etc/rsyslog.conf` file and the `.conf` files in `/etc/rsyslog.d/` should be owned by `root`.

## Rationale{% #rationale %}

The rsyslog configuration decides which messages are kept, where they go and which remote hosts may send messages. A user who can change it can hide activity from the logs or send them elsewhere.

## 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 rsyslog; then

newown=""
if id "0" >/dev/null 2>&1; then
  newown="0"
fi

if [[ -z "$newown" ]]; then
  >&2 echo "0 is not a defined user on the system"
else

find -P /etc/ -maxdepth 1 -type f  ! -user 0 -regextype posix-extended -regex '^(.*/)?rsyslog\.conf$' -exec chown --no-dereference "$newown" {} \;

find -P /etc/rsyslog.d/ -maxdepth 1 -type f  ! -user 0 -regextype posix-extended -regex '^.*\.conf$' -exec chown --no-dereference "$newown" {} \;

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-87819-9
  - configure_strategy
  - file_owner_etc_rsyslog_conf
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set the file_owner_etc_rsyslog_conf_newown variable if represented by uid
  ansible.builtin.set_fact:
    file_owner_etc_rsyslog_conf_newown: '0'
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87819-9
  - configure_strategy
  - file_owner_etc_rsyslog_conf
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Find /etc/ file(s) matching ^(.*/)?rsyslog\.conf$
  ansible.builtin.command: find -P /etc/ -maxdepth 1 -type f  ! -user 0 -regextype
    posix-extended -regex "^(.*/)?rsyslog\.conf$"
  register: files_found
  changed_when: false
  failed_when: false
  check_mode: false
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87819-9
  - configure_strategy
  - file_owner_etc_rsyslog_conf
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Ensure owner on /etc/ file(s) matching ^(.*/)?rsyslog\.conf$
  ansible.builtin.file:
    path: '{{ item }}'
    follow: false
    owner: '{{ file_owner_etc_rsyslog_conf_newown }}'
    state: file
  with_items:
  - '{{ files_found.stdout_lines }}'
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87819-9
  - configure_strategy
  - file_owner_etc_rsyslog_conf
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Find /etc/rsyslog.d/ file(s) matching ^.*\.conf$
  ansible.builtin.command: find -P /etc/rsyslog.d/ -maxdepth 1 -type f  ! -user 0
    -regextype posix-extended -regex "^.*\.conf$"
  register: files_found
  changed_when: false
  failed_when: false
  check_mode: false
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87819-9
  - configure_strategy
  - file_owner_etc_rsyslog_conf
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Ensure owner on /etc/rsyslog.d/ file(s) matching ^.*\.conf$
  ansible.builtin.file:
    path: '{{ item }}'
    follow: false
    owner: '{{ file_owner_etc_rsyslog_conf_newown }}'
    state: file
  with_items:
  - '{{ files_found.stdout_lines }}'
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87819-9
  - configure_strategy
  - file_owner_etc_rsyslog_conf
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
```
