-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
openid-connect plugin leaving server-side sessions locked by not calling explicit session:close() #8017
Comments
Can you give detailed configuration information? This would help us to reproduce it. |
Sure, this is my configuration with keycloak as the idp in kubernetes: Keycloak realm configuration (KeycloakRealmImport):
notes:
Keycloak APISIX route configuration (ApisixRoute):
notes:
Httpbin deployment (httpbin)
Httpbin APISIX route configuration (ApisixRoute):
notes:
Server-side session store patch for configmap/apisix:
notes:
Resulting nginx.conf sections:
Let me know if you need anything else. Thanks for a great product! |
@brentmjohnson Yes, for server-side session storages, it's necessary to close session explicicitly. However, this plugin assumes the user to use default storage adapter, i.e. save-all-in-cookie and does not pass any session options to lua-resty-openidc. But for compatibility with all stroages, we need to close it at right place. Do you expect a bugfix or make a PR youself? |
We can provide a |
@tzssangglass Not necessary at all. The |
@kingluo that is what I understand as well - that session:close() should be safe to call explicitly regardless of the configured storage implementation (supported by the underlying bungle/lua-resty-session). I am happy to make a PR for the change, but it will be a few weeks until I can get to it if that is okay. One note on the current cookie storage implementation. It seems like with nginx.conf worker_processes != 1, there are no guarantees for worker affinity for subsequent connections to the same protected route. When the request is handled by a different worker, the session cookie is not valid. I believe the result is actually a plugin error rather than a redirect to the auth endpoint. Since APISIX ships with worker_processes: auto as the default, it might be worth considering moving to the shared-dictionary-storage-adapter as a new default session store. |
|
No, there are two misunderstandings here.
|
Okay got it - thanks for clarifying. And the issue I was encountering related to worker process actually turned out to be this: #2426 (comment) Using a worker_processes: 1 seems to avoid potential errors related to an uninitialized session_secret on first login / logout redirect. Confirmed this for both default cookie storage as well as server-side redis. |
@brentmjohnson Yes, it's a bug of the plugin. My colleague is making a PR to add options to invoke |
Thanks, works great @kingluo! |
@kingluo is there any progress on the PR? |
@shreemaan-abhishek , please assign me this issue. |
…l expired when using lockable session storage backend (apache#8017)
…l expired when using lockable session storage backend (apache#8017)
@sheharyaar please help to check this: #10788 |
…l expired when using lockable session storage backend (apache#8017)
…l expired when using lockable session storage backend (apache#8017)
Current Behavior
Server-side session stores that support locking remain locked after authentication until the default or configured lock ttl (https://github.com/bungle/lua-resty-session#redis-storage-adapter) expires. This results in subsequent requests (using the same APISIX session) hanging until the lock expires.
Apisix plugin code:
apisix/apisix/plugins/openid-connect.lua
Line 312 in cf8de8e
Does not implement explicit session:close() as recommended by zmartzone/lua-resty-openidc https://github.com/zmartzone/lua-resty-openidc#sessions-and-locking
Expected Behavior
APISIX openid-connect plugin should call explicit session:close() and subsequent requests (using the same APISIX session) should complete immediately.
Error Logs
No response
Steps to Reproduce
Environment
apisix version
): 2.15.0uname -a
): Linux apisix-6fcbf58999-t8x9r 5.15.0-48-generic # 54-Ubuntu SMP Fri Aug 26 13:26:29 UTC 2022 x86_64 Linuxopenresty -V
ornginx -V
): nginx version: openresty/1.21.4.1curl http://127.0.0.1:9090/v1/server_info
): N/Aluarocks --version
): /usr/local/bin/luarocks 3.8.The text was updated successfully, but these errors were encountered: