wazuh / wazuh-packages

Wazuh - Tools for packages creation
https://wazuh.com
GNU General Public License v2.0
105 stars 97 forks source link

Bug in ossec.conf Reconstruction During Wazuh RPM Upgrade #2935

Closed juliancnn closed 4 months ago

juliancnn commented 7 months ago
Wazuh version Install type Action performed Platform
at least since 4.1.5 Manager/Agent Upgrade (via rpm) -

Overview

A critical issue has been identified in the RPM upgrade process for both Wazuh Agent and Manager. This bug occurs when the ossec.conf configuration file is deleted before an upgrade or a reinstallation using RPM packages. Instead of regenerating a valid ossec.conf file, the system incorrectly inserts an incomplete and sometimes invalid configuration. This issue prevents the Wazuh Agent and Manager from starting, leading to significant operational disruptions.

Affected Versions

Issue Description

During an RPM package upgrade or reinstallation where the ossec.conf file has been manually removed, the newly generated configuration file lacks several critical default settings. Most notably, the file includes an improperly placed logging block which is either misplaced or incorrectly formatted, resulting in configuration syntax errors that prevent startup.

Specific Misconfiguration Example

The auto-generated ossec.conf incorrectly includes the following block outside the proper XML structure, causing syntax errors:

<!-- Choose between "plain", "json", or "plain,json" for the format of internal logs -->
<logging>
  <log_format>plain</log_format>
</logging>

For the manager installation, while the configuration does not contain the improper logging block and thus remains syntactically valid, it still fails to include necessary localfile definitions, leading to incomplete functionality.

Steps to Reproduce

  1. Initial Setup:

    • Install Wazuh agent or manager via YUM: yum install wazuh-agent
  2. Remove Configuration:

    • Remove the ossec.conf file: rm /var/ossec/etc/ossec.conf
  3. Trigger the Bug:

    • Reinstall the agent or manager, or upgrade to a higher version: yum reinstall wazuh-agent
    • Check the contents of the newly created ossec.conf file and attempt to start the service.

Expected Behavior

After reinstalling or upgrading the Wazuh component, a new, valid ossec.conf should be automatically generated with all necessary default configurations intact, allowing the agent or manager to start and function properly.

Actual Behavior

The agent or manager fails to start due to syntactical errors in the regenerated ossec.conf file. Additionally, necessary default configurations, such as localfile entries, are missing, crippling the functionality.

Impact

Proposed Steps for Investigation and Fix

vikman90 commented 4 months ago

Hi @juliancnn,

Regarding the issue raised, there are two important points to consider:

  1. During an upgrade, our system is designed to not alter the existing configuration, even if it is incorrect. We ensure forward compatibility, meaning a newer agent will accept configurations from previous versions. Therefore, if an upgraded agent fails to start, it indicates a pre-existing misconfiguration.
  2. Our packaging system does not support the reinstall operation. To reinstall, users must follow the installation guide to uninstall and then perform a clean install, which will provide the correct configuration file.

Given this, the issue highlights the need to implement a reinstall operation, categorizing it as a medium-impact bug or a feature request.

Best regards,