Skip to content
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

feat(conf) control the set_real_ip_from NGINX variable in kong.conf #1662

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
#proxy_listen_ssl = 0.0.0.0:8443 # Address and port on which Kong will accept
# HTTPS requests if `ssl` is enabled.

#proxy_set_real_ip_from = 0.0.0.0/0 # Defines trusted addresses that are known
# to send correct replacement addresses.
# If the special value unix: is specified,
# all UNIX-domain sockets will be trusted.
# Note: See http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
# for a list of accepted values.

#admin_listen = 0.0.0.0:8001 # Address and port on which Kong will expose
# an entrypoint to the Admin API.
# This API lets you configure and manage Kong,
Expand Down
1 change: 1 addition & 0 deletions kong/conf_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ local CONF_INFERENCES = {
-- forced string inferences (or else are retrieved as numbers)
proxy_listen = {typ = "string"},
proxy_listen_ssl = {typ = "string"},
proxy_set_real_ip_from = {typ = "string"},
admin_listen = {typ = "string"},
cluster_listen = {typ = "string"},
cluster_listen_rpc = {typ = "string"},
Expand Down
1 change: 1 addition & 0 deletions kong/templates/kong_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ anonymous_reports = on

proxy_listen = 0.0.0.0:8000
proxy_listen_ssl = 0.0.0.0:8443
proxy_set_real_ip_from = 0.0.0.0/0
admin_listen = 0.0.0.0:8001
nginx_worker_processes = auto
nginx_optimizations = on
Expand Down
4 changes: 2 additions & 2 deletions kong/templates/nginx_kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ proxy_ssl_server_name on;
underscores_in_headers on;

real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
set_real_ip_from ${{PROXY_SET_REAL_IP_FROM}};
real_ip_recursive on;

lua_package_path '${{LUA_PACKAGE_PATH}};;';
Expand Down Expand Up @@ -141,4 +141,4 @@ server {
return 200 'User-agent: *\nDisallow: /';
}
}
]]
]]
1 change: 1 addition & 0 deletions spec/01-unit/02-conf_loader_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("Configuration loader", function()
assert.equal("0.0.0.0:8001", conf.admin_listen)
assert.equal("0.0.0.0:8000", conf.proxy_listen)
assert.equal("0.0.0.0:8443", conf.proxy_listen_ssl)
assert.equal("0.0.0.0/0", conf.proxy_set_real_ip_from)
assert.is_nil(conf.ssl_cert) -- check placeholder value
assert.is_nil(conf.ssl_cert_key)
assert.is_nil(getmetatable(conf))
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/custom_nginx.template
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ http {
underscores_in_headers on;

real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
set_real_ip_from ${{PROXY_SET_REAL_IP_FROM}};
real_ip_recursive on;

lua_package_path '${{LUA_PACKAGE_PATH}};;';
Expand Down