-
Notifications
You must be signed in to change notification settings - Fork 5k
fix(plugins/ip-restriction): function cannot be called in preread phase #14750
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: master
Are you sure you want to change the base?
Conversation
Could we add some tests for this fix? thanks. |
@merusso could you change the merge target to "master" branch? thanks. |
I assumed if I did this that the fix would only be in the next release. Is that correct? What is the process for applying a fix to prior releases? Edit: Changed merge target to master. |
When configuring the IP Restriction plugin for TCP ingress, and this plugin rejects a connection due to the IP not being allowed, it writes the following error in Kong server logs: ``` proxy 2023/08/11 14:46:49 [warn] 2190#0: *3416565 [kong] handler.lua:33 IP address not allowed: 10.76.130.208 while prereading client data, client: 10.76.130.208, server: 0.0.0.0:2000 proxy 2023/08/11 14:46:49 [error] 2190#0: *3416565 lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/kong/pdk/private/phases.lua:97: function cannot be called in preread phase (only in: rewrite, access, response, header_filter, error, admin_api) proxy stack traceback: proxy coroutine 0: proxy [C]: in function 'error' proxy /usr/local/share/lua/5.1/kong/pdk/private/phases.lua:97: in function 'check_phase' proxy /usr/local/share/lua/5.1/kong/pdk/response.lua:1101: in function </usr/local/share/lua/5.1/kong/pdk/response.lua:1096> proxy /usr/local/share/lua/5.1/kong/init.lua:352: in function 'execute_plugins_iterator' proxy /usr/local/share/lua/5.1/kong/init.lua:868: in function 'preread' proxy preread_by_lua(nginx-kong-stream.conf:104):2: in main chunk while prereading client data, client: 10.76.130.208, server: 0.0.0.0:2000 ``` The error is caused by a bug in the IP restriction plugin when handling TCP connections. The plugin calls function kong.response.error regardless of connection type, but this function isn't applicable to TCP. To resolve the issue, this change alters the do_exit function to use ngx.exit instead of kong.response.error for TCP connections. Fix Kong#14749
d969ed4
to
4cc5b5e
Compare
We also need a change log YAML, thanks. |
I added some asserts to existing tests to check for the logger error, but I'm unable to run the tests. Can you please verify? I can't set up the environment correctly, getting an error attempting to use the dev container.
|
I think there's an issue with the changelog util. Was it moved? Should I create this YAML manually?
Edit: I added it manually. IMO, the contributor docs here are confusing, maybe out of date? |
Co-authored-by: Chrono <[email protected]>
@chobits could you take a look too? thanks. |
Summary
When configuring the IP Restriction plugin for TCP ingress, and this plugin rejects a connection due to the IP not being allowed, it writes the following error in Kong server logs:
The error is caused by a bug in the IP restriction plugin when handling TCP connections. The plugin calls function kong.response.error regardless of connection type, but this function isn't applicable to TCP.
To resolve the issue, this change alters the do_exit function to use ngx.exit instead of kong.response.error for TCP connections.
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Fix #14749