/
242377.go
59 lines (48 loc) · 2 KB
/
242377.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package v1r11
import (
"context"
"fmt"
"log/slog"
"slices"
"sigs.k8s.io/controller-runtime/pkg/client"
kubeutils "github.com/gardener/diki/pkg/kubernetes/utils"
"github.com/gardener/diki/pkg/rule"
sharedv1r11 "github.com/gardener/diki/pkg/shared/ruleset/disak8sstig/v1r11"
)
var _ rule.Rule = &Rule242377{}
type Rule242377 struct {
Client client.Client
Namespace string
Logger *slog.Logger
}
func (r *Rule242377) ID() string {
return sharedv1r11.ID242377
}
func (r *Rule242377) Name() string {
return "Kubernetes Scheduler must use TLS 1.2, at a minimum, to protect the confidentiality of sensitive data during electronic dissemination (MEDIUM 242377)"
}
func (r *Rule242377) Run(ctx context.Context) (rule.RuleResult, error) {
const (
ksName = "kube-scheduler"
option = "tls-min-version"
)
target := rule.NewTarget("cluster", "seed", "name", ksName, "namespace", r.Namespace, "kind", "deployment")
optSlice, err := kubeutils.GetCommandOptionFromDeployment(ctx, r.Client, ksName, ksName, r.Namespace, option)
if err != nil {
return rule.SingleCheckResult(r, rule.ErroredCheckResult(err.Error(), target)), nil
}
// empty options are allowed because min version defaults to TLS 1.2
switch {
case len(optSlice) == 0:
return rule.SingleCheckResult(r, rule.PassedCheckResult(fmt.Sprintf("Option %s has not been set.", option), target)), nil
case len(optSlice) > 1:
return rule.SingleCheckResult(r, rule.WarningCheckResult(fmt.Sprintf("Option %s has been set more than once in container command.", option), target)), nil
case slices.Contains([]string{"VersionTLS10", "VersionTLS11"}, optSlice[0]):
return rule.SingleCheckResult(r, rule.FailedCheckResult(fmt.Sprintf("Option %s set to not allowed value.", option), target)), nil
default:
return rule.SingleCheckResult(r, rule.PassedCheckResult(fmt.Sprintf("Option %s set to allowed value.", option), target)), nil
}
}