/
242388.go
59 lines (45 loc) · 1.72 KB
/
242388.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"
"sigs.k8s.io/controller-runtime/pkg/client"
kubeutils "github.com/gardener/diki/pkg/kubernetes/utils"
"github.com/gardener/diki/pkg/rule"
)
var _ rule.Rule = &Rule242388{}
type Rule242388 struct {
Client client.Client
Namespace string
DeploymentName string
ContainerName string
}
func (r *Rule242388) ID() string {
return ID242388
}
func (r *Rule242388) Name() string {
return "The Kubernetes API server must have the insecure bind address not set (HIGH 242388)"
}
func (r *Rule242388) Run(ctx context.Context) (rule.RuleResult, error) {
const optName = "insecure-bind-address"
deploymentName := "kube-apiserver"
containerName := "kube-apiserver"
if r.DeploymentName != "" {
deploymentName = r.DeploymentName
}
if r.ContainerName != "" {
containerName = r.ContainerName
}
target := rule.NewTarget("kind", "deployment", "name", deploymentName, "namespace", r.Namespace)
insecureBindAddressOptionSlice, err := kubeutils.GetCommandOptionFromDeployment(ctx, r.Client, deploymentName, containerName, r.Namespace, optName)
if err != nil {
return rule.SingleCheckResult(r, rule.ErroredCheckResult(err.Error(), target)), nil
}
if len(insecureBindAddressOptionSlice) == 0 {
return rule.SingleCheckResult(r, rule.PassedCheckResult(fmt.Sprintf("Option %s not set.", optName), target)), nil
}
// insecure-bind-address is deprecated but still needed for health checks. ref https://github.com/kubernetes/kubernetes/issues/43784
return rule.SingleCheckResult(r, rule.FailedCheckResult(fmt.Sprintf("Option %s set.", optName), target)), nil
}