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

internal/envoy/v3: Strip port from hostname #3458

Merged
merged 3 commits into from
Mar 12, 2021

Conversation

sunjayBhatia
Copy link
Member

@sunjayBhatia sunjayBhatia commented Mar 8, 2021

  • Strips host port using the strip_any_host_port field on HTTP connection manager
  • All filter/router processing will be done internally without the port number attached
  • Ensures :<PORT_NUM> is accepted and treated the same as the plain
  • Removes Lua logic to check port number as it is no longer needed, the filter will never see the port on the :authority header
  • Removes :* wildcard domain match in router, the router will never see the port on the domain to match
  • Note that this will strip the port from the Host/:authority header sent to upstreams
  • Bumps go-control-plane as latest tagged release is not new enough and does not include the field used
  • Will be useful in implementing wildcard host matching, makes internal logic simpler

See: https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto.html#envoy-v3-api-field-extensions-filters-network-http-connection-manager-v3-httpconnectionmanager-strip-any-host-port

@sunjayBhatia sunjayBhatia requested a review from a team as a code owner March 8, 2021 22:36
@sunjayBhatia sunjayBhatia requested review from danehans and skriss and removed request for a team March 8, 2021 22:36
- Strips host port using the strip_any_host_port field on HTTP connection manager
- All filter/router processing will be done internally without the port number attached
- Ensures <HOST>:<PORT_NUM> is accepted and treated the same as the plain <HOST>
- Removes Lua logic to check port number as it is no longer needed, the filter will never see the port on the :authority header
- Removes <HOST>:* wildcard domain match in router, the router will never see the port on the domain to match
- Note that this will strip the port from the Host/:authority header sent to upstreams
- Bumps go-control-plane as latest tagged release is not new enough and does not include the field used

See: https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto.html#envoy-v3-api-field-extensions-filters-network-http-connection-manager-v3-httpconnectionmanager-strip-any-host-port

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
@codecov
Copy link

codecov bot commented Mar 8, 2021

Codecov Report

Merging #3458 (d1bad53) into main (f679537) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3458      +/-   ##
==========================================
+ Coverage   75.18%   75.20%   +0.02%     
==========================================
  Files          98       98              
  Lines        6593     6587       -6     
==========================================
- Hits         4957     4954       -3     
+ Misses       1523     1520       -3     
  Partials      113      113              
Impacted Files Coverage Δ
internal/envoy/v3/listener.go 98.13% <100.00%> (-0.02%) ⬇️
internal/envoy/v3/route.go 98.94% <100.00%> (-0.02%) ⬇️
internal/k8s/log.go 69.56% <0.00%> (+6.52%) ⬆️

// before processing by filters or routing.
// Note that the port a listener is bound to will already be selected
// and that the port is stripped from the header sent upstream as well.
StripPortMode: &http.HttpConnectionManager_StripAnyHostPort{
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: I did not mention the redirect/multiple listener thing b/c I don't think it should be relevant.

@@ -4,7 +4,7 @@ go 1.15

require (
github.com/ahmetb/gen-crd-api-reference-docs v0.3.0
github.com/envoyproxy/go-control-plane v0.9.8
github.com/envoyproxy/go-control-plane v0.9.9-0.20210111201334-f1f47757da33
Copy link
Member Author

Choose a reason for hiding this comment

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

This commit is the one that mirrored the protos from the 1.17.0 release

Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

Looks ok to me, but someone more familiar with the Lua should definitely look too

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Copy link
Member

@youngnick youngnick left a comment

Choose a reason for hiding this comment

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

LGTM, we'll revisit when we do multiple listeners later.

@sunjayBhatia sunjayBhatia added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Mar 12, 2021
@stevesloka stevesloka merged commit 2a9fb9b into projectcontour:main Mar 12, 2021
@sunjayBhatia sunjayBhatia deleted the strip-host-port branch March 12, 2021 18:13
@sunjayBhatia
Copy link
Member Author

Release Note: Ensure Envoy strips port from :authority/Host header. Simplifies internal routing logic. Note that host in header sent to upstream will have port stripped.

sunjayBhatia added a commit to sunjayBhatia/contour that referenced this pull request Jun 5, 2023
…ualhost

Previously we stripped the port from the Host header when matching a
virtualhost, which also resulted in the header being modified for the
downstream. For Gateway API conformance, we no longer want to do this.

This basically reverts projectcontour#3458 and uses the newer RouteConfiguration field
that allows us to ignore port when choosing a virtualhost. We
reintroduce the logic in the SNI/Host misdirected request Lua to strip
the port when checking the hostname against SNI.

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
sunjayBhatia added a commit that referenced this pull request Jun 5, 2023
…ualhost (#5437)

Previously we stripped the port from the Host header when matching a
virtualhost, which also resulted in the header being modified for the
downstream. For Gateway API conformance, we no longer want to do this.

This basically reverts #3458 and uses the newer RouteConfiguration field
that allows us to ignore port when choosing a virtualhost. We
reintroduce the logic in the SNI/Host misdirected request Lua to strip
the port when checking the hostname against SNI.

We also make sure the Ingress/HTTPProxy wildcard matching ignores the
port in the Host header.

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants