-
Notifications
You must be signed in to change notification settings - Fork 335
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
Kong, OIDC and Keycloak: Authentication fails with an error "KONG Error - an unexpected error occured" from time to time. #23
Comments
Update the version of this plugin to the newest (1.0.4). |
just a short update on the issue:
|
Any updates here? Did you try on 11.x Kong with the newest 1.0.4? |
@jeremyjpj0916 Sorry for the late response. I've been ill last week, sadly. Will try this out with my colleague who is the domainowner of the api gateway today and will give further response shortly. Had to set up a whole dev environment with new components in the process, working out how to set up keycloak-usage with ssl via a kong-route (/auth), so this had been a fairly more complex matter than I thought. May I ask one question by the way?!: Question is: If I use this plugin, there's no need to use any Keycloak Client Adapters, because kong does all the things I need, right? or did I get something wrong? That said another question (sorry): Is there an integration into the spring security adapter to obtain the roles automatically, yet? Or do I have to write this myself (which I would do, for sure) |
so, the first error here is gone, upgrading kong to 0.11.1, keycloak to 3.4.0 Final and the oidc plugin to 1.0.4... this is the call with the wrong token: the '..' seems to be wrong. |
oh, just seen i've posted under the wrong account. my bad. |
So, my situation as is is mentioned above ("dominikguhr" being another account of me, actually, wrong mail used ;) ). I'll try to give you some important data about my environment, though I couldn't get it to work yet, sadly. I really, really want this. I hope you or anyone reading this could help me out here:
Following is my customized nginx_kong.lua, which I refactored according to several stackoverflow-threads to send the right headers etc. (would be great to have an example nginxkonf.lua, btw!):
Keycloak works using a kong-route, too, so I can call my https://gateway/auth ... to call keycloaks endpoint config etc. via 8443/https. My Keycloak dockerfile looks like this:
There's a little jboss-cli script called in config.sh which sets the following entries to my standalone.xml (checked it in container, the entries are there):
As I understood, this should be fairly enough low-level config to make the plugin work as rp. After deploying these two components to my openshift platform (3.6, just 1 pod each), I have set up a confidential client in a realm named "hub" and copied the client id ("landingpage") and client secret to use them in the oidc config. On the realm config-level, I only changed the switch "Require SSL" to Clientconfig in keycloak: So then I went to kong (using the kong-dashboard gui) and I've set up the following APIs (see pictures): The "App" I want to secure is a simple html landingpage and I want to call it via gateway/lop, for testing purposes. The API looks like this at the moment: I tried around a bit with Strip Uri and Preserve Host, but didn't help. Then I added the oidc plugin to the API. Configuration for the plugin is here (hope not too small): So,after doing this I tried to call gateway/lop. I got redirected to the loginpage of keycloak with a url like this: Next request after adding credentials is a POST to this url: Corresponding kong logs: https://pastebin.com/v8ELbsbC So, that's the situation. The Session is established successfully in keycloak, btw. Would be absolutely great to get some help here. I guess it's something in the nginx.conf I am missing, or I am having a knot in the brain (might be a big one). Best regards and thanks in advance, Dominik |
couldn'T solve this, yet. Is there really nothing you could help me with? even an example kong/nginx conf would be nice. |
Hi Just guessing ... In our first issue, #1, I wrote "In nginx conf-file we have added under following line set_decode_base64 $session_secret 'XX'; In XX we use some decoded default value which kong-oidc will later change." You have session_secret in "location / " |
Have you enabled kong_oidc plugin "globally" or for specific apis? If I remember right we had this issue when we enabled kong_oidc plugin globally. That is why added filters into schema.lua. So you have /auth API to access keycloak. Then you should add "config.filters=^/auth$,^/auth[^%w_%-%.~]" when you enable kong_oidc plugin. |
Hi guys, and thanks for the answers so-far! I finally found a solution (nearly). The cause of the problem was the version of lua resty-session plugin which is 2.8-1 as stated here as minimum req: https://luarocks.org/modules/hanszandbelt/lua-resty-openidc After upgrading it to 2.19.1 the error was gone, login worked - yay. I found this issue at the repo which led me to the right direction: bungle/lua-resty-session#35 I think so because I checked with version 2.13-1, the last before the fix in 2.15.1 => redirect loop. Now sadly, there's one thing missing: The X-UserInfo Header which should come back after logging in. So may it be possible that your plugin doesn't support chunked cookies? If so, could you please make this work? Would be great! If I could give you any help, just ask. Sadly I never did a thing in lua ;) Here are the kong debug logs with version 2.19-1 if you're interested. I cannot see why there shouldn't be the userinfo header set, I can even see the call the plugin makes: but in the browser my requests are looking like this when logged in: @tsyrjanen @Trojan295 Thank you very much so far, and if you need more info feel free to reach out! I hope we get this last hurdle fixed fast so I can finally use Keycloak and oidc in our scenario :) |
One thing besides: Would be very nice to exactly know which versions of the oidc plugin and its dependencies you are using together with which kc version, because maybe that I have another "wrong" version. Here's my actualised version-list for oidc plugin:
This is part of my Dockerfile, as stated in another post above. Keycloak used was 3.4.0.Final, and then 3.3 for testing, but it should work with 3.2.1, 3.3 and 3.4 nevertheless. |
okay, you can close the issue. after cleaning up kc-config and nginx.conf (I removed the whole /auth route, its not necessary - just left the session_secret in server, as @tsyrjanen stated), the X-UserInfo header appeared when routing to httpbin.org/get as upstream to check the headers. Thank you for your support. btw: a list of dependency versions would be nice, nevertheless ;) |
Situation:
We've added an API "myapi" to kong (0.10.3, not clustered, just 1 pod in openshift v3) which is secured by keycloak (3.2.1.Final) via its js client adapter and the kong oidc plugin in version 1.0.1.
Now, when calling https://mykong/myapi as a non-authenticated user, it always(!) redirects to the login and it is possible to login with valid credentials.
So far, so good, but:
In say 4 of 10 cases, the redirect works perfectly. We get access to the API. Yay!
Sadly, the other 6/10 cases (approx.) are failing, showing a Browser Error Page showing nothing more than "KONG Error - an unexpected error occured". Yes, sadly one of these "the one time it works, other time it doesn't"-kind of errors.
The Keycloak event logs showing that it successfully returns a token to kong, no matter if the 500 shows up or not, so my first guess: on this side, everything works.
This is the output of the concerned Kong logs as far as I could find some:
`2017/10/25 13:59:32 [error] 100#0: *28057 lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/kong/plugins/oidc/utils.lua:63: attempt to index local 'user' (a nil value)
stack traceback:
coroutine 0:
/usr/local/share/lua/5.1/kong/plugins/oidc/utils.lua: in function 'injectUser'
/usr/local/share/lua/5.1/kong/plugins/oidc/handler.lua:43: in function 'access'
/usr/local/share/lua/5.1/kong.lua:295: in function 'access'
access_by_lua(nginx-kong.conf:94):2: in function <access_by_lua(nginx-kong.conf:94):1>, client: 10.104.159.85, server: kong, request: "GET /cfg HTTP/1.1", host: "gateway.hub-test.ose.db.de"
10.104.159.85 - - [25/Oct/2017:13:59:32 +0000] "GET /cfg HTTP/1.1" 500 131 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"`
We've tested this with all major browsers, same outcome, so I think its no browserspecific thing. Seems that, from time to time, there's a user missing, as far as I can read the logs?! Would be great to get some help in this case!
Feel free to ask for more info, i'll be happy to help!
Best regards,
Dominik
The text was updated successfully, but these errors were encountered: