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

StripTrailingHostDot: Expose new configuration option to enable Envoy removal of trailing dot on hostnames #6792

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

saley89
Copy link
Contributor

@saley89 saley89 commented Nov 27, 2024

Fixes #6334

This PR adds:

  • A new configuration option in the NetworkParameters of Contour.
  • The new option is called StripTrailingHostDot.
  • This option when set to true will configure all Envoy routing to strip any trailing dot from a hostname before processing the request. This will allow it to be matched by any existing routes for that hostname without a dot.
  • Tests to show the configuration option set to to true being added to the underlying listener configuration.

@saley89 saley89 requested a review from a team as a code owner November 27, 2024 09:44
@saley89 saley89 requested review from tsaarni and skriss and removed request for a team November 27, 2024 09:44
@sunjayBhatia sunjayBhatia requested review from a team, rajatvig and izturn and removed request for a team November 27, 2024 09:44
Copy link

Hi @saley89! Welcome to our community and thank you for opening your first Pull Request. Someone will review it soon. Thank you for committing to making Contour better. You can also join us on our mailing list and in our channel in the Kubernetes Slack Workspace

Copy link

The Contour project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 14d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, the PR is closed

You can:

  • Ensure your PR is passing all CI checks. PRs that are fully green are more likely to be reviewed. If you are having trouble with CI checks, reach out to the #contour channel in the Kubernetes Slack workspace.
  • Mark this PR as fresh by commenting or pushing a commit
  • Close this PR
  • Offer to help out with triage

Please send feedback to the #contour channel in the Kubernetes Slack

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 16, 2024
@saley89
Copy link
Contributor Author

saley89 commented Dec 16, 2024

Any thoughts on this one? This is quite a small, safe change adding a new configuration flag to add the option to the configured listener.

It is based heavily on the XffNumTrustedHops flag and usage in similar areas of the code.

@github-actions github-actions bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 17, 2024
@tsaarni tsaarni added the release-note/small A small change that needs one line of explanation in the release notes. label Dec 17, 2024
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.

Project coverage is 80.70%. Comparing base (39c7cb9) to head (3ef268b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/contour/serve.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #6792   +/-   ##
=======================================
  Coverage   80.70%   80.70%           
=======================================
  Files         131      131           
  Lines       19805    19816   +11     
=======================================
+ Hits        15983    15993   +10     
- Misses       3532     3533    +1     
  Partials      290      290           
Files with missing lines Coverage Δ
cmd/contour/servecontext.go 84.37% <100.00%> (+0.03%) ⬆️
internal/contourconfig/contourconfiguration.go 98.18% <100.00%> (+0.01%) ⬆️
internal/envoy/v3/listener.go 98.50% <100.00%> (+<0.01%) ⬆️
internal/xdscache/v3/listener.go 91.64% <100.00%> (+0.07%) ⬆️
pkg/config/parameters.go 87.69% <100.00%> (+0.03%) ⬆️
cmd/contour/serve.go 21.91% <0.00%> (-0.03%) ⬇️

@saley89
Copy link
Contributor Author

saley89 commented Dec 20, 2024

@tsaarni for this one is there anything else I need to do/add or is it in a state that it can be added to an upcoming release? I ask mainly for our planning purposes as we are maintaining a fork for now with some of our changes and will take the upstream once they become merged.

Thanks.

Copy link

github-actions bot commented Jan 9, 2025

The Contour project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 14d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, the PR is closed

You can:

  • Ensure your PR is passing all CI checks. PRs that are fully green are more likely to be reviewed. If you are having trouble with CI checks, reach out to the #contour channel in the Kubernetes Slack workspace.
  • Mark this PR as fresh by commenting or pushing a commit
  • Close this PR
  • Offer to help out with triage

Please send feedback to the #contour channel in the Kubernetes Slack

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 9, 2025
@tsaarni tsaarni removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 9, 2025
@sunjayBhatia sunjayBhatia modified the milestone: 1.31.0 Jan 13, 2025
Copy link

The Contour project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 14d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, the PR is closed

You can:

  • Ensure your PR is passing all CI checks. PRs that are fully green are more likely to be reviewed. If you are having trouble with CI checks, reach out to the #contour channel in the Kubernetes Slack workspace.
  • Mark this PR as fresh by commenting or pushing a commit
  • Close this PR
  • Offer to help out with triage

Please send feedback to the #contour channel in the Kubernetes Slack

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 28, 2025
@tsaarni
Copy link
Member

tsaarni commented Feb 13, 2025

Hi @saley89 apologies for the extra-delayed review! The change looks great overall! Just a couple of small adjustments are needed. I hope you are still able to make these despite the time that has passed.

There are no conflicts, but some updates on the main branch require a rebase, running make generate, and applying the following small changes:

diff --git a/internal/featuretests/v3/listeners_test.go b/internal/featuretests/v3/listeners_test.go
index a98d41fa..525c7601 100644
--- a/internal/featuretests/v3/listeners_test.go
+++ b/internal/featuretests/v3/listeners_test.go
@@ -1234,6 +1234,9 @@ func TestHTTPProxyStripTrailingHostDot(t *testing.T) {
        })

        defer done()
+       envoyGen := envoy_v3.NewEnvoyGen(envoy_v3.EnvoyGenOpt{
+               XDSClusterName: envoy_v3.DefaultXDSClusterName,
+       })

        rh.OnAdd(fixture.NewService("backend").
                WithPorts(core_v1.ServicePort{Name: "http", Port: 80}))
@@ -1264,7 +1267,7 @@ func TestHTTPProxyStripTrailingHostDot(t *testing.T) {
        // verify that the xff-num-trusted-hops have been set to 1.
        httpListener := defaultHTTPListener()

-       httpListener.FilterChains = envoy_v3.FilterChains(envoy_v3.HTTPConnectionManagerBuilder().
+       httpListener.FilterChains = envoy_v3.FilterChains(envoyGen.HTTPConnectionManagerBuilder().
                RouteConfigName("ingress_http").
                MetricsPrefix("ingress_http").
                AccessLoggers(envoy_v3.FileAccessLogEnvoy("/dev/stdout", "", nil, contour_v1alpha1.LogLevelInfo)).
diff --git a/internal/xdscache/v3/listener_test.go b/internal/xdscache/v3/listener_test.go
index 3e271ac4..18f9d32d 100644
--- a/internal/xdscache/v3/listener_test.go
+++ b/internal/xdscache/v3/listener_test.go
@@ -2148,7 +2148,7 @@ func TestListenerVisit(t *testing.T) {
                                Name:    ENVOY_HTTP_LISTENER,
                                Address: envoy_v3.SocketAddress("0.0.0.0", 8080),
                                FilterChains: envoy_v3.FilterChains(
-                                       envoy_v3.HTTPConnectionManagerBuilder().
+                                       envoyGen.HTTPConnectionManagerBuilder().
                                                RouteConfigName(ENVOY_HTTP_LISTENER).
                                                MetricsPrefix(ENVOY_HTTP_LISTENER).
                                                AccessLoggers(envoy_v3.FileAccessLogEnvoy(DEFAULT_HTTP_ACCESS_LOG, "", nil, contour_v1alpha1.LogLevelInfo)).

Additionally, the config file documentation needs an update:

diff --git a/site/content/docs/main/configuration.md b/site/content/docs/main/configuration.md
index 5277ab79..5fad112b 100644
--- a/site/content/docs/main/configuration.md
+++ b/site/content/docs/main/configuration.md
@@ -184,6 +184,7 @@ The network configuration block can be used to configure various parameters netw
 | ---------------- | ---- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
 | num-trusted-hops | int  | 0       | Configures the number of additional ingress proxy hops from the right side of the x-forwarded-for HTTP header to trust. |
 | admin-port       | int  | 9001    | Configures the Envoy Admin read-only listener on Envoy. Set to `0` to disable.                                          |
+| strip-trailing-host-dot | bool | false | Defines if trailing dot of the host should be removed from host/authority header before any processing of request by HTTP filters or routing. This affects the upstream host header. Without setting this option to true, incoming requests with host example.com. will not match against route with domains match set to example.com. See [the Envoy documentation][15] for more information. |

 ### Listener Configuration

@@ -539,3 +540,4 @@ connects to Contour:
 [12]: https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto#envoy-v3-api-field-extensions-filters-network-http-connection-manager-v3-httpconnectionmanager-request-timeout
 [13]: https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto#envoy-v3-api-field-extensions-filters-network-http-connection-manager-v3-httpconnectionmanager-delayed-close-timeout
 [14]: https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/listener/v3/listener.proto#config-listener-v3-listener-connectionbalanceconfig
+[15]: https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto?highlight=strip_trailing_host_dot

@tsaarni tsaarni removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 13, 2025
@saley89
Copy link
Contributor Author

saley89 commented Feb 13, 2025

@tsaarni no problem at all. Those changes should be made now.

Please let me know if you see any issues/require any further changes and thanks for following it up.

@tsaarni tsaarni merged commit 38346c5 into projectcontour:main Feb 13, 2025
26 checks passed
@tsaarni
Copy link
Member

tsaarni commented Feb 13, 2025

Thank you @saley89 for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/small A small change that needs one line of explanation in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request to path returning 404 for trailing dot domain
3 participants