Skip to content

service-setup: survive duplicate Keycloak protocol mappers#689

Merged
AlexGodbehere merged 1 commit into
mainfrom
ag/openid-mapper-dedup
Jul 21, 2026
Merged

service-setup: survive duplicate Keycloak protocol mappers#689
AlexGodbehere merged 1 commit into
mainfrom
ag/openid-mapper-dedup

Conversation

@AlexGodbehere

Copy link
Copy Markdown
Contributor

Summary

On amrc-fp the 6.1.1 upgrade's service-setup job fails permanently: PUT /admin/realms/factory_plus/clients/<acs-cli> returns 500. Keycloak's log shows IllegalStateException: Duplicate key openid-connect%fp_principal_uuid - the stored client has BOTH F+ mappers duplicated (confirmed via the admin API: two fp_principal_uuid, two fp_permissions). Keycloak accepts same-name mapper POSTs, so two service-setup jobs racing at some point double-created them; updateClientProtocolMappers then throws on every full-client update, so every retry fails identically.

Fix:

  • ensure_client no longer echoes protocolMappers in the PUT body. Mappers are managed separately; omitting the field means "leave unchanged", so the client update succeeds even against damaged state.
  • ensure_factoryplus_claim_mappers deletes duplicate F+ mappers (keeps the first), so existing damage self-heals on the next run with no manual Keycloak surgery.

How to test

  1. On a realm where a client has duplicated fp_principal_uuid/fp_permissions mappers (amrc-fp's acs-cli currently does), run service-setup from this build.
  2. It should log "Updating client acs-cli", then "Deleting duplicate ... mapper" twice, and complete.
  3. Verify the client now has exactly one mapper of each name and that a subsequent full-client PUT (any later service-setup run) succeeds.

🤖 Generated with Claude Code

Keycloak accepts same-name protocol-mapper POSTs (ids are the only
uniqueness), but a client holding duplicates fails every subsequent
full-client PUT with 'Duplicate key openid-connect%<name>', bricking
service-setup permanently - seen in production after two setup jobs
raced. Stop echoing protocolMappers in the client PUT (they are
managed separately; omitting the field leaves them untouched) so the
update succeeds regardless, and delete duplicate F+ mappers when
ensuring them so existing damage self-heals on the next run.
@AlexGodbehere
AlexGodbehere merged commit 269bd24 into main Jul 21, 2026
1 check passed
@AlexGodbehere
AlexGodbehere deleted the ag/openid-mapper-dedup branch July 21, 2026 14:45
AlexGodbehere added a commit that referenced this pull request Jul 21, 2026
Adds the v6.1.2 section covering the service-setup duplicate-mapper fix
(#689).

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant