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

Conversation

kylegato
Copy link

@kylegato kylegato commented Sep 20, 2016

Summary

Adding the ability to control the set_real_ip_from NGINX variable in the kong.conf file.

Full changelog

Added set_real_ip_from config option - See http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from

Issues resolved

Fix #1661

@kylegato
Copy link
Author

CC: @thefosk

@subnetmarco
Copy link
Member

LGTM

@subnetmarco
Copy link
Member

@kylegato can you also send a PR against the release/0.10 branch on to https://github.com/Mashape/getkong.org to add the relevant documentation?

@subnetmarco subnetmarco added this to the 0.10 milestone Sep 22, 2016
# correct replacement addresses.
# If the special value unix: is specified,
# all UNIX-domain sockets will be trusted.
# See: http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you align those 4 to the same column as the comments of the other properties?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please include # See [link] on the next line, like so: https://github.com/Mashape/kong/blob/master/kong.conf.default#L34-L35

# Note: See http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
# for a list of accepted values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the trailing ; would throw an error when starting nginx?

Copy link
Member

@thibaultcha thibaultcha Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally: please move this property below the proxy_listen and proxy_listen_ssl properties. And it should probably be renamed to proxy_set_real_ip_from.

Copy link
Member

@subnetmarco subnetmarco Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's right, I missed the ;. This will certainly cause an error because when it's being added with set_real_ip_from ${{SET_REAL_IP_FROM}}; it basically appends a double semicolon.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated PR, thanks guys.

# all UNIX-domain sockets will be trusted.
# See: http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous line jump

# correct replacement addresses.
# If the special value unix: is specified,
# all UNIX-domain sockets will be trusted.
# See: http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the trailing ; would throw an error when starting nginx?

@subnetmarco subnetmarco added pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) pr/status/needs review and removed pr/status/needs review pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) labels Sep 22, 2016
@@ -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 ${{SET_REAL_IP_FROM}};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See here, semicolon is already provided.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, sorry about that!

# correct replacement addresses.
# If the special value unix: is specified,
# all UNIX-domain sockets will be trusted.
# See: http://nginx.org/en/docs/http/ngx_http_realip_module.html#set_real_ip_from
Copy link
Member

@thibaultcha thibaultcha Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally: please move this property below the proxy_listen and proxy_listen_ssl properties. And it should probably be renamed to proxy_set_real_ip_from.

Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@thibaultcha thibaultcha added pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. and removed pr/status/needs review labels Sep 22, 2016
@thibaultcha
Copy link
Member

Ultimately, I wonder if we shouldn't also implement an on/off flag for this behavior in order to also solve #1615.

@thibaultcha
Copy link
Member

Also: there should probably be a test for this in 02-real_ip_spec.lua?

@kylegato
Copy link
Author

@thibaultcha I'm having trouble coming up with my own original idea for modifying 02-real_ip_spec.lua after reviewing it and what it's doing.

Maybe we would have the test set the "set_real_ip_from" to something like 123.123.123.0/0 and then check that the sent header IP does not match?

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please respect the 80 chars columns limit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: the # should be 2 white spaces after the last /0

#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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please align those comments with the hash from L62

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thibaultcha Please review my latest config update, I believe i did.

@thibaultcha
Copy link
Member

Maybe we would have the test set the "set_real_ip_from" to something like 123.123.123.0/0 and then check that the sent header IP does not match?

I think that is reasonable enough, given another test exists which asserts the contrary when set_real_ip_from is 0.0.0.0/0.

Kyle Gato and others added 3 commits September 22, 2016 16:10
we go over the 80 chars limit for the link but that's ok for now.
style(conf) correct formatting
@thibaultcha
Copy link
Member

Latest update: this is just waiting on a test as discussed in this thread. @kylegato said he would write one in the next few days.

@subnetmarco
Copy link
Member

@kylegato any updates?

@thibaultcha thibaultcha changed the title Adding the ability to control the set_real_ip_from NGINX variable in the kong.conf file. feat(conf) control the set_real_ip_from NGINX variable in kong.conf Oct 6, 2016
@thibaultcha
Copy link
Member

This would be a great addition to have in 0.9.4, alongside #1615. Would love to see some tests and docs updates, if not, we'll try to find time to do it ourselves.

@subnetmarco
Copy link
Member

@kylegato would you be able to update this PR?

@thibaultcha
Copy link
Member

It should be possible to provide a list of trusted addresses, as several occurrences of this directive can be applied.

@thibaultcha
Copy link
Member

thibaultcha commented Mar 14, 2017

Moved to #2202. Closing this as the current implementation takes care of a few more things + has tests. Thanks!

thibaultcha added a commit that referenced this pull request Mar 14, 2017
* Add real_ip_recursive and set_real_ip_from Kong configuration fields to
configure ngx_http_realip_module directives.
* Move the real_ip directives to the Kong proxy location block.
* Add configuration building unit tests for those 2 new directives.

Fix #1661
Deprecates #1662
bungle pushed a commit that referenced this pull request Mar 22, 2017
* Add real_ip_recursive and set_real_ip_from Kong configuration fields to
configure ngx_http_realip_module directives.
* Move the real_ip directives to the Kong proxy location block.
* Add configuration building unit tests for those 2 new directives.

Fix #1661
Deprecates #1662
thibaultcha added a commit that referenced this pull request Apr 15, 2017
* Add real_ip_recursive and set_real_ip_from Kong configuration fields to
configure ngx_http_realip_module directives.
* Move the real_ip directives to the Kong proxy location block.
* Add configuration building unit tests for those 2 new directives.

Fix #1661
Deprecates #1662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants