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

Add configuration option to toggle changing Host to X-Forwarded-Host #3045

Conversation

lewisheadden
Copy link

What this PR does / why we need it:
Allows users to supply a use-forwarded-host-header boolean option in the ConfigMap for the ingress controller which toggles whether the X-Forwarded-Host header is placed into the Host header.

Many proxies in front of nginx-ingress may terminate SSL or similar and require usage of X-Forwarded-Proto or pass client IPs in X-Forwarded-For but very few will move the Host header to X-Forwarded-Host and require us to place X-Forwarded-Host back into the Host header in nginx-ingress. We could disable all X-Forwarded-* headers using use-forwarded-headers however processing X-Forwarded-Proto and X-Forwarded-For can still be useful even when X-Forwarded-Hostshould not be considered for placement into the Host header.

Further certain L7 proxies or CDNs (such as Fastly) will produce multi-valued X-Forwarded-Host headers which should never be placed into the Host header.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #
Fixes #2463

Special notes for your reviewer:
I think this is the most appropriate and generic way to resolve #2463 but I'm open to alternate approaches as I wrestled with this for a while. I'm also not 100% sold on my resolution for {{ $proxySetHeader }} X-Forwarded-Host but after talking with some co-workers we agreed that this is likely the correct approach in our opinion.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lewisheadden
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: antoineco

If they are not already assigned, you can assign the PR to them by writing /assign @antoineco in a comment when ready.

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 5, 2018
Copy link

@diazjf diazjf left a comment

Choose a reason for hiding this comment

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

Also please squash the commits.

default $this_host;
}
{{ end }}
{{ else }}
Copy link

Choose a reason for hiding this comment

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

Include a newline before this so that we know its for {{ if $cfg.UseForwardedHeaders }} not being true.

@@ -1097,7 +1103,11 @@ stream {
{{ else }}
{{ $proxySetHeader }} X-Forwarded-For $the_real_ip;
{{ end }}
{{ if and $all.Cfg.UseForwardedHeaders (not $all.Cfg.UseForwardedHostHeader) }}
Copy link

@diazjf diazjf Sep 5, 2018

Choose a reason for hiding this comment

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

Should the not be removed? Why would we forward the host header if we set UseForwardedHostHeader to false?

Copy link
Author

@lewisheadden lewisheadden Sep 5, 2018

Choose a reason for hiding this comment

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

Yeah, this is a little bit confusing.

Existing behavior always sets X-Forwarded-Host and Host to $best_http_host. If we set UseForwardedHeaders, $best_http_host will be X-Forwarded-Host otherwise it will be the default value of the current backend.

Setting UseForwardedHostHeader to false prevents X-Forwarded-Host being set as the Host but we've still said we trust X-Forwarded-* by setting UseForwardedHeaders. As such the right behavior of the ingress seems to be to forward the X-Forwarded-Host value. I'm pretty sure this logic preserves this behavior:

If we're trusting the X-Forwarded-* headers ($all.Cfg.UseForwardedHeaders) but not assigning X-Forwarded-Host to Host (not $all.Cfg.UseForwardedHostHeader) then we should forwarded the X-Forwarded-Host on. Otherwise we supply what was determined to be $best_http_host.

This makes X-Forwarded-Host be treated in the same way as X-Forwarded-Proto and X-Forwarded-Port that are just forwarded on to the backend.

Please let me know if this doesn't make sense or if I'm misunderstanding what the desired behavior should be!

Copy link
Author

Choose a reason for hiding this comment

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

Perhaps changing the configuration option name would make this clearer? OverrideHostHeader perhaps?

@aledbf aledbf added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 5, 2018
@lewisheadden lewisheadden force-pushed the AddCfgForXForwardedHostMapping branch from 34bcf65 to 3ac5ffa Compare September 5, 2018 18:45
@lewisheadden
Copy link
Author

@diazjf any thoughts on how you'd like me to proceed? I have some time this week free at work.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 16, 2018
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 15, 2019
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

X-Forwarded-Host header is copied into the Host header
5 participants