Skip to content

Commit c2f87d9

Browse files
azimuth-automation-bot[bot]mkjpryorm-bull
authored
Update keycloak-operator to 26.2.0 (#640)
* Update keycloak-operator to 26.2.0 * Fix deployment process for Keycloak 26.x (#789) * Remove deprecated options from keycloak config Docs [1] imply that hostname-strict-https option is now deprecated. [1] https://www.keycloak.org/docs/latest/upgrading/#new-hostname-options * Set keycloak hostname to full URL Without the protocol part, Keycloak cannot determine whether to enforce strict https or not [1]. [1] https://www.keycloak.org/docs/latest/upgrading/#new-hostname-options * Test temp-admin username for bootstrap admin user * Update process for setting Keycloak admin password Keycloak 26.0.0 introduced a new approach for bootstrapping admin accounts in the master realm [1], involving a temporary admin account that should be used for bootstrapping the master realm. Refactor the Keycloak admin account bootstrapping process to create a new "admin" account with the "admin" realm-role rather than reusing the existing admin account. Also delete the temporary admin-bootstrapping account. [1] https://www.keycloak.org/docs/latest/release_notes/index.html#admin-bootstrapping-and-recovery * Fix apt locking failures in CI * Get an admin token from the new admin user * Move deleting the bootstrap admin to the end * Fix conditional syntax --------- Co-authored-by: mkjpryor <[email protected]> Co-authored-by: Matt Anson <[email protected]>
1 parent fe0276a commit c2f87d9

File tree

3 files changed

+78
-16
lines changed

3 files changed

+78
-16
lines changed

roles/community_images/tasks/main.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
---
22

33
- block:
4+
- name: Update apt cache
5+
apt:
6+
update_cache: true
7+
register: cache_updated
8+
changed_when: false
9+
until:
10+
- cache_updated is success
11+
412
- name: Ensure required packages are available
513
apt:
614
name:
715
- python3-pip
816
- qemu-utils
917
state: present
10-
update_cache: yes
1118

1219
- name: Ensure OpenStack CLI (and SDK) are available
1320
pip:

roles/keycloak/defaults/main.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ keycloak_spec_defaults:
4545
http:
4646
httpEnabled: true
4747
hostname:
48-
hostname: "{{ keycloak_ingress_host }}"
48+
hostname: "{{ keycloak_base_url }}"
4949
strict: false
5050
strictBackchannel: false
5151
db: >-
@@ -98,12 +98,9 @@ keycloak_spec_defaults:
9898
if keycloak_trust_bundle
9999
else {}
100100
}}
101-
# Use the additional options to disable strict HTTPS if TLS is disabled
102101
additionalOptions:
103102
- name: metrics-enabled
104103
value: "true"
105-
- name: hostname-strict-https
106-
value: "{{ 'true' if keycloak_ingress_tls_enabled else 'false' }}"
107104
keycloak_spec_overrides: {}
108105
keycloak_spec: "{{ keycloak_spec_defaults | combine(keycloak_spec_overrides, recursive = True) }}"
109106

@@ -195,7 +192,7 @@ keycloak_ingress_spec: >-
195192
}}
196193
197194
# The version of the Keycloak operator to install
198-
keycloak_operator_version: 25.0.6
195+
keycloak_operator_version: 26.2.0
199196
# The base URL for the Keycloak operator manifests
200197
keycloak_operator_base_url: https://raw.githubusercontent.com/keycloak/keycloak-k8s-resources
201198

@@ -244,6 +241,8 @@ keycloak_admin_password: "{{ undef(hint = 'keycloak_admin_password is not define
244241
keycloak_admin_creds_secret_name: "{{ keycloak_name }}-admin-creds"
245242
# The name of the secret containing the initial admin password
246243
keycloak_initial_admin_secret_name: "{{ keycloak_name }}-initial-admin"
244+
# The bootstrap admin username
245+
keycloak_bootstrap_admin_username: "temp-admin"
247246

248247
# The base URL of Keycloak
249248
keycloak_base_url: >-

roles/keycloak/tasks/main.yml

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,24 +219,24 @@
219219

220220
# If the token request fails with an auth error, try using the initial password to
221221
# update the password to the one from config
222-
- name: Update Keycloak admin password
222+
- name: Update Keycloak admin password and remove bootstrap admin user
223223
block:
224-
- name: Get initial admin password
224+
- name: Get bootstrap admin password
225225
command: >-
226226
kubectl get secret {{ keycloak_initial_admin_secret_name }}
227227
--namespace {{ keycloak_namespace }}
228228
--output go-template='{% raw %}{{ .data.password | base64decode }}{% endraw %}'
229229
register: keycloak_initial_admin_password_cmd
230230

231-
- name: Get Keycloak admin token using initial admin password
231+
- name: Get Keycloak admin token using bootstrap admin password
232232
uri:
233233
url: "{{ keycloak_base_url }}/realms/master/protocol/openid-connect/token"
234234
method: POST
235235
body_format: form-urlencoded
236236
body:
237237
grant_type: password
238238
client_id: admin-cli
239-
username: "{{ keycloak_admin_username }}"
239+
username: "{{ keycloak_bootstrap_admin_username }}"
240240
password: "{{ keycloak_initial_admin_password_cmd.stdout }}"
241241
ca_path: "{{ keycloak_ca_path }}"
242242
validate_certs: "{{ keycloak_validate_certs }}"
@@ -246,6 +246,24 @@
246246
set_fact:
247247
keycloak_admin_token: "{{ keycloak_admin_token_initial_req.json.access_token }}"
248248

249+
- name: Create Keycloak admin user
250+
uri:
251+
url: "{{ keycloak_base_url }}/admin/realms/master/users"
252+
method: POST
253+
headers:
254+
authorization: "Bearer {{ keycloak_admin_token }}"
255+
body_format: json
256+
body:
257+
username: "{{ keycloak_admin_username }}"
258+
enabled: true
259+
credentials:
260+
- type: "password"
261+
temporary: false
262+
value: "{{ keycloak_admin_password }}"
263+
ca_path: "{{ keycloak_ca_path }}"
264+
validate_certs: "{{ keycloak_validate_certs }}"
265+
status_code: [201]
266+
249267
- name: Get Keycloak master realm users
250268
uri:
251269
url: "{{ keycloak_base_url }}/admin/realms/master/users"
@@ -256,17 +274,26 @@
256274
validate_certs: "{{ keycloak_validate_certs }}"
257275
register: keycloak_realm_users_req
258276

259-
- name: Set Keycloak admin password
277+
- name: Get Keycloak master realm roles
260278
uri:
261-
url: "{{ keycloak_base_url }}/admin/realms/master/users/{{ keycloak_admin_user_id }}/reset-password"
262-
method: PUT
279+
url: "{{ keycloak_base_url }}/admin/realms/master/roles"
280+
method: GET
281+
headers:
282+
authorization: "Bearer {{ keycloak_admin_token }}"
283+
ca_path: "{{ keycloak_ca_path }}"
284+
validate_certs: "{{ keycloak_validate_certs }}"
285+
register: keycloak_realm_roles_req
286+
287+
- name: Add the Keycloak admin realm role to the admin user
288+
uri:
289+
url: "{{ keycloak_base_url }}/admin/realms/master/users/{{ keycloak_admin_user_id }}/role-mappings/realm"
290+
method: POST
263291
headers:
264292
authorization: "Bearer {{ keycloak_admin_token }}"
265293
body_format: json
266294
body:
267-
type: password
268-
temporary: false
269-
value: "{{ keycloak_admin_password }}"
295+
- id: "{{ keycloak_admin_role_id }}"
296+
name: "admin"
270297
ca_path: "{{ keycloak_ca_path }}"
271298
validate_certs: "{{ keycloak_validate_certs }}"
272299
status_code: [204]
@@ -278,6 +305,14 @@
278305
first |
279306
json_query("id")
280307
}}
308+
keycloak_admin_role_id: >-
309+
{{-
310+
keycloak_realm_roles_req.json |
311+
selectattr("name", "eq", "admin") |
312+
first |
313+
json_query("id")
314+
}}
315+
281316
when: keycloak_admin_token_req.status != 200
282317

283318
- name: Configure SSL requirement for master realm
@@ -292,3 +327,24 @@
292327
ca_path: "{{ keycloak_ca_path }}"
293328
validate_certs: "{{ keycloak_validate_certs }}"
294329
status_code: [204]
330+
331+
- name: Delete the Keycloak bootstrap admin user
332+
uri:
333+
url: "{{ keycloak_base_url }}/admin/realms/master/users/{{ keycloak_bootstrap_admin_user_id }}"
334+
method: DELETE
335+
headers:
336+
authorization: "Bearer {{ keycloak_admin_token }}"
337+
ca_path: "{{ keycloak_ca_path }}"
338+
validate_certs: "{{ keycloak_validate_certs }}"
339+
status_code: [204]
340+
when:
341+
- keycloak_realm_users_req is defined
342+
- keycloak_bootstrap_admin_username in (keycloak_realm_users_req.json | map(attribute="username"))
343+
vars:
344+
keycloak_bootstrap_admin_user_id: >-
345+
{{-
346+
keycloak_realm_users_req.json |
347+
selectattr("username", "eq", keycloak_bootstrap_admin_username) |
348+
first |
349+
json_query("id")
350+
}}

0 commit comments

Comments
 (0)