Skip to content

Commit fc72eb4

Browse files
committed
add variable for plain users
1 parent f6d95cf commit fc72eb4

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

defaults/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ attackmate_api_server_url: "https://github.com/ait-testbed/attackmate-api-server
6161
attackmate_api_server_version: "main"
6262
attackmate_api_server_dest: "{{ attackmate_shared_dir }}/attackmate-api-server"
6363

64-
attackmate_api_logs_to_disk: "False"
64+
attackmate_api_logs_to_disk: False
6565
attackmate_api_log_dir: "/var/log/attackmate-api"
6666

6767
attackmate_api_bin_path: "/usr/local/bin/attackmate-api"
6868
attackmate_api_service_path: "/etc/systemd/system/attackmate-api.service"
6969
attackmate_ssl_key_path: "/etc/ssl/private/attackmate.key"
7070
attackmate_ssl_cert_path: "/etc/ssl/certs/attackmate.pem"
7171
attackmate_api_server_port: 8445
72+
attackmate_api_plain_users: {}

tasks/api_server.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,34 @@
111111
- { path: "{{ attackmate_ssl_key_path }}", mode: '0640' }
112112
- { path: "{{ attackmate_ssl_cert_path }}", mode: '0644' }
113113

114+
# --- User hashes for .env file (Optional) ---
115+
116+
- name: Install argon2-cffi for hash generation
117+
ansible.builtin.pip:
118+
name: argon2-cffi
119+
state: present
120+
delegate_to: localhost
121+
become: false
122+
when: attackmate_api_plain_users | length > 0
123+
124+
- name: Generate argon2 hashes for API users
125+
ansible.builtin.shell:
126+
cmd: "python3 -c \"from argon2 import PasswordHasher; ph = PasswordHasher(); print(ph.hash('{{ item.value }}'))\""
127+
loop: "{{ attackmate_api_plain_users | dict2items }}"
128+
register: argon2_hashes
129+
changed_when: false
130+
delegate_to: localhost
131+
become: false
132+
#no_log: true
133+
when: attackmate_api_plain_users | length > 0
134+
135+
- name: Build USERS json string
136+
ansible.builtin.set_fact:
137+
attackmate_api_users: >-
138+
{{ dict(argon2_hashes.results | map(attribute='item.key') |
139+
zip(argon2_hashes.results | map(attribute='stdout'))) | to_json }}
140+
#no_log: true
141+
when: attackmate_api_plain_users | length > 0
114142

115143
# --- Env file ---
116144

0 commit comments

Comments
 (0)