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

NGINX: add X-Original-Forwarded-Host header #12999

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

clementnuss
Copy link
Contributor

@clementnuss clementnuss commented Mar 19, 2025

adds the equivalent of the existing X-Original-Forwarded-For header but for the X-Forwarded-Host instead.
typically helps in the context of configuration snippet deprecation, as there is currently no safe way to add this header when it was already set upstream

What this PR does / why we need it:

with nginx controller version 1.12.0, configuration snippets are considered Critical per default and not allowed anymore. as a result, some users who relied on config snippets to set an X-Original-Forwarded-Host header are left without a solution.

this PR adds the X-Original-Forwarded-Host per default, akin to the existing X-Original-Forwarded-For header. Those headers are used to pass the original X-Forwarded-{For,Host} further to the upstream.

ℹ️ it would be nice to cherry-pick this commit back to release/v1.12 if it gets merged.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • CVE Report (Scanner found CVE and adding report)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation only

How Has This Been Tested?

I tested the implementation locally and added an e2e test to cover this new header.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added unit and/or e2e tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 19, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If Ingress contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 19, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @clementnuss. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-priority size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 19, 2025
@k8s-ci-robot k8s-ci-robot requested review from Gacko and strongjz March 19, 2025 16:31
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: clementnuss
Once this PR has been reviewed and has the lgtm label, please assign strongjz for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

Copy link

netlify bot commented Mar 19, 2025

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit 6f0114d
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/67dfd565c5b0810008a2ef49

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 19, 2025
@clementnuss clementnuss marked this pull request as draft March 19, 2025 16:59
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 19, 2025
@clementnuss clementnuss force-pushed the original-x-forwarded-host branch 3 times, most recently from 03df00f to 095d039 Compare March 20, 2025 10:48
@clementnuss
Copy link
Contributor Author

I modified a series of test that were using assert.Contains(...,"host=myhost") and switched to using a regexp that checks whether we have a whitespace before host, as otherwise the new x-original-forwarded-host=myhost header will trigger the Contains expression.

the logic can be checked here: https://go.dev/play/p/cgkKxJZtCCp

in the current state I believe that the tests should pass, the one that failed looks like a false positive to me.

also sorry for abusing github action to run the tests, but locally on my arm64 mac it was complicated to run the e2e tests.

@clementnuss clementnuss marked this pull request as ready for review March 20, 2025 12:02
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 20, 2025
adds the equivalent of the existing X-Original-Forwarded-For header but
for the X-Forwarded-Host instead. helps in the context of configuration
snippet deprecations, as there is currently no safe way to add this
header when it was already set upstream

Signed-off-by: Clément Nussbaumer <[email protected]>
Signed-off-by: Clément Nussbaumer <[email protected]>
@clementnuss
Copy link
Contributor Author

clementnuss commented Apr 9, 2025

hi @Gacko

sorry for the ping, I would just need to know whether there's a chance this PR gets merged or not (even if it only lands in 1.13).

then based on your feedback, we will have to decide wether we keep allowing configuration snippet as fallback 😟 to generate this X-Original-Forwarded-Host header, or if we start building a custom nginx release until this PR gets merged 🤞🏼

also please let me know if it needs more tests or anything else.

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. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants