Continental Innovates with Rancher and Kubernetes
Click here to download a PDF version of this document
This document is a companion to the Rancher v2.3.5 security hardening guide. The hardening guide provides prescriptive guidance for hardening a production installation of Rancher, and this benchmark guide is meant to help you evaluate the level of security of the hardened cluster against each control in the benchmark.
This guide corresponds to specific versions of the hardening guide, Rancher, Kubernetes, and the CIS Benchmark:
Because Rancher and RKE install Kubernetes services as Docker containers, many of the control verification checks in the CIS Kubernetes Benchmark don’t apply and will have a result of Not Applicable. This guide will walk through the various controls and provide updated example commands to audit compliance in Rancher-created clusters.
Not Applicable
This document is to be used by Rancher operators, security teams, auditors and decision makers.
For more detail about each audit, including rationales and remediations for failing tests, you can refer to the corresponding section of the CIS Kubernetes Benchmark v1.5. You can download the benchmark after logging in to CISecurity.org.
Rancher and RKE install Kubernetes services via Docker containers. Configuration is defined by arguments passed to the container at the time of initialization, not via configuration files.
Where control audits differ from the original CIS benchmark, the audit commands specific to Rancher Labs are provided for testing. When performing the tests, you will need access to the Docker command line on the hosts of all three RKE roles. The commands also make use of the the jq and kubectl (with valid config) tools to and are required in the testing and evaluation of test results.
NOTE: only scored tests are covered in this guide.
644
Result: Not Applicable
Remediation: RKE doesn’t require or maintain a configuration file for the API server. All configuration is passed in as arguments at container run time.
root:root
Remediation: RKE doesn’t require or maintain a configuration file for the controller manager. All configuration is passed in as arguments at container run time.
Remediation: RKE doesn’t require or maintain a configuration file for the scheduler. All configuration is passed in as arguments at container run time.
Remediation: RKE doesn’t require or maintain a configuration file for etcd. All configuration is passed in as arguments at container run time.
700
Result: PASS
Remediation: On the etcd server node, get the etcd data directory, passed as an argument --data-dir, from the below command:
--data-dir
ps -ef | grep etcd
Run the below command (based on the etcd data directory found above). For example,
chmod 700 /var/lib/etcd
Audit Script: 1.1.11.sh
#!/bin/bash -e etcd_bin=${1} test_dir=$(ps -ef | grep ${etcd_bin} | grep -- --data-dir | sed 's%.*data-dir[= ]\([^ ]*\).*%\1%') docker inspect etcd | jq -r '.[].HostConfig.Binds[]' | grep "${test_dir}" | cut -d ":" -f 1 | xargs stat -c %a
Audit Execution:
./1.1.11.sh etcd
Expected result:
'700' is equal to '700'
etcd:etcd
chown etcd:etcd /var/lib/etcd
Audit Script: 1.1.12.sh
#!/bin/bash -e etcd_bin=${1} test_dir=$(ps -ef | grep ${etcd_bin} | grep -- --data-dir | sed 's%.*data-dir[= ]\([^ ]*\).*%\1%') docker inspect etcd | jq -r '.[].HostConfig.Binds[]' | grep "${test_dir}" | cut -d ":" -f 1 | xargs stat -c %U:%G
./1.1.12.sh etcd
'etcd:etcd' is present
admin.conf
Remediation: RKE does not store the kubernetes default kubeconfig credentials file on the nodes. It’s presented to user where RKE is run. We recommend that this kube_config_cluster.yml file be kept in secure store.
kube_config_cluster.yml
scheduler.conf
controller-manager.conf
Remediation: Run the below command (based on the file location on your system) on the master node. For example,
chown -R root:root /etc/kubernetes/ssl
Audit:
stat -c %U:%G /etc/kubernetes/ssl
'root:root' is present
chmod -R 644 /etc/kubernetes/ssl
Audit Script: check_files_permissions.sh
#!/usr/bin/env bash # This script is used to ensure the file permissions are set to 644 or # more restrictive for all files in a given directory or a wildcard # selection of files # # inputs: # $1 = /full/path/to/directory or /path/to/fileswithpattern # ex: !(*key).pem # # $2 (optional) = permission (ex: 600) # # outputs: # true/false # Turn on "extended glob" for use of '!' in wildcard shopt -s extglob # Turn off history to avoid surprises when using '!' set -H USER_INPUT=$1 if [[ "${USER_INPUT}" == "" ]]; then echo "false" exit fi if [[ -d ${USER_INPUT} ]]; then PATTERN="${USER_INPUT}/*" else PATTERN="${USER_INPUT}" fi PERMISSION="" if [[ "$2" != "" ]]; then PERMISSION=$2 fi FILES_PERMISSIONS=$(stat -c %n\ %a ${PATTERN}) while read -r fileInfo; do p=$(echo ${fileInfo} | cut -d' ' -f2) if [[ "${PERMISSION}" != "" ]]; then if [[ "$p" != "${PERMISSION}" ]]; then echo "false" exit fi else if [[ "$p" != "644" && "$p" != "640" && "$p" != "600" ]]; then echo "false" exit fi fi done <<< "${FILES_PERMISSIONS}" echo "true" exit
./check_files_permissions.sh '/etc/kubernetes/ssl/*.pem'
'true' is present
600
chmod -R 600 /etc/kubernetes/ssl/certs/serverca
Audit Script: 1.1.21.sh
#!/bin/bash -e check_dir=${1:-/etc/kubernetes/ssl} for file in $(find ${check_dir} -name "*key.pem"); do file_permission=$(stat -c %a ${file}) if [[ "${file_permission}" == "600" ]]; then continue else echo "FAIL: ${file} ${file_permission}" exit 1 fi done echo "pass"
./1.1.21.sh /etc/kubernetes/ssl
'pass' is present
--basic-auth-file
Remediation: Follow the documentation and configure alternate mechanisms for authentication. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and remove the --basic-auth-file=<filename> parameter.
/etc/kubernetes/manifests/kube-apiserver.yaml
--basic-auth-file=<filename>
/bin/ps -ef | grep kube-apiserver | grep -v grep
'--basic-auth-file' is not present
--token-auth-file
Remediation: Follow the documentation and configure alternate mechanisms for authentication. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and remove the --token-auth-file=<filename> parameter.
--token-auth-file=<filename>
'--token-auth-file' is not present
--kubelet-https
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and remove the --kubelet-https parameter.
'--kubelet-https' is present OR '--kubelet-https' is not present
--kubelet-client-certificate
--kubelet-client-key
Remediation: Follow the Kubernetes documentation and set up the TLS connection between the apiserver and kubelets. Then, edit API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the kubelet client certificate and key parameters as below.
--kubelet-client-certificate=<path/to/client-certificate-file> --kubelet-client-key=<path/to/client-key-file>
'--kubelet-client-certificate' is present AND '--kubelet-client-key' is present
--kubelet-certificate-authority
Remediation: Follow the Kubernetes documentation and setup the TLS connection between the apiserver and kubelets. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --kubelet-certificate-authority parameter to the path to the cert file for the certificate authority. --kubelet-certificate-authority=<ca-string>
--kubelet-certificate-authority=<ca-string>
'--kubelet-certificate-authority' is present
--authorization-mode
AlwaysAllow
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --authorization-mode parameter to values other than AlwaysAllow. One such example could be as below.
--authorization-mode=RBAC
'Node,RBAC' not have 'AlwaysAllow'
Node
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --authorization-mode parameter to a value that includes Node.
--authorization-mode=Node,RBAC
'Node,RBAC' has 'Node'
RBAC
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --authorization-mode parameter to a value that includes RBAC, for example:
'Node,RBAC' has 'RBAC'
AlwaysAdmit
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and either remove the --enable-admission-plugins parameter, or set it to a value that does not include AlwaysAdmit.
--enable-admission-plugins
'NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota,NodeRestriction,Priority,TaintNodesByCondition,PersistentVolumeClaimResize,PodSecurityPolicy,EventRateLimit' not have 'AlwaysAdmit' OR '--enable-admission-plugins' is not present
ServiceAccount
Remediation: Follow the documentation and create ServiceAccount objects as per your environment. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and ensure that the --disable-admission-plugins parameter is set to a value that does not include ServiceAccount.
--disable-admission-plugins
'NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota,NodeRestriction,Priority,TaintNodesByCondition,PersistentVolumeClaimResize,PodSecurityPolicy,EventRateLimit' has 'ServiceAccount' OR '--enable-admission-plugins' is not present
NamespaceLifecycle
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --disable-admission-plugins parameter to ensure it does not include NamespaceLifecycle.
'--disable-admission-plugins' is present OR '--disable-admission-plugins' is not present
PodSecurityPolicy
Remediation: Follow the documentation and create Pod Security Policy objects as per your environment. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --enable-admission-plugins parameter to a value that includes PodSecurityPolicy:
--enable-admission-plugins=...,PodSecurityPolicy,...
Then restart the API Server.
'NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota,NodeRestriction,Priority,TaintNodesByCondition,PersistentVolumeClaimResize,PodSecurityPolicy,EventRateLimit' has 'PodSecurityPolicy'
NodeRestriction
Remediation: Follow the Kubernetes documentation and configure NodeRestriction plug-in on kubelets. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --enable-admission-plugins parameter to a value that includes NodeRestriction.
--enable-admission-plugins=...,NodeRestriction,...
'NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota,NodeRestriction,Priority,TaintNodesByCondition,PersistentVolumeClaimResize,PodSecurityPolicy,EventRateLimit' has 'NodeRestriction'
--insecure-bind-address
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and remove the --insecure-bind-address parameter.
'--insecure-bind-address' is not present
--insecure-port
0
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the below parameter.
--insecure-port=0
'0' is equal to '0'
--secure-port
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and either remove the --secure-port parameter or set it to a different (non-zero) desired port.
6443 is greater than 0 OR '--secure-port' is not present
--profiling
false
--profiling=false
'false' is equal to 'false'
--audit-log-path
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --audit-log-path parameter to a suitable path and file where you would like audit logs to be written, for example:
--audit-log-path=/var/log/apiserver/audit.log
'--audit-log-path' is present
--audit-log-maxage
30
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --audit-log-maxage parameter to 30 or as an appropriate number of days:
--audit-log-maxage=30
30 is greater or equal to 30
--audit-log-maxbackup
10
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --audit-log-maxbackup parameter to 10 or to an appropriate value.
--audit-log-maxbackup=10
10 is greater or equal to 10
--audit-log-maxsize
100
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --audit-log-maxsize parameter to an appropriate size in MB. For example, to set it as 100 MB:
--audit-log-maxsize=100
100 is greater or equal to 100
--request-timeout
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml and set the below parameter as appropriate and if needed. For example,
--request-timeout=300s
'--request-timeout' is not present OR '--request-timeout' is present
--service-account-lookup
true
--service-account-lookup=true
Alternatively, you can delete the --service-account-lookup parameter from this file so that the default takes effect.
'--service-account-lookup' is not present OR 'true' is equal to 'true'
--service-account-key-file
Remediation: Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --service-account-key-file parameter to the public key file for service accounts:
--service-account-key-file=<filename>
'--service-account-key-file' is present
--etcd-certfile
--etcd-keyfile
Remediation: Follow the Kubernetes documentation and set up the TLS connection between the apiserver and etcd. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the etcd certificate and key file parameters.
--etcd-certfile=<path/to/client-certificate-file> --etcd-keyfile=<path/to/client-key-file>
'--etcd-certfile' is present AND '--etcd-keyfile' is present
--tls-cert-file
--tls-private-key-file
Remediation: Follow the Kubernetes documentation and set up the TLS connection on the apiserver. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the TLS certificate and private key file parameters.
--tls-cert-file=<path/to/tls-certificate-file> --tls-private-key-file=<path/to/tls-key-file>
'--tls-cert-file' is present AND '--tls-private-key-file' is present
--client-ca-file
Remediation: Follow the Kubernetes documentation and set up the TLS connection on the apiserver. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the client certificate authority file.
--client-ca-file=<path/to/client-ca-file>
'--client-ca-file' is present
--etcd-cafile
Remediation: Follow the Kubernetes documentation and set up the TLS connection between the apiserver and etcd. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the etcd certificate authority file parameter.
--etcd-cafile=<path/to/ca-file>
'--etcd-cafile' is present
--encryption-provider-config
Remediation: Follow the Kubernetes documentation and configure a EncryptionConfig file. Then, edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml on the master node and set the --encryption-provider-config parameter to the path of that file:
--encryption-provider-config=</path/to/EncryptionConfig/File>
'--encryption-provider-config' is present
Remediation: Follow the Kubernetes documentation and configure a EncryptionConfig file. In this file, choose aescbc, kms or secretbox as the encryption provider.
EncryptionConfig
Audit Script: 1.2.34.sh
#!/bin/bash -e check_file=${1} grep -q -E 'aescbc|kms|secretbox' ${check_file} if [ $? -eq 0 ]; then echo "--pass" exit 0 else echo "fail: encryption provider found in ${check_file}" exit 1 fi
./1.2.34.sh /etc/kubernetes/ssl/encryption.yaml
'--pass' is present
--terminated-pod-gc-threshold
Remediation: Edit the Controller Manager pod specification file /etc/kubernetes/manifests/kube-controller-manager.yaml on the master node and set the --terminated-pod-gc-threshold to an appropriate threshold, for example:
/etc/kubernetes/manifests/kube-controller-manager.yaml
--terminated-pod-gc-threshold=10
/bin/ps -ef | grep kube-controller-manager | grep -v grep
'--terminated-pod-gc-threshold' is present
Remediation: Edit the Controller Manager pod specification file /etc/kubernetes/manifests/kube-controller-manager.yaml on the master node and set the below parameter.
--use-service-account-credentials
Remediation: Edit the Controller Manager pod specification file /etc/kubernetes/manifests/kube-controller-manager.yaml on the master node to set the below parameter.
--use-service-account-credentials=true
'true' is not equal to 'false'
--service-account-private-key-file
Remediation: Edit the Controller Manager pod specification file /etc/kubernetes/manifests/kube-controller-manager.yaml on the master node and set the --service-account-private-key-file parameter to the private key file for service accounts.
--service-account-private-key-file=<filename>
'--service-account-private-key-file' is present
--root-ca-file
Remediation: Edit the Controller Manager pod specification file /etc/kubernetes/manifests/kube-controller-manager.yaml on the master node and set the --root-ca-file parameter to the certificate bundle file`.
--root-ca-file=<path/to/file>
'--root-ca-file' is present
RotateKubeletServerCertificate
Remediation: Edit the Controller Manager pod specification file /etc/kubernetes/manifests/kube-controller-manager.yaml on the master node and set the --feature-gates parameter to include RotateKubeletServerCertificate=true.
--feature-gates
RotateKubeletServerCertificate=true
--feature-gates=RotateKubeletServerCertificate=true
'RotateKubeletServerCertificate=true' is equal to 'RotateKubeletServerCertificate=true'
--bind-address argument
127.0.0.1
Remediation: Edit the Controller Manager pod specification file /etc/kubernetes/manifests/kube-controller-manager.yaml on the master node and ensure the correct value for the --bind-address parameter.
--bind-address
'--bind-address' is present OR '--bind-address' is not present
Remediation: Edit the Scheduler pod specification file /etc/kubernetes/manifests/kube-scheduler.yaml file on the master node and set the below parameter.
/etc/kubernetes/manifests/kube-scheduler.yaml
/bin/ps -ef | grep kube-scheduler | grep -v grep
Remediation: Edit the Scheduler pod specification file /etc/kubernetes/manifests/kube-scheduler.yaml on the master node and ensure the correct value for the --bind-address parameter.
--cert-file
--key-file
Remediation: Follow the etcd service documentation and configure TLS encryption. Then, edit the etcd pod specification file /etc/kubernetes/manifests/etcd.yaml on the master node and set the below parameters.
/etc/kubernetes/manifests/etcd.yaml
--cert-file=</path/to/ca-file> --key-file=</path/to/key-file>
/bin/ps -ef | /bin/grep etcd | /bin/grep -v grep
'--cert-file' is present AND '--key-file' is present
--client-cert-auth
Remediation: Edit the etcd pod specification file /etc/kubernetes/manifests/etcd.yaml on the master node and set the below parameter.
--client-cert-auth="true"
'true' is equal to 'true'
--auto-tls
Remediation: Edit the etcd pod specification file /etc/kubernetes/manifests/etcd.yaml on the master node and either remove the --auto-tls parameter or set it to false.
--auto-tls=false
'--auto-tls' is not present OR '--auto-tls' is not present
--peer-cert-file
--peer-key-file
Remediation: Follow the etcd service documentation and configure peer TLS encryption as appropriate for your etcd cluster. Then, edit the etcd pod specification file /etc/kubernetes/manifests/etcd.yaml on the master node and set the below parameters.
--peer-client-file=</path/to/peer-cert-file> --peer-key-file=</path/to/peer-key-file>
'--peer-cert-file' is present AND '--peer-key-file' is present
--peer-client-cert-auth
--peer-client-cert-auth=true
--peer-auto-tls
Remediation: Edit the etcd pod specification file /etc/kubernetes/manifests/etcd.yaml on the master node and either remove the --peer-auto-tls parameter or set it to false.
--peer-auto-tls=false
'--peer-auto-tls' is not present OR '--peer-auto-tls' is present
Remediation: Create an audit policy file for your cluster.
Audit Script: 3.2.1.sh
#!/bin/bash -e api_server_bin=${1} /bin/ps -ef | /bin/grep ${api_server_bin} | /bin/grep -v ${0} | /bin/grep -v grep
./3.2.1.sh kube-apiserver
'--audit-policy-file' is present
Remediation: RKE doesn’t require or maintain a configuration file for the kubelet service. All configuration is passed in as arguments at container run time.
Remediation: Run the below command (based on the file location on your system) on the each worker node. For example,
chmod 644 /etc/kubernetes/ssl/kubecfg-kube-proxy.yaml
/bin/sh -c 'if test -e /etc/kubernetes/ssl/kubecfg-kube-proxy.yaml; then stat -c %a /etc/kubernetes/ssl/kubecfg-kube-proxy.yaml; fi'
'644' is present OR '640' is present OR '600' is equal to '600' OR '444' is present OR '440' is present OR '400' is present OR '000' is present
chown root:root /etc/kubernetes/ssl/kubecfg-kube-proxy.yaml
/bin/sh -c 'if test -e /etc/kubernetes/ssl/kubecfg-kube-proxy.yaml; then stat -c %U:%G /etc/kubernetes/ssl/kubecfg-kube-proxy.yaml; fi'
chmod 644 /etc/kubernetes/ssl/kubecfg-kube-node.yaml
/bin/sh -c 'if test -e /etc/kubernetes/ssl/kubecfg-kube-node.yaml; then stat -c %a /etc/kubernetes/ssl/kubecfg-kube-node.yaml; fi'
chown root:root /etc/kubernetes/ssl/kubecfg-kube-node.yaml
/bin/sh -c 'if test -e /etc/kubernetes/ssl/kubecfg-kube-node.yaml; then stat -c %U:%G /etc/kubernetes/ssl/kubecfg-kube-node.yaml; fi'
'root:root' is equal to 'root:root'
Remediation: Run the following command to modify the file permissions of the
--client-ca-file chmod 644 <filename>
stat -c %a /etc/kubernetes/ssl/kube-ca.pem
'644' is equal to '644' OR '640' is present OR '600' is present
Remediation: Run the following command to modify the ownership of the --client-ca-file.
chown root:root <filename>
/bin/sh -c 'if test -e /etc/kubernetes/ssl/kube-ca.pem; then stat -c %U:%G /etc/kubernetes/ssl/kube-ca.pem; fi'
--anonymous-auth argument
Remediation: If using a Kubelet config file, edit the file to set authentication: anonymous: enabled to false. If using executable arguments, edit the kubelet service file /etc/systemd/system/kubelet.service.d/10-kubeadm.conf on each worker node and set the below parameter in KUBELET_SYSTEM_PODS_ARGS variable.
anonymous
/etc/systemd/system/kubelet.service.d/10-kubeadm.conf
KUBELET_SYSTEM_PODS_ARGS
--anonymous-auth=false
Based on your system, restart the kubelet service. For example:
systemctl daemon-reload systemctl restart kubelet.service
/bin/ps -fC kubelet
Audit Config:
/bin/cat /var/lib/kubelet/config.yaml
Remediation: If using a Kubelet config file, edit the file to set authorization: mode to Webhook. If using executable arguments, edit the kubelet service file /etc/systemd/system/kubelet.service.d/10-kubeadm.conf on each worker node and set the below parameter in KUBELET_AUTHZ_ARGS variable.
mode
Webhook
KUBELET_AUTHZ_ARGS
--authorization-mode=Webhook
'Webhook' not have 'AlwaysAllow'
Remediation: If using a Kubelet config file, edit the file to set authentication: x509: clientCAFile to the location of the client CA file. If using command line arguments, edit the kubelet service file /etc/systemd/system/kubelet.service.d/10-kubeadm.conf on each worker node and set the below parameter in KUBELET_AUTHZ_ARGS variable.
x509
clientCAFile
--read-only-port
Remediation: If using a Kubelet config file, edit the file to set readOnlyPort to 0. If using command line arguments, edit the kubelet service file /etc/systemd/system/kubelet.service.d/10-kubeadm.conf on each worker node and set the below parameter in KUBELET_SYSTEM_PODS_ARGS variable.
readOnlyPort
--read-only-port=0
--streaming-connection-idle-timeout
Remediation: If using a Kubelet config file, edit the file to set streamingConnectionIdleTimeout to a value other than 0. If using command line arguments, edit the kubelet service file /etc/systemd/system/kubelet.service.d/10-kubeadm.conf on each worker node and set the below parameter in KUBELET_SYSTEM_PODS_ARGS variable.
streamingConnectionIdleTimeout
--streaming-connection-idle-timeout=5m
'30m' is not equal to '0' OR '--streaming-connection-idle-timeout' is not present
--protect-kernel-defaults
Remediation: If using a Kubelet config file, edit the file to set protectKernelDefaults: true. If using command line arguments, edit the kubelet service file /etc/systemd/system/kubelet.service.d/10-kubeadm.conf on each worker node and set the below parameter in KUBELET_SYSTEM_PODS_ARGS variable.
protectKernelDefaults
--protect-kernel-defaults=true
--make-iptables-util-chains
Remediation: If using a Kubelet config file, edit the file to set makeIPTablesUtilChains: true. If using command line arguments, edit the kubelet service file /etc/systemd/system/kubelet.service.d/10-kubeadm.conf on each worker node and remove the --make-iptables-util-chains argument from the KUBELET_SYSTEM_PODS_ARGS variable. Based on your system, restart the kubelet service. For example:
makeIPTablesUtilChains
'true' is equal to 'true' OR '--make-iptables-util-chains' is not present
--rotate-certificates
Remediation: If using a Kubelet config file, edit the file to add the line rotateCertificates: true or remove it altogether to use the default value. If using command line arguments, edit the kubelet service file /etc/systemd/system/kubelet.service.d/10-kubeadm.conf on each worker node and remove --rotate-certificates=false argument from the KUBELET_CERTIFICATE_ARGS variable. Based on your system, restart the kubelet service. For example:
rotateCertificates
--rotate-certificates=false
KUBELET_CERTIFICATE_ARGS
'--rotate-certificates' is present OR '--rotate-certificates' is not present
Remediation: Edit the kubelet service file /etc/systemd/system/kubelet.service.d/10-kubeadm.conf on each worker node and set the below parameter in KUBELET_CERTIFICATE_ARGS variable.
Remediation: Create explicit service accounts wherever a Kubernetes workload requires specific access to the Kubernetes API server. Modify the configuration of each default service account to include this value
automountServiceAccountToken: false
Audit Script: 5.1.5.sh
#!/bin/bash export KUBECONFIG=${KUBECONFIG:-/root/.kube/config} kubectl version > /dev/null if [ $? -ne 0 ]; then echo "fail: kubectl failed" exit 1 fi accounts="$(kubectl --kubeconfig=${KUBECONFIG} get serviceaccounts -A -o json | jq -r '.items[] | select(.metadata.name=="default") | select((.automountServiceAccountToken == null) or (.automountServiceAccountToken == true)) | "fail \(.metadata.name) \(.metadata.namespace)"')" if [[ "${accounts}" != "" ]]; then echo "fail: automountServiceAccountToken not false for accounts: ${accounts}" exit 1 fi default_binding="$(kubectl get rolebindings,clusterrolebindings -A -o json | jq -r '.items[] | select(.subjects[].kind=="ServiceAccount" and .subjects[].name=="default" and .metadata.name=="default").metadata.uid' | wc -l)" if [[ "${default_binding}" -gt 0 ]]; then echo "fail: default service accounts have non default bindings" exit 1 fi echo "--pass" exit 0
./5.1.5.sh
Remediation: Create a PSP as described in the Kubernetes documentation, ensuring that the .spec.hostPID field is omitted or set to false.
.spec.hostPID
kubectl --kubeconfig=/root/.kube/config get psp -o json | jq .items[] | jq -r 'select((.spec.hostPID == null) or (.spec.hostPID == false))' | jq .metadata.name | wc -l | xargs -I {} echo '--count={}'
1 is greater than 0
Remediation: Create a PSP as described in the Kubernetes documentation, ensuring that the .spec.hostIPC field is omitted or set to false.
.spec.hostIPC
kubectl --kubeconfig=/root/.kube/config get psp -o json | jq .items[] | jq -r 'select((.spec.hostIPC == null) or (.spec.hostIPC == false))' | jq .metadata.name | wc -l | xargs -I {} echo '--count={}'
Remediation: Create a PSP as described in the Kubernetes documentation, ensuring that the .spec.hostNetwork field is omitted or set to false.
.spec.hostNetwork
kubectl --kubeconfig=/root/.kube/config get psp -o json | jq .items[] | jq -r 'select((.spec.hostNetwork == null) or (.spec.hostNetwork == false))' | jq .metadata.name | wc -l | xargs -I {} echo '--count={}'
allowPrivilegeEscalation
Remediation: Create a PSP as described in the Kubernetes documentation, ensuring that the .spec.allowPrivilegeEscalation field is omitted or set to false.
.spec.allowPrivilegeEscalation
kubectl --kubeconfig=/root/.kube/config get psp -o json | jq .items[] | jq -r 'select((.spec.allowPrivilegeEscalation == null) or (.spec.allowPrivilegeEscalation == false))' | jq .metadata.name | wc -l | xargs -I {} echo '--count={}'
Remediation: Follow the documentation and create NetworkPolicy objects as you need them.
NetworkPolicy
Audit Script: 5.3.2.sh
#!/bin/bash -e export KUBECONFIG=${KUBECONFIG:-"/root/.kube/config"} kubectl version > /dev/null if [ $? -ne 0 ]; then echo "fail: kubectl failed" exit 1 fi for namespace in $(kubectl get namespaces -A -o json | jq -r '.items[].metadata.name'); do policy_count=$(kubectl get networkpolicy -n ${namespace} -o json | jq '.items | length') if [ ${policy_count} -eq 0 ]; then echo "fail: ${namespace}" exit 1 fi done echo "pass"
./5.3.2.sh
Remediation: Ensure that namespaces are created to allow for appropriate segregation of Kubernetes resources and that all new resources are created in a specific namespace.
Audit Script: 5.6.4.sh
#!/bin/bash -e export KUBECONFIG=${KUBECONFIG:-/root/.kube/config} kubectl version > /dev/null if [[ $? -gt 0 ]]; then echo "fail: kubectl failed" exit 1 fi default_resources=$(kubectl get all -o json | jq --compact-output '.items[] | select((.kind == "Service") and (.metadata.name == "kubernetes") and (.metadata.namespace == "default") | not)' | wc -l) echo "--count=${default_resources}"
./5.6.4.sh