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

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

# Verify Owner on the rsyslog Work Directory
 
## Description{% #description %}

The rsyslog work directory `/var/lib/rsyslog` should be owned by `root`.

## Rationale{% #rationale %}

The work directory holds the rsyslog queue files and state, which contain log messages not yet written or forwarded. Other users must not read or alter them.

## 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 /var/lib/rsyslog/ -maxdepth 0 -type d  ! -user 0 -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-87854-6
  - configure_strategy
  - directory_owner_var_lib_rsyslog
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Set the directory_owner_var_lib_rsyslog_newown variable if represented by
    uid
  ansible.builtin.set_fact:
    directory_owner_var_lib_rsyslog_newown: '0'
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87854-6
  - configure_strategy
  - directory_owner_var_lib_rsyslog
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed

- name: Ensure owner on directory /var/lib/rsyslog/
  ansible.builtin.file:
    path: /var/lib/rsyslog/
    follow: false
    state: directory
    owner: '{{ directory_owner_var_lib_rsyslog_newown }}'
  when:
  - '"kernel-core" in ansible_facts.packages'
  - '"rsyslog" in ansible_facts.packages'
  tags:
  - CCE-87854-6
  - configure_strategy
  - directory_owner_var_lib_rsyslog
  - low_complexity
  - low_disruption
  - medium_severity
  - no_reboot_needed
```
