Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command Manager configuration file #180

Open
7 tasks done
Tracked by #349
AlexRuiz7 opened this issue Dec 11, 2024 · 5 comments · May be fixed by #213
Open
7 tasks done
Tracked by #349

Command Manager configuration file #180

AlexRuiz7 opened this issue Dec 11, 2024 · 5 comments · May be fixed by #213
Assignees
Labels
level/task Task issue mvp Minimum Viable Product type/enhancement Enhancement issue

Comments

@AlexRuiz7
Copy link
Member

AlexRuiz7 commented Dec 11, 2024

Description

Aside from using the OpenSearch's keystore for storing sensitive data, the Command Manager needs to expose several non-sensitive settings that modify its behavior. The values for these properties are currently set by code, so the CM plugin needs to expose these settings to a configuration file, read, validate and apply these settings correctly.

A proposition of the settings to be exposed, and their accepted values, must be provided.

wazuh/wazuh#27158 can be used as reference.

Functional requirements

  • The CM plugin reads and applies valid settings from the configuration file.
  • The CM plugins rejects invalid settings, raising an error. In this case, default values must be used.
  • The configuration file is created / updated and added to the wazuh-indexer package.

Implementation restrictions

  • opensearch.yml is preferred.

Plan

  • Spike. Check if custom settings can be added to opensearch.yml.
  • Identify settings to expose.
  • Register the settings.
  • Load values from the settings file at start up.
  • Unit tests.
  • Documentation.

Related issues

@AlexRuiz7 AlexRuiz7 added level/task Task issue type/enhancement Enhancement issue labels Dec 11, 2024
@AlexRuiz7 AlexRuiz7 added the mvp Minimum Viable Product label Dec 11, 2024
@QU3B1M
Copy link
Member

QU3B1M commented Dec 12, 2024

Spike. Check if custom settings can be added to opensearch.yml

OpenSearch supports adding custom configurations to the opensearch.yml, and it can be done in a friendly way, as we researched in #86, and as we can see from the code of this third-party plugin as reference.


Proof of concept

To validate the implementation is possible, I've generated a custom package with the changes required to read the settings m_api.auth.username, m_api.auth.password & m_api.urifrom the configuration file:

  • Convert the settings from SecureSetting.secureString to Setting.simpleString

    public class PluginSettings {
        public static final Setting<String> M_API_AUTH_USERNAME = Setting.simpleString("m_api.auth.username", Setting.Property.NodeScope, Setting.Property.Filtered);
        public static final Setting<String> M_API_AUTH_PASSWORD = Setting.simpleString("m_api.auth.password", Setting.Property.NodeScope, Setting.Property.Filtered);
        public static final Setting<String> M_API_URI = Setting.simpleString("m_api.uri", Setting.Property.NodeScope, Setting.Property.Filtered);
        ...
    }
  • On the build.gradle for the integTest section define the values storage to be on setting instead of keystore

    testClusters.integTest {
         ...
         setting 'm_api.auth.username', 'admin'
         setting 'm_api.auth.password', 'test'
         setting 'm_api.uri', 'https://127.0.0.1:55000' 
         ...
    }
  • Add some logs to check the values at wazuh-indexer startup

        private PluginSettings(@NonNull final Settings settings) {
            ...
            log.info("[SETTINGS] Username: {}", this.authUsername);
            log.info("[SETTINGS] URI: {}", this.uri);
        }

Functionality validation

  1. Install the custom wazuh-indexer package with the POC changes
  2. Configure the settings on the opensearch.yml
    m_api:
      auth:
        username: "test_user"
        password: "test_pwd"
      uri: "test_uri"
  3. Restart wazuh-indexer and check the logs
    [2024-12-17T10:02:38,276][INFO ][c.w.c.s.PluginSettings   ] [node-1] [SETTINGS] Username: test_user
    [2024-12-17T10:02:38,276][INFO ][c.w.c.s.PluginSettings   ] [node-1] [SETTINGS] URI: test_uri

@AlexRuiz7
Copy link
Member Author

AlexRuiz7 commented Dec 16, 2024

Identify settings to expose

  • command_manager.client.timeout: integer (seconds)
  • command_manager.job.schedule: integer (minutes)
  • command_manager.job.page_size: integer
  • command_manager.job.pit_keep_alive: integer (seconds)
  • command_manager.job.index.template: string
  • command_manager.api.prefix: string
  • command_manager.api.endpoint: string
  • command_manager.index.name: string
  • command_manager.index.template: string

Note

Some configurations were kept as constants rather than settings preventing runtime changes, which could lead to inconsistencies within plugin components and external interactions.


Based on the previous definitions, we have analyzed a potential structure for the command-manager configuration. Here is a proposed YAML structure:

command_manager:
  client:
    timeout: int           # Default: 20
  job:
    schedule: int         # Default: 1
    page_size: int        # Default: 100
    pit_keep_alive: int   # Default: 30

Further research and testing is required to validate if this approach is possible, for now we only tested for "simple" key values on the yaml. On the POC from the previous comment we have validated this configuration format in a minor scale.

@QU3B1M
Copy link
Member

QU3B1M commented Dec 17, 2024

We need to evaluate the possibility of supporting multiple management_api connections. Currently, the configuration supports only one host with a username and password, making it incompatible with multiple connections. To address this, we should consider modifying the configuration to use an array for each API node, which will require additional development on the plugin.

The updated configuration might look like this:
management_api:
  nodes:
    - auth:
        username: secure string
        password: secure string
      host: string

@wazuhci wazuhci moved this from In progress to On hold in XDR+SIEM/Release 5.0.0 Dec 19, 2024
@wazuhci wazuhci moved this from On hold to Blocked in XDR+SIEM/Release 5.0.0 Dec 19, 2024
@wazuhci wazuhci moved this from Blocked to On hold in XDR+SIEM/Release 5.0.0 Jan 10, 2025
@wazuhci wazuhci moved this from On hold to In progress in XDR+SIEM/Release 5.0.0 Jan 10, 2025
@QU3B1M QU3B1M linked a pull request Jan 13, 2025 that will close this issue
@QU3B1M
Copy link
Member

QU3B1M commented Jan 13, 2025

The settings are registered, and the constant usages have been replaced with their corresponding values. These settings will be loaded from the opensearch.yml file. None of the settings are mandatory, as each has a default value registered in the PluginSettings class.

The job.index.name setting is discarded and retained as a constant in PluginSettings because the job's index name value is used in the getJobIndex() getter function of the CommandManagerPlugin class, and this is required for the JobSchedulerExtension interface, which is loaded before the settings.

@QU3B1M
Copy link
Member

QU3B1M commented Jan 14, 2025

Generated a documentation proposal that can be found at the main comment of the PR #213

@wazuhci wazuhci moved this from In progress to Pending review in XDR+SIEM/Release 5.0.0 Jan 14, 2025
@wazuhci wazuhci moved this from Pending review to In review in XDR+SIEM/Release 5.0.0 Jan 14, 2025
@wazuhci wazuhci moved this from In review to On hold in XDR+SIEM/Release 5.0.0 Jan 14, 2025
@wazuhci wazuhci moved this from On hold to In progress in XDR+SIEM/Release 5.0.0 Jan 14, 2025
@wazuhci wazuhci moved this from In progress to Pending review in XDR+SIEM/Release 5.0.0 Jan 15, 2025
@wazuhci wazuhci moved this from Pending review to In review in XDR+SIEM/Release 5.0.0 Jan 16, 2025
@wazuhci wazuhci moved this from In review to On hold in XDR+SIEM/Release 5.0.0 Jan 16, 2025
@wazuhci wazuhci moved this from On hold to Blocked in XDR+SIEM/Release 5.0.0 Jan 16, 2025
@wazuhci wazuhci moved this from Blocked to Pending review in XDR+SIEM/Release 5.0.0 Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/task Task issue mvp Minimum Viable Product type/enhancement Enhancement issue
Projects
Status: Pending review
2 participants