Skip to content

Commit 5713c6e

Browse files
committed
feat: Fix up Kubelet file permissions
As per CIS benchmarks 4.1.1 and 4.1.9.
1 parent 733f3a6 commit 5713c6e

File tree

8 files changed

+65
-0
lines changed

8 files changed

+65
-0
lines changed

charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses/aws-cluster-class.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ spec:
103103
kubeletExtraArgs:
104104
cloud-provider: external
105105
name: '{{ ds.meta_data.local_hostname }}'
106+
postKubeadmCommands:
107+
- chmod 600 "$(systemctl show -P FragmentPath kubelet.service)"
108+
- chmod 600 /var/lib/kubelet/config.yaml
106109
---
107110
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
108111
kind: AWSMachineTemplate
@@ -142,3 +145,6 @@ spec:
142145
kubeletExtraArgs:
143146
cloud-provider: external
144147
name: '{{ ds.meta_data.local_hostname }}'
148+
postKubeadmCommands:
149+
- chmod 600 "$(systemctl show -P FragmentPath kubelet.service)"
150+
- chmod 600 /var/lib/kubelet/config.yaml

charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses/docker-cluster-class.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ spec:
9494
nodeRegistration: {}
9595
joinConfiguration:
9696
nodeRegistration: {}
97+
postKubeadmCommands:
98+
- chmod 600 "$(systemctl show -P FragmentPath kubelet.service)"
99+
- chmod 600 /var/lib/kubelet/config.yaml
97100
---
98101
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
99102
kind: DockerMachineTemplate
@@ -132,3 +135,6 @@ spec:
132135
spec:
133136
joinConfiguration:
134137
nodeRegistration: {}
138+
postKubeadmCommands:
139+
- chmod 600 "$(systemctl show -P FragmentPath kubelet.service)"
140+
- chmod 600 /var/lib/kubelet/config.yaml

charts/cluster-api-runtime-extensions-nutanix/defaultclusterclasses/nutanix-cluster-class.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ spec:
1515
tls-cipher-suites: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
1616
postKubeadmCommands:
1717
- echo "after kubeadm call" > /var/log/postkubeadm.log
18+
- chmod 600 "$(systemctl show -P FragmentPath kubelet.service)"
19+
- chmod 600 /var/lib/kubelet/config.yaml
1820
preKubeadmCommands:
1921
- echo "before kubeadm call" > /var/log/prekubeadm.log
2022
- hostnamectl set-hostname "{{ ds.meta_data.hostname }}"
@@ -223,6 +225,9 @@ spec:
223225
- echo "127.0.0.1 {{ ds.meta_data.hostname }}" >> /etc/hosts
224226
useExperimentalRetryJoin: true
225227
verbosity: 10
228+
postKubeadmCommands:
229+
- chmod 600 "$(systemctl show -P FragmentPath kubelet.service)"
230+
- chmod 600 /var/lib/kubelet/config.yaml
226231
---
227232
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
228233
kind: NutanixClusterTemplate

hack/examples/overlays/clusterclasses/aws/kustomization.yaml.tmpl

+12
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,16 @@ patches:
6969
- target:
7070
kind: KubeadmControlPlaneTemplate
7171
path: ../../../patches/disable-kubeadmcontrolplane-profiling.yaml
72+
- target:
73+
kind: KubeadmControlPlaneTemplate
74+
path: ../../../patches/initialize-postkubeadmcommands.yaml
75+
- target:
76+
kind: KubeadmControlPlaneTemplate
77+
path: ../../../patches/kubelet-file-permissions.yaml
78+
- target:
79+
kind: KubeadmConfigTemplate
80+
path: ../../../patches/initialize-postkubeadmcommands.yaml
81+
- target:
82+
kind: KubeadmConfigTemplate
83+
path: ../../../patches/kubelet-file-permissions.yaml
7284
# END CIS patches

hack/examples/overlays/clusterclasses/docker/kustomization.yaml.tmpl

+12
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,16 @@ patches:
3030
- target:
3131
kind: KubeadmControlPlaneTemplate
3232
path: ../../../patches/disable-kubeadmcontrolplane-profiling.yaml
33+
- target:
34+
kind: KubeadmControlPlaneTemplate
35+
path: ../../../patches/initialize-postkubeadmcommands.yaml
36+
- target:
37+
kind: KubeadmControlPlaneTemplate
38+
path: ../../../patches/kubelet-file-permissions.yaml
39+
- target:
40+
kind: KubeadmConfigTemplate
41+
path: ../../../patches/initialize-postkubeadmcommands.yaml
42+
- target:
43+
kind: KubeadmConfigTemplate
44+
path: ../../../patches/kubelet-file-permissions.yaml
3345
# END CIS patches

hack/examples/overlays/clusterclasses/nutanix/kustomization.yaml.tmpl

+9
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ patches:
3030
- target:
3131
kind: KubeadmControlPlaneTemplate
3232
path: ../../../patches/disable-kubeadmcontrolplane-profiling.yaml
33+
- target:
34+
kind: KubeadmControlPlaneTemplate
35+
path: ../../../patches/initialize-postkubeadmcommands.yaml
36+
- target:
37+
kind: KubeadmControlPlaneTemplate
38+
path: ../../../patches/kubelet-file-permissions.yaml
39+
- target:
40+
kind: KubeadmConfigTemplate
41+
path: ../../../patches/kubelet-file-permissions.yaml
3342
# END CIS patches
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright 2025 Nutanix. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
- op: add
5+
path: /spec/template/spec/postKubeadmCommands
6+
value: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2025 Nutanix. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
- op: add
5+
path: /spec/template/spec/postKubeadmCommands/-
6+
value: chmod 600 "$(systemctl show -P FragmentPath kubelet.service)"
7+
- op: add
8+
path: /spec/template/spec/postKubeadmCommands/-
9+
value: chmod 600 /var/lib/kubelet/config.yaml

0 commit comments

Comments
 (0)