Skip to content

Prevent client secrets from being reassigned on every run - #369

Merged
treydock merged 1 commit into
treydock:masterfrom
drkp:keycloak-client-secret-readback
Sep 23, 2026
Merged

treydock merged 1 commit into
treydock:masterfrom
drkp:keycloak-client-secret-readback

Conversation

@drkp

@drkp drkp commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

I noticed that I was getting
Notice: /Stage[main]/…/Keycloak_client[name]/secret: created secret (corrective)
log messages on every run.

After some investigation, the root cause seems to be that any client that has a name key is treated as a built-in client:

# avoid built-in clients
if d.key?('clientAuthenticatorType') &&
   d['clientAuthenticatorType'] == 'client-secret' &&
   !d.key?('name')

...which means that if a client has a name, its secret isn't fetched, and the module correctively recreates the secret on every run. Note that it's possible for a client to wind up with a name even if that wasn't intended -- the module creates clients with name = nil, but opening the client in the admin UI and saving an unrelated change will convert that to name = ''.

Unfortunately, AFAICT there isn't a perfect programmatic way to tell if a client is built-in. This uses a heuristic: known keycloak builtin client ids (account, account-console, admin-cli, broker, realm-management, security-admin-console) with a ${client_…} placeholder display name, and realm management clients ("realmname-realm" clientId with "realmname Realm" name). If you have any better ideas for how to do this, happy to hear them! It doesn't have to be perfect, though; false negatives just result in an extra kcadm call, and false positives result in the current behavior of an extra secret reset on each run.

Unparsable output from the client-secret endpoint also now logs a warning.

Added test cases, which fail on master and pass with this fix.

@treydock
treydock merged commit 3e26827 into treydock:master Sep 23, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants