-
Notifications
You must be signed in to change notification settings - Fork 227
CNTRLPLANE-3429: Respect configured cipher order for inject-tls #1386
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ import ( | |
| "encoding/json" | ||
| "fmt" | ||
| "reflect" | ||
| "sort" | ||
| "testing" | ||
| "text/template" | ||
|
|
||
|
|
@@ -77,10 +76,10 @@ func makeGenericControllerConfigYAML(cipherSuites []string, minTLSVersion string | |
| return makeGenericConfigYAML(configv1.GroupVersion.String(), "GenericControllerConfig", cipherSuites, minTLSVersion) | ||
| } | ||
|
|
||
| func getDefaultCipherSuitesSorted() []string { | ||
| cipherSuites := crypto.CipherSuitesToNamesOrDie(crypto.DefaultCiphers()) | ||
|
Member
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. Why not just drop the sort.Strings statement?
Author
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. Because Ideally I would have taken the cipher suite by calling
Member
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.
That does not play well with the cipher ordering either. Both config/v1/types_tlssecurityprofile.go and DefaultCiphers() need to respect the same ordering then. Maybe noone has though of it before? |
||
| sort.Strings(cipherSuites) | ||
| return cipherSuites | ||
| // Returns the same default cipher suite as apiserver.ObserveTLSSecurityProfile() | ||
| func getDefaultCipherSuites() []string { | ||
| profile := configv1.TLSProfiles[crypto.DefaultTLSProfileType] | ||
| return crypto.OpenSSLToIANACipherSuites(profile.Ciphers) | ||
| } | ||
|
|
||
| const ( | ||
|
|
@@ -99,35 +98,37 @@ const ( | |
| ) | ||
|
|
||
| var ( | ||
| // testCipherSuites is a common cipher suite list used across multiple test cases | ||
| // Common cipher suite used across multiple test cases | ||
| testCipherSuites = []string{ | ||
| "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", | ||
| "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", | ||
| } | ||
|
|
||
| testCipherSuites2 = []string{ | ||
| "TLS_RSA_WITH_AES_128_CBC_SHA256", | ||
| "TLS_RSA_WITH_AES_128_GCM_SHA256", | ||
| "TLS_RSA_WITH_AES_256_GCM_SHA384", | ||
| } | ||
|
|
||
| // Same as previous, but using OpenSSL ids | ||
| testOpenSSLCipherSuites = []string{ | ||
| "ECDHE-ECDSA-AES128-GCM-SHA256", | ||
| "ECDHE-RSA-AES128-GCM-SHA256", | ||
| } | ||
|
|
||
| // Same as previous, but in a different order | ||
| testOpenSSLCipherSuitesReversed = []string{ | ||
| "ECDHE-RSA-AES128-GCM-SHA256", | ||
| "ECDHE-ECDSA-AES128-GCM-SHA256", | ||
| } | ||
|
|
||
| // Alternate cipher suite | ||
|
vincentdephily marked this conversation as resolved.
|
||
| testCipherSuites2 = []string{ | ||
| "TLS_RSA_WITH_AES_128_CBC_SHA256", | ||
| "TLS_RSA_WITH_AES_128_GCM_SHA256", | ||
| "TLS_RSA_WITH_AES_256_GCM_SHA384", | ||
| } | ||
| // Same as previous, but using OpenSSL ids | ||
| testOpenSSLCipherSuites2 = []string{ | ||
| "AES128-SHA256", | ||
| "AES128-GCM-SHA256", | ||
| "AES256-GCM-SHA384", | ||
| "AES128-SHA256", | ||
| } | ||
|
|
||
| defaultCipherSuites = getDefaultCipherSuitesSorted() | ||
| // Default cipher suite returned bu library-go | ||
|
Member
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. nit: bu -> by |
||
| defaultCipherSuites = getDefaultCipherSuites() | ||
| ) | ||
|
|
||
| // makeConfigMap is a helper to create a ConfigMap with optional annotation and data | ||
|
|
@@ -273,8 +274,6 @@ func validateGenericConfigTLSInjected(modified *corev1.ConfigMap, fieldName stri | |
| return fmt.Errorf("servingInfo.cipherSuites not found") | ||
| } | ||
|
|
||
| sort.Strings(expectedCiphers) | ||
| sort.Strings(cipherSuites) | ||
| if diff := cmp.Diff(expectedCiphers, cipherSuites); diff != "" { | ||
| return fmt.Errorf("list of ciphers mismatch (-want +got):\n%s", diff) | ||
| } | ||
|
|
@@ -563,16 +562,16 @@ servingInfo: | |
| }, | ||
| }, | ||
| { | ||
| name: "ConfigMap with TLS already injected - same ciphers in different order with no modification", | ||
| // Cipher order matters for TLS preference, so different order should trigger update | ||
| name: "ConfigMap with TLS already injected - same ciphers in different order - TLS injected with correct order", | ||
| configMap: makeConfigMap(true, map[string]string{ | ||
| genericOperatorConfigCMKey: makeGenericOperatorConfigYAML(testCipherSuites, tlsVersion13), | ||
| genericOperatorConfigCMKey: makeGenericOperatorConfigYAML(testOpenSSLCipherSuitesReversed, tlsVersion13), | ||
| }), | ||
| // Reverse the cipher order to test that same ciphers in different order don't trigger update | ||
| apiServer: makeAPIServerConfig(withCustomTLSProfile(testOpenSSLCipherSuitesReversed, configv1.VersionTLS13)), | ||
| apiServer: makeAPIServerConfig(withCustomTLSProfile(testOpenSSLCipherSuites, configv1.VersionTLS13)), | ||
| expectError: false, | ||
| validateConfigMap: func(t *testing.T, original, modified *corev1.ConfigMap) { | ||
| if diff := cmp.Diff(original.Data[genericOperatorConfigCMKey], modified.Data[genericOperatorConfigCMKey]); diff != "" { | ||
| t.Errorf("ConfigMap YAML mismatch (-want +got):\n%s", diff) | ||
| if err := validateGenericOperatorConfigTLSInjected(modified, genericOperatorConfigCMKey, testCipherSuites, tlsVersion13); err != nil { | ||
| t.Fatalf("validation failed: %v", err) | ||
| } | ||
| }, | ||
| }, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
This is very interesting.
Have you reached out to the relevant centralized-tls-profile folks about whether the API description should be updated?
Currently, the relevant APIServer API is described as [1]:
No mention of preferred ordering. Maybe there should be?
Ideally, the majority of components use library functions, which hopefully respect the ordering. Hopefully. However, at a minimum, some components will not respect this.
Also, the tls-scanner compliance check does not seem to check the ordering [2] as well. Maybe it should?
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.
Just a note: this will be less a problem from TLS v1.3 given the list of ciphers will be ignored/rejected.