Skip to content

Commit

Permalink
enhancement(#5229): Enhancement of os validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-akim committed Apr 18, 2024
1 parent 98abbd8 commit 2c925fa
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 9 deletions.
16 changes: 10 additions & 6 deletions deployability/modules/testing/tests/helpers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ def register_agent(inventory_path, manager_path):

with open(manager_path, 'r') as yaml_file:
manager_path = yaml.safe_load(yaml_file)

host = manager_path.get('ansible_host')

if 'linux' in inventory_path:
os_type = HostInformation.get_os_type(inventory_path)
if os_type == 'linux':
host_ip = HostInformation.get_internal_ip_from_aws_dns(host) if 'amazonaws' in host else host
commands = [
f"sed -i 's/<address>MANAGER_IP<\/address>/<address>{host_ip}<\/address>/g' {WAZUH_CONF}",
Expand All @@ -105,7 +107,7 @@ def register_agent(inventory_path, manager_path):
Executor.execute_commands(inventory_path, commands)
assert host_ip in Executor.execute_command(inventory_path, f'cat {WAZUH_CONF}'), logger.error(f'Error configuring the Manager IP ({host_ip}) in: {HostInformation.get_os_name_and_version_from_inventory(inventory_path)} agent')

elif 'macos' in inventory_path:
elif os_type == 'macos':
host_ip = HostInformation.get_public_ip_from_aws_dns(host) if 'amazonaws' in host else host
commands = [
f"sed -i '.bak' 's/<address>MANAGER_IP<\/address>/<address>{host_ip}<\/address>/g' /Library/Ossec/etc/ossec.conf",
Expand Down Expand Up @@ -199,7 +201,7 @@ def perform_action_and_scan(agent_params, action_callback) -> dict:
os_name = HostInformation.get_os_name_from_inventory(agent_params)
logger.info(f'Applying filters in checkfiles in {HostInformation.get_os_name_and_version_from_inventory(agent_params)}')

if 'linux' in agent_params:
if 'linux' == HostInformation.get_os_type(agent_params):
if 'debian' in os_name:
filter_data = {
'/boot': {'added': [], 'removed': [], 'modified': ['grubenv']},
Expand Down Expand Up @@ -235,7 +237,7 @@ def perform_action_and_scan(agent_params, action_callback) -> dict:
'/root': {'added': ['trustdb.gpg', 'lesshst'], 'removed': [], 'modified': []},
'/usr/sbin': {'added': [], 'removed': [], 'modified': []}
}
elif 'macos' in agent_params:
elif 'macos' == HostInformation.get_os_type(agent_params):
filter_data = {
'/usr/bin': {'added': [], 'removed': [], 'modified': []},
'/usr/sbin': {'added': [], 'removed': [], 'modified': []}
Expand Down Expand Up @@ -291,11 +293,13 @@ def assert_results(result, agent_params) -> None:
result (dict): result of comparison between pre and post action scan
"""
if 'linux' in agent_params:
os_name = HostInformation.get_os_name_from_inventory(agent_params)
if os_name == 'linux':
categories = ['/root', '/usr/bin', '/usr/sbin', '/boot']
elif 'macos' in agent_params:
elif os_name == 'macos':
categories = ['/usr/bin', '/usr/sbin']
actions = ['added', 'modified', 'removed']

# Testing the results
for category in categories:
for action in actions:
Expand Down
6 changes: 3 additions & 3 deletions deployability/modules/testing/tests/helpers/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,13 @@ def _checkfiles(inventory_path, os_type, directory, filter= None, hash_algorithm
Returns:
Dict: dict of directories:hash
"""
if 'linux' in os_type:
if 'linux' == os_type:
command = f'sudo find {directory} -type f -exec sha256sum {{}} + {filter}'
result = Executor.execute_command(inventory_path, command)
elif 'macos' in os_type:
elif 'macos' == os_type:
command = f'sudo find {directory} -type f -exec shasum -a 256 {{}} \; {filter}'
result = Executor.execute_command(inventory_path, command)
elif 'windows' in os_type:
elif 'windows' == os_type:
command = 'dir /a-d /b /s | findstr /v /c:"\\.$" /c:"\\..$"| find /c ":"'
else:
logger.info(f'Unsupported operating system')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
version: 0.1
description: This workflow is used to test agents' deployment for DDT1 PoC
variables:
agent-os:
- linux-oracle-9-amd64

manager-os: linux-ubuntu-22.04-amd64
infra-provider: vagrant
working-dir: /tmp/dtt1-poc

tasks:
# Unique manager allocate task
- task: "allocate-manager-{manager-os}"
description: "Allocate resources for the manager."
do:
this: process
with:
path: python3
args:
- modules/allocation/main.py
- action: create
- provider: "{infra-provider}"
- size: large
- composite-name: "{manager-os}"
- inventory-output: "{working-dir}/manager-{manager-os}/inventory.yaml"
- track-output: "{working-dir}/manager-{manager-os}/track.yaml"
- label-termination-date: "1d"
- label-team: "qa"
on-error: "abort-all"
cleanup:
this: process
with:
path: python3
args:
- modules/allocation/main.py
- action: delete
- track-output: "{working-dir}/manager-{manager-os}/track.yaml"

# Unique agent allocate task
- task: "allocate-agent-{agent}"
description: "Allocate resources for the agent."
do:
this: process
with:
path: python3
args:
- modules/allocation/main.py
- action: create
- provider: "{infra-provider}"
- size: small
- composite-name: "{agent}"
- inventory-output: "{working-dir}/agent-{agent}/inventory.yaml"
- track-output: "{working-dir}/agent-{agent}/track.yaml"
- label-termination-date: "1d"
- label-team: "qa"
foreach:
- variable: agent-os
as: agent
cleanup:
this: process
with:
path: python3
args:
- modules/allocation/main.py
- action: delete
- track-output: "{working-dir}/agent-{agent}/track.yaml"
depends-on:
- "provision-manager-{manager-os}"

# Unique manager provision task
- task: "provision-manager-{manager-os}"
description: "Provision the manager."
do:
this: process
with:
path: python3
args:
- modules/provision/main.py
- inventory: "{working-dir}/manager-{manager-os}/inventory.yaml"
- install:
- component: wazuh-manager
type: assistant
version: 4.7.3
live: True
depends-on:
- "allocate-manager-{manager-os}"


# Generic agent test task
- task: "run-agent-{agent}-tests"
description: "Run tests install for the agent {agent}."
do:
this: process
with:
path: python3
args:
- modules/testing/main.py
- targets:
- wazuh-1: "{working-dir}/manager-{manager-os}/inventory.yaml"
- agent: "{working-dir}/agent-{agent}/inventory.yaml"
- tests: "install,registration,restart,stop,uninstall"
- component: "agent"
- wazuh-version: "4.7.3"
- wazuh-revision: "40714"
- live: "True"
foreach:
- variable: agent-os
as: agent
depends-on:
- "allocate-agent-{agent}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: 0.1
description: Test agent restart with provisioning agents' with provision module
variables:
agent-os:
- macos-ventura-13.4.1-arm64
manager-os: linux-ubuntu-18.04-amd64
infra-provider: aws
working-dir: /tmp/dtt1-poc

tasks:



# Generic agent test task
- task: "run-agent-{agent}-tests"
description: "Run tests install for the agent {agent}."
do:
this: process
with:
path: python3
args:
- modules/testing/main.py
- targets:
- wazuh-1: "{working-dir}/manager-{manager-os}/inventory.yaml"
- agent: "{working-dir}/agent-{agent}/inventory.yaml"
- tests: "install,registration,restart,stop,uninstall"
- component: "agent"
- wazuh-version: "4.7.3"
- wazuh-revision: "40714"
- live: "True"
foreach:
- variable: agent-os
as: agent

0 comments on commit 2c925fa

Please sign in to comment.