Repository navigation
fix(keycloak): reconcile Admin API client scope - #4534
Conversation
Change-Id: I2445e130b670f8c5713dd2227c63b3524a10d261 Signed-off-by: Dong Ma <dong.ma@vexxhost.com>
Replace the raw token request, client-scope listing and set_fact loop with a check-mode keycloak_clientscope lookup. The scope is returned in end_state when it exists, so the assignment task can be skipped on servers older than Keycloak 26.8.2 without obtaining or handling admin tokens directly. Signed-off-by: Mohammed Naser <mnaser@vexxhost.com>
Mohammed Naser (mnaser)
left a comment
There was a problem hiding this comment.
Dong Ma (@larainema) I pushed cec2af8 on top of your commit, can you take a look?
It replaces the token request, the /client-scopes listing and the set_fact loop with a single community.general.keycloak_clientscope task in check mode. That only looks the scope up: it comes back in end_state when it exists, and nothing gets created when it doesn't. The assignment task now loops over those results and skips realms where end_state is empty. It still uses keycloak_client with client_scopes_behavior: patch. The role no longer handles admin tokens itself.
I tested it against Keycloak 26.8.2 with community.general 11.4.9 (the version we pin):
- the
keystoneservice account got 401 from the Admin API before the change and 200 after it - the existing default scopes (
acr,basic,email,profile,roles,service_account,web-origins) stayed on the client - a realm with
kc-admin-apideleted, standing in for a pre-26.8.2 server, was skipped without errors - a second run reported no changes for both new tasks
The first Zuul run failed only because the yul2 Ubuntu mirror returned 503s; the keycloak job timed out before it reached the Keystone role. So the oss/check run on this push is the first that will actually exercise this code.
Two more things before this merges, see inline comments: the release note needs an upgrade section, and the verify step should check that the other scopes survive.
Change-Id: Iddb1ee3c62e8da6623efce52f1fb4c080dd8df89 Signed-off-by: Dong Ma <dong.ma@vexxhost.com>
09842bc to
e9cdfa1
Compare
There was a problem hiding this comment.
Mohammed Naser (@mnaser) Thanks — I reviewed cec2af8. The native keycloak_clientscope check-mode lookup is a cleaner approach than the raw token/API calls, and the additive scope patch correctly preserves existing client scopes.
And addressed both inline comments in e9cdfa1:
- Added Keycloak 26.8.2 upgrade guidance to the release note, including the required Keystone reconciliation step and the no-rolling-upgrade requirement for multi-replica deployments.
- Extended the Keycloak Molecule verifier to ensure
kc-admin-api,profile, andemailremain default scopes on the Keystone client.
ansible-playbook --syntax-check and molecule syntax -s keycloak passed locally. The remaining GitHub build/go-test and Zuul checks are still running.
Replace the admin token request and the two raw Admin REST API calls with a check-mode keycloak_client lookup. Its "existing" result holds the client's default scopes, and a missing client returns an empty list, so the scope assertions also cover the client not existing. Signed-off-by: Mohammed Naser <mnaser@vexxhost.com>
Signed-off-by: Mohammed Naser <mnaser@vexxhost.com> # Conflicts: # roles/defaults/vars/main.yml
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin stable/zed
git worktree add -d .worktree/backport-4534-to-stable/zed origin/stable/zed
cd .worktree/backport-4534-to-stable/zed
git switch --create backport-4534-to-stable/zed
git cherry-pick -x 12cc97ecd51b06a6fc3174afd21a31d28a917c1f |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin stable/2023.1
git worktree add -d .worktree/backport-4534-to-stable/2023.1 origin/stable/2023.1
cd .worktree/backport-4534-to-stable/2023.1
git switch --create backport-4534-to-stable/2023.1
git cherry-pick -x 12cc97ecd51b06a6fc3174afd21a31d28a917c1f |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin stable/2023.2
git worktree add -d .worktree/backport-4534-to-stable/2023.2 origin/stable/2023.2
cd .worktree/backport-4534-to-stable/2023.2
git switch --create backport-4534-to-stable/2023.2
git cherry-pick -x 12cc97ecd51b06a6fc3174afd21a31d28a917c1f |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin stable/2024.1
git worktree add -d .worktree/backport-4534-to-stable/2024.1 origin/stable/2024.1
cd .worktree/backport-4534-to-stable/2024.1
git switch --create backport-4534-to-stable/2024.1
git cherry-pick -x 12cc97ecd51b06a6fc3174afd21a31d28a917c1f |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin stable/2024.2
git worktree add -d .worktree/backport-4534-to-stable/2024.2 origin/stable/2024.2
cd .worktree/backport-4534-to-stable/2024.2
git switch --create backport-4534-to-stable/2024.2
git cherry-pick -x 12cc97ecd51b06a6fc3174afd21a31d28a917c1f |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin stable/2025.1
git worktree add -d .worktree/backport-4534-to-stable/2025.1 origin/stable/2025.1
cd .worktree/backport-4534-to-stable/2025.1
git switch --create backport-4534-to-stable/2025.1
git cherry-pick -x 12cc97ecd51b06a6fc3174afd21a31d28a917c1f |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin stable/2025.2
git worktree add -d .worktree/backport-4534-to-stable/2025.2 origin/stable/2025.2
cd .worktree/backport-4534-to-stable/2025.2
git switch --create backport-4534-to-stable/2025.2
git cherry-pick -x 12cc97ecd51b06a6fc3174afd21a31d28a917c1f |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin stable/2026.1
git worktree add -d .worktree/backport-4534-to-stable/2026.1 origin/stable/2026.1
cd .worktree/backport-4534-to-stable/2026.1
git switch --create backport-4534-to-stable/2026.1
git cherry-pick -x 12cc97ecd51b06a6fc3174afd21a31d28a917c1f |
Summary
kc-admin-apion Keystone only when the server exposes the built-in scopeValidation
git diff --checkuv run --locked --group dev ansible-playbook --syntax-check -i 'localhost,' molecule/keycloak/verify.ymluv run --locked --group dev molecule syntax -s keycloak