|
15 | 15 | state: directory
|
16 | 16 |
|
17 | 17 | - name: Generate a random password which meets the Wazuh password requirements
|
18 |
| - cmd: python3 |
19 |
| - stdin: | |
20 |
| - import random |
21 |
| - import string |
22 |
| - import re |
23 |
| -
|
24 |
| - # The password requirements required by Wazuh (wazuh/framework/wazuh/security.py) |
25 |
| - valid_password = re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$') |
26 |
| -
|
27 |
| - # Generate a random password containg at least one of each: |
28 |
| - # special character, digit, lowercase letter, uppercase letter |
29 |
| - def pw_gen(pw_len): |
30 |
| - random_pass = ([random.choice("@$!%*?&-_"), |
31 |
| - random.choice(string.digits), |
32 |
| - random.choice(string.ascii_lowercase), |
33 |
| - random.choice(string.ascii_uppercase), |
34 |
| - ] |
35 |
| - + [random.choice(string.ascii_lowercase |
36 |
| - + string.ascii_uppercase |
37 |
| - + "@$!%*?&-_" |
38 |
| - + string.digits) for i in range(pw_len)]) |
39 |
| -
|
40 |
| - random.shuffle(random_pass) |
41 |
| - random_pass = ''.join(random_pass) |
42 |
| - return random_pass |
43 |
| -
|
44 |
| - # Check if the generated password meets the requirements |
45 |
| - def check_user_password(password): |
46 |
| - if valid_password.match(password): |
47 |
| - return True |
48 |
| - else: |
49 |
| - return False |
50 |
| - |
51 |
| - # Generate a password |
52 |
| - random_pass = pw_gen(30) |
53 |
| -
|
54 |
| - # Check if the generated password meets the requirements |
55 |
| - # if not, keep generating a new password until it does |
56 |
| - while not check_user_password(random_pass): |
57 |
| - random_pass = pw_gen(30) |
58 |
| - |
59 |
| - register: random_pass |
| 18 | + no_log: True |
| 19 | + command: |
| 20 | + cmd: python3 scripts/pwgen.py |
| 21 | + register: random_password |
60 | 22 |
|
61 | 23 | - name: Store the valid password
|
| 24 | + no_log: True |
62 | 25 | set_fact:
|
63 |
| - wazuh_password: "{{ random_pass }}" |
| 26 | + wazuh_password: "{{ random_password.stdout }}" |
64 | 27 |
|
65 | 28 | - name: Template new secrets
|
| 29 | + no_log: True |
66 | 30 | template:
|
67 | 31 | src: wazuh-secrets.yml.j2
|
68 | 32 | dest: "{{ wazuh_secrets_path }}"
|
69 |
| - notify: Please encrypt keys |
70 | 33 |
|
71 |
| - handlers: |
72 |
| - - name: Please encrypt keys |
73 |
| - debug: |
74 |
| - msg: >- |
75 |
| - Please encrypt the keys using Ansible Vault. |
| 34 | + - name: In-place encrypt wazuh-secrets |
| 35 | + copy: |
| 36 | + content: "{{ lookup('ansible.builtin.file', wazuh_secrets_path) | ansible.builtin.vault(ansible_vault_password) }}" |
| 37 | + dest: "{{ wazuh_secrets_path }}" |
| 38 | + decrypt: false |
| 39 | + vars: |
| 40 | + ansible_vault_password: "{{ lookup('ansible.builtin.env', 'KAYOBE_VAULT_PASSWORD') }}" |
| 41 | + |
0 commit comments