-
Notifications
You must be signed in to change notification settings - Fork 270
✨ add TLS configuration flags #1867
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
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:main
from
Nordix:tuomo/tls-configuration-flags
Feb 9, 2024
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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,111 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
"k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
func TestTLSInsecureCiperSuite(t *testing.T) { | ||
t.Run("test insecure cipher suite passed as TLS flag", func(t *testing.T) { | ||
g := NewWithT(t) | ||
tlsMockOptions := TLSOptions{ | ||
TLSMaxVersion: "TLS13", | ||
TLSMinVersion: "TLS12", | ||
TLSCipherSuites: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", | ||
} | ||
ctrl.Log.WithName("setup") | ||
ctrl.SetLogger(klog.Background()) | ||
|
||
bufWriter := bytes.NewBuffer(nil) | ||
klog.SetOutput(bufWriter) | ||
klog.LogToStderr(false) // this is important, because klog by default logs to stderr only | ||
_, err := GetTLSOptionOverrideFuncs(tlsMockOptions) | ||
g.Expect(err).Should(BeNil()) | ||
g.Expect(bufWriter.String()).Should(ContainSubstring("use of insecure cipher 'TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256' detected.")) | ||
}) | ||
} | ||
|
||
func TestTLSMinAndMaxVersion(t *testing.T) { | ||
t.Run("should fail if TLS min version is greater than max version.", func(t *testing.T) { | ||
g := NewWithT(t) | ||
tlsMockOptions := TLSOptions{ | ||
TLSMaxVersion: "TLS12", | ||
TLSMinVersion: "TLS13", | ||
} | ||
_, err := GetTLSOptionOverrideFuncs(tlsMockOptions) | ||
g.Expect(err.Error()).To(Equal("TLS version flag min version (TLS13) is greater than max version (TLS12)")) | ||
}) | ||
} | ||
|
||
func Test13CipherSuite(t *testing.T) { | ||
t.Run("should reset ciphersuite flag if TLS min and max version are set to 1.3", func(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
// Here TLS_RSA_WITH_AES_128_CBC_SHA is a tls12 cipher suite. | ||
tlsMockOptions := TLSOptions{ | ||
TLSMaxVersion: "TLS13", | ||
TLSMinVersion: "TLS13", | ||
TLSCipherSuites: "TLS_RSA_WITH_AES_128_CBC_SHA,TLS_AES_256_GCM_SHA384", | ||
} | ||
|
||
ctrl.Log.WithName("setup") | ||
ctrl.SetLogger(klog.Background()) | ||
|
||
bufWriter := bytes.NewBuffer(nil) | ||
klog.SetOutput(bufWriter) | ||
klog.LogToStderr(false) // this is important, because klog by default logs to stderr only | ||
_, err := GetTLSOptionOverrideFuncs(tlsMockOptions) | ||
g.Expect(bufWriter.String()).Should(ContainSubstring("warning: Cipher suites should not be set for TLS version 1.3. Ignoring ciphers")) | ||
g.Expect(err).Should(BeNil()) | ||
}) | ||
} | ||
|
||
func TestGetTLSVersion(t *testing.T) { | ||
t.Run("should error out when incorrect tls version passed", func(t *testing.T) { | ||
g := NewWithT(t) | ||
tlsVersion := "TLS11" | ||
_, err := GetTLSVersion(tlsVersion) | ||
g.Expect(err.Error()).Should(Equal("unexpected TLS version \"TLS11\" (must be one of: TLS12, TLS13)")) | ||
}) | ||
t.Run("should pass and output correct tls version", func(t *testing.T) { | ||
const VersionTLS12 uint16 = 771 | ||
g := NewWithT(t) | ||
tlsVersion := "TLS12" | ||
version, err := GetTLSVersion(tlsVersion) | ||
g.Expect(version).To(Equal(VersionTLS12)) | ||
g.Expect(err).Should(BeNil()) | ||
}) | ||
} | ||
|
||
func TestTLSOptions(t *testing.T) { | ||
t.Run("should pass with all the correct options below with no error.", func(t *testing.T) { | ||
g := NewWithT(t) | ||
tlsMockOptions := TLSOptions{ | ||
TLSMinVersion: "TLS12", | ||
TLSMaxVersion: "TLS13", | ||
TLSCipherSuites: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", | ||
} | ||
_, err := GetTLSOptionOverrideFuncs(tlsMockOptions) | ||
g.Expect(err).Should(BeNil()) | ||
}) | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.