Debian Codegraph @

ansible_collections/community/okd/molecule/default/tasks/openshift_auth.yml

raw
1 ---
2 - block:
3 - set_fact:
4 admin_user: test
5 admin_pass: testing123
6
7 - name: Retrieve cluster info
8 kubernetes.core.k8s_cluster_info:
9 register: k8s_cluster
10
11 - name: set openshift host value
12 set_fact:
13 openshift_host: "{{ k8s_cluster.connection.host }}"
14
15 - name: Log in (obtain access token)
16 community.okd.openshift_auth:
17 username: "{{ admin_user }}"
18 password: "{{ admin_pass }}"
19 host: '{{ openshift_host }}'
20 verify_ssl: false
21 register: openshift_auth_results
22
23 - set_fact:
24 auth_api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
25
26 - name: "Get the {{ admin_user }} User"
27 kubernetes.core.k8s_info:
28 api_key: "{{ auth_api_key }}"
29 host: '{{ openshift_host }}'
30 verify_ssl: false
31 kind: User
32 api_version: user.openshift.io/v1
33 name: "{{ admin_user }}"
34 register: user_result
35
36 - name: assert that the user was found
37 assert:
38 that: (user_result.resources | length) == 1
39
40 - name: list available tokens
41 kubernetes.core.k8s_info:
42 kind: UserOAuthAccessToken
43 version: oauth.openshift.io/v1
44 register: tokens
45
46 - debug: var=tokens
47
48 - set_fact:
49 token_names: "{{ tokens.resources | map(attribute='metadata.name') | list }}"
50
51 - block:
52 - debug: var=token_names
53
54 - name: Revoke access token
55 community.okd.openshift_auth:
56 state: absent
57 api_key: "{{ auth_api_key }}"
58 host: '{{ openshift_host }}'
59 verify_ssl: false
60 register: _revoke
61
62 - name: Ensure that token has been revoked
63 assert:
64 that:
65 - _revoke is changed
66
67 - name: "Get the {{ admin_user }} User (after token deletion)"
68 kubernetes.core.k8s_info:
69 api_key: "{{ auth_api_key }}"
70 host: '{{ openshift_host }}'
71 verify_ssl: false
72 kind: User
73 api_version: user.openshift.io/v1
74 name: "{{ admin_user }}"
75 ignore_errors: true
76 retries: 50
77 until: user_result is failed
78 delay: 20
79 register: user_result
80
81 - name: Ensure that task has failed due to revoked token
82 assert:
83 that:
84 - user_result is failed
85
86 - name: Revoke access token once again (should fail)
87 community.okd.openshift_auth:
88 state: absent
89 api_key: "{{ auth_api_key }}"
90 host: '{{ openshift_host }}'
91 verify_ssl: false
92 register: _revoke
93 ignore_errors: true
94
95 - name: Ensure that nothing changed
96 assert:
97 that:
98 - _revoke is failed
99 - _revoke.msg.startswith("Couldn't delete user oauth access token")
100
101 when: token_names | length > 0
102
103 always:
104 - name: If login succeeded, try to log out (revoke access token)
105 when: auth_api_key is defined
106 community.okd.openshift_auth:
107 state: absent
108 api_key: "{{ auth_api_key }}"
109 host: '{{ openshift_host }}'
110 verify_ssl: false
111 ignore_errors: true