Debian Codegraph @

ansible_collections/community/okd/molecule/default/roles/openshift_adm_groups/tasks/rfc2307.yml

raw
1 ---
2 - block:
3 - name: Get LDAP definition
4 set_fact:
5 ldap_resources: "{{ lookup('template', 'rfc2307/definition.j2') | from_yaml }}"
6
7 - name: Delete openshift groups if existing
8 community.okd.k8s:
9 state: absent
10 kind: Group
11 version: "user.openshift.io/v1"
12 name: "{{ item }}"
13 with_items:
14 - admins
15 - engineers
16 - developers
17
18 - name: Delete existing LDAP entries
19 openshift_ldap_entry:
20 bind_dn: "{{ ldap_bind_dn }}"
21 bind_pw: "{{ ldap_bind_pw }}"
22 server_uri: "{{ ldap_server_uri }}"
23 dn: "{{ item.dn }}"
24 state: absent
25 with_items: "{{ ldap_resources.users + ldap_resources.groups + ldap_resources.units | reverse | list }}"
26
27 - name: Create LDAP units
28 openshift_ldap_entry:
29 bind_dn: "{{ ldap_bind_dn }}"
30 bind_pw: "{{ ldap_bind_pw }}"
31 server_uri: "{{ ldap_server_uri }}"
32 dn: "{{ item.dn }}"
33 attributes: "{{ item.attr }}"
34 objectClass: "{{ item.class }}"
35 with_items: "{{ ldap_resources.units }}"
36
37 - name: Create LDAP Groups
38 openshift_ldap_entry:
39 bind_dn: "{{ ldap_bind_dn }}"
40 bind_pw: "{{ ldap_bind_pw }}"
41 server_uri: "{{ ldap_server_uri }}"
42 dn: "{{ item.dn }}"
43 attributes: "{{ item.attr }}"
44 objectClass: "{{ item.class }}"
45 with_items: "{{ ldap_resources.groups }}"
46
47 - name: Create LDAP users
48 openshift_ldap_entry:
49 bind_dn: "{{ ldap_bind_dn }}"
50 bind_pw: "{{ ldap_bind_pw }}"
51 server_uri: "{{ ldap_server_uri }}"
52 dn: "{{ item.dn }}"
53 attributes: "{{ item.attr }}"
54 objectClass: "{{ item.class }}"
55 with_items: "{{ ldap_resources.users }}"
56
57 - name: Load test configurations
58 set_fact:
59 configs: "{{ lookup('template', 'rfc2307/sync-config.j2') | from_yaml }}"
60
61 - name: Synchronize Groups
62 community.okd.openshift_adm_groups_sync:
63 config: "{{ configs.simple }}"
64 check_mode: yes
65 register: result
66
67 - name: Validate Group going to be created
68 assert:
69 that:
70 - result is changed
71 - admins_group
72 - devs_group
73 - '"[email protected]" in admins_group.users'
74 - '"[email protected]" in devs_group.users'
75 - '"[email protected]" in devs_group.users'
76 - admins_group.users | length == 1
77 - devs_group.users | length == 2
78 vars:
79 admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'admins') | first }}"
80 devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'developers') | first }}"
81
82 - name: Synchronize Groups - User defined mapping
83 community.okd.openshift_adm_groups_sync:
84 config: "{{ configs.user_defined }}"
85 check_mode: yes
86 register: result
87
88 - name: Validate Group going to be created
89 assert:
90 that:
91 - result is changed
92 - admins_group
93 - devs_group
94 - '"[email protected]" in admins_group.users'
95 - '"[email protected]" in devs_group.users'
96 - '"[email protected]" in devs_group.users'
97 - admins_group.users | length == 1
98 - devs_group.users | length == 2
99 vars:
100 admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'ansible-admins') | first }}"
101 devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'ansible-devs') | first }}"
102
103 - name: Synchronize Groups - Using dn for every query
104 community.okd.openshift_adm_groups_sync:
105 config: "{{ configs.dn_everywhere }}"
106 check_mode: yes
107 register: result
108
109 - name: Validate Group going to be created
110 assert:
111 that:
112 - result is changed
113 - admins_group
114 - devs_group
115 - '"cn=Jane,ou=people,ou=rfc2307,"+ldap_root in admins_group.users'
116 - '"cn=Jim,ou=people,ou=rfc2307,"+ldap_root in devs_group.users'
117 - '"cn=Jordan,ou=people,ou=rfc2307,"+ldap_root in devs_group.users'
118 - admins_group.users | length == 1
119 - devs_group.users | length == 2
120 vars:
121 admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'cn=admins,ou=groups,ou=rfc2307,' + ldap_root ) | first }}"
122 devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'cn=developers,ou=groups,ou=rfc2307,' + ldap_root ) | first }}"
123
124 - name: Synchronize Groups - Partially user defined mapping
125 community.okd.openshift_adm_groups_sync:
126 config: "{{ configs.partially_user_defined }}"
127 check_mode: yes
128 register: result
129
130 - name: Validate Group going to be created
131 assert:
132 that:
133 - result is changed
134 - admins_group
135 - devs_group
136 - '"[email protected]" in admins_group.users'
137 - '"[email protected]" in devs_group.users'
138 - '"[email protected]" in devs_group.users'
139 - admins_group.users | length == 1
140 - devs_group.users | length == 2
141 vars:
142 admins_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'ansible-admins') | first }}"
143 devs_group: "{{ result.groups | selectattr('metadata.name', 'equalto', 'developers') | first }}"
144
145 - name: Delete Group 'engineers' if created before
146 community.okd.k8s:
147 state: absent
148 kind: Group
149 version: "user.openshift.io/v1"
150 name: 'engineers'
151 wait: yes
152 ignore_errors: yes
153
154 - name: Synchronize Groups - Partially user defined mapping
155 community.okd.openshift_adm_groups_sync:
156 config: "{{ configs.out_scope }}"
157 check_mode: yes
158 register: result
159 ignore_errors: yes
160
161 - name: Assert group sync failed due to non-existent member
162 assert:
163 that:
164 - result is failed
165 - result.msg.startswith("Entry not found for base='cn=Matthew,ou=people,ou=outrfc2307,"+ldap_root+"'")
166
167 - name: Define sync configuration with tolerateMemberNotFoundErrors
168 set_fact:
169 config_out_of_scope_tolerate_not_found: "{{ configs.out_scope | combine({'rfc2307': merge_rfc2307 })}}"
170 vars:
171 merge_rfc2307: "{{ configs.out_scope.rfc2307 | combine({'tolerateMemberNotFoundErrors': 'true'}) }}"
172
173 - name: Synchronize Groups - Partially user defined mapping (tolerateMemberNotFoundErrors=true)
174 community.okd.openshift_adm_groups_sync:
175 config: "{{ config_out_of_scope_tolerate_not_found }}"
176 check_mode: yes
177 register: result
178
179 - name: Assert group sync did not fail (tolerateMemberNotFoundErrors=true)
180 assert:
181 that:
182 - result is changed
183 - result.groups | length == 1
184 - result.groups.0.metadata.name == 'engineers'
185 - result.groups.0.users == ['Abraham']
186
187 - name: Create Group 'engineers'
188 community.okd.k8s:
189 state: present
190 wait: yes
191 definition:
192 kind: Group
193 apiVersion: "user.openshift.io/v1"
194 metadata:
195 name: engineers
196 users: []
197
198 - name: Try to sync LDAP group with Openshift existing group not created using sync should failed
199 community.okd.openshift_adm_groups_sync:
200 config: "{{ config_out_of_scope_tolerate_not_found }}"
201 check_mode: yes
202 register: result
203 ignore_errors: yes
204
205 - name: Validate group sync failed
206 assert:
207 that:
208 - result is failed
209 - '"openshift.io/ldap.host label did not match sync host" in result.msg'
210
211 - name: Define allow_groups and deny_groups groups
212 set_fact:
213 allow_groups:
214 - "cn=developers,ou=groups,ou=rfc2307,{{ ldap_root }}"
215 deny_groups:
216 - "cn=admins,ou=groups,ou=rfc2307,{{ ldap_root }}"
217
218 - name: Synchronize Groups using allow_groups
219 community.okd.openshift_adm_groups_sync:
220 config: "{{ configs.simple }}"
221 allow_groups: "{{ allow_groups }}"
222 register: result
223 check_mode: yes
224
225 - name: Validate Group going to be created
226 assert:
227 that:
228 - result is changed
229 - result.groups | length == 1
230 - result.groups.0.metadata.name == "developers"
231
232 - name: Synchronize Groups using deny_groups
233 community.okd.openshift_adm_groups_sync:
234 config: "{{ configs.simple }}"
235 deny_groups: "{{ deny_groups }}"
236 register: result
237 check_mode: yes
238
239 - name: Validate Group going to be created
240 assert:
241 that:
242 - result is changed
243 - result.groups | length == 1
244 - result.groups.0.metadata.name == "developers"
245
246 - name: Synchronize groups, remove check_mode
247 community.okd.openshift_adm_groups_sync:
248 config: "{{ configs.simple }}"
249 register: result
250
251 - name: Validate result is changed
252 assert:
253 that:
254 - result is changed
255
256 - name: Read Groups
257 kubernetes.core.k8s_info:
258 kind: Group
259 version: "user.openshift.io/v1"
260 name: admins
261 register: result
262
263 - name: Validate group was created
264 assert:
265 that:
266 - result.resources | length == 1
267 - '"[email protected]" in result.resources.0.users'
268
269 - name: Read Groups
270 kubernetes.core.k8s_info:
271 kind: Group
272 version: "user.openshift.io/v1"
273 name: developers
274 register: result
275
276 - name: Validate group was created
277 assert:
278 that:
279 - result.resources | length == 1
280 - '"[email protected]" in result.resources.0.users'
281 - '"[email protected]" in result.resources.0.users'
282
283 - name: Set users to delete (no admins users anymore and only 1 developer kept)
284 set_fact:
285 users_to_delete:
286 - "cn=Jane,ou=people,ou=rfc2307,{{ ldap_root }}"
287 - "cn=Jim,ou=people,ou=rfc2307,{{ ldap_root }}"
288
289 - name: Delete users from LDAP servers
290 openshift_ldap_entry:
291 bind_dn: "{{ ldap_bind_dn }}"
292 bind_pw: "{{ ldap_bind_pw }}"
293 server_uri: "{{ ldap_server_uri }}"
294 dn: "{{ item }}"
295 state: absent
296 with_items: "{{ users_to_delete }}"
297
298 - name: Define sync configuration with tolerateMemberNotFoundErrors
299 set_fact:
300 config_simple_tolerate_not_found: "{{ configs.simple | combine({'rfc2307': merge_rfc2307 })}}"
301 vars:
302 merge_rfc2307: "{{ configs.simple.rfc2307 | combine({'tolerateMemberNotFoundErrors': 'true'}) }}"
303
304 - name: Synchronize groups once again after users deletion
305 community.okd.openshift_adm_groups_sync:
306 config: "{{ config_simple_tolerate_not_found }}"
307 register: result
308
309 - name: Validate result is changed
310 assert:
311 that:
312 - result is changed
313
314 - name: Read Groups
315 kubernetes.core.k8s_info:
316 kind: Group
317 version: "user.openshift.io/v1"
318 name: admins
319 register: result
320
321 - name: Validate admins group does not contains users anymore
322 assert:
323 that:
324 - result.resources | length == 1
325 - result.resources.0.users == []
326
327 - name: Read Groups
328 kubernetes.core.k8s_info:
329 kind: Group
330 version: "user.openshift.io/v1"
331 name: developers
332 register: result
333
334 - name: Validate group was created
335 assert:
336 that:
337 - result.resources | length == 1
338 - '"[email protected]" in result.resources.0.users'
339
340 - name: Set group to delete
341 set_fact:
342 groups_to_delete:
343 - "cn=developers,ou=groups,ou=rfc2307,{{ ldap_root }}"
344
345 - name: Delete Group from LDAP servers
346 openshift_ldap_entry:
347 bind_dn: "{{ ldap_bind_dn }}"
348 bind_pw: "{{ ldap_bind_pw }}"
349 server_uri: "{{ ldap_server_uri }}"
350 dn: "{{ item }}"
351 state: absent
352 with_items: "{{ groups_to_delete }}"
353
354 - name: Prune groups
355 community.okd.openshift_adm_groups_sync:
356 config: "{{ config_simple_tolerate_not_found }}"
357 state: absent
358 register: result
359 check_mode: yes
360
361 - name: Validate that only developers group is candidate for Prune
362 assert:
363 that:
364 - result is changed
365 - result.groups | length == 1
366 - result.groups.0.metadata.name == "developers"
367
368 - name: Read Group (validate that check_mode did not performed update in the cluster)
369 kubernetes.core.k8s_info:
370 kind: Group
371 version: "user.openshift.io/v1"
372 name: developers
373 register: result
374
375 - name: Assert group was found
376 assert:
377 that:
378 - result.resources | length == 1
379
380 - name: Prune using allow_groups
381 community.okd.openshift_adm_groups_sync:
382 config: "{{ config_simple_tolerate_not_found }}"
383 allow_groups:
384 - developers
385 state: absent
386 register: result
387 check_mode: yes
388
389 - name: assert developers group was candidate for prune
390 assert:
391 that:
392 - result is changed
393 - result.groups | length == 1
394 - result.groups.0.metadata.name == "developers"
395
396 - name: Prune using deny_groups
397 community.okd.openshift_adm_groups_sync:
398 config: "{{ config_simple_tolerate_not_found }}"
399 deny_groups:
400 - developers
401 state: absent
402 register: result
403 check_mode: yes
404
405 - name: assert nothing found candidate for prune
406 assert:
407 that:
408 - result is not changed
409 - result.groups | length == 0
410
411 - name: Prune groups
412 community.okd.openshift_adm_groups_sync:
413 config: "{{ config_simple_tolerate_not_found }}"
414 state: absent
415 register: result
416
417 - name: Validate result is changed
418 assert:
419 that:
420 - result is changed
421 - result.groups | length == 1
422
423 - name: Get developers group info
424 kubernetes.core.k8s_info:
425 kind: Group
426 version: "user.openshift.io/v1"
427 name: developers
428 register: result
429
430 - name: assert group was deleted
431 assert:
432 that:
433 - result.resources | length == 0
434
435 - name: Get admins group info
436 kubernetes.core.k8s_info:
437 kind: Group
438 version: "user.openshift.io/v1"
439 name: admins
440 register: result
441
442 - name: assert group was not deleted
443 assert:
444 that:
445 - result.resources | length == 1
446
447 - name: Prune groups once again (idempotency)
448 community.okd.openshift_adm_groups_sync:
449 config: "{{ config_simple_tolerate_not_found }}"
450 state: absent
451 register: result
452
453 - name: Assert nothing changed
454 assert:
455 that:
456 - result is not changed
457 - result.groups | length == 0
458
459 always:
460 - name: Delete openshift groups if existing
461 community.okd.k8s:
462 state: absent
463 kind: Group
464 version: "user.openshift.io/v1"
465 name: "{{ item }}"
466 with_items:
467 - admins
468 - engineers
469 - developers