Skip to content

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

Merged
Mohammed Naser (mnaser) merged 5 commits into
mainfrom
fix/keycloak-kc-admin-api-scope
Nov 26, 2026
Merged

Mohammed Naser (mnaser) merged 5 commits into
mainfrom
fix/keycloak-kc-admin-api-scope

Conversation

@larainema

@larainema Dong Ma (larainema) commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

  • update the bundled Keycloak image to 26.8.2
  • reconcile kc-admin-api on Keystone only when the server exposes the built-in scope
  • add Keycloak Molecule coverage and a release note

Validation

  • git diff --check
  • YAML parsing/linting for modified files
  • uv run --locked --group dev ansible-playbook --syntax-check -i 'localhost,' molecule/keycloak/verify.yml
  • uv run --locked --group dev molecule syntax -s keycloak

Dong Ma (larainema) and others added 2 commits November 12, 2026 10:22
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>

@mnaser Mohammed Naser (mnaser) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 keystone service 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-api deleted, 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.

Comment thread molecule/keycloak/verify.yml Resolved
Change-Id: Iddb1ee3c62e8da6623efce52f1fb4c080dd8df89
Signed-off-by: Dong Ma <dong.ma@vexxhost.com>
@larainema
Dong Ma (larainema) force-pushed the fix/keycloak-kc-admin-api-scope branch from 09842bc to e9cdfa1 Compare November 13, 2026 16:11

@larainema Dong Ma (larainema) left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and email remain 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
@vexxhost-bot

Copy link
Copy Markdown
Collaborator

Backport failed for stable/zed, because it was unable to cherry-pick the commit(s).

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

@vexxhost-bot

Copy link
Copy Markdown
Collaborator

Backport failed for stable/2023.1, because it was unable to cherry-pick the commit(s).

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

@vexxhost-bot

Copy link
Copy Markdown
Collaborator

Backport failed for stable/2023.2, because it was unable to cherry-pick the commit(s).

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

@vexxhost-bot

Copy link
Copy Markdown
Collaborator

Backport failed for stable/2024.1, because it was unable to cherry-pick the commit(s).

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

@vexxhost-bot

Copy link
Copy Markdown
Collaborator

Backport failed for stable/2024.2, because it was unable to cherry-pick the commit(s).

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

@vexxhost-bot

Copy link
Copy Markdown
Collaborator

Backport failed for stable/2025.1, because it was unable to cherry-pick the commit(s).

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

@vexxhost-bot

Copy link
Copy Markdown
Collaborator

Backport failed for stable/2025.2, because it was unable to cherry-pick the commit(s).

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

@vexxhost-bot

Copy link
Copy Markdown
Collaborator

Backport failed for stable/2026.1, because it was unable to cherry-pick the commit(s).

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants