Skip to content

Commit

Permalink
add arguments to improve cis compliance and adjust tests accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
eaudetcobello committed Jun 13, 2024
1 parent ee01731 commit cb905cb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/k8s/pkg/k8sd/setup/kube_apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func KubeAPIServer(snap snap.Snap, serviceCIDR string, authWebhookURL string, en
defer authTokenWebhookFile.Close()

args := map[string]string{
"--anonymous-auth": "false",
"--allow-privileged": "true",
"--authentication-token-webhook-config-file": authTokenWebhookConfigFile,
"--authorization-mode": authorizationMode,
Expand All @@ -73,6 +74,8 @@ func KubeAPIServer(snap snap.Snap, serviceCIDR string, authWebhookURL string, en
"--kubelet-client-certificate": path.Join(snap.KubernetesPKIDir(), "apiserver-kubelet-client.crt"),
"--kubelet-client-key": path.Join(snap.KubernetesPKIDir(), "apiserver-kubelet-client.key"),
"--kubelet-preferred-address-types": "InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP",
"--profiling": "false",
"--request-timeout": "300s",
"--secure-port": "6443",
"--service-account-issuer": "https://kubernetes.default.svc",
"--service-account-key-file": path.Join(snap.KubernetesPKIDir(), "serviceaccount.key"),
Expand Down
9 changes: 9 additions & 0 deletions src/k8s/pkg/k8sd/setup/kube_apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestKubeAPIServer(t *testing.T) {
key string
expectedVal string
}{
{key: "--anonymous-auth", expectedVal: "false"},
{key: "--allow-privileged", expectedVal: "true"},
{key: "--authentication-token-webhook-config-file", expectedVal: path.Join(s.Mock.ServiceExtraConfigDir, "auth-token-webhook.conf")},
{key: "--authorization-mode", expectedVal: "Node,RBAC"},
Expand All @@ -52,6 +53,7 @@ func TestKubeAPIServer(t *testing.T) {
{key: "--kubelet-client-certificate", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "apiserver-kubelet-client.crt")},
{key: "--kubelet-client-key", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "apiserver-kubelet-client.key")},
{key: "--kubelet-preferred-address-types", expectedVal: "InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP"},
{key: "--profiling", expectedVal: "false"},
{key: "--secure-port", expectedVal: "6443"},
{key: "--service-account-issuer", expectedVal: "https://kubernetes.default.svc"},
{key: "--service-account-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "serviceaccount.key")},
Expand All @@ -61,6 +63,7 @@ func TestKubeAPIServer(t *testing.T) {
{key: "--tls-cipher-suites", expectedVal: apiserverTLSCipherSuites},
{key: "--tls-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "apiserver.key")},
{key: "--etcd-servers", expectedVal: fmt.Sprintf("unix://%s", path.Join(s.Mock.K8sDqliteStateDir, "k8s-dqlite.sock"))},
{key: "--request-timeout", expectedVal: "300s"},
{key: "--requestheader-client-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "front-proxy-ca.crt")},
{key: "--requestheader-allowed-names", expectedVal: "front-proxy-client"},
{key: "--requestheader-extra-headers-prefix", expectedVal: "X-Remote-Extra-"},
Expand Down Expand Up @@ -98,6 +101,7 @@ func TestKubeAPIServer(t *testing.T) {
key string
expectedVal string
}{
{key: "--anonymous-auth", expectedVal: "false"},
{key: "--allow-privileged", expectedVal: "true"},
{key: "--authentication-token-webhook-config-file", expectedVal: path.Join(s.Mock.ServiceExtraConfigDir, "auth-token-webhook.conf")},
{key: "--authorization-mode", expectedVal: "Node,RBAC"},
Expand All @@ -107,6 +111,8 @@ func TestKubeAPIServer(t *testing.T) {
{key: "--kubelet-client-certificate", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "apiserver-kubelet-client.crt")},
{key: "--kubelet-client-key", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "apiserver-kubelet-client.key")},
{key: "--kubelet-preferred-address-types", expectedVal: "InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP"},
{key: "--profiling", expectedVal: "false"},
{key: "--request-timeout", expectedVal: "300s"},
{key: "--secure-port", expectedVal: "6443"},
{key: "--service-account-issuer", expectedVal: "https://kubernetes.default.svc"},
{key: "--service-account-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "serviceaccount.key")},
Expand Down Expand Up @@ -151,6 +157,7 @@ func TestKubeAPIServer(t *testing.T) {
key string
expectedVal string
}{
{key: "--anonymous-auth", expectedVal: "false"},
{key: "--authentication-token-webhook-config-file", expectedVal: path.Join(s.Mock.ServiceExtraConfigDir, "auth-token-webhook.conf")},
{key: "--authorization-mode", expectedVal: "Node,RBAC"},
{key: "--client-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "client-ca.crt")},
Expand All @@ -159,6 +166,7 @@ func TestKubeAPIServer(t *testing.T) {
{key: "--kubelet-client-certificate", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "apiserver-kubelet-client.crt")},
{key: "--kubelet-client-key", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "apiserver-kubelet-client.key")},
{key: "--kubelet-preferred-address-types", expectedVal: "InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP"},
{key: "--profiling", expectedVal: "false"},
{key: "--secure-port", expectedVal: "1337"},
{key: "--service-account-issuer", expectedVal: "https://kubernetes.default.svc"},
{key: "--service-account-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "serviceaccount.key")},
Expand All @@ -168,6 +176,7 @@ func TestKubeAPIServer(t *testing.T) {
{key: "--tls-cipher-suites", expectedVal: apiserverTLSCipherSuites},
{key: "--tls-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "apiserver.key")},
{key: "--etcd-servers", expectedVal: fmt.Sprintf("unix://%s", path.Join(s.Mock.K8sDqliteStateDir, "k8s-dqlite.sock"))},
{key: "--request-timeout", expectedVal: "300s"},
{key: "--requestheader-client-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "front-proxy-ca.crt")},
{key: "--requestheader-allowed-names", expectedVal: "front-proxy-client"},
{key: "--requestheader-extra-headers-prefix", expectedVal: "X-Remote-Extra-"},
Expand Down
1 change: 1 addition & 0 deletions src/k8s/pkg/k8sd/setup/kube_controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func KubeControllerManager(snap snap.Snap, extraArgs map[string]*string) error {
"--profiling": "false",
"--root-ca-file": path.Join(snap.KubernetesPKIDir(), "ca.crt"),
"--service-account-private-key-file": path.Join(snap.KubernetesPKIDir(), "serviceaccount.key"),
"--terminated-pod-gc-threshold": "12500",
"--use-service-account-credentials": "true",
}
// enable cluster-signing if certificates are available
Expand Down
3 changes: 3 additions & 0 deletions src/k8s/pkg/k8sd/setup/kube_controller_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestKubeControllerManager(t *testing.T) {
{key: "--profiling", expectedVal: "false"},
{key: "--root-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "ca.crt")},
{key: "--service-account-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "serviceaccount.key")},
{key: "--terminated-pod-gc-threshold", expectedVal: "12500"},
{key: "--use-service-account-credentials", expectedVal: "true"},
{key: "--cluster-signing-cert-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "ca.crt")},
{key: "--cluster-signing-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "ca.key")},
Expand Down Expand Up @@ -93,6 +94,7 @@ func TestKubeControllerManager(t *testing.T) {
{key: "--profiling", expectedVal: "false"},
{key: "--root-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "ca.crt")},
{key: "--service-account-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "serviceaccount.key")},
{key: "--terminated-pod-gc-threshold", expectedVal: "12500"},
{key: "--use-service-account-credentials", expectedVal: "true"},
}
for _, tc := range tests {
Expand Down Expand Up @@ -145,6 +147,7 @@ func TestKubeControllerManager(t *testing.T) {
{key: "--profiling", expectedVal: "true"},
{key: "--root-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "ca.crt")},
{key: "--service-account-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "serviceaccount.key")},
{key: "--terminated-pod-gc-threshold", expectedVal: "12500"},
{key: "--use-service-account-credentials", expectedVal: "true"},
{key: "--cluster-signing-cert-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "ca.crt")},
{key: "--cluster-signing-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "ca.key")},
Expand Down
4 changes: 3 additions & 1 deletion src/k8s/pkg/k8sd/setup/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func KubeletWorker(snap snap.Snap, hostname string, nodeIP net.IP, clusterDNS st
// kubelet configures kubelet on the local node.
func kubelet(snap snap.Snap, hostname string, nodeIP net.IP, clusterDNS string, clusterDomain string, cloudProvider string, taints []string, labels []string, extraArgs map[string]*string) error {
args := map[string]string{
"--authorization-mode": "Webhook",
"--anonymous-auth": "false",
"--authentication-token-webhook": "true",
"--cert-dir": snap.KubernetesPKIDir(),
"--client-ca-file": path.Join(snap.KubernetesPKIDir(), "client-ca.crt"),
"--container-runtime-endpoint": path.Join(snap.ContainerdSocketDir(), "containerd.sock"),
"--containerd": path.Join(snap.ContainerdSocketDir(), "containerd.sock"),
Expand All @@ -59,6 +59,8 @@ func kubelet(snap snap.Snap, hostname string, nodeIP net.IP, clusterDNS string,
"--root-dir": snap.KubeletRootDir(),
"--serialize-image-pulls": "false",
"--tls-cipher-suites": strings.Join(kubeletTLSCipherSuites, ","),
"--tls-cert-file": path.Join(snap.KubernetesPKIDir(), "kubelet.crt"),
"--tls-private-key-file": path.Join(snap.KubernetesPKIDir(), "kubelet.key"),
}
if cloudProvider != "" {
args["--cloud-provider"] = cloudProvider
Expand Down
24 changes: 18 additions & 6 deletions src/k8s/pkg/k8sd/setup/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func TestKubelet(t *testing.T) {
key string
expectedVal string
}{
{key: "--authorization-mode", expectedVal: "Webhook"},
{key: "--anonymous-auth", expectedVal: "false"},
{key: "--authentication-token-webhook", expectedVal: "true"},
{key: "--cert-dir", expectedVal: s.Mock.KubernetesPKIDir},
{key: "--client-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "client-ca.crt")},
{key: "--container-runtime-endpoint", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
{key: "--containerd", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
Expand All @@ -69,6 +69,8 @@ func TestKubelet(t *testing.T) {
{key: "--root-dir", expectedVal: s.Mock.KubeletRootDir},
{key: "--serialize-image-pulls", expectedVal: "false"},
{key: "--tls-cipher-suites", expectedVal: kubeletTLSCipherSuites},
{key: "--tls-cert-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.crt")},
{key: "--tls-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.key")},
{key: "--cluster-dns", expectedVal: "10.152.1.1"},
{key: "--cloud-provider", expectedVal: "provider"},
{key: "--cluster-domain", expectedVal: "test-cluster.local"},
Expand Down Expand Up @@ -108,9 +110,9 @@ func TestKubelet(t *testing.T) {
key string
expectedVal string
}{
{key: "--authorization-mode", expectedVal: "Webhook"},
{key: "--anonymous-auth", expectedVal: "false"},
{key: "--authentication-token-webhook", expectedVal: "true"},
{key: "--cert-dir", expectedVal: s.Mock.KubernetesPKIDir},
{key: "--client-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "client-ca.crt")},
{key: "--container-runtime-endpoint", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
{key: "--containerd", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
Expand All @@ -124,6 +126,8 @@ func TestKubelet(t *testing.T) {
{key: "--root-dir", expectedVal: s.Mock.KubeletRootDir},
{key: "--serialize-image-pulls", expectedVal: "false"},
{key: "--tls-cipher-suites", expectedVal: kubeletTLSCipherSuites},
{key: "--tls-cert-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.crt")},
{key: "--tls-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.key")},
{key: "--cluster-dns", expectedVal: "10.152.1.1"},
// Overwritten by extraArgs
{key: "--cluster-domain", expectedVal: "override.local"},
Expand Down Expand Up @@ -163,9 +167,9 @@ func TestKubelet(t *testing.T) {
key string
expectedVal string
}{
{key: "--authorization-mode", expectedVal: "Webhook"},
{key: "--anonymous-auth", expectedVal: "false"},
{key: "--authentication-token-webhook", expectedVal: "true"},
{key: "--cert-dir", expectedVal: s.Mock.KubernetesPKIDir},
{key: "--client-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "client-ca.crt")},
{key: "--container-runtime-endpoint", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
{key: "--containerd", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
Expand All @@ -179,6 +183,8 @@ func TestKubelet(t *testing.T) {
{key: "--root-dir", expectedVal: s.Mock.KubeletRootDir},
{key: "--serialize-image-pulls", expectedVal: "false"},
{key: "--tls-cipher-suites", expectedVal: kubeletTLSCipherSuites},
{key: "--tls-cert-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.crt")},
{key: "--tls-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.key")},
}
for _, tc := range tests {
t.Run(tc.key, func(t *testing.T) {
Expand Down Expand Up @@ -209,9 +215,9 @@ func TestKubelet(t *testing.T) {
key string
expectedVal string
}{
{key: "--authorization-mode", expectedVal: "Webhook"},
{key: "--anonymous-auth", expectedVal: "false"},
{key: "--authentication-token-webhook", expectedVal: "true"},
{key: "--cert-dir", expectedVal: s.Mock.KubernetesPKIDir},
{key: "--client-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "client-ca.crt")},
{key: "--container-runtime-endpoint", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
{key: "--containerd", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
Expand All @@ -225,6 +231,8 @@ func TestKubelet(t *testing.T) {
{key: "--root-dir", expectedVal: s.Mock.KubeletRootDir},
{key: "--serialize-image-pulls", expectedVal: "false"},
{key: "--tls-cipher-suites", expectedVal: kubeletTLSCipherSuites},
{key: "--tls-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.key")},
{key: "--tls-cert-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.crt")},
{key: "--cloud-provider", expectedVal: "provider"},
{key: "--cluster-dns", expectedVal: "10.152.1.1"},
{key: "--cluster-domain", expectedVal: "test-cluster.local"},
Expand Down Expand Up @@ -264,9 +272,9 @@ func TestKubelet(t *testing.T) {
key string
expectedVal string
}{
{key: "--authorization-mode", expectedVal: "Webhook"},
{key: "--anonymous-auth", expectedVal: "false"},
{key: "--authentication-token-webhook", expectedVal: "true"},
{key: "--cert-dir", expectedVal: s.Mock.KubernetesPKIDir},
{key: "--client-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "client-ca.crt")},
{key: "--container-runtime-endpoint", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
{key: "--containerd", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
Expand All @@ -280,6 +288,8 @@ func TestKubelet(t *testing.T) {
{key: "--root-dir", expectedVal: s.Mock.KubeletRootDir},
{key: "--serialize-image-pulls", expectedVal: "false"},
{key: "--tls-cipher-suites", expectedVal: kubeletTLSCipherSuites},
{key: "--tls-cert-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.crt")},
{key: "--tls-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.key")},
{key: "--cluster-dns", expectedVal: "10.152.1.1"},
{key: "--cluster-domain", expectedVal: "override.local"},
{key: "--node-ip", expectedVal: "192.168.0.1"},
Expand Down Expand Up @@ -318,9 +328,9 @@ func TestKubelet(t *testing.T) {
key string
expectedVal string
}{
{key: "--authorization-mode", expectedVal: "Webhook"},
{key: "--anonymous-auth", expectedVal: "false"},
{key: "--authentication-token-webhook", expectedVal: "true"},
{key: "--cert-dir", expectedVal: s.Mock.KubernetesPKIDir},
{key: "--client-ca-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "client-ca.crt")},
{key: "--container-runtime-endpoint", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
{key: "--containerd", expectedVal: path.Join(s.Mock.ContainerdSocketDir, "containerd.sock")},
Expand All @@ -334,6 +344,8 @@ func TestKubelet(t *testing.T) {
{key: "--root-dir", expectedVal: s.Mock.KubeletRootDir},
{key: "--serialize-image-pulls", expectedVal: "false"},
{key: "--tls-cipher-suites", expectedVal: kubeletTLSCipherSuites},
{key: "--tls-cert-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.crt")},
{key: "--tls-private-key-file", expectedVal: path.Join(s.Mock.KubernetesPKIDir, "kubelet.key")},
}
for _, tc := range tests {
t.Run(tc.key, func(t *testing.T) {
Expand Down

0 comments on commit cb905cb

Please sign in to comment.