Skip to content

Commit d5f5d22

Browse files
authored
Merge pull request #647 from stackhpc/feature/environment-aware-wazuh-certificates
Move wazuh certificates
2 parents d651f42 + 28028e8 commit d5f5d22

File tree

5 files changed

+69
-40
lines changed

5 files changed

+69
-40
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ etc/kolla
4545

4646
# Ignore wazuh
4747
etc/kayobe/ansible/roles/wazuh-ansible/
48-
etc/kayobe/ansible/wazuh/certificates/*
49-
etc/kayobe/ansible/wazuh/certificates/custom_certificates/*
5048

5149
# Ignore ceph generated config in AUFN env
5250
etc/kayobe/environments/aufn-ceph/kolla/config/glance/ceph.conf

doc/source/configuration/wazuh.rst

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ By default, Wazuh Ansible uses `wazuh-cert-tool.sh <https://documentation.wazuh.
260260
to automatically
261261
generate certificates for wazuh-indexer (previously Elasticsearch and opendistro)
262262
and wazuh-dashbooard (previously Kibana) using a local CA.
263-
If the certificates directory ``etc/kayobe/ansible/wazuh/certificates``
264-
does not exist, it will generate the following certificates in ``etc/kayobe/ansible/wazuh/certificates/certs/``
263+
If the certificates directory ``{{ kayobe_env_config_path }}/wazuh``
264+
does not exist, it will generate the following certificates in ``{{ kayobe_env_config_path }}/wazuh/wazuh-certificates/``
265265
(here os-wazuh is set as ``elasticsearch_node_name`` and ``kibana_node_name``:
266266

267267

@@ -275,12 +275,24 @@ does not exist, it will generate the following certificates in ``etc/kayobe/ansi
275275
* root-ca.key root-ca.pem
276276

277277

278-
It is also possible to use externally generated certificates for wazuh-dashboard. root-ca.pem should contain the CA chain.
279-
Those certificates can be uploaded to ``etc/kayobe/ansible/wazuh/custom_certificates``,
280-
and will replace certificates generated by wazuh.
281-
Certificates should have the same name scheme as those generated by wazuh (typicaly <node-name>.pem)
282-
The key for the external certificate should be in PKCS#8 format
283-
(in its header it may have BEGIN PRIVATE KEY instead of BEGIN RSA PRIVATE KEY or BEGIN OPENSSH PRIVATE KEY).
278+
It is also possible to use externally generated certificates for
279+
wazuh-dashboard. Customise the ``dashboard_node_name`` variable so that you can
280+
use a separate certificate and key for this service e.g:
281+
282+
.. code-block:: yaml
283+
:caption: $KAYOBE_CONFIG_PATH/inventory/group_vars/wazuh-manager/wazuh-manager
284+
285+
dashboard_node_name: "wazuh-dashboard"
286+
287+
You will need to create two files matching the following pattern:
288+
289+
- ``{{ dashboard_node_name }}-key.pem`` for the private key
290+
- ``{{ dashboard_node_name }}.pem`` for the certificate
291+
292+
Drop these files into ``$KAYOBE_CONFIG_PATH/environments/<environment>/wazuh/wazuh-certificates/`` if
293+
using the kayobe environments feature, or ``$KAYOBE_CONFIG_PATH/wazuh/wazuh-certificates/`` if not.
294+
The key for the external certificate should be in PKCS#8 format (in its header it may have BEGIN
295+
PRIVATE KEY instead of BEGIN RSA PRIVATE KEY or BEGIN OPENSSH PRIVATE KEY).
284296

285297
Example OpenSSL rune to convert to PKCS#8:
286298

etc/kayobe/ansible/wazuh-manager.yml

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
11
---
2+
- name: Pre-checks
3+
gather_facts: false
4+
hosts: localhost
5+
tags:
6+
- prechecks
7+
tasks:
8+
- block:
9+
- name: Fail if using old path for Wazuh certificates
10+
fail:
11+
msg: >-
12+
The path used for Wazuh SSL certificates was changed in a previous release. The certificates
13+
were found in the wrong location. Please move all files and directories in
14+
{{ playbook_dir }}/wazuh/certificates to {{ kayobe_env_config_path }}/wazuh/ and remove the
15+
empty directory.
16+
when:
17+
- (playbook_dir ~ '/wazuh/certificates') is exists
18+
19+
- name: Fail if using old path for custom certificates
20+
fail:
21+
msg: >-
22+
Wazuh custom SSL certificates have been merged with regular certificates. The certificates
23+
were found in the wrong location. Please move them from {{ playbook_dir }}/wazuh/custom_certificates
24+
to {{ kayobe_env_config_path }}/wazuh/wazuh-certificates and remove the empty directory.
25+
when:
26+
- (playbook_dir ~ '/wazuh/custom_certificates') is exists
27+
28+
- name: Check that removed variable, local_custom_certs_path, is not set
29+
assert:
30+
that: local_custom_certs_path is not defined
31+
fail_msg: "The variable, `local_custom_certs_path`, is no longer used. Please remove this variable."
32+
when:
33+
- groups["wazuh-manager"] | length > 0
34+
235
# Certificates generation
336
- hosts: localhost
437
roles:
@@ -31,27 +64,6 @@
3164
notify:
3265
- Restart wazuh
3366

34-
- name: Check if custom certificates exists
35-
stat:
36-
path: "{{ local_custom_certs_path }}"
37-
register: custom_certificates_folder
38-
delegate_to: localhost
39-
become: no
40-
41-
- name: Copy the node & admin certificates to Wazuh dashboard
42-
copy:
43-
src: "{{ local_custom_certs_path }}/{{ item }}"
44-
dest: /etc/wazuh-dashboard/certs/
45-
owner: wazuh-dashboard
46-
group: wazuh-dashboard
47-
mode: 0400
48-
with_items:
49-
- "{{ indexer_node_name }}-key.pem"
50-
- "{{ indexer_node_name }}.pem"
51-
when: custom_certificates_folder.stat.exists
52-
notify:
53-
- Restart wazuh-dashboard
54-
5567
- name: Perform health check against filebeat
5668
command: filebeat test output
5769
changed_when: false
@@ -63,8 +75,3 @@
6375
service:
6476
name: wazuh-manager
6577
state: restarted
66-
67-
- name: Restart wazuh-dashboard
68-
service:
69-
name: wazuh-dashboard
70-
state: restarted

etc/kayobe/inventory/group_vars/wazuh-manager/wazuh-manager

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ minimum_master_nodes: 1
1919
indexer_node_master: true
2020

2121
# Ansible control host certificate directory
22-
local_certs_path: "{{ playbook_dir }}/wazuh/certificates"
23-
24-
# Ansible control host custom certificates directory
25-
local_custom_certs_path: "{{ playbook_dir }}/wazuh/custom_certificates"
22+
local_certs_path: "{{ kayobe_env_config_path }}/wazuh"
2623

2724
# Indexer variables
2825
indexer_node_name: "{{ inventory_hostname }}"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
upgrade:
3+
- |
4+
The path used to store Wazuh certificates has changed. ``local_certs_path`` is
5+
now set to the environment directory e.g
6+
``$KAYOBE_CONFIG_PATH/environments/<environment>/wazuh`` or
7+
``$KAYOBE_CONFIG_PATH/wazuh/`` if not using environments. The contents of
8+
``$KAYOBE_CONFIG_PATH/ansible/wazuh/certificates`` should be moved to the
9+
new location and the empty directory should be removed.
10+
- |
11+
The ``local_custom_certs_path`` variable has been removed. Custom wazuh
12+
certificates should be moved to
13+
``$KAYOBE_CONFIG_PATH/environments/<environment>/wazuh/wazuh-certificates/``
14+
if using environments, or
15+
``$KAYOBE_CONFIG_PATH/wazuh/wazuh-certificates`` if not.

0 commit comments

Comments
 (0)