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

Prevent double encryption #1176

Open
wants to merge 4 commits into
base: stackhpc/2023.1
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion etc/kayobe/ansible/templates/wazuh-secrets.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ secrets_wazuh:
# Strengthen default wazuh api user pass
wazuh_api_users:
- username: "wazuh"
password: "{{ secrets_wazuh.wazuh_api_users[0].password | default(lookup('community.general.random_string', min_lower=1, min_upper=1, min_special=1, min_numeric=1, length=30)) }}"
password: '{{ secrets_wazuh.wazuh_api_users[0].password | default(lookup("community.general.random_string", min_lower=1, min_upper=1, min_special=1, min_numeric=1, length=30, override_special=override_special_characters)) }}'
# OpenSearch 'admin' user pass
opendistro_admin_password: "{{ secrets_wazuh.opendistro_admin_password | default(lookup('password', '/dev/null'), true) }}"
# OpenSearch 'kibanaserver' user pass
Expand Down
24 changes: 24 additions & 0 deletions etc/kayobe/ansible/wazuh-secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
gather_facts: false
vars:
wazuh_secrets_path: "{{ kayobe_env_config_path }}/wazuh-secrets.yml"
override_special_characters: '"#$%&()*+,-./:;<=>?@[\]^_{|}~'
tasks:
- name: install passlib[bcrypt]
pip:
Expand All @@ -14,13 +15,36 @@
path: "{{ wazuh_secrets_path | dirname }}"
state: directory

- name: Check whether wazuh-secrets.yml exists
stat:
path: "{{ wazuh_secrets_path }}"
register: waz_exist_result

- name: Check if secret is encrypted
block:
- name: Try to decrypt secret
no_log: True
copy:
content: "{{ lookup('ansible.builtin.file', wazuh_secrets_path) | ansible.builtin.vault(ansible_vault_password) }}"
dest: "{{ wazuh_secrets_path }}"
decrypt: True
vars:
ansible_vault_password: "{{ lookup('ansible.builtin.env', 'KAYOBE_VAULT_PASSWORD') }}"
rescue:
- name: Secrets already decrypted
ansible.builtin.debug:
msg: 'Secret was already decrypted'
when: waz_exist_result.stat.exists

- name: Template new secrets
no_log: True
template:
src: wazuh-secrets.yml.j2
dest: "{{ wazuh_secrets_path }}"
when: not waz_exist_result.stat.exists

- name: In-place encrypt wazuh-secrets
no_log: True
copy:
content: "{{ lookup('ansible.builtin.file', wazuh_secrets_path) | ansible.builtin.vault(ansible_vault_password) }}"
dest: "{{ wazuh_secrets_path }}"
Expand Down