diff --git a/molecule/keycloak/verify.yml b/molecule/keycloak/verify.yml index adeceec4e8..e5b41dc6e2 100644 --- a/molecule/keycloak/verify.yml +++ b/molecule/keycloak/verify.yml @@ -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 diff --git a/releasenotes/notes/keycloak-admin-api-scope-f9355ebc7bf7243d.yaml b/releasenotes/notes/keycloak-admin-api-scope-f9355ebc7bf7243d.yaml new file mode 100644 index 0000000000..d25f7d0629 --- /dev/null +++ b/releasenotes/notes/keycloak-admin-api-scope-f9355ebc7bf7243d.yaml @@ -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. diff --git a/roles/defaults/vars/main.yml b/roles/defaults/vars/main.yml index 1cdf2c6366..d84f4280d0 100644 --- a/roles/defaults/vars/main.yml +++ b/roles/defaults/vars/main.yml @@ -101,7 +101,7 @@ _atmosphere_images: ironic_retrive_cleaning_network: "{{ atmosphere_image_prefix }}ghcr.io/vexxhost/heat:2023.2@sha256:1dc2f23eee70ae7f339c904b2529598db8958ad0466237f43b7e9cdcd61ca374" ironic_retrive_swift_config: "{{ atmosphere_image_prefix }}ghcr.io/vexxhost/heat:2023.2@sha256:1dc2f23eee70ae7f339c904b2529598db8958ad0466237f43b7e9cdcd61ca374" 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:2023.2@sha256:096ad6ebfdb1e4a02a5a7c58483e301879a3d33c3f9e92bc7475abababd987eb" keystone_credential_cleanup: "{{ atmosphere_image_prefix }}ghcr.io/vexxhost/heat:2023.2@sha256:1dc2f23eee70ae7f339c904b2529598db8958ad0466237f43b7e9cdcd61ca374" keystone_credential_rotate: "{{ atmosphere_image_prefix }}ghcr.io/vexxhost/keystone:2023.2@sha256:096ad6ebfdb1e4a02a5a7c58483e301879a3d33c3f9e92bc7475abababd987eb" diff --git a/roles/keystone/tasks/main.yml b/roles/keystone/tasks/main.yml index c869c7b574..d11b4e3cf5 100644 --- a/roles/keystone/tasks/main.yml +++ b/roles/keystone/tasks/main.yml @@ -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