Skip to content

feat: Secure ciphers, min TLS v1.2, and disable auto TLS for etcd #808

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
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions pkg/handlers/generic/mutation/etcd/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package etcd

import (
"context"
"crypto/tls"
"strings"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -45,6 +47,21 @@ func newEtcdPatchHandler(
}
}

var defaultEtcdExtraArgs = map[string]string{
"auto-tls": "false",
"peer-auto-tls": "false",
"cipher-suites": strings.Join(
[]string{
tls.CipherSuiteName(tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256),
tls.CipherSuiteName(tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
tls.CipherSuiteName(tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384),
tls.CipherSuiteName(tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384),
},
",",
),
"tls-min-version": "TLS1.2",
}

func (h *etcdPatchHandler) Mutate(
ctx context.Context,
obj *unstructured.Unstructured,
Expand All @@ -62,11 +79,7 @@ func (h *etcdPatchHandler) Mutate(
h.variableName,
h.variableFieldPath...,
)
if err != nil {
if variables.IsNotFoundError(err) {
log.V(5).Info("etcd variable not defined")
return nil
}
if err != nil && !variables.IsNotFoundError(err) {
return err
}

Expand Down Expand Up @@ -95,10 +108,25 @@ func (h *etcdPatchHandler) Mutate(
}

localEtcd := obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.Local
if etcd.Image != nil && etcd.Image.Tag != "" {

if localEtcd.ExtraArgs == nil {
localEtcd.ExtraArgs = make(map[string]string, len(defaultEtcdExtraArgs))
}

for k, v := range defaultEtcdExtraArgs {
if _, ok := localEtcd.ExtraArgs[k]; !ok {
localEtcd.ExtraArgs[k] = v
}
}

if etcd.Image == nil {
return nil
}

if etcd.Image.Tag != "" {
localEtcd.ImageTag = etcd.Image.Tag
}
if etcd.Image != nil && etcd.Image.Repository != "" {
if etcd.Image.Repository != "" {
localEtcd.ImageRepository = etcd.Image.Repository
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/handlers/generic/mutation/etcd/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ var _ = Describe("Generate etcd patches", func() {
"local": map[string]interface{}{
"imageRepository": "my-registry.io/my-org/my-repo",
"imageTag": "v3.5.99_custom.0",
"extraArgs": map[string]interface{}{
"auto-tls": "false",
"peer-auto-tls": "false",
"cipher-suites": "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", //nolint:lll // Long list of ciphers ok in test.
"tls-min-version": "TLS1.2",
},
},
},
),
Expand Down Expand Up @@ -85,6 +91,12 @@ var _ = Describe("Generate etcd patches", func() {
map[string]interface{}{
"local": map[string]interface{}{
"imageRepository": "my-registry.io/my-org/my-repo",
"extraArgs": map[string]interface{}{
"auto-tls": "false",
"peer-auto-tls": "false",
"cipher-suites": "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", //nolint:lll // Long list of ciphers ok in test.
"tls-min-version": "TLS1.2",
},
},
},
),
Expand Down Expand Up @@ -114,6 +126,12 @@ var _ = Describe("Generate etcd patches", func() {
map[string]interface{}{
"local": map[string]interface{}{
"imageTag": "v3.5.99_custom.0",
"extraArgs": map[string]interface{}{
"auto-tls": "false",
"peer-auto-tls": "false",
"cipher-suites": "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", //nolint:lll // Long list of ciphers ok in test.
"tls-min-version": "TLS1.2",
},
},
},
),
Expand Down
Loading