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

Add configuration methods #56

Merged
merged 12 commits into from
Sep 6, 2023
Merged

Conversation

juliamagan
Copy link
Member

@juliamagan juliamagan commented Jun 14, 2023

Description

In this PR, functions have been added that will be used for the configuration of Wazuh nodes. This configuration can be done either in parallel or not.

The following functions have been added which are responsible for modifying and restoring the configuration:

  • configure_host().
  • change_agents_configured_manager().
  • backup_host_configuration().
  • restore_host_backup_configuration()

In addition, the following functions have been added, which are responsible for executing the above functions in parallel when desired:

  • configure_environment().
  • backup_environment_configuration().
  • restore_environment_backup_configuration().

The configuration expected by these functions will have the following format:

wazuh-manager1:
  local_internal_options.conf:
    remoted.debug: '2'
  ossec.conf:
  - section: client
    elements:
    - server:
        elements:
        - address:
            value: 121.1.3.1
  agent.conf:
    group: default
    configuration:
    - section: client
      elements:
      - server:
          elements:
          - address:
              value: 121.1.3.1
  api.yaml:
    logs:
      level: debug

wazuh-agent1:
  ossec.conf:
    ...

The supported files are ossec.conf, agent.conf, api.yaml and agent.conf

@juliamagan juliamagan self-assigned this Jun 14, 2023
@juliamagan juliamagan changed the base branch from main to system-refactor June 14, 2023 14:26
@juliamagan juliamagan linked an issue Jun 14, 2023 that may be closed by this pull request
@juliamagan juliamagan requested a review from Rebits June 16, 2023 14:15
@juliamagan juliamagan marked this pull request as ready for review June 16, 2023 14:33
Copy link
Member

@Rebits Rebits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GJ! Some minor changes are required

Comment on lines 15 to +24
DEFAULT_INSTALL_PATH = {
'linux': '/var/ossec',
'windows': 'C:\\Program Files\\ossec-agent',
'windows': 'C:/Program Files (x86)/ossec-agent',
'darwin': '/Library/Ossec'
}

DEFAULT_TEMPORAL_DIRECTORY = {
'linux': '/tmp',
'windows': 'C:/Users/qa/AppData/Local/Temp'
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These vars should be moved into a common variables module

Copy link
Member Author

@juliamagan juliamagan Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the development can be long and goes out of the scope of this PR, the following issue has been created and will be worked on:

Comment on lines 27 to 50
def configure_local_internal_options(new_conf):
local_internal_configuration_string = ''
for option_name, option_value in new_conf.items():
local_internal_configuration_string += f"{str(option_name)}={str(option_value)}\n"
return local_internal_configuration_string


def configure_ossec_conf(new_conf, template):
new_configuration = ''.join(set_section_wazuh_conf(new_conf, template))
return new_configuration


def configure_api_yaml(new_conf):
new_configuration = yaml.dump(new_conf)
return new_configuration


conf_functions = {
'local_internal_options.conf': configure_local_internal_options,
'ossec.conf': configure_ossec_conf,
'agent.conf': configure_ossec_conf,
'api.yaml': configure_api_yaml
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move all these functions to the configuration module.
Functions to get the directory path should be moved to a separate module too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ecc6d4c

@@ -340,7 +371,7 @@ def get_ruleset_directory_path(self, host):

return ruleset_directory_path

def configure_host(self, host, configuration_host):
def configure_host(self, host, configuration_file, configuration_values):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the examples in the docstring

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8aa3f89

parameters = {'new_conf': configuration_values}

# Get template for ossec.conf and agent.conf
if configuration_file == 'ossec.conf' or configuration_file == 'agent.conf':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if configuration_file == 'ossec.conf' or configuration_file == 'agent.conf':
if configuration_file in ['ossec.conf', 'agent.conf']:

We can also move that list into a variable called xml_configuration_files

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1deaf31

src/wazuh_qa_framework/system/wazuh_handler.py Outdated Show resolved Hide resolved
src/wazuh_qa_framework/system/wazuh_handler.py Outdated Show resolved Hide resolved
src/wazuh_qa_framework/system/wazuh_handler.py Outdated Show resolved Hide resolved
src/wazuh_qa_framework/system/wazuh_handler.py Outdated Show resolved Hide resolved
@QU3B1M
Copy link
Member

QU3B1M commented Aug 2, 2023

LGTM! 🚀

@BelenValdivia
Copy link

LGTM!

@davidjiglesias davidjiglesias merged commit fb5f2d0 into system-refactor Sep 6, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wazuh Handler: Parallel host configuration
5 participants