mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-11-12 21:40:29 +00:00
add options for min tls levels
This commit is contained in:
@@ -54,6 +54,9 @@ type SecureServingOptions struct {
|
||||
// CipherSuites is the list of allowed cipher suites for the server.
|
||||
// Values are from tls package constants (https://golang.org/pkg/crypto/tls/#pkg-constants).
|
||||
CipherSuites []string
|
||||
// MinTLSVersion is the minimum TLS version supported.
|
||||
// Values are from tls package constants (https://golang.org/pkg/crypto/tls/#pkg-constants).
|
||||
MinTLSVersion string
|
||||
}
|
||||
|
||||
type CertKey struct {
|
||||
@@ -142,6 +145,10 @@ func (s *SecureServingOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
"Values are from tls package constants (https://golang.org/pkg/crypto/tls/#pkg-constants). "+
|
||||
"If omitted, the default Go cipher suites will be used")
|
||||
|
||||
fs.StringVar(&s.MinTLSVersion, "tls-min-version", s.MinTLSVersion,
|
||||
"Minimum TLS version supported. "+
|
||||
"Value must match version names from https://golang.org/pkg/crypto/tls/#pkg-constants.")
|
||||
|
||||
fs.Var(utilflag.NewNamedCertKeyArray(&s.SNICertKeys), "tls-sni-cert-key", ""+
|
||||
"A pair of x509 certificate and private key file paths, optionally suffixed with a list of "+
|
||||
"domain patterns which are fully qualified domain names, possibly with prefixed wildcard "+
|
||||
@@ -249,6 +256,11 @@ func (s *SecureServingOptions) applyServingInfoTo(c *server.Config) error {
|
||||
secureServingInfo.CipherSuites = cipherSuites
|
||||
}
|
||||
|
||||
secureServingInfo.MinTLSVersion, err = utilflag.TLSVersion(s.MinTLSVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// load SNI certs
|
||||
namedTLSCerts := make([]server.NamedTLSCert, 0, len(s.SNICertKeys))
|
||||
for _, nck := range s.SNICertKeys {
|
||||
|
||||
@@ -62,3 +62,26 @@ func TLSCipherSuites(cipherNames []string) ([]uint16, error) {
|
||||
}
|
||||
return ciphersIntSlice, nil
|
||||
}
|
||||
|
||||
var versions = map[string]uint16{
|
||||
"VersionTLS10": tls.VersionTLS10,
|
||||
"VersionTLS11": tls.VersionTLS11,
|
||||
"VersionTLS12": tls.VersionTLS12,
|
||||
}
|
||||
|
||||
func TLSVersion(versionName string) (uint16, error) {
|
||||
if len(versionName) == 0 {
|
||||
return DefaultTLSVersion(), nil
|
||||
}
|
||||
if version, ok := versions[versionName]; ok {
|
||||
return version, nil
|
||||
}
|
||||
return 0, fmt.Errorf("unknown tls version %q", versionName)
|
||||
}
|
||||
|
||||
func DefaultTLSVersion() uint16 {
|
||||
// Can't use SSLv3 because of POODLE and BEAST
|
||||
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
|
||||
// Can't use TLSv1.1 because of RC4 cipher usage
|
||||
return tls.VersionTLS12
|
||||
}
|
||||
|
||||
@@ -80,8 +80,12 @@ func TestConstantMaps(t *testing.T) {
|
||||
fmt.Printf("error: %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
discoveredVersions := map[string]bool{}
|
||||
discoveredCiphers := map[string]bool{}
|
||||
for _, declName := range pkg.Scope().Names() {
|
||||
if strings.HasPrefix(declName, "VersionTLS") {
|
||||
discoveredVersions[declName] = true
|
||||
}
|
||||
if strings.HasPrefix(declName, "TLS_RSA_") || strings.HasPrefix(declName, "TLS_ECDHE_") {
|
||||
discoveredCiphers[declName] = true
|
||||
}
|
||||
@@ -97,4 +101,14 @@ func TestConstantMaps(t *testing.T) {
|
||||
t.Errorf("ciphers map has %s not in tls package", k)
|
||||
}
|
||||
}
|
||||
for k := range discoveredVersions {
|
||||
if _, ok := versions[k]; !ok {
|
||||
t.Errorf("discovered version tls.%s not in version map", k)
|
||||
}
|
||||
}
|
||||
for k := range versions {
|
||||
if _, ok := discoveredVersions[k]; !ok {
|
||||
t.Errorf("versions map has %s not in tls package", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user