Skip to main content

CIS Hardening Guide

This document outlines the configurations and controls required to address controls from the Center for Internet Security (CIS).

For more details about evaluating a hardened cluster against the official CIS benchmark, refer to the appropriate CIS Self-Assessment Guide:

The Kubernetes and Operating System (Ubuntu 22 LTS) is "hardened by default" and pass the majority of the CIS controls without modification. There are a few notable exceptions to this that require manual intervention to fully pass the CIS Benchmark:

Host-level

Partitions

PartitionCompliantComment
/varyesSince the /var directory may contain world-writable files and directories, there is a risk of resource exhaustion if it is not bound to a separate partition.
/var/logyesThere are two important reasons to ensure that system logs are stored on a separate partition: protection against resource exhaustion (since logs can grow quite large) and protection of audit data.
/bootyes
/homeyesThe system is intended to support local users (at least one for Kubernetes), create a separate partition for the /home directory to protect against resource exhaustion and restrict the type of files that can be stored under /home .
/tmpyesMaking /tmp its own file system allows to set the noexec option on the mount, making /tmp useless for an attacker to install executable code.
/srvnoKubernetes irrelevant
/optnoKubernetes irrelevant
/usrnoto justified

CIS Level 1

RecommendationTitleCompliantComment
1.1.1.1Ensure cramfs kernel module is not availableYes
1.1.1.2Ensure freevxfs kernel module is not availableYes
1.1.1.3Ensure hfs kernel module is not availableYes
1.1.1.4Ensure hfsplus kernel module is not availableYes
1.1.1.5Ensure jffs2 kernel module is not availableYes
1.1.1.8Ensure usb-storage kernel module is not availableYes
1.1.2.1.1Ensure /tmp is a separate partitionYes
1.1.2.1.2Ensure nodev option set on /tmp partitionYes
1.1.2.1.3Ensure nosuid option set on /tmp partitionYes
1.1.2.1.4Ensure noexec option set on /tmp partitionYes
1.1.2.2.1Ensure /dev/shm is a separate partitionYes
1.1.2.2.2Ensure nodev option set on /dev/shm partitionYes
1.1.2.2.3Ensure nosuid option set on /dev/shm partitionYes
1.1.2.2.4Ensure noexec option set on /dev/shm partitionYes
1.1.2.3.2Ensure nodev option set on /home partitionYes
1.1.2.3.3Ensure nosuid option set on /home partitionYes
1.1.2.4.2Ensure nodev option set on /var partitionYes
1.1.2.4.3Ensure nosuid option set on /var partitionYes
1.1.2.5.2Ensure nodev option set on /var/tmp partitionYes
1.1.2.5.3Ensure nosuid option set on /var/tmp partitionYes
1.1.2.5.4Ensure noexec option set on /var/tmp partitionYes
1.1.2.6.2Ensure nodev option set on /var/log partitionYes
1.1.2.6.3Ensure nosuid option set on /var/log partitionYes
1.1.2.6.4Ensure noexec option set on /var/log partitionYes
1.1.2.7.2Ensure nodev option set on /var/log/audit partitionYes
1.1.2.7.3Ensure nosuid option set on /var/log/audit partitionYes
1.1.2.7.4Ensure noexec option set on /var/log/audit partitionYes
1.2.1.1Ensure GPG keys are configuredNoConfiguration dependent
1.2.1.2Ensure package manager repositories are configuredNoConfiguration dependent
1.2.2.1Ensure updates, patches, and additional security software are installedNoConfiguration dependent
1.3.1.1Ensure AppArmor is installedYes
1.3.1.2Ensure AppArmor is enabled in the bootloader configurationYes
1.3.1.3Ensure all AppArmor Profiles are in enforce or complain modeYes
1.4.1Ensure bootloader password is setNoOs will not be able to boot
1.4.2Ensure access to bootloader config is configuredYes
1.5.1Ensure address space layout randomization is enabledYes
1.5.2Ensure ptrace_scope is restrictedYesDefault value, script does not enforce
1.5.3Ensure core dumps are restrictedYes
1.5.4Ensure prelink is not installedYes
1.5.5Ensure Automatic Error Reporting is not enabledYes
1.6.1Ensure message of the day is configured properlyYesMessage to be configured
1.6.2Ensure local login warning banner is configured properlyYesMessage to be configured
1.6.3Ensure remote login warning banner is configured properlyYesMessage to be configured
1.6.4Ensure access to /etc/motd is configuredYes
1.6.5Ensure access to /etc/issue is configuredYes
1.6.6Ensure access to /etc/issue.net is configuredYes
1.7.2Ensure GDM login banner is configuredYes
1.7.3Ensure GDM disable-user-list option is enabledYes
1.7.4Ensure GDM screen locks when the user is idleYes
1.7.5Ensure GDM screen locks cannot be overriddenYes
1.7.6Ensure GDM automatic mounting of removable media is disabledYes
1.7.7Ensure GDM disabling automatic mounting of removable media is not overriddenYes
1.7.8Ensure GDM autorun-never is enabledYes
1.7.9Ensure GDM autorun-never is not overriddenYes
1.7.10Ensure XDCMP is not enabledYes
2.1.1Ensure autofs services are not in useYes
2.1.2Ensure avahi daemon services are not in useYes
2.1.3Ensure dhcp server services are not in useYes
2.1.4Ensure dns server services are not in useYes
2.1.5Ensure dnsmasq services are not in useYes
2.1.6Ensure ftp server services are not in useYes
2.1.7Ensure ldap server services are not in useYes
2.1.8Ensure message access server services are not in useYes
2.1.9Ensure network file system services are not in useYes
2.1.10Ensure nis server services are not in useYes
2.1.11Ensure print server services are not in useYes
2.1.12Ensure rpcbind services are not in useYes
2.1.13Ensure rsync services are not in useYes
2.1.14Ensure samba file server services are not in useYes
2.1.15Ensure snmp services are not in useYes
2.1.16Ensure tftp server services are not in useYesMinimal installation not installed
2.1.17Ensure web proxy server services are not in useYes
2.1.18Ensure web server services are not in useYes
2.1.19Ensure xinetd services are not in useYesMinimal installation not installed
2.1.21Ensure mail transfer agent is configured for local-only modeYes
2.1.22Ensure only approved services are listening on a network interfaceYesMinimal installation
2.2.1Ensure NIS Client is not installedYes
2.2.2Ensure rsh client is not installedYes
2.2.3Ensure talk client is not installedYes
2.2.4Ensure telnet client is not installedYes
2.2.5Ensure ldap client is not installedNoRequired for ssh bastion
2.2.6Ensure ftp client is not installedYes
2.3.1.1Ensure a single time synchronization daemon is in usePartSCAP does not check if only one daemon is used, minimal install ony use systemd-timesyncd
2.3.2.1Ensure systemd-timesyncd configured with authorized timeserverNo
2.3.2.2Ensure systemd-timesyncd is enabled and runningYes
2.3.3.1Ensure chrony is configured with authorized timeserverNosystemd-timesyncd installed
2.3.3.2Ensure chrony is running as user chronyNosystemd-timesyncd installed
2.3.3.3Ensure chrony is enabled and runningNosystemd-timesyncd installed
2.4.1.1Ensure cron daemon is enabled and activeYes
2.4.1.2Ensure permissions on /etc/crontab are configuredYes
2.4.1.3Ensure permissions on /etc/cron.hourly are configuredYes
2.4.1.4Ensure permissions on /etc/cron.daily are configuredYes
2.4.1.5Ensure permissions on /etc/cron.weekly are configuredYes
2.4.1.6Ensure permissions on /etc/cron.monthly are configuredYes
2.4.1.7Ensure permissions on /etc/cron.d are configuredYes
2.4.1.8Ensure crontab is restricted to authorized usersYes
2.4.2.1Ensure at is restricted to authorized usersYes
3.1.1Ensure IPv6 status is identifiedYesIPv6 is enabled by default
3.1.2Ensure wireless interfaces are disabledYes
3.1.3Ensure bluetooth services are not in useYesMinimal installation, not installed
3.3.1Ensure ip forwarding is disabledNoRequired for kubernetes to work
3.3.2Ensure packet redirect sending is disabledYes
3.3.3Ensure bogus icmp responses are ignoredYes
3.3.4Ensure broadcast icmp requests are ignoredYes
3.3.5Ensure icmp redirects are not acceptedYes
3.3.6Ensure secure icmp redirects are not acceptedYes
3.3.7Ensure reverse path filtering is enabledNoRequired for kubernetes to work
3.3.8Ensure source routed packets are not acceptedYes
3.3.9Ensure suspicious packets are loggedYes
3.3.10Ensure tcp syn cookies is enabledYes
3.3.11Ensure ipv6 router advertisements are not acceptedYes
4.1.1Ensure ufw is installedNonftables installed
4.1.2Ensure iptables-persistent is not installed with ufwYesnftables installed
4.1.3Ensure ufw service is enabledNonftables installed
4.1.4Ensure ufw loopback traffic is configuredNonftables installed
4.1.5Ensure ufw outbound connections are configuredNonftables installed
4.1.6Ensure ufw firewall rules exist for all open portsNonftables installed
4.1.7Ensure ufw default deny firewall policyNonftables installed
4.2.1Ensure nftables is installedYes
4.2.2Ensure ufw is uninstalled or disabled with nftablesYes
4.2.3Ensure iptables are flushed with nftablesYes
4.2.4Ensure a nftables table existsYes
4.2.5Ensure nftables base chains existYes
4.2.6Ensure nftables loopback traffic is configuredYes
4.2.7Ensure nftables outbound and established connections are configuredNoNot in hardening script
4.2.8Ensure nftables default deny firewall policyNoNot in hardening script
4.2.9Ensure nftables service is enabledYes
4.2.10Ensure nftables rules are permanentYes
4.3.1.1Ensure iptables packages are installedNonftables installed in place must be removed manually apt purge -y iptables
4.3.1.2Ensure nftables is not installed with iptablesNonftables installed in place must be removed manually apt purge -y iptables
4.3.1.3Ensure ufw is uninstalled or disabled with iptablesNonftables installed in place must be removed manually apt purge -y iptables
4.3.2.1Ensure iptables default deny firewall policyNonftables installed in place must be removed manually apt purge -y iptables
4.3.2.2Ensure iptables loopback traffic is configuredNonftables installed in place must be removed manually apt purge -y iptables
4.3.2.3Ensure iptables outbound and established connections are configuredNonftables installed in place must be removed manually apt purge -y iptables
4.3.2.4Ensure iptables firewall rules exist for all open portsNonftables installed in place must be removed manually apt purge -y iptables
4.3.3.1Ensure ip6tables default deny firewall policyNonftables installed in place must be removed manually apt purge -y iptables
4.3.3.2Ensure ip6tables loopback traffic is configuredNonftables installed in place must be removed manually apt purge -y iptables
4.3.3.3Ensure ip6tables outbound and established connections are configuredNonftables installed in place must be removed manually apt purge -y iptables
4.3.3.4Ensure ip6tables firewall rules exist for all open portsNonftables installed in place must be removed manually apt purge -y iptables
5.1.1Ensure permissions on /etc/ssh/sshd_config are configuredYes
5.1.2Ensure permissions on SSH private host key files are configuredYes
5.1.3Ensure permissions on SSH public host key files are configuredYes
5.1.4Ensure sshd access is configuredNoDirectives AllowUsers,AllowGroups,DenyUsers and DenyGroups need to be configured
5.1.5Ensure sshd Banner is configuredYes
5.1.6Ensure sshd Ciphers are configuredYes
5.1.7Ensure sshd ClientAliveInterval and ClientAliveCountMax are configuredYes
5.1.10Ensure sshd HostbasedAuthentication is disabledYes
5.1.11Ensure sshd IgnoreRhosts is enabledYes
5.1.12Ensure sshd KexAlgorithms is configuredYes
5.1.13Ensure sshd LoginGraceTime is configuredYes
5.1.14Ensure sshd LogLevel is configuredYes
5.1.15Ensure sshd MACs are configuredYes
5.1.16Ensure sshd MaxAuthTries is configuredYes
5.1.17Ensure sshd MaxSessions is configuredYes
5.1.18Ensure sshd MaxStartups is configuredYes
5.1.19Ensure sshd PermitEmptyPasswords is disabledYes
5.1.20Ensure sshd PermitRootLogin is disabledYes
5.1.21Ensure sshd PermitUserEnvironment is disabledYes
5.1.22Ensure sshd UsePAM is enabledYes
5.2.1Ensure sudo is installedYes
5.2.2Ensure sudo commands use ptyYes
5.2.3Ensure sudo log file existsYes
5.2.5Ensure re-authentication for privilege escalation is not disabled globallyYes
5.2.6Ensure sudo authentication timeout is configured correctlyYes
5.2.7Ensure access to the su command is restrictedYes
5.3.1.1Ensure latest version of pam is installedNoDoes not upgrade
5.3.1.2Ensure libpam-modules is installedYes
5.3.1.3Ensure libpam-pwquality is installedYes
5.3.2.1Ensure pam_unix module is enabledYes
5.3.2.2Ensure pam_faillock module is enabledYes
5.3.2.3Ensure pam_pwquality module is enabledYes
5.3.2.4Ensure pam_pwhistory module is enabledYes
5.3.3.1.1Ensure password failed attempts lockout is configuredYes
5.3.3.1.2Ensure password unlock time is configuredYes
5.3.3.2.1Ensure password number of changed characters is configuredYes
5.3.3.2.2Ensure minimum password length is configuredYes
5.3.3.2.3Ensure password complexity is configuredYes
5.3.3.2.4Ensure password same consecutive characters is configuredNoNot in hardening script
5.3.3.2.5Ensure password maximum sequential characters is configuredNoNot in hardening script
5.3.3.2.6Ensure password dictionary check is enabledYes
5.3.3.2.7Ensure password quality checking is enforcedYes
5.3.3.2.8Ensure password quality is enforced for the root userYes
5.3.3.3.1Ensure password history remember is configuredNoNot in hardening script
5.3.3.3.2Ensure password history is enforced for the root userNoNot in hardening script
5.3.3.3.3Ensure pam_pwhistory includes use_authtokNoNot in hardening script
5.3.3.4.1Ensure pam_unix does not include nullokNoNot in hardening script
5.3.3.4.2Ensure pam_unix does not include rememberNoNot in hardening script
5.3.3.4.3Ensure pam_unix includes a strong password hashing algorithmYes
5.3.3.4.4Ensure pam_unix includes use_authtokYes
5.4.1.1Ensure password expiration is configuredYes
5.4.1.3Ensure password expiration warning days is configuredYes
5.4.1.4Ensure strong password hashing algorithm is configuredYes
5.4.1.5Ensure inactive password lock is configuredYes
5.4.1.6Ensure all users last password change date is in the pastYes
5.4.2.1Ensure root is the only UID 0 accountYes
5.4.2.2Ensure root is the only GID 0 accountYes
5.4.2.3Ensure group root is the only GID 0 groupYes
5.4.2.4Ensure root password is setNoNeeds to be configured manually
5.4.2.5Ensure root path integrityYes
5.4.2.6Ensure root user umask is configuredYes
5.4.2.7Ensure system accounts do not have a valid login shellYes
5.4.2.8Ensure accounts without a valid login shell are lockedNoAccounts need to be validated manually
5.4.3.2Ensure default user shell timeout is configuredYes
5.4.3.3Ensure default user umask is configuredYes
6.1.1Ensure AIDE is installedNoNot installed
6.1.2Ensure filesystem integrity is regularly checkedNoAide Not installed
6.2.1.1.1Ensure journald service is enabled and activeYes
6.2.1.1.2Ensure journald log file access is configuredNoUses default configuration
6.2.1.1.3Ensure journald log file rotation is configuredNoUses default configuration
6.2.1.1.4Ensure journald ForwardToSyslog is disabledYes
6.2.1.1.5Ensure journald Storage is configuredYes
6.2.1.1.6Ensure journald Compress is configuredYes
6.2.1.2.1Ensure systemd-journal-remote is installedYes
6.2.1.2.2Ensure systemd-journal-remote authentication is configuredNoNot in hardening script
6.2.1.2.3Ensure systemd-journal-upload is enabled and activeNoNot in hardening script
6.2.1.2.4Ensure systemd-journal-remote service is not in useYes
6.2.2.1Ensure access to all logfiles has been configuredYes
7.1.1Ensure permissions on /etc/passwd are configuredYes
7.1.2Ensure permissions on /etc/passwd- are configuredYes
7.1.3Ensure permissions on /etc/group are configuredYes
7.1.4Ensure permissions on /etc/group- are configuredYes
7.1.5Ensure permissions on /etc/shadow are configuredYes
7.1.6Ensure permissions on /etc/shadow- are configuredYes
7.1.7Ensure permissions on /etc/gshadow are configuredYes
7.1.8Ensure permissions on /etc/gshadow- are configuredYes
7.1.9Ensure permissions on /etc/shells are configuredYes
7.1.10Ensure permissions on /etc/security/opasswd are configuredYes
7.1.11Ensure world writable files and directories are securedYes
7.1.12Ensure no files or directories without an owner and a group existYes
7.1.13Ensure SUID and SGID files are reviewedYes
7.2.1Ensure accounts in /etc/passwd use shadowed passwordsYes
7.2.2Ensure /etc/shadow password fields are not emptyYes
7.2.3Ensure all groups in /etc/passwd exist in /etc/groupYes
7.2.4Ensure shadow group is emptyYes
7.2.5Ensure no duplicate UIDs existYes
7.2.6Ensure no duplicate GIDs existYes
7.2.7Ensure no duplicate user names existYes
7.2.8Ensure no duplicate group names existYes
7.2.9Ensure local interactive user home directories are configuredYes
7.2.10Ensure local interactive user dot files access is configuredYes

Kubelet parameter protect-kernel-defaults is set to true

This is a kubelet flag that will cause the kubelet to exit if the required kernel parameters are unset or are set to values that are different from the kubelet's defaults.

Etcd is configured properly

The CIS Benchmark requires that the etcd data directory be owned by the etcd user and group. This implicitly requires the etcd process run as the host-level etcd user.

  1. etcd` user and group exists on the host.
  2. etcd's data directory with etcd as the user and group owner.
  3. etcd process is run as the etcd user and group by setting the etcd static pod's SecurityContext appropriately.

Configuration

Generic CIS configuration

RKE2 MinorsApplicable CIS BenchmarkProfile Flag
1.27+1.8cis

Kubernetes runtime requirements

The runtime requirements to pass the CIS Benchmark are centered around pod security and network policies.

Pod Security

RKE2 always runs with some amount of pod security.

On v1.25 and newer, Pod Security Admission (PSA) are used for pod security. A default Pod Security Admission config file will be added to the cluster upon startup as follows:

With the cis profile:

  • RKE2 will apply a restricted pod security standard via a configuration file which will enforce restricted mode throughout the cluster with an exception to the kube-system, cis-operator-system namespaces to ensure successful operation of system pods.

See the Pod Security Policies page for more details.

note

The Kubernetes control plane components and critical additions such as CNI, DNS, and Ingress are ran as pods in the kube-system namespace. Therefore, this namespace will have a policy that is less restrictive so that these components can run properly.

Network Policies

RKE2 will put NetworkPolicies in place that passes the CIS Benchmark for Kubernetes' built-in namespaces. These namespaces are: kube-system, kube-public, and default.

The NetworkPolicy used will only allow pods within the same namespace to talk to each other. There are some notable exceptions to this is that it allows DNS requests to be resolved.

  • DNS requests are allowed to reach the dns server
  • HTTP/s requests are allowed to reach the ingress-nginx service
  • HTTPs requests are allowed to reach the metrics-server
  • Requests to the ingress-nginx webhook on the specified pod by the ingress-nginx pod (normally 8443)
  • HTTPs requests to the rke2-snapshot-validation-webhook
Operator Intervention Required

Operators must manage network policies as normal for additional namespaces that are created.

Configure default service account

Set automountServiceAccountToken to false for default service accounts

Kubernetes provides a default service account which is used by cluster workloads where no specific service account is assigned to the pod. Where access to the Kubernetes API from a pod is required, a specific service account should be created for that pod, and rights granted to that service account. The default service account should be configured such that it does not provide a service account token and does not have any explicit rights assignments.

RKE2 will automatically set the value correctly for kube-system, cis-operator-system, kube-node-lease namespaces.

API Server audit configuration

CIS requirements 1.2.22 to 1.2.25 are related to configuring audit logs for the API Server. When RKE2 is started with the profile flag set, it will automatically configure hardened --audit-log- parameters in the API Server to pass those CIS checks.

Default audit policy is configured to not log requests in the API Server. This is done to allow cluster operators flexibility to customize an audit policy that suits their auditing requirements and needs, as these are specific to each users' environment and policies.

A default audit policy is created by RKE2 when started with the profile flag set. The policy is defined in /etc/rancher/rke2/audit-policy.yaml.

apiVersion: audit.k8s.io/v1
kind: Policy
metadata:
creationTimestamp: null
rules:
- level: None

Known issues

The following are controls that default RKE2 currently does not pass. Each gap will be explained and how it is addressed.

Control 1.1.12

Ensure that the etcd data directory ownership is set to etcd:etcd.

Rationale
etcd is a highly-available key-value store used by Kubernetes deployments for persistent storage of all of its REST API objects. This data directory should be protected from any unauthorized reads or writes. It should be owned by etcd:etcd.

Remediation
This can be remediated by creating an etcd user and group as described above.

Control 5.1.5

Ensure that default service accounts are not actively used

Rationale
Kubernetes provides a default service account which is used by cluster workloads where no specific service account is assigned to the pod.

Where access to the Kubernetes API from a pod is required, a specific service account should be created for that pod, and rights granted to that service account.

The default service account should be configured such that it does not provide a service account token and does not have any explicit rights assignments.

This can be remediated by updating the automountServiceAccountToken field to false for the default service account in each namespace.

Conclusion

If you have followed this guide, your RKE2 cluster will be configured to pass the CIS Kubernetes Benchmark. You can review our CIS Self-Assessment Guides to understand how we verified each of the benchmarks and how you can do the same on your cluster.