forwarded headers support for reverse proxy deployments - #10016
forwarded headers support for reverse proxy deployments#10016Mohammed-suhail-devops wants to merge 8 commits into
Conversation
|
✅ All required contributors have signed the F5 CLA for this PR. Thank you! |
|
I have hereby read the F5 CLA and agree to its terms |
|
Hi @spencerugbo, could you please check this pr we need this change as soon as its blocked the whole migration of us. |
|
Hi @javorszky @vepatel, please look into this pr we need this change |
|
Hi @suhail-blueocean, we plan on addressing this hopefully later in this year (see #7555) We do like what is here but there is still a lot of discussion internally about related things. We will credit you if we end up taking in some/all of your PR Thanks |
|
hey @Mohammed-suhail-devops #10539 might supersede this PR as its covers VirtualServer as well |
|
Hi @vepatel After reviewing the implementation, I don't believe this change resolves the issue described in this enhancement request. The current implementation adds support for overriding the proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;when no explicit The problem described in this issue is different. In deployments behind Azure Front Door, F5, CDNs, or other reverse proxies, the original client hostname is already available in the incoming request as For example: Current behaviour: Backend receives: Expected behaviour: The newly added annotation allows users to manually configure: proxy_set_header Host $http_x_forwarded_host;on every Ingress, but this does not solve the underlying problem. It simply provides a manual workaround. The enhancement requested here is for the controller to automatically preserve the original client-facing host by preferring So, while this change improves configurability, I don't believe it addresses the issue reported in this enhancement request. One thing I'd like to highlight is that the VirtualServer implementation already provides a mechanism to override the default {{- if not ($custom_headers | hasCIKey "X-Forwarded-Host") }}
{{ $proxyOrGRPC }}_set_header X-Forwarded-Host $host;
{{- end }}With this implementation, the default This makes it possible for VirtualServer users to preserve the original client-facing hostname by configuring: X-Forwarded-Host: $http_x_forwarded_hostinstead of always sending: X-Forwarded-Host: $hostIn comparison, the Ingress template currently generates: proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;by default, which causes the original hostname to be replaced with the ingress/origin hostname whenever traffic passes through multiple proxy layers. My request is to provide similar behaviour for Ingress. If an incoming This would make the behaviour consistent between VirtualServer and Ingress and would solve the host preservation issue for DR and multi-origin deployments without requiring manual per-Ingress workarounds. |
|
Hi @Mohammed-suhail-devops, thanks for explaining the use case. We have renamed the ConfigMap key in #10539 to That said, you would still not be able to set the I have reopened #10015 to track this specific gap, and we aim to deliver a complete solution for this with the milestone set to 5.7.0. On this PR specifically, rather than changing the native behaviour, I think it would be better to have an opt-in ConfigMap key Because of the ongoing work in #10557 and #10539 scheduled for 5.6.0, the template could look like this. It's a rough draft and needs testing: Would something like this fix your use case? Let me know what you think. I'll track the details in #10015. Thanks again for raising this. The use case is valid and we want to support it natively. |
Fixes #10015
Use Case
When the NGINX Ingress Controller is deployed behind reverse proxies (Azure Application Gateway, AWS ALB, etc.), the original Host header is modified to an internal service name, but the original hostname is preserved in the
X-Forwarded-Hostheader. Currently, the controller always uses$hostwhich contains the modified hostname, causing backend applications to reject requests (403/404) or generate incorrect URLs.Changes
This PR adds logic to prioritize the
X-Forwarded-Hostheader (when present) over the standard$hostvariable, with a safe fallback.Implementation:
$best_http_hostvariable with conditional logicX-Forwarded-Hostwhen present (original hostname from proxy)$hostwhenX-Forwarded-Hostis absent or emptynginx.ingress.tmpl(OSS) andnginx-plus.ingress.tmpl(Plus)NGINX Configuration Added: