Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions molecule/keycloak/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions releasenotes/notes/keycloak-admin-api-scope-f9355ebc7bf7243d.yaml
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion roles/defaults/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
47 changes: 47 additions & 0 deletions roles/keystone/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading