-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix Keycloak devservice base URL #49843
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
base: main
Are you sure you want to change the base?
Conversation
Eng-Fouad
commented
Sep 3, 2025
- Fixes Keycloak devservice uses wrong port when https is enabled with fixed port #49842
Alternative implementation would be to introduce a new config for fixed-https-port, then use it in the base URL. |
It would be ideal to have a test for this, especially since #49542 is coming soon, but fix looks sensible. |
This comment has been minimized.
This comment has been minimized.
@Eng-Fouad Thanks for the PR. I'm not sure setting the
when the fixed port is used and https is expected. Should we make it work such that in this case it is only |
Yes, I think that would work. If so, then |
Hmm, I don't recall why we even had to have Are you also using a shared network ? Can you please give me a favor and check how many ports are exposed, what is the mapping, when no fixed port is used ? I agree with Holly the fix looks sensible. But unfortunately the tests fail. |
I am not setting
Got random mapping for both ports:
|
Thanks @Eng-Fouad, so I guess we can try to retain the randomness for |
@Eng-Fouad Maybe, we'd also have to do what you proposed about the fixed port https configuration, but for now, just using the fixed port for https should do |
Original: Lines 552 to 588 in 97cebb8
Patch:
@sberyozkin Could you please check if it is a valid implementation? Thanks. |
Thanks @Eng-Fouad, it does look fine, easier to understand how the HTTPS port allocation is done with or without the fixed port, and will be also easier to update it further should we see some demand for managing fixed port for both http and https. Please update the PR and let's see what happens |
This comment has been minimized.
This comment has been minimized.
@Eng-Fouad Unfortunately it does not work either or may be some more updates are needed... |
This comment has been minimized.
This comment has been minimized.
@Eng-Fouad But it does look better compared to the previous build, only keycloak admin tests are failing |
So, I discovered something interesting. In this line:
and the Keycloak base URL would be valid and accessible: However, when we remove
and the Keycloak base URL would be invalid and inaccessible in both cases: CI fails on this PR because on those tests Keycloak running https on 8080 inside the container, and the exposed ports are:
and the Keycloak base URL would be invalid and inaccessible: If we remove |
The Line 4 in a747f3d
Line 4 in a747f3d
|
Interesting. So, with the current PR, when HTTPS is expected and the fixed port is mapped to the HTTPS port (as I proposed), the fixed port configuration conflicts with the Keycloak I guess we need a bit more time to figure out the best option, the current one seems not bad, but we'll probably break some existing tests... Now that we have it all working (thanks a million for all the analysis), what about the alternative option where you proposed adding https specific fixed port, say I.e, the fixed port, if set with What do you think, @Eng-Fouad, @holly-cummins ? And also @michalvavrik |
Status for workflow
|
May be, the current approach is right after all, ultimately, it is the startup command that dictates the choice of either HTTP or HTTPS, with a possible new |
Tricky. This morning, my instinct was that adding extra config wasn't ideal, both since it's verbose and since the 'default' behaviour would be surprising to users and violate the principle of least surprise. Papering over surprising behaviour with extra config is something we'd ideally avoid. But then I saw all the test failures and debugging over the course of today, and I wondered if maybe there isn't any non-surprising behaviour. I'm also unsure how all this will interact with my dev service rewrite, and if that might change the current behaviour in any way. It shouldn't change much except for preventing port conflicts when multiple tests use the same fixed port. But it did happen for lambdas that my changes broke ephemeral ports, so there might be other side effects in the keycloak area, since it's apparently quite complex! |
I am thinking of an implementation like this:
|
Also this behavior is weird (uses |
@@ -1,7 +1,7 @@ | |||
# Configure Dev Services for Keycloak | |||
quarkus.keycloak.devservices.create-realm=false | |||
quarkus.keycloak.devservices.port=8083 | |||
quarkus.keycloak.devservices.start-command=start --https-client-auth=required --hostname-strict=false --https-key-store-file=/etc/server-keystore.p12 --https-key-store-password=secret --truststore-paths=/etc/server-ca.crt --https-port=8080 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are fixing legit issue, thanks for that and yes, this test worked around that (and it wasn't hard to do 😀 ), but did you mention that Keycloak only exposes one port - HTTPS port? So why should be an issue to have --https-port=8080
? Does it fail with it? If yes, it is a problem because it is unnecessary (KC only listens to one port).
So my question is, how often is it that users want to combine HTTPS port and HTTP port? I have vague memory that Keycloak team mentioned that they want to support that in the future, but I don't know if they already do and if so, let's wait for a feature request from someone that needs it.
My solution would be to determine port once and use it everywhere in the KeycloakDevServicesProcessor
, it will be either HTTPS port or HTTP port. I think current state is too complicated, I spend last 20 minutes running this test and I can't tell you what is expected behavior....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am OK with using HTTPS only. If I remember correctly, when I used --https-port=8080
, I faced a problem in integration testing as Keycloak devservice was starting with wrong KEYCLOAK_URL
, something like http://keycloak-xxxxx:8080
. I had to disable discovery of the OIDC endpoints (because all URLs were wrongly starting with http://
) and I had to specify quarkus.oidc.jwks-path
and quarkus.oidc.token-path
manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[OPTIONAL] It would also be interesting to drop quarkus.keycloak.admin-client.server-url=https://localhost:${quarkus.keycloak.devservices.port}
as it should be inferred automatically, so that we know it works.