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

Fixes in Molecule tests, Wazuh components installation and Versioning Control #206

Merged
merged 19 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ wazuh-elastic_stack-single.yml
wazuh-elastic.yml
wazuh-kibana.yml
wazuh-manager.yml
*.pyc
*.pyc
Pipfile.lock
*.swp
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ verify_ssl = true
name = "pypi"

[packages]
molecule = "*"
docker-py = "*"
ansible = "*"
ansible = "==2.7.11"
molecule = "*"

[dev-packages]

Expand Down
2 changes: 1 addition & 1 deletion molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def get_wazuh_version():
"""This return the version of Wazuh."""
return "3.9.2"
return "3.9.0"
manuasir marked this conversation as resolved.
Show resolved Hide resolved


def test_wazuh_packages_are_installed(host):
Expand Down
22 changes: 13 additions & 9 deletions molecule/elasticsearch/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,39 @@ driver:
name: docker
lint:
name: yamllint
options:
config-data:
ignore: .virtualenv
platforms:
- name: bionic
image: solita/ubuntu-systemd:bionic
command: /sbin/init
ulimits:
- nofile:262144:262144
privileged: true
memory_reservation: 1024m
memory_reservation: 2048m
- name: xenial
image: solita/ubuntu-systemd:xenial
privileged: true
memory_reservation: 1024m
memory_reservation: 2048m
command: /sbin/init
ulimits:
- nofile:262144:262144
- name: trusty
image: ubuntu:trusty
memory_reservation: 1024m
ulimits:
- nofile:262144:262144
# - name: trusty
# image: ubuntu:trusty
# privileged: true
# memory_reservation: 2048m
# ulimits:
# - nofile:262144:262144
- name: centos6
image: centos:6
privileged: true
memory_reservation: 1024m
memory_reservation: 2048m
ulimits:
- nofile:262144:262144
- name: centos7
image: milcom/centos7-systemd
memory_reservation: 1024m
memory_reservation: 2048m
privileged: true
ulimits:
- nofile:262144:262144
Expand Down
2 changes: 1 addition & 1 deletion molecule/elasticsearch/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_elasticsearch_is_installed(host):
"""Test if the elasticsearch package is installed."""
elasticsearch = host.package("elasticsearch")
assert elasticsearch.is_installed
assert elasticsearch.version.startswith('6.7.1')
assert elasticsearch.version.startswith('7.1.1')


def test_elasticsearch_is_running(host):
Expand Down
3 changes: 3 additions & 0 deletions molecule/filebeat/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ driver:
name: docker
lint:
name: yamllint
options:
manuasir marked this conversation as resolved.
Show resolved Hide resolved
config-data:
ignore: .virtualenv
platforms:
- name: trusty
image: ubuntu:trusty
Expand Down
7 changes: 7 additions & 0 deletions molecule/filebeat/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_filebeat_is_installed(host):
"""Test if the elasticsearch package is installed."""
filebeat = host.package("filebeat")
assert filebeat.is_installed
assert filebeat.version.startswith('7.1.1')
13 changes: 8 additions & 5 deletions molecule/kibana/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ driver:
name: docker
lint:
name: yamllint
options:
config-data:
ignore: .virtualenv
platforms:
- name: bionic
image: solita/ubuntu-systemd:bionic
Expand All @@ -20,11 +23,11 @@ platforms:
command: /sbin/init
ulimits:
- nofile:262144:262144
- name: trusty
image: ubuntu:trusty
memory_reservation: 1024m
ulimits:
- nofile:262144:262144
# - name: trusty
# image: ubuntu:trusty
# memory_reservation: 1024m
# ulimits:
# - nofile:262144:262144
- name: centos6
image: centos:6
privileged: true
Expand Down
2 changes: 1 addition & 1 deletion molecule/kibana/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_port_kibana_is_open(host):
def test_find_correct_elasticsearch_version(host):
"""Test if we find the kibana/elasticsearch version in package.json"""
kibana = host.file("/usr/share/kibana/plugins/wazuh/package.json")
assert kibana.contains("6.7.1")
assert kibana.contains("7.1.1")


def test_wazuh_plugin_installed(host):
Expand Down
6 changes: 5 additions & 1 deletion molecule/wazuh-agent/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ dependency:
name: galaxy
driver:
name: docker
#lint:
# name: yamllint
lint:
name: yamllint
options:
config-data:
ignore: .virtualenv
platforms:
- name: wazuh_server_centos7
image: milcom/centos7-systemd
Expand Down Expand Up @@ -72,7 +77,6 @@ provisioner:
ssl_agent_cert: null
ssl_agent_key: null
ssl_auto_negotiate: 'no'

lint:
name: ansible-lint
enabled: true
Expand Down
5 changes: 5 additions & 0 deletions molecule/wazuh-agent/tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('agent')


def get_wazuh_version():
"""This return the version of Wazuh."""
return "3.9.0"


def test_ossec_package_installed(Package):
ossec = Package('wazuh-agent')
assert ossec.is_installed
Expand Down
30 changes: 30 additions & 0 deletions roles/elastic-stack/ansible-elasticsearch/tasks/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,47 @@
- ansible_distribution == "Ubuntu"
- ansible_distribution_major_version | int == 14

- name: Update and upgrade apt packages
become: true
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 86400 #One day
when:
- ansible_distribution == "Ubuntu"
- ansible_distribution_major_version | int == 14

- name: Install Oracle Java 8
become: true
apt: name=openjdk-8-jdk state=latest

when:
- ansible_distribution == "Ubuntu"
- ansible_distribution_major_version | int == 14

- name: Update and upgrade apt packages
become: true
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 86400 #One day
when:
- ansible_distribution == "Ubuntu"
- ansible_distribution_major_version | int == 14

- name: Debian/Ubuntu | Add Elasticsearch GPG key.
apt_key:
url: "https://artifacts.elastic.co/GPG-KEY-elasticsearch"
state: present


- name: Debian/Ubuntu | Install Elastic repo
apt_repository:
repo: 'deb https://artifacts.elastic.co/packages/7.x/apt stable main'
state: present
filename: 'elastic_repo'
update_cache: true
changed_when: false

- name: Debian/Ubuntu | Install Elasticsarch
apt:
Expand Down
7 changes: 7 additions & 0 deletions roles/elastic-stack/ansible-elasticsearch/tasks/RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
gpgcheck: true
changed_when: false

- name: CentOS x.x => x.x < 7.0 | Installing Java
yum:
name: java-1.8.0-openjdk.x86_64
state: present
when:
- ansible_distribution in ['CentOS', 'RedHat'] and ansible_distribution_major_version|int < 7

- name: RedHat/CentOS/Fedora | Install Elasticsarch
package: name=elasticsearch-{{ elastic_stack_version }} state=present
tags: install
32 changes: 30 additions & 2 deletions roles/elastic-stack/ansible-elasticsearch/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,29 @@
when:
- elasticsearch_xpack_security

- name: Reload systemd
- name: Trusty | set MAX_LOCKED_MEMORY=unlimited in Elasticsearch in /etc/security/limits.conf
lineinfile:
path: /etc/security/limits.conf
line: elasticsearch - memlock unlimited
create: yes
become: true
when:
- ansible_distribution == "Ubuntu"
- ansible_distribution_major_version | int == 14
changed_when: false

- name: Trusty | set MAX_LOCKED_MEMORY=unlimited in Elasticsearch in /etc/security/limits.d/elasticsearch.conf
lineinfile:
path: /etc/security/limits.d/elasticsearch.conf
line: elasticsearch - memlock unlimited
create: yes
become: true
changed_when: false
when:
- ansible_distribution == "Ubuntu"
- ansible_distribution_major_version | int == 14

- name: Distribution != one of [ centos 6.*, trusty ] | Reload systemd
systemd: daemon_reload=true
ignore_errors: true
when:
Expand All @@ -206,6 +228,13 @@
- not (ansible_distribution == "Debian" and ansible_distribution_version is version('8', '<'))
- not (ansible_os_family == "RedHat" and ansible_distribution_version is version('7', '<'))

- name: Distribution is centos 6.* | Enable Elasticsearch
service: name=elasticsearch enabled=yes

- name: Distribution is centos 6.* | Start Elasticsearch
service: name=elasticsearch state=started
ignore_errors: true

- name: Ensure Elasticsearch started and enabled
service:
name: elasticsearch
Expand Down Expand Up @@ -247,6 +276,5 @@
- import_tasks: "RMRedHat.yml"
when: ansible_os_family == "RedHat"


- import_tasks: "RMDebian.yml"
when: ansible_os_family == "Debian"
40 changes: 26 additions & 14 deletions roles/elastic-stack/ansible-kibana/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,47 @@

- name: Check if certificate exists locally
stat:
path: "{{node_certs_destination}}/{{ kibana_node_name }}.crt"
path: "{{ node_certs_destination }}/{{ kibana_node_name }}.crt"
register: certificate_file_exists
when:
- kibana_xpack_security
- kibana_xpack_security

- name: Copy key & certificate files in generator node (locally)
synchronize:
src: "{{node_certs_source}}/{{kibana_node_name}}/"
dest: "{{node_certs_destination}}/"
src: "{{ node_certs_source }}/{{ kibana_node_name }}/"
dest: "{{ node_certs_destination }}/"
delegate_to: "{{ node_certs_generator_ip }}"
when:
when:
- node_certs_generator
- kibana_xpack_security
- not certificate_file_exists.stat.exists
tags: xpack-security

- name: Copy ca certificate file in generator node (locally)
synchronize:
src: "{{node_certs_source}}/ca/"
dest: "{{node_certs_destination}}/"
src: "{{ node_certs_source }}/ca/"
dest: "{{ node_certs_destination }}/"
delegate_to: "{{ node_certs_generator_ip }}"
when:
when:
- node_certs_generator
- kibana_xpack_security
- not certificate_file_exists.stat.exists
tags: xpack-security

- name: Importing key & certificate files from generator node
shell: "{{rsync_path}} {{rsync_extra_parameters}} {{rsync_user}}@{{node_certs_generator_ip}}:{{node_certs_source}}/{{kibana_node_name}}/ {{node_certs_destination}}/"
command: >-
{{ rsync_path }} {{ rsync_extra_parameters }} {{ rsync_user }}@{{ node_certs_generator_ip }}:
{{ node_certs_source }}/{{ kibana_node_name }}/ {{ node_certs_destination }}/
when:
- not node_certs_generator
- kibana_xpack_security
- not certificate_file_exists.stat.exists
tags: xpack-security

- name: Importing ca certificate file from generator node
shell: "{{rsync_path}} {{rsync_extra_parameters}} {{rsync_user}}@{{node_certs_generator_ip}}:{{node_certs_source}}/ca/ {{node_certs_destination}}/"
- name: Importing ca certificate file from generator node
command: >-
{{ rsync_path }} {{ rsync_extra_parameters }} {{ rsync_user }}@{{ node_certs_generator_ip }}:
{{ node_certs_source }}/ca/ {{ node_certs_destination }}/
when:
- not node_certs_generator
- kibana_xpack_security
Expand All @@ -61,14 +65,22 @@
tags: xpack-security

- name: Ensuring certificates folder owner
shell: "chown -R kibana: {{node_certs_destination}}/"
file:
path: "{{ node_certs_destination }}/"
state: directory
recurse: yes
owner: kibana
group: kibana
when:
- check_certs_permissions is defined
- kibana_xpack_security
tags: xpack-security

- name: Ensuring certificates folder owner
shell: "chmod -R 770 {{node_certs_destination}}/"
file:
path: "{{ node_certs_destination }}/"
mode: '0770'
recurse: yes
when:
- check_certs_permissions is defined
- kibana_xpack_security
Expand Down
2 changes: 2 additions & 0 deletions roles/wazuh/ansible-filebeat/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
filebeat_version: 7.1.1

filebeat_create_config: true

filebeat_prospectors:
Expand Down
Loading