Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container marked as initialized before admin password is populated #133

Closed
ZIRAKrezovic opened this issue Apr 19, 2024 · 9 comments · Fixed by #136
Closed

Container marked as initialized before admin password is populated #133

ZIRAKrezovic opened this issue Apr 19, 2024 · 9 comments · Fixed by #136
Labels
bug Something isn't working improvement Improves already available features
Milestone

Comments

@ZIRAKrezovic
Copy link

Describe the bug

I have a problem where container is marked as ready and KeycloakClient starts calling it before admin user has been created.

This is quite random and (probably) depends on system load. The current probe looks for HTTP port, which becomes available before the admin is initialized, resulting in 401 when calling any ADMIN API.

Version

3.3.0

Expected behavior

I would like a guarantee that I can use admin user immediately after "start" command returns.

Actual behavior

5 out of 10 times, calling admin API with provided admin user results in 401 as admin gets created a bit later (several milliseconds to two seconds difference)

How to Reproduce?

A simplest reproducer was to start two Keycloak container instances. I have multiple @SpringBootTest-s in my app, each runs in different Java container so each of them spawns their own Keycloak container. I can try and get a reproducer in plain java if you need it.

Relevant log output

2024-04-19 13:11:18,085 INFO  [io.quarkus] (main) Profile dev activated.
2024-04-19 13:11:18,085 INFO  [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, jdbc-h2, keycloak, logging-gelf, narayana-jta, reactive-routes, resteasy-reactive, resteasy-reactive-jackson, smallrye-context-propagation, vertx]
2024-04-19 13:11:18,578 WARN  [org.keycloak.events] (executor-thread-2) type="LOGIN_ERROR", realmId="bc1830f9-43e4-4ea2-9799-70a1ab02e8b4", clientId="admin-cli", userId="null", ipAddress="172.29.0.1", error="user_not_found", auth_method="openid-connect", grant_type="password", client_auth_method="client-secret", username="admin"
2024-04-19 13:11:18,810 INFO  [org.keycloak.services] (main) KC-SERVICES0009: Added user 'admin' to realm 'master'
2024-04-19 13:11:18,816 WARN  [org.keycloak.quarkus.runtime.KeycloakMain] (main) Running the server in development mode. DO NOT use this configuration in production.

Anything else?

No response

@ZIRAKrezovic ZIRAKrezovic added the bug Something isn't working label Apr 19, 2024
@dasniko
Copy link
Owner

dasniko commented Apr 23, 2024

Thanks for reporting the issue.
I've also already discovered this behavior, but haven't found a proper solution. I've experimented with the various health endpoints, but even the started endpoint does not work reliable.
Currently I have not idea how to solve this and have still to explore other possibilities.
if you have any ideas, they are more than appreciated!

@ZIRAKrezovic
Copy link
Author

I have filled a request in Keycloak repo asking for a (semi) official implementation for what you described.

@dasniko dasniko linked a pull request Apr 24, 2024 that will close this issue
@dasniko
Copy link
Owner

dasniko commented Apr 24, 2024

@ZIRAKrezovic Pls. try #136 - this should solve the issue.
Can you confirm?

@dasniko dasniko added the improvement Improves already available features label Apr 24, 2024
@ZIRAKrezovic
Copy link
Author

Hi, it looks like it may fix the issue for the described use-case. But I may have seen some times where the log message for dev mode is logged before admin user is created - again quite hard to reproduce.

@ZIRAKrezovic
Copy link
Author

The last solution I'll try if this one fails will be to ship a pre-initialized H2 database with admin user and mount it as a file - but then again this is out of scope of this project.

@dasniko
Copy link
Owner

dasniko commented Apr 24, 2024

But I may have seen some times where the log message for dev mode is logged before admin user is created

TBH, I haven't seen this ever. 🤷‍♂️

1 similar comment
@dasniko
Copy link
Owner

dasniko commented Apr 24, 2024

But I may have seen some times where the log message for dev mode is logged before admin user is created

TBH, I haven't seen this ever. 🤷‍♂️

@lmachacek
Copy link

We had the same problem and this waiting strategy fixed that, thanks 👍

@ZIRAKrezovic
Copy link
Author

And to debunk myself, I have started 10 keycloak containers on the same machine and all 10 of them were initialized correctly - with the log message about dev mode being last

for i in 0 1 2 3 4 5 6 7 8 9 ; do docker run -d --rm --name keycloak-$i keycloak/keycloak:23.0.7 start-dev ; done

Thanks for the promt fix @dasniko.

@dasniko dasniko added this to the 3.3.1 milestone Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working improvement Improves already available features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants