fix(keycloak): reconcile Admin API client scope (#4534)

Signed-off-by: Dong Ma <dong.ma@vexxhost.com>
Signed-off-by: Mohammed Naser <mnaser@vexxhost.com>
Co-authored-by: Mohammed Naser <mnaser@vexxhost.com>
This commit is contained in:
Dong MaandMohammed Naser authored and GitHub committed 2026-11-26 11:11:28 -05:00
1 parent b4f7197693
commit 12cc97ecd5
4 files changed
+88 -1

No files matched your search

+28
View File
@@ -15,6 +15,34 @@
- name: Create user and assert it exists inside Keystone
hosts: all
tasks:
- name: Get Keystone Keycloak client
run_once: true
delegate_to: localhost
check_mode: true
changed_when: false
community.general.keycloak_client:
# Keycloak settings
auth_keycloak_url: "https://{{ keycloak_host }}"
auth_realm: master
auth_client_id: admin-cli
auth_username: admin
auth_password: "{{ keycloak_admin_password }}"
validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
# Client settings
realm: atmosphere
client_id: keystone
register: keycloak_keystone_client
# NOTE: A missing client returns empty scope lists, so these checks also
# fail if the client does not exist.
- name: Assert Keystone Keycloak client has expected default scopes
run_once: true
ansible.builtin.assert:
that:
- "'kc-admin-api' in keycloak_keystone_client.existing.defaultClientScopes"
- "'profile' in keycloak_keystone_client.existing.defaultClientScopes"
- "'email' in keycloak_keystone_client.existing.defaultClientScopes"
- name: Create Keycloak user
run_once: true
delegate_to: localhost
@@ -0,0 +1,12 @@
---
fixes:
- |
Updates Keycloak to ``26.8.2`` and assigns the built-in
``kc-admin-api`` client scope to the Keystone service account. This keeps
Keystone able to use the Keycloak Admin REST API after the upgrade.
upgrade:
- |
Run the Keystone role immediately after upgrading Keycloak to reconcile
the ``kc-admin-api`` client scope before using federated identity lookups.
For deployments with more than one Keycloak replica, stop and upgrade all
replicas together: Keycloak 26.8.2 does not support a rolling upgrade.
+1 -1
View File
@@ -118,7 +118,7 @@ _atmosphere_images:
ironic_retrive_cleaning_network: "{{ atmosphere_image_prefix }}ghcr.io/vexxhost/heat:2026.1@sha256:6d6975d11648a56c51b1dbed0f4a752d098821efc91e72671f8c11838f090731"
ironic_retrive_swift_config: "{{ atmosphere_image_prefix }}ghcr.io/vexxhost/heat:2026.1@sha256:6d6975d11648a56c51b1dbed0f4a752d098821efc91e72671f8c11838f090731"
keepalived: "{{ atmosphere_image_prefix }}ghcr.io/vexxhost/keepalived:latest@sha256:630645917bdb5cd4fee92c79a220c6728aea95cb527801957312bcd2a8004e7a"
keycloak: "{{ atmosphere_image_prefix }}quay.io/keycloak/keycloak:26.8.1-1@sha256:a78d6b79572168cb25886b80a8b5b8d4ed4390743e3eecb810538683e209dd6b"
keycloak: "{{ atmosphere_image_prefix }}quay.io/keycloak/keycloak:26.8.2-1@sha256:723b1d6e254c0fc96d5cffec860c7e0744d6a3277822b865bb538cf891575e41"
keystone_api: "{{ atmosphere_image_prefix }}ghcr.io/vexxhost/keystone:2026.1@sha256:45575171eea16842dd3a3799092ec5df52831aacea91c32f5184fd174e74195e"
keystone_credential_cleanup: "{{ atmosphere_image_prefix }}ghcr.io/vexxhost/heat:2026.1@sha256:6d6975d11648a56c51b1dbed0f4a752d098821efc91e72671f8c11838f090731"
keystone_credential_rotate: "{{ atmosphere_image_prefix }}ghcr.io/vexxhost/keystone:2026.1@sha256:45575171eea16842dd3a3799092ec5df52831aacea91c32f5184fd174e74195e"
+47
View File
@@ -67,6 +67,30 @@
kubernetes.core.k8s:
template: configmap-openid-metadata.yml.j2
# NOTE: Keycloak 26.8.2+ only accepts Admin REST API tokens that carry the
# built-in "kc-admin-api" client scope. Older servers do not have it, so
# look it up first. Check mode makes this a read-only lookup: the scope
# is returned in "end_state" when it exists, and nothing is created.
- name: Check for the Keycloak Admin API client scope
run_once: true
check_mode: true
changed_when: false
community.general.keycloak_clientscope:
# Keycloak settings
auth_keycloak_url: "{{ item.keycloak_server_url }}"
auth_realm: "{{ item.keycloak_user_realm_name }}"
auth_client_id: "{{ item.keycloak_admin_client_id }}"
auth_username: "{{ item.keycloak_admin_user }}"
auth_password: "{{ item.keycloak_admin_password }}"
validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
# Client scope settings
realm: "{{ item.keycloak_realm }}"
name: kc-admin-api
register: _keystone_keycloak_admin_api_scope
loop: "{{ keystone_domains }}"
loop_control:
label: "{{ item.name }}"
- name: Create Keycloak clients
no_log: true
run_once: true
@@ -93,6 +117,29 @@
loop_control:
label: "{{ item.name }}"
- name: Assign Keycloak Admin API scope to Keystone client
no_log: true
run_once: true
community.general.keycloak_client:
# Keycloak settings
auth_keycloak_url: "{{ item.item.keycloak_server_url }}"
auth_realm: "{{ item.item.keycloak_user_realm_name }}"
auth_client_id: "{{ item.item.keycloak_admin_client_id }}"
auth_username: "{{ item.item.keycloak_admin_user }}"
auth_password: "{{ item.item.keycloak_admin_password }}"
validate_certs: "{{ cluster_issuer_type != 'self-signed' }}"
# Realm settings
realm: "{{ item.item.keycloak_realm }}"
client_id: "{{ item.item.keycloak_client_id }}"
default_client_scopes:
- kc-admin-api
# NOTE: "patch" only adds missing scopes and keeps the existing ones.
client_scopes_behavior: patch
loop: "{{ _keystone_keycloak_admin_api_scope.results }}"
loop_control:
label: "{{ item.item.name }}"
when: item.end_state | length > 0
- name: Assign realm-management roles to service account
no_log: true
run_once: true