Skip to content

Commit d51805f

Browse files
authored
feat: Secure ciphers, min TLS v1.2, and disable auto TLS for etcd (#808)
This increases ootb security and provides STIG compliance for this area at least. Fixes #806.
1 parent 4a5e1a8 commit d51805f

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

pkg/handlers/generic/mutation/etcd/inject.go

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package etcd
55

66
import (
77
"context"
8+
"crypto/tls"
9+
"strings"
810

911
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1012
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -45,6 +47,25 @@ func newEtcdPatchHandler(
4547
}
4648
}
4749

50+
// defaultEtcdExtraArgs holds secure default flags for etcd. These flags are
51+
// set in order to satisfy both STIG and FIPS requirements by explicitly disabling certain
52+
// insecure features (e.g. `auto-tls`), setting a required minimum TLS version to v1.2,
53+
// and setting a list of secure cipher suites that satisfy both FIPS and non-FIPS scenarios.
54+
var defaultEtcdExtraArgs = map[string]string{
55+
"auto-tls": "false",
56+
"peer-auto-tls": "false",
57+
"cipher-suites": strings.Join(
58+
[]string{
59+
tls.CipherSuiteName(tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256),
60+
tls.CipherSuiteName(tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
61+
tls.CipherSuiteName(tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384),
62+
tls.CipherSuiteName(tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384),
63+
},
64+
",",
65+
),
66+
"tls-min-version": "TLS1.2",
67+
}
68+
4869
func (h *etcdPatchHandler) Mutate(
4970
ctx context.Context,
5071
obj *unstructured.Unstructured,
@@ -62,11 +83,7 @@ func (h *etcdPatchHandler) Mutate(
6283
h.variableName,
6384
h.variableFieldPath...,
6485
)
65-
if err != nil {
66-
if variables.IsNotFoundError(err) {
67-
log.V(5).Info("etcd variable not defined")
68-
return nil
69-
}
86+
if err != nil && !variables.IsNotFoundError(err) {
7087
return err
7188
}
7289

@@ -95,10 +112,25 @@ func (h *etcdPatchHandler) Mutate(
95112
}
96113

97114
localEtcd := obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.Local
98-
if etcd.Image != nil && etcd.Image.Tag != "" {
115+
116+
if localEtcd.ExtraArgs == nil {
117+
localEtcd.ExtraArgs = make(map[string]string, len(defaultEtcdExtraArgs))
118+
}
119+
120+
for k, v := range defaultEtcdExtraArgs {
121+
if _, ok := localEtcd.ExtraArgs[k]; !ok {
122+
localEtcd.ExtraArgs[k] = v
123+
}
124+
}
125+
126+
if etcd.Image == nil {
127+
return nil
128+
}
129+
130+
if etcd.Image.Tag != "" {
99131
localEtcd.ImageTag = etcd.Image.Tag
100132
}
101-
if etcd.Image != nil && etcd.Image.Repository != "" {
133+
if etcd.Image.Repository != "" {
102134
localEtcd.ImageRepository = etcd.Image.Repository
103135
}
104136

pkg/handlers/generic/mutation/etcd/inject_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ func TestEtcdPolicyPatch(t *testing.T) {
2222
RunSpecs(t, "etcd mutator suite")
2323
}
2424

25+
// tlsExtraArgs holds the final set of extraArgs that should be set in the etcd for a default configuration.
26+
// See inject.go for the reasoning behind these values.
27+
var tlsExtraArgs = map[string]interface{}{
28+
"auto-tls": "false",
29+
"peer-auto-tls": "false",
30+
"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.
31+
"tls-min-version": "TLS1.2",
32+
}
33+
2534
var _ = Describe("Generate etcd patches", func() {
2635
patchGenerator := func() mutation.GeneratePatches {
2736
return mutation.NewMetaGeneratePatchesHandler("", helpers.TestEnv.Client, NewPatch()).(mutation.GeneratePatches)
@@ -56,6 +65,7 @@ var _ = Describe("Generate etcd patches", func() {
5665
"local": map[string]interface{}{
5766
"imageRepository": "my-registry.io/my-org/my-repo",
5867
"imageTag": "v3.5.99_custom.0",
68+
"extraArgs": tlsExtraArgs,
5969
},
6070
},
6171
),
@@ -85,6 +95,7 @@ var _ = Describe("Generate etcd patches", func() {
8595
map[string]interface{}{
8696
"local": map[string]interface{}{
8797
"imageRepository": "my-registry.io/my-org/my-repo",
98+
"extraArgs": tlsExtraArgs,
8899
},
89100
},
90101
),
@@ -113,7 +124,8 @@ var _ = Describe("Generate etcd patches", func() {
113124
"etcd",
114125
map[string]interface{}{
115126
"local": map[string]interface{}{
116-
"imageTag": "v3.5.99_custom.0",
127+
"imageTag": "v3.5.99_custom.0",
128+
"extraArgs": tlsExtraArgs,
117129
},
118130
},
119131
),

0 commit comments

Comments
 (0)