-
Notifications
You must be signed in to change notification settings - Fork 321
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
NET-4413 Implement translation + validation of TLS options #2711
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
94ae6fc
Implement validation of TLS options
nathancoleman 6161ea8
Use constants for annotation keys
nathancoleman 9dae3ee
Add changelog entry
nathancoleman 7239814
Implement TLS options translation
nathancoleman c9c1179
Update changelog entry
nathancoleman bdbf0c3
Add unit test coverage for TLS option validation
nathancoleman cff48ba
Code review feedback
nathancoleman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:feature | ||
api-gateway: translate and validate TLS configuration options, including min/max version and cipher suites, setting Gateway status appropriately | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,45 @@ var ( | |
gwv1beta1.Kind("HTTPRoute"): {}, | ||
gwv1beta1.Kind("TCPRoute"): {}, | ||
} | ||
|
||
allSupportedTLSVersions = map[string]struct{}{ | ||
"TLS_AUTO": {}, | ||
"TLSv1_0": {}, | ||
"TLSv1_1": {}, | ||
"TLSv1_2": {}, | ||
"TLSv1_3": {}, | ||
} | ||
|
||
allTLSVersionsWithConfigurableCipherSuites = map[string]struct{}{ | ||
// Remove these two if Envoy ever sets TLS 1.3 as default minimum | ||
nathancoleman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"": {}, | ||
"TLS_AUTO": {}, | ||
"TLSv1_0": {}, | ||
"TLSv1_1": {}, | ||
"TLSv1_2": {}, | ||
} | ||
|
||
allSupportedTLSCipherSuites = map[string]struct{}{ | ||
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": {}, | ||
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256": {}, | ||
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256": {}, | ||
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256": {}, | ||
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": {}, | ||
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": {}, | ||
|
||
// NOTE: the following cipher suites are currently supported by Envoy | ||
// but have been identified as insecure and are pending removal | ||
// https://github.com/envoyproxy/envoy/issues/5399 | ||
"TLS_RSA_WITH_AES_128_GCM_SHA256": {}, | ||
"TLS_RSA_WITH_AES_128_CBC_SHA": {}, | ||
"TLS_RSA_WITH_AES_256_GCM_SHA384": {}, | ||
"TLS_RSA_WITH_AES_256_CBC_SHA": {}, | ||
// https://github.com/envoyproxy/envoy/issues/5400 | ||
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA": {}, | ||
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": {}, | ||
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA": {}, | ||
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": {}, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are basically copy-pasted from the legacy implementation with some simplification of the structure |
||
) | ||
|
||
// validateRefs validates backend references for a route, determining whether or | ||
|
@@ -167,43 +206,92 @@ func (m mergedListeners) validateHostname(index int, listener gwv1beta1.Listener | |
// validateTLS validates that the TLS configuration for a given listener is valid and that | ||
// the certificates that it references exist. | ||
func validateTLS(gateway gwv1beta1.Gateway, tls *gwv1beta1.GatewayTLSConfig, resources *common.ResourceMap) (error, error) { | ||
namespace := gateway.Namespace | ||
|
||
// If there's no TLS, there's nothing to validate | ||
if tls == nil { | ||
return nil, nil | ||
} | ||
|
||
var err error | ||
// Validate the certificate references and then return any error | ||
// alongside any TLS configuration error that we find below. | ||
refsErr := validateCertificateRefs(gateway, tls.CertificateRefs, resources) | ||
|
||
if tls.Mode != nil && *tls.Mode == gwv1beta1.TLSModePassthrough { | ||
return errListenerNoTLSPassthrough, refsErr | ||
} | ||
|
||
if err := validateTLSOptions(tls.Options); err != nil { | ||
return err, refsErr | ||
} | ||
|
||
return nil, refsErr | ||
} | ||
|
||
for _, cert := range tls.CertificateRefs { | ||
// break on the first error | ||
func validateCertificateRefs(gateway gwv1beta1.Gateway, refs []gwv1beta1.SecretObjectReference, resources *common.ResourceMap) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
for _, cert := range refs { | ||
// Verify that the reference has a group and kind that we support | ||
if !common.NilOrEqual(cert.Group, "") || !common.NilOrEqual(cert.Kind, common.KindSecret) { | ||
err = errListenerInvalidCertificateRef_NotSupported | ||
break | ||
return errListenerInvalidCertificateRef_NotSupported | ||
} | ||
|
||
// Verify that the reference is within the namespace or, | ||
// if cross-namespace, that it's allowed by a ReferenceGrant | ||
if !resources.GatewayCanReferenceSecret(gateway, cert) { | ||
err = errRefNotPermitted | ||
break | ||
return errRefNotPermitted | ||
} | ||
|
||
key := common.IndexedNamespacedNameWithDefault(cert.Name, cert.Namespace, namespace) | ||
// Verify that the referenced resource actually exists | ||
key := common.IndexedNamespacedNameWithDefault(cert.Name, cert.Namespace, gateway.Namespace) | ||
secret := resources.Certificate(key) | ||
|
||
if secret == nil { | ||
err = errListenerInvalidCertificateRef_NotFound | ||
break | ||
return errListenerInvalidCertificateRef_NotFound | ||
} | ||
|
||
err = validateCertificateData(*secret) | ||
// Verify that the referenced resource contains the data shape that we expect | ||
if err := validateCertificateData(*secret); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if tls.Mode != nil && *tls.Mode == gwv1beta1.TLSModePassthrough { | ||
return errListenerNoTLSPassthrough, err | ||
return nil | ||
} | ||
|
||
func validateTLSOptions(options map[gwv1beta1.AnnotationKey]gwv1beta1.AnnotationValue) error { | ||
if options == nil { | ||
return nil | ||
} | ||
|
||
tlsMinVersionValue := string(options[common.TLSMinVersionAnnotationKey]) | ||
if tlsMinVersionValue != "" { | ||
if _, supported := allSupportedTLSVersions[tlsMinVersionValue]; !supported { | ||
return errListenerUnsupportedTLSMinVersion | ||
} | ||
} | ||
|
||
tlsMaxVersionValue := string(options[common.TLSMaxVersionAnnotationKey]) | ||
if tlsMaxVersionValue != "" { | ||
if _, supported := allSupportedTLSVersions[tlsMaxVersionValue]; !supported { | ||
return errListenerUnsupportedTLSMaxVersion | ||
} | ||
} | ||
|
||
// TODO: validate tls options | ||
return nil, err | ||
tlsCipherSuitesValue := string(options[common.TLSCipherSuitesAnnotationKey]) | ||
if tlsCipherSuitesValue != "" { | ||
// If a minimum TLS version is configured, verify that it supports configuring cipher suites | ||
if tlsMinVersionValue != "" { | ||
if _, supported := allTLSVersionsWithConfigurableCipherSuites[tlsMinVersionValue]; !supported { | ||
return errListenerTLSCipherSuiteNotConfigurable | ||
} | ||
} | ||
|
||
for _, tlsCipherSuiteValue := range strings.Split(tlsCipherSuitesValue, ",") { | ||
tlsCipherSuite := strings.TrimSpace(tlsCipherSuiteValue) | ||
if _, supported := allSupportedTLSCipherSuites[tlsCipherSuite]; !supported { | ||
return errListenerUnsupportedTLSCipherSuite | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func validateCertificateData(secret corev1.Secret) error { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The snake_case values here refer to the annotation keys that you'll find in
common/constants.go
below