-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Correct nginx tmpl #1222
Correct nginx tmpl #1222
Conversation
@aledbf Please take a look at the CI, apparently the first check failed but passed anyway :) |
@rikatz this is not a solution. If you are running in aws using an elb in http mode we need all this headers |
@aledbf Is this the case to create a flag like 'notCloud deployment' to protect this? |
@aledbf I'm refactoring this, creating a new config in ConfigMap called
and then in SERVER template, doing this:
Does this make any sense? This way, if You're running Ingress Controller inside Amazon/GCE you set this config to 'true', otherwise it will use the remote_addr :) Also, I'll probably open a different PR, as I've made some mess here in my repo :) Thanks! |
I think we should inspect the |
OK, sounds good! I'll take a look in that and will let you know |
@aledbf I've been looking into the docs and it's not guaranted that GCE users will use the publish-service flag. Also It's not a must to AWS users. So I'll try to achieve this by using the cloudid verification, is that a problem using a new external lib? EDIT: cloudid seems to detect wrong cloudid here. I'm running a baremetal controller with docker in my notebook and it detects a GCE cloud. Will change the approach to detecting if service type is LoadBalancer. Thanks |
@aledbf sorry for taking so long, I'm pretty lost here. I'm trying to figure out where I put the right code. I'm trying to follow the same logic as 'default-backend-service' here, but I'm not able to use the config here. I've seen there's a piece of code here that could be used, but don't know if launch.go is the best place to put my code. Also, I'm trying to figure out how to use this information further, to set a config that could be used in nginx.tmpl. Can you provide me some light? :) Thanks! |
The current and change configuration still poses a security risk in some (or most?) cases. It's very easy to override Ingress whitelisting this way. Let's say I whitelist only IPs in the range: 144.13.99.0/24 A smart adversary can just do this: The best practice to prevent with the Forwarded headers is to always clear them or overwrite them unless specified otherwise in a configuration flag. In this case, we should probably have a different configuration flag than UseProxyProtocol, since the HTTP Forwarded headers and the TCP proxy protocol are orthogonal and more often than not mutually exclusive. I don't understand why they're bundled together here. |
You're right. But isn't this only the case now to flag if it is, or isn't a LoadBalancer service and then deal with that in nginx.tmpl? I'll finish modifying the code here to support this kind of detection, and then we can use this flag in nginx.tmpl to take actions. |
Also, clarify me something (as I don't use GCE). When we have a LoadBalancer, can the ExternalIP from the LoadBalancer be used as a trustable source of IP? Or they're different (internal and external IPs)? Is there somewhere a spec/status in Service object that says which is the internal Load Balancer IP? If this is the case, doesn't google/AWS loadbalancers sanitize this before passing them to the next hop (in our case, NGINX)? |
OK, I've made this commit Which adds the support to detect the publish-service type. @boazy take a look that I set here only as a comment the directive fetched from the Service Object. Maybe, If we can grab also the internal IP address we could set this as the realip trusted source, otherwise we could respect the protocol and ignore any X-Forwarded-For sent header. Also we have to deal with situations where the user uses an external proxy (not ELB or AWS), like a cache (Varnish as an example), and then we respect this if user forces the 'use proxy protocol' directive. Thanks |
In my particular case I don't even have a LoadBalancer service set in GCE (since a LoadBalancer service doesn't support global load balancing, and as far as I remember doesn't even support the proxy protocol). I configured my ingress controller as DaemonSet listening on NodePort and manually set up GCE load balancers pointing there. So looking at the Service type won't solve it in my case. It's also not useful for people who want to set up an L4 load balancer themselves using HAProxy. So it looks like this would only solve the issue for ELB and some GCE LB configurations. I would really prefer a separate setting, even as an override. |
OK, so maybe this is the case that we have a directive in ConfigMap for that (defaulting to false), but that's overriden by publish-service type? Also, this config that I'm doing here enforces the usage of real ip address and only uses the X-Forwarded-For if the publish-service is LoadBalancer (didn't changed the nginx.tmpl here yet). There's also a config in ConfigMap with trusted ips that could be used. |
Yes, but if the service is not a LoadBalancer you enforce the use of What I'm saying is that there are too many use-cases to rely on "smart" autodetection. The best approach would be to:
For clarification: |
You can even just call default |
@boazy OK, so let's turn this into code.
Does this sounds good? |
@rikatz Sorry for the late reply I think you misunderstood me (or perhaps I misunderstood you?) This should all depend on these variables:
Putting that into go template code it would look like this:
|
@rikatz any update on this? |
I'm on vacation right now, so will be able to fully work on that next week
:)
Em 7 de set de 2017 1:59 PM, "Manuel Alejandro de Brito Fontes" <
notifications@github.com> escreveu:
@rikatz <https://github.com/rikatz> any update on this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1222 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AG2YBX5H6gz2fQnIL3AgvQQT_6lNV7vsks5sgCDBgaJpZM4O_Jy->
.
|
@rikatz do you mind if I use this code and continue with the work? |
@aledbf No problem at all! Please, and let me know if you need someone to test this later :) I'm really sorry about not being able to continue this right now. Do you want access to our original repo, or are you going to work directly here? Thanks!! |
This is an improvement to NGINX template security, with the following logic:
Additionally, I've made a correction in template in line 262 putting this comment as inside template comment, instead of a repeat comment for each upstream.
This solves #1000