Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rke-cis-1.7 | Folder is wrong - should be changed to /etc/kubernetes/ssl #1746

Closed
guyjerby opened this issue Dec 5, 2024 · 10 comments · Fixed by #1747
Closed

rke-cis-1.7 | Folder is wrong - should be changed to /etc/kubernetes/ssl #1746

guyjerby opened this issue Dec 5, 2024 · 10 comments · Fixed by #1747
Assignees

Comments

@guyjerby
Copy link

guyjerby commented Dec 5, 2024

folder name on the rke master should be chanegd from: /node/etc/kubernetes/ssl to: /etc/kubernetes/ssl on the following checks:

1.1.19 =>

audit: "check_files_owner_in_dir.sh /node/etc/kubernetes/ssl"

4.1.7 =>

audit: "stat -c permissions=%a /node/etc/kubernetes/ssl/kube-ca.pem"

4.1.8 =>

audit: "stat -c %U:%G /node/etc/kubernetes/ssl/kube-ca.pem"

as we can see , the files under /etc/kubernetes/ssl has root owner and this is being checked by 1.1.19:

root@ip-10-0-5-79:/etc/kubernetes/ssl# ls -l
total 108
-rwxr-xr-x 1 root root 838 Dec 5 21:26 check_files_owner_in_dir.sh
-rw------- 1 root root 1679 Dec 5 09:29 kube-apiserver-key.pem
-rw------- 1 root root 1675 Dec 5 09:29 kube-apiserver-proxy-client-key.pem
-rw------- 1 root root 1151 Dec 5 09:29 kube-apiserver-proxy-client.pem
-rw------- 1 root root 1679 Dec 5 09:29 kube-apiserver-requestheader-ca-key.pem
-rw------- 1 root root 1123 Dec 5 09:29 kube-apiserver-requestheader-ca.pem
-rw------- 1 root root 1306 Dec 5 09:29 kube-apiserver.pem
-rw------- 1 root root 1679 Dec 5 09:29 kube-ca-key.pem
-rw------- 1 root root 1058 Dec 5 09:29 kube-ca.pem
-rw------- 1 root root 1675 Dec 5 09:29 kube-controller-manager-key.pem
-rw------- 1 root root 1107 Dec 5 09:29 kube-controller-manager.pem
-rw------- 1 root root 1675 Dec 5 09:29 kube-etcd-10-0-5-79-key.pem
-rw------- 1 root root 1302 Dec 5 09:29 kube-etcd-10-0-5-79.pem
-rw------- 1 root root 1679 Dec 5 09:29 kube-node-key.pem
-rw------- 1 root root 1115 Dec 5 09:29 kube-node.pem
-rw------- 1 root root 1679 Dec 5 09:29 kube-proxy-key.pem
-rw------- 1 root root 1090 Dec 5 09:29 kube-proxy.pem
-rw------- 1 root root 1675 Dec 5 09:29 kube-scheduler-key.pem
-rw------- 1 root root 1094 Dec 5 09:29 kube-scheduler.pem
-rw------- 1 root root 1679 Dec 5 09:29 kube-service-account-token-key.pem
-rw------- 1 root root 1306 Dec 5 09:29 kube-service-account-token.pem
-rw------- 1 root root 517 Dec 5 09:29 kubecfg-kube-apiserver-proxy-client.yaml
-rw------- 1 root root 533 Dec 5 09:29 kubecfg-kube-apiserver-requestheader-ca.yaml
-rw------- 1 root root 501 Dec 5 09:29 kubecfg-kube-controller-manager.yaml
-rw------- 1 root root 445 Dec 5 09:29 kubecfg-kube-node.yaml
-rw------- 1 root root 449 Dec 5 09:29 kubecfg-kube-proxy.yaml
-rw------- 1 root root 465 Dec 5 09:29 kubecfg-kube-scheduler.yaml
root@ip-10-0-5-79:/etc/kubernetes/ssl# ./check_files_owner_in_dir.sh /etc/kubernetes/ssl/
true
root@ip-10-0-5-79:/etc/kubernetes/ssl#

@guyjerby guyjerby changed the title Folder is wrong - should be changed to /etc/kubernetes/ssl rke-cis-1.7 | Folder is wrong - should be changed to /etc/kubernetes/ssl Dec 5, 2024
@guyjerby guyjerby assigned guyjerby and ttousai and unassigned guyjerby Dec 5, 2024
@mozillazg
Copy link
Collaborator

cc @andypitcher

@guyjerby
Copy link
Author

guyjerby commented Dec 5, 2024

@ttousai , @afdesk - can we have a quick fix here and a new build? even tomorrow?
(this is a super minor fix)

@ttousai
Copy link
Contributor

ttousai commented Dec 6, 2024

@guyjerby , @afdesk please review #1747 with the fixes.

@andypitcher
Copy link
Contributor

cc @andypitcher

Just to add context to the use of /node in /node/etc/kubernetes/ssl is used to serve the Deployment needs when using our CIS Benchmark App in Rancher.
For reference, all of our profiles at Rancher are currently maintained here: https://github.com/rancher/security-scan/tree/main/package/cfg. There might be some differences from kube-bench cfgs and ours, that we are addressing and ultimately moving completely inside kube-bench.
cc @dereknola

@guyjerby
Copy link
Author

guyjerby commented Dec 9, 2024

Hi @andypitcher ,
you mean that rancher deployment that include CIS benchmark test in the UI will requires the /node while other type of deployment will be without the /node?

can you provide an example?

@guyjerby
Copy link
Author

while testing the change, the helper script check_files_owner_in_dir.sh is not founded under /go/bin, therefore this test was never worked.

this is due to 3 issues:

  1. typo in the docker file:

    COPY helper_scripts/check_files_owner_in_dir.sh /go/bin

    it should copy the script to /go/bin/check_files_owner_in_dir.sh but it put it as /go/bin because of the missing "/" after b

  2. missing bash that required to run the script - the docker file should contains: apk add bash or any other method to have bash on kube-bench container

  3. chmode +x - the script should be executable

@ttousai - can you assist with fixing it?

@guyjerby guyjerby reopened this Dec 10, 2024
@andypitcher
Copy link
Contributor

Hi @andypitcher , you mean that rancher deployment that include CIS benchmark test in the UI will requires the /node while other type of deployment will be without the /node?

can you provide an example?

Hey @guyjerby, as I mentioned this is only particular to the CIS Benchmark App inside Rancher, a dedicated pod is created to run the scans, and mounts the node's / dir as /node, see this.

The best way would be to remove the /node as you proposed, and to use the kube-bench variables instead which would get populated by config.yaml.

@andypitcher
Copy link
Contributor

while testing the change, the helper script check_files_owner_in_dir.sh is not founded under /go/bin, therefore this test was never worked.

this is due to 3 issues:

  1. typo in the docker file:

    COPY helper_scripts/check_files_owner_in_dir.sh /go/bin

    it should copy the script to /go/bin/check_files_owner_in_dir.sh but it put it as /go/bin because of the missing "/" after b

  2. missing bash that required to run the script - the docker file should contains: apk add bash or any other method to have bash on kube-bench container

  3. chmode +x - the script should be executable

@ttousai - can you assist with fixing it?

If I may add some info here, we proposed some changes for K3s/RKE2 not to use these helper_scripts anymore, see this related PR.
We haven't proposed this change in RKE1, feel free to change it.

@guyjerby
Copy link
Author

Hi @andypitcher , you mean that rancher deployment that include CIS benchmark test in the UI will requires the /node while other type of deployment will be without the /node?
can you provide an example?

Hey @guyjerby, as I mentioned this is only particular to the CIS Benchmark App inside Rancher, a dedicated pod is created to run the scans, and mounts the node's / dir as /node, see this.

The best way would be to remove the /node as you proposed, and to use the kube-bench variables instead which would get populated by config.yaml.

Thank you very much @andypitcher , now it is clear from where the /node prefix was collected and yes - in kube-bench we have different conifguration and the host is not mounted under /node so it is not relevant.

@guyjerby
Copy link
Author

while testing the change, the helper script check_files_owner_in_dir.sh is not founded under /go/bin, therefore this test was never worked.
this is due to 3 issues:

  1. typo in the docker file:

    COPY helper_scripts/check_files_owner_in_dir.sh /go/bin

    it should copy the script to /go/bin/check_files_owner_in_dir.sh but it put it as /go/bin because of the missing "/" after b

  2. missing bash that required to run the script - the docker file should contains: apk add bash or any other method to have bash on kube-bench container

  3. chmode +x - the script should be executable

@ttousai - can you assist with fixing it?

If I may add some info here, we proposed some changes for K3s/RKE2 not to use these helper_scripts anymore, see this related PR. We haven't proposed this change in RKE1, feel free to change it.

Thanks @andypitcher , to have a quick fix for this bug I suggest to fix the existing script while in parallel to check for the next update the use without the scrips , but I will let @ttousai to decide what works better to close this issue.

looking at this check from rancher repo - it is implemented like that in a k3s check:

  • id: 1.1.19
    text: "Ensure that the Kubernetes PKI directory and file ownership is set to root:root (Automated)"
    audit: "stat -c %U:%G /var/lib/rancher/k3s/server/tls"
    use_multiple_values: true
    tests:
    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 -R root:root /var/lib/rancher/k3s/server/tls
    scored: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants