Skip to content

Commit 4365c7e

Browse files
authored
Implement/password sanitation before hashing (#122)
* added tests to verify proper password sanitizion * added password sanitizion * created the password_verify function * updated the __eq__ function so that the password is no longer ignored and verified if updated * splited up the add_or_update function, so that passwords are only created if updated or not existing * updated tests, so that password_verify can be used * updated naming * added default value for password * added additonal tests * sanity errors * applied DonGiovanni suggestion * applied DonGiovanni suggestion * applied DonGiovanni suggestion * applied DonGiovanni suggestion (password_verify typing) * updated tests, so that a new testuser can be added * updated group removal, so that the groupname attribute is removed from the user as well * updated tests to verify changes * added fragment * added minor_changes fragment
1 parent 90943a5 commit 4365c7e

File tree

4 files changed

+326
-82
lines changed

4 files changed

+326
-82
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
bugfixes:
3+
- system_access_users - Introduced password sanitization to fix parsing errors.
4+
- system_access_users - Introduced password verification to fix passwords not being updated.
5+
6+
minor_changes:
7+
- system_access_users - Enhanced group removal handling

molecule/system_access_users/converge.yml

Lines changed: 74 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,165 +7,165 @@
77
ansible.builtin.debug:
88
msg: "test"
99

10-
# Test User minimum requirements
10+
# Test User minimum requirements
1111
- name: "Test User 1: Test minimum requirements User Creation"
1212
puzzle.opnsense.system_access_users:
1313
username: test_user_1
1414
password: test_password_1
1515

16-
# Test User minimum requirements disabled
16+
# Test User minimum requirements disabled
1717
- name: "Test User 2: Test disabled User Creation"
1818
puzzle.opnsense.system_access_users:
1919
username: test_user_2
2020
password: test_password_2
2121
full_name: "Test User 2: Test disabled User Creation"
2222
disabled: True
2323

24-
# Test User with Full Name
24+
# Test User with Full Name
2525
- name: "Test User 3: Test User Creation with Full Name"
2626
puzzle.opnsense.system_access_users:
2727
username: test_user_3
2828
password: test_password_3
2929
full_name: "Test User 3: Test User Creation with Full Name"
3030

31-
# Test User with E-Mail
31+
# Test User with E-Mail
3232
- name: "Test User 4: Test User Creation with E-Mail"
3333
puzzle.opnsense.system_access_users:
3434
username: test_user_4
3535
password: test_password_4
3636
email: test_user_4@test.ch
3737
full_name: "Test User 4: Test User Creation with E-Mail"
3838

39-
# Test User with Comment
39+
# Test User with Comment
4040
- name: "Test User 5: Test User Creation with Comment"
4141
puzzle.opnsense.system_access_users:
4242
username: test_user_5
4343
password: test_password_5
4444
comment: Test User 5 Comment
4545
full_name: "Test User 5: Test User Creation with Comment"
4646

47-
# Test User with Preferred landing page
47+
# Test User with Preferred landing page
4848
- name: "Test User 6: Test User Creation with Preferred landing page"
4949
puzzle.opnsense.system_access_users:
5050
username: test_user_6
5151
password: test_password_6
5252
landing_page: /ui/ipsec/sessions
5353
full_name: "Test User 6: Test User Creation with Preferred landing page"
5454

55-
# Test User with nologin shell
55+
# Test User with nologin shell
5656
- name: "Test User 7: Test User Creation with nologin shell"
5757
puzzle.opnsense.system_access_users:
5858
username: test_user_7
5959
password: test_password_7
6060
shell: /sbin/nologin
6161
full_name: "Test User 7: Test User Creation with nologin shell"
6262

63-
# Test User with csh shell
63+
# Test User with csh shell
6464
- name: "Test User 8: Test User Creation with csh shell"
6565
puzzle.opnsense.system_access_users:
6666
username: test_user_8
6767
password: test_password_8
6868
shell: /bin/csh
6969
full_name: "Test User 8: Test User Creation with csh shell"
7070

71-
# Test User with sh shell
71+
# Test User with sh shell
7272
- name: "Test User 9: Test User Creation with sh shell"
7373
puzzle.opnsense.system_access_users:
7474
username: test_user_9
7575
password: test_password_9
7676
shell: /bin/sh
7777
full_name: "Test User 9: Test User Creation with sh shell"
7878

79-
# Test User with tcsh shell
79+
# Test User with tcsh shell
8080
- name: "Test User 10: Test User Creation with tcsh shell"
8181
puzzle.opnsense.system_access_users:
8282
username: test_user_10
8383
password: test_password_10
8484
shell: /bin/tcsh
8585
full_name: "Test User 10: Test User Creation with tcsh shell"
8686

87-
# Test User with Expiration date
87+
# Test User with Expiration date
8888
- name: "Test User 11: Test User Creation with Expiration date"
8989
puzzle.opnsense.system_access_users:
9090
username: test_user_11
9191
password: test_password_11
9292
expires: 02/27/2024
9393
full_name: "Test User 11: Test User Creation with Expiration date"
9494

95-
# Test User with group as string
95+
# Test User with group as string
9696
- name: "Test User 12: Test User Creation with group as string"
9797
puzzle.opnsense.system_access_users:
9898
username: test_user_12
9999
password: test_password_12
100100
full_name: "Test User 12: Test User Creation with group as string"
101101
groups: admins
102102

103-
# Test User with group as list
103+
# Test User with group as list
104104
- name: "Test User 13: Test User Creation with group as list"
105105
puzzle.opnsense.system_access_users:
106106
username: test_user_13
107107
password: test_password_13
108108
full_name: "Test User 13: Test User Creation with group as list"
109109
groups:
110-
- admins
110+
- admins
111111

112-
# Test User with not existing group as list
112+
# Test User with not existing group as list
113113
- name: "Test User 14: Test User Creation with not existing group as list"
114114
puzzle.opnsense.system_access_users:
115115
username: test_user_14
116116
password: test_password_14
117117
full_name: "Test User 14: Test User Creation with not existing group as list"
118118
groups:
119-
- test
119+
- test
120120
register: test_user_14_result
121121
ignore_errors: yes
122122

123123
- name: "Verify that the user creation failed due to non-existing group"
124124
ansible.builtin.assert:
125125
that:
126-
- test_user_14_result is failed
126+
- test_user_14_result is failed
127127
fail_msg: "User creation should fail due to non-existing group"
128128
success_msg: "User creation failed as expected due to non-existing group"
129129

130-
# Test User with empty otp_seed
130+
# Test User with empty otp_seed
131131
- name: "Test User 15: Test User Creation with empty otp_seed"
132132
puzzle.opnsense.system_access_users:
133133
username: test_user_15
134134
password: test_password_15
135135
otp_seed: ""
136136
full_name: "Test User 15: Test User Creation with empty otp_seed"
137137

138-
# Test User with otp_seed
138+
# Test User with otp_seed
139139
- name: "Test User 16: Test User Creation with otp_seed"
140140
puzzle.opnsense.system_access_users:
141141
username: test_user_16
142142
password: test_password_16
143143
otp_seed: test_seed
144144
full_name: "Test User 16: Test User Creation with otp_seed"
145145

146-
# Test User with empty authorizedkeys
146+
# Test User with empty authorizedkeys
147147
- name: "Test User 17: Test User Creation with empty authorizedkeys"
148148
puzzle.opnsense.system_access_users:
149149
username: test_user_17
150150
password: test_password_17
151151
authorizedkeys: ""
152152
full_name: "Test User 17: Test User Creation with empty authorizedkeys"
153153

154-
# Test User with authorizedkeys
154+
# Test User with authorizedkeys
155155
- name: "Test User 18: Test User Creation with authorizedkeys"
156156
puzzle.opnsense.system_access_users:
157-
username: test_user_18
158-
password: test_password_18
159-
authorizedkeys: test_authorized_key
160-
full_name: "Test User 18: Test User Creation with authorizedkeys"
157+
username: test_user_18
158+
password: test_password_18
159+
authorizedkeys: test_authorized_key
160+
full_name: "Test User 18: Test User Creation with authorizedkeys"
161161

162-
# Test User with empty api_keys
162+
# Test User with empty api_keys
163163
- name: "Test User 19: Test User Creation with empty api_keys"
164164
puzzle.opnsense.system_access_users:
165-
username: test_user_19
166-
password: test_password_19
167-
apikeys: ""
168-
full_name: "Test User 19: Test User Creation with empty api_keys"
165+
username: test_user_19
166+
password: test_password_19
167+
apikeys: ""
168+
full_name: "Test User 19: Test User Creation with empty api_keys"
169169
register: api_keys_result
170170

171171
- name: Return the created apikeys and secret of Test User 19
@@ -175,35 +175,67 @@
175175
- "'generated_apikeys' in api_keys_result"
176176
- api_keys_result.generated_apikeys | length > 0
177177

178-
# Test User with too short api_keys
178+
# Test User with too short api_keys
179179
- name: "Test User 20: Test User Creation with too short api_keys"
180180
puzzle.opnsense.system_access_users:
181-
username: test_user_20
182-
password: test_password_20
183-
apikeys: "TEST_API_KEY"
184-
full_name: "Test User 20: Test User Creation with too short api_keys"
181+
username: test_user_20
182+
password: test_password_20
183+
apikeys: "TEST_API_KEY"
184+
full_name: "Test User 20: Test User Creation with too short api_keys"
185185
register: test_user_20_result
186186
ignore_errors: yes
187187

188188
- name: "Verify that the user creation failed due to too short api key"
189189
ansible.builtin.assert:
190190
that:
191-
- test_user_20_result is failed
191+
- test_user_20_result is failed
192192
fail_msg: "The API key: TEST_API_KEY is not a valid string. Must be >= 80 characters."
193193
success_msg: "The API key: TEST_API_KEY is not a valid string. Must be >= 80 characters."
194194

195-
# Test User with valid api_keys
195+
# Test User with valid api_keys
196196
- name: "Test User 21: Test User Creation with valid api_keys"
197197
puzzle.opnsense.system_access_users:
198-
username: test_user_21
199-
password: test_password_21
200-
apikeys: "TEST_API_KEY_WITH_RANDOM_CHARS_UNTIL_80_zo5Y3bUpOQFfbQnAOB6GqbHsPAP9Jqbjofnqu9xc"
201-
full_name: "Test User 21: Test User Creation with valid api_keys"
198+
username: test_user_21
199+
password: test_password_21
200+
apikeys: "TEST_API_KEY_WITH_RANDOM_CHARS_UNTIL_80_zo5Y3bUpOQFfbQnAOB6GqbHsPAP9Jqbjofnqu9xc"
201+
full_name: "Test User 21: Test User Creation with valid api_keys"
202202
register: api_keys_result
203203

204204
- name: Return the created apikeys and secret of Test User 21
205205
ansible.builtin.debug:
206206
msg: "The following api_keys were created {{ api_keys_result.generated_apikeys }}"
207207
when:
208208
- "'generated_apikeys' in api_keys_result"
209-
- api_keys_result.generated_apikeys | length > 0
209+
- api_keys_result.generated_apikeys | length > 0
210+
211+
# Test User password escaping
212+
- name: "Test User 22: Test password escaping"
213+
puzzle.opnsense.system_access_users:
214+
username: test_user_22
215+
password: test_password_22\
216+
shell: /bin/sh
217+
groups:
218+
- admins
219+
220+
# Test User password escaping
221+
- name: "Test User 23: Test password escaping"
222+
puzzle.opnsense.system_access_users:
223+
username: test_user_23
224+
password: test_password_23'
225+
shell: /bin/sh
226+
groups:
227+
- admins
228+
229+
# we have no alternative way to compare the values
230+
# other than getting them from the config
231+
# see https://github.com/opnsense/core/blob/24.1/src/opnsense/scripts/syslog/log_archive#L36
232+
- name: Get current config
233+
ansible.builtin.slurp:
234+
src: /conf/config.xml
235+
register: current_config
236+
237+
- name: Test that no error message is in config
238+
ansible.builtin.assert:
239+
that:
240+
- "'syntax error, unexpected identifier \"cost\", expecting \")\" in Command line code on line 1' not in (current_config.content | b64decode | string)"
241+
- "'syntax error, unexpected single-quoted string \",PASSWORD_BCRYPT,[ \", expecting \")\" in Command line code on line 1' not in (current_config.content | b64decode | string)"

0 commit comments

Comments
 (0)