3.1.4 Ensure that the kubelet configuration file ownership is set to root:root (Automated)
Profile Applicability
- Level 1
Description
Ensure that if the kubelet configuration file exists, it is owned by root:root.
Rationale
The kubelet reads various parameters, including security settings, from a config file specified by the --config argument. If this file is specified you should restrict its file permissions to maintain the integrity of the file. The file should be owned by root:root.
Impact
Overly permissive file access increases the security risk to the platform.
Audit
Using Google Cloud Console
- Go to Kubernetes Engine by visiting https://console.cloud.google.com/kubernetes/list
- Click on the desired cluster to open the Details page, then click on the desired Node pool to open the Node pool Details page
- Note the name of the desired node
- Go to VM Instances by visiting https://console.cloud.google.com/compute/instances
- Find the desired node and click on 'SSH' to open an SSH connection to the node.
Using Command Line
Method 1
First, SSH to the relevant worker node. To check to see if the kubelet service is running:
sudo systemctl status kubelet
The output should return Active: active (running) since...
Run the following command on each node to find the appropriate kubelet config file:
ps -ef | grep kubelet
The output of the above command should return something similar to --config /etc/kubernetes/kubelet/kubelet-config.yaml which is the location of the kubelet config file.
Run the following command:
stat -c %U:%G /etc/kubernetes/kubelet/kubelet-config.yaml
The output of the above command is the kubelet config file's ownership. Verify that the ownership is set to root:root.
Method 2
Create and Run a Privileged Pod.
You will need to run a pod that is privileged enough to access the host's file system. This can be achieved by deploying a pod that uses the hostPath volume to mount the node's file system into the pod.
Here's an example of a simple pod definition that mounts the root of the host to /host within the pod:
apiVersion: v1
kind: Pod
metadata:
name: file-check
spec:
volumes:
- name: host-root
hostPath:
path: /
type: Directory
containers:
- name: nsenter
image: busybox
command: ["sleep", "3600"]
volumeMounts:
- name: host-root
mountPath: /host
securityContext:
privileged: true
Save this to a file (e.g., file-check-pod.yaml) and create the pod:
kubectl apply -f file-check-pod.yaml
Once the pod is running, you can exec into it to check file ownership on the node:
kubectl exec -it file-check -- sh
Now you are in a shell inside the pod, but you can access the node's file system through the /host directory and check the ownership of the file:
ls -l /host/etc/kubernetes/kubelet/kubelet-config.yaml
The output of the above command gives you the file's ownership. Verify that the ownership is set to root:root.
Remediation
Run the following command (using the config file location identified in the Audit step):
chown root:root <kubelet_config_file>
Default Value
The default file ownership is root:root.
References
- https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/
- https://cloud.google.com/kubernetes-engine/docs/concepts/cis-benchmarks
CIS Controls
| Controls Version | Control | IG 1 | IG 2 | IG 3 |
|---|---|---|---|---|
| v8 | 3.3 Configure Data Access Control Lists - Configure data access control lists based on a user's need to know. Apply data access control lists, also known as access permissions, to local and remote file systems, databases, and applications. | X | X | X |
| v7 | 5.2 Maintain Secure Images - Maintain secure images or templates for all systems in the enterprise based on the organization's approved configuration standards. Any new system deployment or existing system that becomes compromised should be imaged using one of those images or templates. | X | X |