-
Notifications
You must be signed in to change notification settings - Fork 4.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
ip address based rate-limiting does not use real client ip address but last proxy ip address #13599
Comments
Thanks for your report. I think this might be what you need: |
thanks @Water-Melon for helping. however, the link you shared indicates it also use nginx variable ' return ngx.var.realip_remote_addr or ngx.var.remote_addr' in my above test, the ngx.var.realip_remote_addr and ngx.var.remote_addr both hold the proxy ip, not the real client ip as http_x_forwarded_for {"kong_client_get_forwarded_ip":"10.0.70.198","ngx_var_realip_remote_addr":"10.0.70.198","ngx_var_http_x_forwarded_for":"2001:420:c0c8:1009::407"} |
Could you try new version of Kong, I tested kong master, it worked as what you expected. see my test case:
You could see that |
This issue is marked as stale because it has been open for 14 days with no activity. |
Dear contributor, We are automatically closing this issue because it has not seen any activity for three weeks. Your contribution is greatly appreciated! Please have a look Sincerely, |
Is there an existing issue for this?
Kong version (
$ kong version
)2.8.0
Current Behavior
when kong use those configurations:
trusted_ips = 0.0.0.0/0,::/0
real_ip_header = X-Forwarded-For
real_ip_recursive = on
the ip address based rate-limiting does not use real client ip address but use the last proxy ip address as identifier for rate limiting control,
the kong PDK method 'kong.client.get_forwarded_ip returns the last proxy ip address , as it uses nginx variable , 'ngx.var.remote_addr' , see
kong/kong/pdk/client.lua
Line 91 in 7ea02bc
Expected Behavior
the PDK API 'kong.client.get_forwarded_ip' should return the real client ip address , rather than the last proxy ip address
Steps To Reproduce
step 0 : config kong wit those
trusted_ips = 0.0.0.0/0,::/0
real_ip_header = X-Forwarded-For
real_ip_recursive = on
step 1 : configure ip address based rate-limiting plugin
step 2 : annotate ingress with the rate-limiting plugin
step 3 : call endpoint with route defined in ingress
step 4 : observe the identifier used by the rate-limiting plugin for rate control
step 5 : found that :
* 5.1 kong PDK method 'kong.client.get_forwarded_ip returns the last proxy ip address
* 5.2 the 'kong.client.get_forwarded_ip' actually get ip address from nginx variable , 'ngx.var.remote_addr' , see
kong/kong/pdk/client.lua
Line 91 in 7ea02bc
* 5.3. added debug headers in rate-limiting plugin, which shows those in response when hit the limits, only the nginx variable 'ngx.var.http_x_forwarded_for' gives the real client ip where the request was sent
Anything else?
the 3.7.x PDK API kong.client.get_forwarded_ip has same issue.
kong/kong/pdk/client.lua
Line 91 in e89feb5
The text was updated successfully, but these errors were encountered: