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

Fix custom sca policies remote checks #717

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions etc/kayobe/ansible/wazuh-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,35 @@
tasks:
- import_role:
name: "wazuh-ansible/wazuh-ansible/roles/wazuh/ansible-wazuh-agent"
post_tasks:
- name: Check if custom SCA policies directory exists
stat:
path: "{{ local_custom_sca_policies_path }}"
register: custom_sca_policies_folder
delegate_to: localhost

- name: Gather list of custom SCA policies
find:
paths: "{{ local_custom_sca_policies_path }}"
patterns: '*.yml'
delegate_to: localhost
register: custom_sca_policies
when: custom_sca_policies_folder.stat.exists

- name: Allow Wazuh agents to execute commands in SCA policies sent from the Wazuh manager
become: yes
blockinfile:
path: "/var/ossec/etc/local_internal_options.conf"
state: present
owner: wazuh
group: wazuh
block: sca.remote_commands=1
when: custom_sca_policies.files | length > 0
notify:
- Restart wazuh-agent

handlers:
- name: Restart wazuh-agent
service:
name: wazuh-agent
state: restarted
12 changes: 1 addition & 11 deletions etc/kayobe/ansible/wazuh-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@
delegate_to: localhost
register: custom_sca_policies
when: custom_sca_policies_folder.stat.exists

- name: Allow Wazuh agents to execute commands in SCA policies sent from the Wazuh manager
blockinfile:
path: "/var/ossec/etc/local_internal_options.conf"
state: present
owner: wazuh
group: wazuh
block: |
sca.remote_commands=1
when: custom_sca_policies.files | length > 0
become: no

- name: Copy custom SCA policy files to Wazuh manager
copy:
Expand Down Expand Up @@ -112,7 +103,6 @@
- name: Perform health check against filebeat
command: filebeat test output
changed_when: false
become: true
retries: 2

handlers:
MoteHue marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 3 additions & 0 deletions etc/kayobe/inventory/group_vars/all/wazuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Ansible custom SCA policies directory
local_custom_sca_policies_path: "{{ kayobe_env_config_path }}/wazuh/custom_sca_policies"
3 changes: 0 additions & 3 deletions etc/kayobe/inventory/group_vars/wazuh-manager/wazuh-manager
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ local_certs_path: "{{ playbook_dir }}/wazuh/certificates"
# Ansible control host custom certificates directory
local_custom_certs_path: "{{ playbook_dir }}/wazuh/custom_certificates"

# Ansible custom SCA policies directory
local_custom_sca_policies_path: "{{ kayobe_env_config_path }}/wazuh/custom_sca_policies"

# Indexer variables
indexer_node_name: "{{ inventory_hostname }}"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
When using custom SCA policies for Wazuh, the agents are now correctly
configured to allow commands to be executed from the manager.