diff --git a/docs/hardening.md b/docs/hardening.md index df757df327d..e6a69d5e875 100644 --- a/docs/hardening.md +++ b/docs/hardening.md @@ -85,6 +85,7 @@ kubelet_streaming_connection_idle_timeout: "5m" kubelet_make_iptables_util_chains: true kubelet_feature_gates: ["RotateKubeletServerCertificate=true","SeccompDefault=true"] kubelet_seccomp_default: true +kubelet_systemd_hardening: true # additional configurations kube_owner: root diff --git a/docs/vars.md b/docs/vars.md index 56f8ff836f1..d377a9290f6 100644 --- a/docs/vars.md +++ b/docs/vars.md @@ -175,26 +175,40 @@ Stack](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/dns-stack.m * *docker_options* - Commonly used to set ``--insecure-registry=myregistry.mydomain:5000`` + * *docker_plugins* - This list can be used to define [Docker plugins](https://docs.docker.com/engine/extend/) to install. + * *containerd_default_runtime* - If defined, changes the default Containerd runtime used by the Kubernetes CRI plugin. + * *containerd_additional_runtimes* - Sets the additional Containerd runtimes used by the Kubernetes CRI plugin. [Default config](https://github.com/kubernetes-sigs/kubespray/blob/master/roles/container-engine/containerd/defaults/main.yml) can be overriden in inventory vars. + * *http_proxy/https_proxy/no_proxy/no_proxy_exclude_workers/additional_no_proxy* - Proxy variables for deploying behind a proxy. Note that no_proxy defaults to all internal cluster IPs and hostnames that correspond to each node. + * *kubelet_cgroup_driver* - Allows manual override of the cgroup-driver option for Kubelet. By default autodetection is used to match container manager configuration. `systemd` is the preferred driver for `containerd` though it can have issues with `cgroups v1` and `kata-containers` in which case you may want to change to `cgroupfs`. + * *kubelet_rotate_certificates* - Auto rotate the kubelet client certificates by requesting new certificates from the kube-apiserver when the certificate expiration approaches. + * *kubelet_rotate_server_certificates* - Auto rotate the kubelet server certificates by requesting new certificates from the kube-apiserver when the certificate expiration approaches. **Note** that server certificates are **not** approved automatically. Approve them manually (`kubectl get csr`, `kubectl certificate approve`) or implement custom approving controller like [kubelet-rubber-stamp](https://github.com/kontena/kubelet-rubber-stamp). + * *kubelet_streaming_connection_idle_timeout* - Set the maximum time a streaming connection can be idle before the connection is automatically closed. + * *kubelet_make_iptables_util_chains* - If `true`, causes the kubelet ensures a set of `iptables` rules are present on host. -* *node_labels* - Labels applied to nodes via kubelet --node-labels parameter. + +* *kubelet_systemd_hardening* - If `true`, provides kubelet systemd service with security features for isolation. + + **N.B.** To enable this feature, ensure you are using **`cgroup v2`** on your system. Check it out with command: `sudo ls -l /sys/fs/cgroup/*.slice`. If directory does not exists, enable this with the following guide: [enable cgroup v2](https://rootlesscontaine.rs/getting-started/common/cgroup2/#enabling-cgroup-v2). + + *node_labels* - Labels applied to nodes via kubelet --node-labels parameter. For example, labels can be set in the inventory as variables or more widely in group_vars. *node_labels* can only be defined as a dict: diff --git a/roles/kubernetes/node/defaults/main.yml b/roles/kubernetes/node/defaults/main.yml index f1657c0e6ad..b268556b351 100644 --- a/roles/kubernetes/node/defaults/main.yml +++ b/roles/kubernetes/node/defaults/main.yml @@ -22,6 +22,9 @@ kubelet_kubelet_cgroups_cgroupfs: "/system.slice/kubelet.service" ### fail with swap on (default true) kubelet_fail_swap_on: true +# Set systemd service hardening features +kubelet_systemd_hardening: false + # Reserve this space for kube resources kube_memory_reserved: 256Mi kube_cpu_reserved: 100m diff --git a/roles/kubernetes/node/templates/kubelet.service.j2 b/roles/kubernetes/node/templates/kubelet.service.j2 index 38360c8df63..efb50b44a3c 100644 --- a/roles/kubernetes/node/templates/kubelet.service.j2 +++ b/roles/kubernetes/node/templates/kubelet.service.j2 @@ -24,6 +24,11 @@ ExecStart={{ bin_dir }}/kubelet \ $KUBELET_CLOUDPROVIDER Restart=always RestartSec=10s +{% if kubelet_systemd_hardening %} +# Hardening setup +IPAddressDeny=any +IPAddressAllow={{ groups['kube_control_plane'] | map('extract', hostvars, ['ansible_host']) | join(' ') }} +{% endif %} [Install] WantedBy=multi-user.target