Skip to content

Commit

Permalink
Minor fixes for K3s checks (rancher#232)
Browse files Browse the repository at this point in the history
* Fix check for K3s 4.1.9 and 4.1.10

Signed-off-by: Derek Nola <[email protected]>

* Set correct K3s 1.1.9 and 1.1.10 for each version of scan

Signed-off-by: Derek Nola <[email protected]>

* Spacing nit

Signed-off-by: Derek Nola <[email protected]>

---------

Signed-off-by: Derek Nola <[email protected]>
Co-authored-by: Andy Pitcher <[email protected]>
  • Loading branch information
dereknola and andypitcher authored Aug 9, 2024
1 parent 66f7fd7 commit 3e7e1fe
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 65 deletions.
2 changes: 0 additions & 2 deletions package/cfg/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ node:
- "/etc/kubernetes/kubelet-kubeconfig"
- "/etc/kubernetes/ssl/kubecfg-kube-node.yaml"
- "/var/lib/rancher/rke2/agent/kubelet.kubeconfig"
- "/var/lib/rancher/k3s/server/cred/admin.kubeconfig"
- "/var/lib/rancher/k3s/agent/kubelet.kubeconfig"
confs:
- "/var/lib/kubelet/config.yaml"
Expand All @@ -144,7 +143,6 @@ node:
- "/etc/systemd/system/kubelet.service"
- "/lib/systemd/system/kubelet.service"
- "/etc/systemd/system/snap.kubelet.daemon.service"
- "/var/lib/rancher/rke2/agent/kubelet.kubeconfig"
defaultconf: "/var/lib/kubelet/config.yaml"
defaultsvc: "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
defaultkubeconfig: "/etc/kubernetes/kubelet.conf"
Expand Down
4 changes: 2 additions & 2 deletions package/cfg/k3s-cis-1.23-hardened/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ groups:
test_items:
- flag: root:root
remediation: |
Run the following command (using the config file location identified in the Audit step)
chown root:root $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.2
Expand Down
4 changes: 2 additions & 2 deletions package/cfg/k3s-cis-1.23-permissive/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ groups:
test_items:
- flag: root:root
remediation: |
Run the following command (using the config file location identified in the Audit step)
chown root:root $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.2
Expand Down
12 changes: 5 additions & 7 deletions package/cfg/k3s-cis-1.24-hardened/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ groups:
- id: 1.1.9
text: "Ensure that the Container Network Interface file permissions are set to 600 or more restrictive (Automated)"
audit: find /var/lib/cni/networks -type f ! -name lock 2> /dev/null | xargs --no-run-if-empty stat -c permissions=%a
type: "skip"
use_multiple_values: true
tests:
test_items:
Expand All @@ -127,10 +128,8 @@ groups:
op: bitmask
value: "600"
remediation: |
By default, K3s sets the CNI file permissions to 600.
Note that for many CNIs, a lock file is created with permissions 750. This is expected and can be ignored.
If you modify your CNI configuration, ensure that the permissions are set to 600.
For example, chmod 600 /var/lib/cni/networks/<filename>
Not Applicable.
The default K3s CNI, flannel, does not create any files in /var/lib/cni/networks.
scored: true

- id: 1.1.10
Expand All @@ -144,9 +143,8 @@ groups:
test_items:
- flag: "root:root"
remediation: |
Run the below command (based on the file location on your system) on the control plane node.
For example,
chown root:root <path/to/cni/files>
Not Applicable.
The default K3s CNI, flannel, does not create any files in /var/lib/cni/networks.
scored: false

- id: 1.1.11
Expand Down
9 changes: 5 additions & 4 deletions package/cfg/k3s-cis-1.24-hardened/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ groups:
- id: 4.1.9
text: "If the kubelet config.yaml configuration file is being used validate permissions set to 600 or more restrictive (Automated)"
audit: '/bin/sh -c ''if test -e $kubeletconf; then stat -c permissions=%a $kubeletconf; fi'' '
type: "skip"
tests:
test_items:
- flag: "permissions"
compare:
op: bitmask
value: "600"
remediation: |
Run the following command (using the config file location identified in the Audit step)
chmod 600 $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.1.10
Expand All @@ -146,8 +147,8 @@ groups:
test_items:
- flag: root:root
remediation: |
Run the following command (using the config file location identified in the Audit step)
chown root:root $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.2
Expand Down
15 changes: 7 additions & 8 deletions package/cfg/k3s-cis-1.24-permissive/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ groups:
- id: 1.1.9
text: "Ensure that the Container Network Interface file permissions are set to 600 or more restrictive (Automated)"
audit: find /var/lib/cni/networks -type f ! -name lock 2> /dev/null | xargs --no-run-if-empty stat -c permissions=%a
type: "skip"
use_multiple_values: true
tests:
test_items:
Expand All @@ -127,14 +128,12 @@ groups:
op: bitmask
value: "600"
remediation: |
By default, K3s sets the CNI file permissions to 600.
Note that for many CNIs, a lock file is created with permissions 750. This is expected and can be ignored.
If you modify your CNI configuration, ensure that the permissions are set to 600.
For example, chmod 600 /var/lib/cni/networks/<filename>
Not Applicable.
The default K3s CNI, flannel, does not create any files in /var/lib/cni/networks.
scored: true

- id: 1.1.10
text: "Ensure that the Container Network Interface file ownership is set to root:root (Automated)"
text: "Ensure that the Container Network Interface file ownership is set to root:root (Manual)"
type: "skip"
audit: |
ps -ef | grep $kubeletbin | grep -- --cni-conf-dir | sed 's%.*cni-conf-dir[= ]\([^ ]*\).*%\1%' | xargs -I{} find {} -mindepth 1 | xargs --no-run-if-empty stat -c %U:%G
Expand All @@ -144,11 +143,11 @@ groups:
test_items:
- flag: "root:root"
remediation: |
Run the below command (based on the file location on your system) on the control plane node.
For example,
chown root:root <path/to/cni/files>
Not Applicable.
The default K3s CNI, flannel, does not create any files in /var/lib/cni/networks.
scored: false


- id: 1.1.11
text: "Ensure that the etcd data directory permissions are set to 700 or more restrictive (Automated)"
audit: |
Expand Down
9 changes: 5 additions & 4 deletions package/cfg/k3s-cis-1.24-permissive/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ groups:
- id: 4.1.9
text: "If the kubelet config.yaml configuration file is being used validate permissions set to 600 or more restrictive (Automated)"
audit: '/bin/sh -c ''if test -e $kubeletconf; then stat -c permissions=%a $kubeletconf; fi'' '
type: "skip"
tests:
test_items:
- flag: "permissions"
compare:
op: bitmask
value: "600"
remediation: |
Run the following command (using the config file location identified in the Audit step)
chmod 600 $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.1.10
Expand All @@ -146,8 +147,8 @@ groups:
test_items:
- flag: root:root
remediation: |
Run the following command (using the config file location identified in the Audit step)
chown root:root $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.2
Expand Down
16 changes: 6 additions & 10 deletions package/cfg/k3s-cis-1.7-hardened/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ groups:
scored: true

- id: 1.1.9
text: "Ensure that the Container Network Interface file permissions are set to 600 or more restrictive (Automated)"
text: "Ensure that the Container Network Interface file permissions are set to 600 or more restrictive (Manual)"
audit: find /var/lib/cni/networks -type f ! -name lock 2> /dev/null | xargs --no-run-if-empty stat -c permissions=%a
use_multiple_values: true
tests:
Expand All @@ -129,28 +129,24 @@ groups:
op: bitmask
value: "600"
remediation: |
By default, K3s sets the CNI file permissions to 600.
By default, K3s sets the CNI file permissions to 644.
Note that for many CNIs, a lock file is created with permissions 750. This is expected and can be ignored.
If you modify your CNI configuration, ensure that the permissions are set to 600.
For example, chmod 600 /var/lib/cni/networks/<filename>
scored: true

- id: 1.1.10
text: "Ensure that the Container Network Interface file ownership is set to root:root (Manual)"
type: skip
audit: |
ps -ef | grep $kubeletbin | grep -- --cni-conf-dir | sed 's%.*cni-conf-dir[= ]\([^ ]*\).*%\1%' | xargs -I{} find {} -mindepth 1 | xargs --no-run-if-empty stat -c %U:%G
find /var/lib/cni/networks -type f 2> /dev/null | xargs --no-run-if-empty stat -c %U:%G
text: "Ensure that the Container Network Interface file ownership is set to root:root (Automated)"
audit: find /var/lib/cni/networks -type f 2> /dev/null | xargs --no-run-if-empty stat -c %U:%G
use_multiple_values: true
tests:
test_items:
- flag: "root:root"
remediation: |
Not Applicable.
Run the below command (based on the file location on your system) on the control plane node.
For example,
chown root:root <path/to/cni/files>
scored: false
chown root:root /var/lib/cni/networks/<filename>
scored: true

- id: 1.1.11
text: "Ensure that the etcd data directory permissions are set to 700 or more restrictive (Automated)"
Expand Down
8 changes: 4 additions & 4 deletions package/cfg/k3s-cis-1.7-hardened/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ groups:
test_items:
- flag: root:root
remediation: |
Run the following command (using the config file location identified in the Audit step)
chown root:root $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
Not Applicable.
All configuration is passed in as arguments at container run time.
scored: true
Expand Down Expand Up @@ -336,8 +336,8 @@ groups:
If for some reason you need to provide your own certificate and key, you can set the
the below parameters in the K3s config file /etc/rancher/k3s/config.yaml.
kubelet-arg:
- "tls-cert-file=<path/to/tls-cert-file>"
- "tls-private-key-file=<path/to/tls-private-key-file>"
- "tls-cert-file=<path/to/tls-cert-file>"
- "tls-private-key-file=<path/to/tls-private-key-file>"
scored: true

- id: 4.2.10
Expand Down
16 changes: 6 additions & 10 deletions package/cfg/k3s-cis-1.7-permissive/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ groups:
scored: true

- id: 1.1.9
text: "Ensure that the Container Network Interface file permissions are set to 600 or more restrictive (Automated)"
text: "Ensure that the Container Network Interface file permissions are set to 600 or more restrictive (Manual)"
audit: find /var/lib/cni/networks -type f ! -name lock 2> /dev/null | xargs --no-run-if-empty stat -c permissions=%a
use_multiple_values: true
tests:
Expand All @@ -129,28 +129,24 @@ groups:
op: bitmask
value: "600"
remediation: |
By default, K3s sets the CNI file permissions to 600.
By default, K3s sets the CNI file permissions to 644.
Note that for many CNIs, a lock file is created with permissions 750. This is expected and can be ignored.
If you modify your CNI configuration, ensure that the permissions are set to 600.
For example, chmod 600 /var/lib/cni/networks/<filename>
scored: true

- id: 1.1.10
text: "Ensure that the Container Network Interface file ownership is set to root:root (Manual)"
type: skip
audit: |
ps -ef | grep $kubeletbin | grep -- --cni-conf-dir | sed 's%.*cni-conf-dir[= ]\([^ ]*\).*%\1%' | xargs -I{} find {} -mindepth 1 | xargs --no-run-if-empty stat -c %U:%G
find /var/lib/cni/networks -type f 2> /dev/null | xargs --no-run-if-empty stat -c %U:%G
text: "Ensure that the Container Network Interface file ownership is set to root:root (Automated)"
audit: find /var/lib/cni/networks -type f 2> /dev/null | xargs --no-run-if-empty stat -c %U:%G
use_multiple_values: true
tests:
test_items:
- flag: "root:root"
remediation: |
Not Applicable.
Run the below command (based on the file location on your system) on the control plane node.
For example,
chown root:root <path/to/cni/files>
scored: false
chown root:root /var/lib/cni/networks/<filename>
scored: true

- id: 1.1.11
text: "Ensure that the etcd data directory permissions are set to 700 or more restrictive (Automated)"
Expand Down
8 changes: 4 additions & 4 deletions package/cfg/k3s-cis-1.7-permissive/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ groups:
op: bitmask
value: "600"
remediation: |
Run the following command (using the config file location identified in the Audit step)
chmod 600 $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.1.10
Expand All @@ -143,8 +143,8 @@ groups:
test_items:
- flag: root:root
remediation: |
Run the following command (using the config file location identified in the Audit step)
chown root:root $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
Not Applicable.
All configuration is passed in as arguments at container run time.
scored: true
Expand Down
10 changes: 6 additions & 4 deletions package/cfg/k3s-cis-1.8-hardened/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,28 @@ groups:
- id: 4.1.9
text: "Ensure that the kubelet --config configuration file has permissions set to 600 or more restrictive (Automated)"
audit: '/bin/sh -c ''if test -e $kubeletconf; then stat -c permissions=%a $kubeletconf; fi'' '
type: "skip"
tests:
test_items:
- flag: "permissions"
compare:
op: bitmask
value: "600"
remediation: |
Run the following command (using the config file location identified in the Audit step)
chmod 600 $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.1.10
text: "Ensure that the kubelet --config configuration file ownership is set to root:root (Automated)"
audit: '/bin/sh -c ''if test -e $kubeletconf; then stat -c %U:%G $kubeletconf; fi'' '
type: "skip"
tests:
test_items:
- flag: root:root
remediation: |
Run the following command (using the config file location identified in the Audit step)
chown root:root $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.2
Expand Down
10 changes: 6 additions & 4 deletions package/cfg/k3s-cis-1.8-permissive/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,28 @@ groups:
- id: 4.1.9
text: "Ensure that the kubelet --config configuration file has permissions set to 600 or more restrictive (Automated)"
audit: '/bin/sh -c ''if test -e $kubeletconf; then stat -c permissions=%a $kubeletconf; fi'' '
type: "skip"
tests:
test_items:
- flag: "permissions"
compare:
op: bitmask
value: "600"
remediation: |
Run the following command (using the config file location identified in the Audit step)
chmod 600 $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.1.10
text: "Ensure that the kubelet --config configuration file ownership is set to root:root (Automated)"
audit: '/bin/sh -c ''if test -e $kubeletconf; then stat -c %U:%G $kubeletconf; fi'' '
type: "skip"
tests:
test_items:
- flag: root:root
remediation: |
Run the following command (using the config file location identified in the Audit step)
chown root:root $kubeletconf
Not Applicable.
The kubelet is embedded in the k3s process. There is no kubelet config file, all configuration is passed in as arguments at runtime.
scored: true

- id: 4.2
Expand Down

0 comments on commit 3e7e1fe

Please sign in to comment.