-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Quarkus 1.13.0: 401 Unauthorized
using different host names for Keycloak
#16294
Comments
@mrizzi Can you please add
and check what is being logged ? thanks |
@mrizzi By the way, once this issue is fixed - please note you don't need to configure |
Hi @sberyozkin, DEBUG [io.qua.oid.run.OidcProvider] (vert.x-eventloop-thread-21) Token verification has failed: Issuer (iss) claim value (https://192.168.49.1:8543/auth/realms/quarkus) doesn't match expected value of https://localhost:8543/auth/realms/quarkus |
@sberyozkin maybe I'm wrong but was this a bug of previous Quarkus versions? |
Hi @mrizzi so, interesting, the issuer is set dynamically using the current request's host, but not to the one advertised in the discovery doc. CC @pedroigor, FYI. Hmm... I'm not sure what to do at the moment. Keycloak returns a |
@sberyozkin locally I'm using Keycloak 12.0.4 |
Well the good news one can indeed set |
It's good because it works but it's not so good when talking about K8s/OCP because it means that when doing a basic deployment using templates, that value can not be provided because it will be generated dynamically at deployment time requiring manual changes to the user. |
It was not better as it was less safe - the issuer was not verified at all by default for the bearer tokens. @pedroigor is it possible to configure Keycloak to use the fixed |
@sberyozkin absolutely right: security always wins 👍 |
@mrizzi Hi, it is an interesting issue, sorry it is happening for your deployments with |
@mrizzi Have a look at https://stackoverflow.com/questions/61966384/keycloak-invalid-token-issuer, can any of the recommendations there work for you ? |
@mrizzi @pedroigor FYI, #16324 |
So, interesting tests starting keycloak's container adding
Furthemore, with Quarkus 1.13.0, it works when the token is requested using the URL The other solution proposed in SO about using the external URL every time might work but it seems to me a useless trip for requests between pods in the same k8s namespace to talk to each other using external URLs. |
Ok, thanks for the tests - so it looks not bad in |
|
@sberyozkin my opinion right now is that we will wait for Then when my team will work on creating an operator, we will enforce there all the "production level" security requirements |
@mrizzi @sberyozkin I was about to suggest a similar setting in Keycloak. As a quick background, that flag forces Keycloak to publish all the frontend URLS (issuer, jwks, authorization endpoint, etc) with a specific URL. There is also a setting for forcing backchannel URLs to use the URL set to the frontend URLs. This configuration is usually done when deploying to production. See https://www.keycloak.org/docs/latest/server_installation/#_hostname. However, it is not yet clear to me why that is now impacting Quarkus apps? |
@pedroigor my understanding/guessing is because the validation implementation changed with Quarkus 1.13.0 from the previous OidcUtils#validateClaims in Quarkus 1.12.2. What surprised me is that our tests were not able to catch this but using keycloak with testcontainer let us use |
Hi @pedroigor @mrizzi Not quite - what has changed is now, by default, the |
I see. The default behavior looks more correct to me. But I think this is not an issue in Quarkus. But missing config in Keycloak. As previously mentioned. Suppose your app is set to But you set the In this case, the issuer will be Even though you have set |
@pedroigor thanks for the explanation @mrizzi can you clarify please why setting |
I think the solutions proposed, from my perspective, are the same: in any case the user has to set a property at runtime (i.e. the keycloak's URL) or in the Considering the proposed solutions from a general perspective, I think each developers for sure owns the application s/he's developing so adding I hope it makes sense and helps. |
@mrizzi So your proposal is more a dev option than actually something for production? Ignoring the issuer is really a problem for production-grade applications. Perhaps you can use some placeholder to resolve the issuer based on an environment variable that can be set in your template. However, even though devs don't have access to Keycloak configuration, I would expect this server properly configured in k8s/OCP with a frontend URL. In this case, even though you obtain tokens using the IP address, you will get the same issuer as your application. |
Hi @pedroigor - we have another issue, #16384 |
Hi @mrizzi and @pedroigor - I've been thinking about it as well, so there is one option you can use right now, even without this PR to disable the issuer verification - disable the auto-discovery - set Pedro, given the above - where one can indirectly disable it - giving a configuration option to do the same does not change the picture but simply makes it consistent. We can certainly make the message stronger about recommending |
@pedroigor yep, my proposal is to let devs have full control without having to request any change to the authentication application (keycloak in my case) and the change for allowing the usage of @sberyozkin sorry, I know it's not my business, but for #16384, I think that my previous suggestiong about |
@mrizzi You are welcome to comment on other issues for sure :-). It won't work unfortunately - it is a dynamic case so they can't be pre-configured statically. In general I don't like the idea of overloading the properties - multiple issuers, then what happens if some other property like the path to the roles depends on the issuer, etc... |
By the way, I had another question - who is controlling the code (SPA script) which uses IP host address ? Are these the same developers who may have to set Please note - I'm just trying to understand the whole picture - I feel the PR may be viable for the consistency's purposes - if anything else |
So, #16384 is related after all - but in a different way - both issues are to do with the fact the issuer is verified by default if it has been discovered - at least here we can control Keycloak.... |
@sberyozkin Thanks for the further solution: I've just found the time to test it.
works without requiring further application or keycloak configuration. |
@sberyozkin during the test I had to debug the Quarkus code to understand that in the hurry of testing I put the absolute URL for So, if it's fine for you, I would open a PR to instantiate the |
Describe the bug
The authorization configuration for endpoints based on
quarkus.http.auth
properties that was working on Quarkus 1.12.2 provides a401 Unauthorized
once migrated to Quarkus 1.13.0.At my understanding, the issue is triggered by requesting the access token to Keycloak using a URL that is different from the one in the application's configurations for the property
quarkus.oidc.auth-server-url
.But this seems to a fair common situation for a K8s/OCP deployment:
Expected behavior
Having the requests to be authorized.
Actual behavior
Requests are unauthorized.
To Reproduce
Reproducer based on
security-keycloak-authorization-quickstart
available at https://github.com/mrizzi/quarkus-quickstarts/tree/401-unauthorized/security-keycloak-authorization-quickstartSteps to reproduce the behavior (based on the commands from https://quarkus.io/guides/security-keycloak-authorization):
./mvnw clean compile quarkus:dev
192.168.49.1
):curl -v -X GET http://localhost:8080/api/users/me -H "Authorization: Bearer "$access_token
gives401 Unauthorized
./mvnw clean compile quarkus:dev -Pquarkus-12
(a profile I've added to use Quarkus1.12.2
)curl -v -X GET http://localhost:8080/api/users/me -H "Authorization: Bearer "$access_token
works (i.e. provided{"userName":"alice"}
)I've also added the
quarkus-999
profile to check if the issue was already fixed upstream but it's not solved.Configuration
I've disabled the policy enforcer to use the Quarkus integrated web security layer because it's the one we're using in our application. The
OIDC
part is unchanged.Environment (please complete the following information):
Output of
uname -a
orver
Linux fedora-p1 5.11.10-200.fc33.x86_64 #1 SMP Thu Mar 25 16:51:31 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Output of
java -version
GraalVM version (if different from Java)
Quarkus version or git rev
1.13.0
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
The text was updated successfully, but these errors were encountered: