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

fix: disable ALPN for non-HTTP routes #4460

Merged
merged 11 commits into from
Oct 24, 2024
Merged

Conversation

guydc
Copy link
Contributor

@guydc guydc commented Oct 16, 2024

What type of PR is this?

What this PR does / why we need it:

  • By default, all non-HTTPS routes opt-out of ALPN
  • If a client traffic policy defines ALPN protocols, non-HTTPS routes are opted-in
  • No changes to upstream ALPN settings

Which issue(s) this PR fixes:

Fixes #4456

@guydc guydc added the release-note Indicates a required release note label Oct 16, 2024
@guydc guydc requested a review from a team as a code owner October 16, 2024 19:03
@@ -355,6 +355,8 @@ type TLSConfig struct {
StatelessSessionResumption bool `json:"statelessSessionResumption,omitempty" yaml:"statelessSessionResumption,omitempty"`
// StatefulSessionResumption determines if stateful (session-id based) session resumption is enabled
StatefulSessionResumption bool `json:"statefulSessionResumption,omitempty" yaml:"statefulSessionResumption,omitempty"`
// ALPNDisabled determined if ALPN extension is disabled
ALPNDisabled bool `json:"alpnDisabled,omitempty" yaml:"alpnDisabled,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

can we reuse ALPNProtocols ? and treat nil as a default and empty as disabled ?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on reusing ALPNProtocols instead of adding a new ALPNDisabled attribute.

Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 65.79%. Comparing base (8adbf1d) to head (9e30830).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
internal/xds/translator/translator.go 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4460      +/-   ##
==========================================
+ Coverage   65.74%   65.79%   +0.04%     
==========================================
  Files         210      210              
  Lines       31516    31526      +10     
==========================================
+ Hits        20721    20742      +21     
+ Misses       9598     9590       -8     
+ Partials     1197     1194       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@guydc guydc requested review from arkodg and liorokman October 22, 2024 10:52

// explicitly disable ALPN by setting an empty list for non-HTTPS use cases
if protocol != gwapiv1.HTTPSProtocolType {
tlsListenerConfigs.ALPNProtocols = ptr.To([]string{})
Copy link
Member

Choose a reason for hiding this comment

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

what's the default behivor of empty/nil?

Copy link
Member

Choose a reason for hiding this comment

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

can you addrees it with comment.

@@ -896,7 +896,7 @@ func buildXdsUpstreamTLSSocketWthCert(tlsConfig *ir.TLSUpstreamConfig) (*corev3.
tlsCtx.CommonTlsContext.TlsParams = tlsParams
}

if len(tlsConfig.ALPNProtocols) > 0 {
if tlsConfig.ALPNProtocols != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be clearer to change buildALPNProtocols to return an empty []string if tlsConfig.ALPNProtocols is nil. There's no need to check the length of the tlsConfig.ALPNProtocols array here - it's already checked in the buildALPNProtocols function.

Copy link
Contributor Author

@guydc guydc Oct 22, 2024

Choose a reason for hiding this comment

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

We have a different behavior for downstream (default: h2, http/1.1) and upstream (default: nil) tls sockets.

For upstreams, envoy manages ALPN options correctly in the connection pools that it initiates per protocol version. So envoy-gateway defaults are really not required, unless a user explicitly opts-in to override this behavior (option 2 in this link)

https://github.com/envoyproxy/envoy/blob/ef96ec4f0c5bbc28bd0b2e599594e8812f6341c4/source/common/tls/client_context_impl.cc#L117

I think that we just don't need to invoke this function at all in case of upstream sockets.

@@ -350,7 +350,7 @@ type TLSConfig struct {
// SignatureAlgorithms supported by this listener
SignatureAlgorithms []string `json:"signatureAlgorithms,omitempty" yaml:"signatureAlgorithms,omitempty"`
// ALPNProtocols exposed by this listener
ALPNProtocols []string `json:"alpnProtocols,omitempty" yaml:"alpnProtocols,omitempty"`
ALPNProtocols *[]string `json:"alpnProtocols,omitempty" yaml:"alpnProtocols,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

is the ptr needed ? the zero value of a slice is nil

Copy link
Contributor Author

@guydc guydc Oct 22, 2024

Choose a reason for hiding this comment

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

Sure. If we don't use a pointer and keep omitempty, the .out files would omit alpnProtocols both for nil and empty slices, so that can make IR/XDS test reading a bit confusing. If we remove omitempty, tests are a bit inflated with alpnProtocols: null. Any preference?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah thanks for explaining why you chose this route :) even if .out files omit alpnProtocols, the test title (-empty-alpn) should hopefully solve the confusion imo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, my bad, it's not just a readability issue. When .out files are parsed, all the omitted slices are assumed to be nil, while the IR structs that they are are compared to might be an empty slice (e.g. for TLSRoutes). The .out testdata would always be wrongly generated in this case.
So, options are:

  • Don't omitempty
  • Customize JSON marshaling with additional tags, methods
  • Pointer to slice

I added the first option in a new commit.

Copy link
Member

@zhaohuabing zhaohuabing left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

Copy link
Contributor

@liorokman liorokman left a comment

Choose a reason for hiding this comment

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

LGTM

@guydc guydc merged commit 0b69387 into envoyproxy:main Oct 24, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Indicates a required release note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

default ALPN settings break TLS-terminated TCP route
5 participants