Refactoring Wazuh Manager role

This commit is contained in:
Miguelangel Freitas 2017-07-12 16:53:33 -04:00
parent d669b3cab6
commit 1d144ee992
27 changed files with 112 additions and 135 deletions

View File

@ -1,95 +1,69 @@
Role Name Ansible Playbook - Wazuh manager
========= ================================
This role will install the Wazuh server on a host. This role will install the Wazuh manager on a host.
Requirements Requirements
------------ ------------
This role will work on: This role will work on:
* Red Hat * Red Hat
* CentOS
* Fedora
* Debian * Debian
* Ubuntu
Role Variables Role Variables
-------------- --------------
This role has some variables which you can or need to override. This role has some variables which you can or need to override.
``` ```
ossec_server_config: [] wazuh_manager_fqdn: []
ossec_agent_configs: [] wazuh_manager_config: []
api_user: [] wazuh_agent_configs: []
``` ```
Vault variables Vault variables
---------------- ----------------
### vars/agentless.yml ### vars/agentless_creeds.yml
This file has the agenless c. This file has the agenless credentials.
``` ```
--- ---
agentless_passlist: agentless_creeds:
- host: wazuh@wazuh.com - type: ssh_integrity_check_linux
passwd: testpasswd frequency: 3600
- host: wazuh2@wazuh.com host: root@example.net
passwd: test2passwd state: periodic
arguments: '/bin /etc/ /sbin'
passwd: qwerty
``` ```
### vars/wazuh_api_creds
### templates/agentless.j2
In this template we create the file with the format .passlist that ossec needs.
```
{% for agentless in agentless_passlist %}
{{ agentless.host }}|{{ agentless.passwd }}
{% endfor %}
```
### tasks/main
In the main we import the variables included in the vault file agentless.yml, then we move to a temporal file the folder /var/ossec/agentless/.passlist_tmp and then encode to base64.
```
- name: Import agentless secret variable file
include_vars: "agentless.yml"
no_log: true
- name: Agentless Credentials
template:
src: agentless.j2
dest: "/var/ossec/agentless/.passlist_tmp"
owner: root
group: root
mode: 0644
no_log: true
when: agentless_passlist is defined
- name: Encode the secret
shell: /usr/bin/base64 /var/ossec/agentless/.passlist_tmp > /var/ossec/agentless/.passlist && rm /var/ossec/agentless/.passlist_tmp
when: agentless_passlist is defined
```
### vars/api_user.yml
This file has user and password created in httpasswd format. This file has user and password created in httpasswd format.
``` ```
--- ---
user: wazuh_api_user:
- "wazuh:$apr1$XSwG938n$tDxKvaCBx5C/kdU2xXP3K." - "foo:$apr1$/axqZYWQ$Xo/nz/IG3PdwV82EnfYKh/"
- "wazuh2:$apr1$XSwG938n$tDxKvaCBx5C/kdU2xXP3K."
``` ```
Default config
--------------
### Example setup ### defaults/main.yml
Edit the vars file for the host which runs the ossec-server:
### host_vars/ossec-server
``` ```
ossec_server_config: ---
wazuh_manager_fqdn: "wazuh-server"
wazuh_manager_config:
email_notification: no
mail_to: mail_to:
- me@example.com - admin@example.net
mail_smtp_server: localhost mail_smtp_server: localhost
mail_from: ossec@example.com mail_from: wazuh-server@example.com
frequency_check: 43200 frequency_check: 43200
syscheck_scan_on_start: 'yes' syscheck_scan_on_start: 'yes'
log_level: 1
email_level: 12
ignore_files: ignore_files:
- /etc/mtab - /etc/mtab
- /etc/mnttab - /etc/mnttab
@ -131,9 +105,7 @@ ossec_server_config:
connection: connection:
- type: 'secure' - type: 'secure'
port: '1514' port: '1514'
protocol: 'udp' protocol: 'tcp'
log_level: 1
email_level: 12
commands: commands:
- name: 'disable-account' - name: 'disable-account'
executable: 'disable-account.sh' executable: 'disable-account.sh'
@ -165,7 +137,7 @@ ossec_server_config:
level: 6 level: 6
timeout: 600 timeout: 600
ossec_agent_configs: wazuh_agent_configs:
- type: os - type: os
type_value: linux type_value: linux
frequency_check: 79200 frequency_check: 79200
@ -195,24 +167,19 @@ ossec_agent_configs:
location: '/var/ossec/logs/active-responses.log' location: '/var/ossec/logs/active-responses.log'
``` ```
####ossec_server_config: #### Custom variables:
At first, there is the server configuration. Change it for your needs, as this default setup won't do any good for you. (You don't have access to use the mail.example.com mailhost. :-)) You can create a YAML file and change the default variables for this role, to later using it with `-e` option in `ansible-playbooks`, for example:
```
---
wazuh_manager_fqdn: "wazuh-server"
####ossec_agent_configs: wazuh_manager_config:
http://ossec-docs.readthedocs.org/en/latest/manual/agent/agent-configuration.html email_notification: yes
mail_to:
There are 3 "types": - myadmin@mydomain.com
* os mail_smtp_server: mysmtp.mydomain.com
* name ```
* profile
In the above setup, the type is os. And this configuration is for the "linux" os. You can have several types configured in the host_vars file, so you can create all kind of different configs.
You can find here some more information about the ossec shared agent configuration: http://ossec-docs.readthedocs.org/en/latest/manual/syscheck/
#### <_role_>/vars/main.yml
nil
Dependencies Dependencies
------------ ------------
@ -224,22 +191,19 @@ Example Playbook
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: ossec-server.example.com - hosts: wazuh-server.example.com
roles: roles:
- { role: ansible-wazuh-manager } - { role: ansible-wazuh-server }
License License and copyright
------- ---------------------
GPLv3 WAZUH Copyright (C) 2017 Wazuh Inc. (License GPLv3)
Author Information ### Based on previous work from dj-wasabi
------------------
Please send suggestion or pull requests to make this role better. - https://github.com/dj-wasabi/ansible-ossec-server
Github: https://github.com/dj-wasabi/ansible-ossec-server ### Modified by Wazuh
mail: ikben [ at ] werner-dijkerman . nl The playbooks have been modified by Wazuh, including some specific requirements, templates and configuration to improve integration with Wazuh ecosystem.
Modificated by **Wazuh**

View File

@ -1,12 +1,12 @@
--- ---
ossec_server_fqdn: "ossec-server" wazuh_manager_fqdn: "wazuh-server"
ossec_server_config: wazuh_manager_config:
email_notification: no email_notification: no
mail_to: mail_to:
- admin@example.net - admin@example.net
mail_smtp_server: localhost mail_smtp_server: localhost
mail_from: ossec@example.com mail_from: wazuh-server@example.com
frequency_check: 43200 frequency_check: 43200
syscheck_scan_on_start: 'yes' syscheck_scan_on_start: 'yes'
log_level: 1 log_level: 1
@ -84,7 +84,7 @@ ossec_server_config:
level: 6 level: 6
timeout: 600 timeout: 600
ossec_agent_configs: wazuh_agent_configs:
- type: os - type: os
type_value: linux type_value: linux
frequency_check: 79200 frequency_check: 79200

View File

@ -1,7 +1,7 @@
--- ---
galaxy_info: galaxy_info:
author: Jose Luis Ruiz author: Wazuh
description: Installing and maintaining the wazuh-manager. description: Installing, deploying and configuring Wazuh Manager.
company: wazuh.com company: wazuh.com
license: license (GPLv3) license: license (GPLv3)
min_ansible_version: 2.0 min_ansible_version: 2.0

View File

@ -0,0 +1,3 @@
- hosts: wazuh-server.example.com
roles:
- { role: ansible-wazuh-server }

View File

@ -15,7 +15,7 @@
- init - init
- name: Generate SSL files - name: Generate SSL files
command: "openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:1825 -keyout sslmanager.key -out sslmanager.cert -subj /CN={{ossec_server_fqdn}}/" command: "openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:1825 -keyout sslmanager.key -out sslmanager.cert -subj /CN={{wazuh_manager_fqdn}}/"
args: args:
creates: sslmanager.cert creates: sslmanager.cert
chdir: /var/ossec/etc/ chdir: /var/ossec/etc/
@ -64,11 +64,11 @@
- name: Enable client-syslog - name: Enable client-syslog
command: /var/ossec/bin/ossec-control enable client-syslog command: /var/ossec/bin/ossec-control enable client-syslog
when: csyslog_running.stdout == '0' and ossec_server_config.syslog_outputs is defined when: csyslog_running.stdout == '0' and wazuh_manager_config.syslog_outputs is defined
- name: Start client-syslog - name: Start client-syslog
command: /var/ossec/bin/ossec-control start client-syslog command: /var/ossec/bin/ossec-control start client-syslog
when: csyslog_running.stdout == '0' and ossec_server_config.syslog_outputs is defined when: csyslog_running.stdout == '0' and wazuh_manager_config.syslog_outputs is defined
- name: Check if ossec-agentlessd is enabled - name: Check if ossec-agentlessd is enabled
shell: "/var/ossec/bin/ossec-control status | grep -c 'ossec-agentlessd is running' | xargs echo" shell: "/var/ossec/bin/ossec-control status | grep -c 'ossec-agentlessd is running' | xargs echo"

View File

@ -8,20 +8,20 @@
<global> <global>
<jsonout_output>yes</jsonout_output> <jsonout_output>yes</jsonout_output>
<alerts_log>yes</alerts_log> <alerts_log>yes</alerts_log>
{% if ossec_server_config.email_notification | lower == "yes" %} {% if wazuh_manager_config.email_notification | lower == "yes" %}
<email_notification>yes</email_notification> <email_notification>yes</email_notification>
{% for to in ossec_server_config.mail_to %}
<email_to>{{ to }}</email_to>
{% endfor %}
<smtp_server>{{ ossec_server_config.mail_smtp_server }}</smtp_server>
<email_from>{{ ossec_server_config.mail_from }}</email_from>
{% else %} {% else %}
<email_notification>no</email_notification> <email_notification>no</email_notification>
{% endif %} {% endif %}
{% for to in wazuh_manager_config.mail_to %}
<email_to>{{ to }}</email_to>
{% endfor %}
<smtp_server>{{ wazuh_manager_config.mail_smtp_server }}</smtp_server>
<email_from>{{ wazuh_manager_config.mail_from }}</email_from>
</global> </global>
{% if ossec_server_config.extra_emails is defined %} {% if wazuh_manager_config.extra_emails is defined %}
{% for mail in ossec_server_config.extra_emails %} {% for mail in wazuh_manager_config.extra_emails %}
<email_alerts> <email_alerts>
<email_to>{{ mail.mail_to }}</email_to> <email_to>{{ mail.mail_to }}</email_to>
{% if mail.format is defined %} {% if mail.format is defined %}
@ -50,12 +50,12 @@
{% endif %} {% endif %}
<alerts> <alerts>
<log_alert_level>{{ ossec_server_config.log_level }}</log_alert_level> <log_alert_level>{{ wazuh_manager_config.log_level }}</log_alert_level>
<email_alert_level>{{ ossec_server_config.email_level }}</email_alert_level> <email_alert_level>{{ wazuh_manager_config.email_level }}</email_alert_level>
</alerts> </alerts>
<remote> <remote>
{% for connection in ossec_server_config.connection %} {% for connection in wazuh_manager_config.connection %}
<connection>{{ connection.type }}</connection> <connection>{{ connection.type }}</connection>
<port>{{ connection.port }}</port> <port>{{ connection.port }}</port>
<protocol>{{ connection.protocol }}</protocol> <protocol>{{ connection.protocol }}</protocol>
@ -89,27 +89,28 @@
<syscheck> <syscheck>
<!-- Frequency that syscheck is executed -- default every 20 hours --> <!-- Frequency that syscheck is executed -- default every 20 hours -->
<frequency>{{ ossec_server_config.frequency_check }}</frequency> <frequency>{{ wazuh_manager_config.frequency_check }}</frequency>
<scan_on_start>{{ ossec_server_config.syscheck_scan_on_start }}</scan_on_start> <scan_on_start>{{ wazuh_manager_config.syscheck_scan_on_start }}</scan_on_start>
<!-- Directories to check (perform all possible verifications) --> <!-- Directories to check (perform all possible verifications) -->
{% for directory in ossec_server_config.directories %} {% for directory in wazuh_manager_config.directories %}
<directories check_all="{{ directory.check_all }}">{{ directory.dirs }}</directories> <directories check_all="{{ directory.check_all }}">{{ directory.dirs }}</directories>
{% endfor %} {% endfor %}
<!-- Files/directories to ignore --> <!-- Files/directories to ignore -->
{% for ignore_file in ossec_server_config.ignore_files %} {% for ignore_file in wazuh_manager_config.ignore_files %}
<ignore>{{ ignore_file }}</ignore> <ignore>{{ ignore_file }}</ignore>
{% endfor %} {% endfor %}
<!-- Files no diff --> <!-- Files no diff -->
{% for no_diff in ossec_server_config.no_diff %} {% for no_diff in wazuh_manager_config.no_diff %}
<nodiff>{{ no_diff }}</nodiff> <nodiff>{{ no_diff }}</nodiff>
{% endfor %} {% endfor %}
</syscheck> </syscheck>
{% if ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'xenial' %} {% if ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'xenial' %}
<wodle name="open-scap"> <wodle name="open-scap">
<disabled>no</disabled>
<timeout>1800</timeout> <timeout>1800</timeout>
<interval>1d</interval> <interval>1d</interval>
<scan-on-start>yes</scan-on-start> <scan-on-start>yes</scan-on-start>
@ -118,8 +119,20 @@
<profile>xccdf_org.ssgproject.content_profile_common</profile> <profile>xccdf_org.ssgproject.content_profile_common</profile>
</content> </content>
</wodle> </wodle>
{% elif ansible_distribution == 'Debian' and ansible_distribution_release == 'jessie' %}
<wodle name="open-scap">
<disabled>no</disabled>
<timeout>1800</timeout>
<interval>1d</interval>
<scan-on-start>yes</scan-on-start>
<content type="xccdf" path="ssg-debian-8-ds.xml">
<profile>xccdf_org.ssgproject.content_profile_common</profile>
</content>
</wodle>
{% elif ansible_distribution == 'CentOS' %} {% elif ansible_distribution == 'CentOS' %}
<wodle name="open-scap"> <wodle name="open-scap">
<disabled>no</disabled>
<timeout>1800</timeout> <timeout>1800</timeout>
<interval>1d</interval> <interval>1d</interval>
<scan-on-start>yes</scan-on-start> <scan-on-start>yes</scan-on-start>
@ -134,7 +147,8 @@
</content> </content>
</wodle> </wodle>
{% elif ansible_distribution == 'RedHat' %} {% elif ansible_distribution == 'RedHat' %}
<wodle name="open-scap"> <wodle name="open-scap">
<disabled>no</disabled>
<timeout>1800</timeout> <timeout>1800</timeout>
<interval>1d</interval> <interval>1d</interval>
<scan-on-start>yes</scan-on-start> <scan-on-start>yes</scan-on-start>
@ -150,7 +164,7 @@
</wodle> </wodle>
{% elif ansible_distribution == 'Fedora' %} {% elif ansible_distribution == 'Fedora' %}
<wodle name="open-scap"> <wodle name="open-scap">
<disabled>yes</disabled> <disabled>no</disabled>
<timeout>1800</timeout> <timeout>1800</timeout>
<interval>1d</interval> <interval>1d</interval>
<scan-on-start>yes</scan-on-start> <scan-on-start>yes</scan-on-start>
@ -178,12 +192,12 @@
{% endif %} {% endif %}
<global> <global>
{% for white_list in ossec_server_config.globals %} {% for white_list in wazuh_manager_config.globals %}
<white_list>{{ white_list }}</white_list> <white_list>{{ white_list }}</white_list>
{% endfor %} {% endfor %}
</global> </global>
{% for command in ossec_server_config.commands %} {% for command in wazuh_manager_config.commands %}
<command> <command>
<name>{{ command.name }}</name> <name>{{ command.name }}</name>
<executable>{{ command.executable }}</executable> <executable>{{ command.executable }}</executable>
@ -206,7 +220,7 @@
</ruleset> </ruleset>
<!-- Active Response Config --> <!-- Active Response Config -->
{% for response in ossec_server_config.active_responses %} {% for response in wazuh_manager_config.active_responses %}
<active-response> <active-response>
<command>{{ response.command }}</command> <command>{{ response.command }}</command>
<location>{{ response.location }}</location> <location>{{ response.location }}</location>
@ -216,7 +230,7 @@
{% endfor %} {% endfor %}
<!-- Files to monitor (localfiles) --> <!-- Files to monitor (localfiles) -->
{% for localfile in ossec_server_config.localfiles %} {% for localfile in wazuh_manager_config.localfiles %}
<localfile> <localfile>
<log_format>{{ localfile.format }}</log_format> <log_format>{{ localfile.format }}</log_format>
{% if localfile.format == 'command' or localfile.format == 'full_command' %} {% if localfile.format == 'command' or localfile.format == 'full_command' %}
@ -228,8 +242,8 @@
</localfile> </localfile>
{% endfor %} {% endfor %}
{% if ossec_server_config.syslog_outputs is defined %} {% if wazuh_manager_config.syslog_outputs is defined %}
{% for syslog_output in ossec_server_config.syslog_outputs %} {% for syslog_output in wazuh_manager_config.syslog_outputs %}
<syslog_output> <syslog_output>
<server>{{ syslog_output.server }}</server> <server>{{ syslog_output.server }}</server>
<port>{{ syslog_output.port }}</port> <port>{{ syslog_output.port }}</port>

View File

@ -1,4 +1,4 @@
{% for item in ossec_agent_configs %} {% for item in wazuh_agent_configs %}
<agent_config {{ item.type }}="{{ item.type_value }}"> <agent_config {{ item.type }}="{{ item.type_value }}">
<syscheck> <syscheck>
<!-- Directories to check (perform all possible verifications) --> <!-- Directories to check (perform all possible verifications) -->

View File

@ -1,4 +1,4 @@
# Be sure you encrypt this file with ansible-vault. ---
# agentless_creeds: # agentless_creeds:
# - type: ssh_integrity_check_linux # - type: ssh_integrity_check_linux
# frequency: 3600 # frequency: 3600

View File

@ -0,0 +1,3 @@
---
wazuh_api_user:
- "foo:$apr1$/axqZYWQ$Xo/nz/IG3PdwV82EnfYKh/"

View File

@ -1 +0,0 @@
192.168.212.138

View File

@ -1,3 +0,0 @@
- hosts: ossec-manager
roles:
- role: ansible-ossec-server

View File

@ -1,3 +0,0 @@
# Be sure you encrypt this file with ansible-vault
wazuh_api_user:
- foo:$apr1$/axqZYWQ$Xo/nz/IG3PdwV82EnfYKh/