mirror of
https://github.com/rancher/rancher-docs.git
synced 2026-09-27 05:28:22 +00:00
EIO-246: add 2.3.5, update hardening guide and self-assessment
This commit is contained in:
@@ -55,7 +55,7 @@ Each version of the hardening guide is intended to be used with specific version
|
|||||||
|
|
||||||
Hardening Guide Version | Rancher Version | CIS Benchmark Version | Kubernetes Version
|
Hardening Guide Version | Rancher Version | CIS Benchmark Version | Kubernetes Version
|
||||||
------------------------|----------------|-----------------------|------------------
|
------------------------|----------------|-----------------------|------------------
|
||||||
[Hardening Guide v2.3.4]({{<baseurl>}}/rancher/v2.x/en/security/hardening-2.3.4/) | Rancher v2.3.4 | Benchmark v1.5 | Kubernetes v1.15
|
[Hardening Guide v2.3.5]({{<baseurl>}}/rancher/v2.x/en/security/hardening-2.3.5/) | Rancher v2.3.5 | Benchmark v1.5 | Kubernetes v1.15
|
||||||
[Hardening Guide v2.3.3]({{<baseurl>}}/rancher/v2.x/en/security/hardening-2.3.3/) | Rancher v2.3.3 | Benchmark v1.4.1 | Kubernetes v1.14, v1.15, and v1.16
|
[Hardening Guide v2.3.3]({{<baseurl>}}/rancher/v2.x/en/security/hardening-2.3.3/) | Rancher v2.3.3 | Benchmark v1.4.1 | Kubernetes v1.14, v1.15, and v1.16
|
||||||
[Hardening Guide v2.3]({{<baseurl>}}/rancher/v2.x/en/security/hardening-2.3/) | Rancher v2.3.0-v2.3.2 | Benchmark v1.4.1 | Kubernetes v1.15
|
[Hardening Guide v2.3]({{<baseurl>}}/rancher/v2.x/en/security/hardening-2.3/) | Rancher v2.3.0-v2.3.2 | Benchmark v1.4.1 | Kubernetes v1.15
|
||||||
[Hardening Guide v2.2]({{<baseurl>}}/rancher/v2.x/en/security/hardening-2.2/) | Rancher v2.2.x | Benchmark v1.4.1 and 1.4.0 | Kubernetes v1.13
|
[Hardening Guide v2.2]({{<baseurl>}}/rancher/v2.x/en/security/hardening-2.2/) | Rancher v2.2.x | Benchmark v1.4.1 and 1.4.0 | Kubernetes v1.13
|
||||||
|
|||||||
+197
-533
File diff suppressed because it is too large
Load Diff
@@ -1,491 +0,0 @@
|
|||||||
---
|
|
||||||
title: Hardening Guide v2.3.4
|
|
||||||
weight: 100
|
|
||||||
---
|
|
||||||
|
|
||||||
This document provides prescriptive guidance for hardening a production installation of Rancher v2.3.4. It outlines the configurations and controls required to address Kubernetes benchmark controls from the Center for Information Security (CIS).
|
|
||||||
|
|
||||||
> This hardening guide describes how to secure the nodes in your cluster, and it is recommended to follow this guide before installing Kubernetes.
|
|
||||||
|
|
||||||
This hardening guide is intended to be used with specific versions of the CIS Kubernetes Benchmark, Kubernetes, and Rancher:
|
|
||||||
|
|
||||||
Hardening Guide Version | Rancher Version | CIS Benchmark Version | Kubernetes Version
|
|
||||||
------------------------|----------------|-----------------------|------------------
|
|
||||||
Hardening Guide v2.3.4 | Rancher v2.3.4 | Benchmark v1.5 | Kubernetes 1.15
|
|
||||||
|
|
||||||
|
|
||||||
[Click here to download a PDF version of this document](https://releases.rancher.com/documents/security/2.3.4/Rancher_Hardening_Guide.pdf)
|
|
||||||
|
|
||||||
### Overview
|
|
||||||
|
|
||||||
This document provides prescriptive guidance for hardening a production installation of Rancher v2.3.4 with Kubernetes v1.15. It outlines the configurations required to address Kubernetes benchmark controls from the Center for Information Security (CIS).
|
|
||||||
|
|
||||||
For more detail about evaluating a hardened cluster against the official CIS benchmark, refer to the [CIS Benchmark Rancher Self-Assessment Guide - Rancher v2.3.4]({{< baseurl >}}/rancher/v2.x/en/security/benchmark-2.3.4/).
|
|
||||||
|
|
||||||
### Configure Kernel Runtime Parameters
|
|
||||||
|
|
||||||
The folowing `sysctl` configuration is recommended for all nodes type in the cluster. Set the following parameters in `/etc/sysctl.d/90-kubelet.conf`:
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
vm.overcommit_memory=1
|
|
||||||
vm.panic_on_oom=0
|
|
||||||
kernel.panic=10
|
|
||||||
kernel.panic_on_oops=1
|
|
||||||
kernel.keys.root_maxkeys=1000000
|
|
||||||
kernel.keys.root_maxbytes=25000000
|
|
||||||
```
|
|
||||||
|
|
||||||
Run `sysctl -p /etc/sysctl.d/90-kubelet.conf` to enable the settings.
|
|
||||||
|
|
||||||
### Configuration Files and Permissions.
|
|
||||||
|
|
||||||
#### kubelet.conf
|
|
||||||
|
|
||||||
**path**: /etc/sysctl.d/kubelet.conf
|
|
||||||
|
|
||||||
**owner**: root:root
|
|
||||||
|
|
||||||
**permissions:** 0644
|
|
||||||
|
|
||||||
**contents**:
|
|
||||||
|
|
||||||
``` text
|
|
||||||
vm.overcommit_memory=1
|
|
||||||
kernel.panic=10
|
|
||||||
kernel.panic_on_oops=1
|
|
||||||
```
|
|
||||||
|
|
||||||
#### admission.yaml
|
|
||||||
|
|
||||||
**path**: /opt/kubernetes/admission.yaml
|
|
||||||
|
|
||||||
**owner**: root:root
|
|
||||||
|
|
||||||
**permissions**: 0600
|
|
||||||
|
|
||||||
**content**:
|
|
||||||
|
|
||||||
``` yaml
|
|
||||||
apiVersion: apiserver.k8s.io/v1alpha1
|
|
||||||
kind: AdmissionConfiguration
|
|
||||||
plugins:
|
|
||||||
- name: EventRateLimit
|
|
||||||
path: /opt/kubernetes/event.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
#### event.yaml
|
|
||||||
|
|
||||||
**path**: /opt/kubernetes/event.yaml
|
|
||||||
|
|
||||||
**owner**: root:root
|
|
||||||
|
|
||||||
**permissions**: 0600
|
|
||||||
|
|
||||||
**content**:
|
|
||||||
|
|
||||||
``` yaml
|
|
||||||
apiVersion: eventratelimit.admission.k8s.io/v1alpha1
|
|
||||||
kind: Configuration
|
|
||||||
limits:
|
|
||||||
- type: Server
|
|
||||||
qps: 5000
|
|
||||||
burst: 20000
|
|
||||||
```
|
|
||||||
|
|
||||||
#### encryption.yaml
|
|
||||||
|
|
||||||
**path**: /opt/kubernetes/encryption.yaml
|
|
||||||
|
|
||||||
**owner**: root:root
|
|
||||||
|
|
||||||
**permissions**: 0600
|
|
||||||
|
|
||||||
**content**:
|
|
||||||
|
|
||||||
``` yaml
|
|
||||||
apiVersion: apiserver.config.k8s.io/v1
|
|
||||||
kind: EncryptionConfiguration
|
|
||||||
resources:
|
|
||||||
- resources:
|
|
||||||
- secrets
|
|
||||||
providers:
|
|
||||||
- aescbc:
|
|
||||||
keys:
|
|
||||||
- name: key1
|
|
||||||
secret: <BASE 64 ENCODED SECRET>
|
|
||||||
- identity: {}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
#### audit.yaml
|
|
||||||
|
|
||||||
**path**: /opt/kubernetes/audit.yaml
|
|
||||||
|
|
||||||
**owner**: root:root
|
|
||||||
|
|
||||||
**permissions**: 0600
|
|
||||||
|
|
||||||
**content**:
|
|
||||||
|
|
||||||
``` yaml
|
|
||||||
apiVersion: audit.k8s.io/v1beta1
|
|
||||||
kind: Policy
|
|
||||||
rules:
|
|
||||||
- level: Metadata
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### Configure `etcd` user and `data-dir` permissions
|
|
||||||
|
|
||||||
#### create `etcd` user and `group`
|
|
||||||
|
|
||||||
```
|
|
||||||
addgroup --gid 52034 etcd
|
|
||||||
useradd --comment "etcd service account" --uid 52034 --gid 52034 etcd
|
|
||||||
```
|
|
||||||
|
|
||||||
#### create `data-dir` and set permissions
|
|
||||||
```
|
|
||||||
mkdir -p /var/lib/etcd && chown etcd.etcd /var/lib/etcd && chmod 0700 /var/lib/etcd
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### Hardened RKE `config.yml` configuration
|
|
||||||
|
|
||||||
``` yaml
|
|
||||||
#
|
|
||||||
# Cluster Config
|
|
||||||
#
|
|
||||||
docker_root_dir: /var/lib/docker
|
|
||||||
enable_cluster_alerting: false
|
|
||||||
enable_cluster_monitoring: false
|
|
||||||
enable_network_policy: false
|
|
||||||
#
|
|
||||||
# Rancher Config
|
|
||||||
#
|
|
||||||
rancher_kubernetes_engine_config:
|
|
||||||
addon_job_timeout: 30
|
|
||||||
addons: |-
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Namespace
|
|
||||||
metadata:
|
|
||||||
name: ingress-nginx
|
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
|
||||||
kind: Role
|
|
||||||
metadata:
|
|
||||||
name: default-psp-role
|
|
||||||
namespace: ingress-nginx
|
|
||||||
rules:
|
|
||||||
- apiGroups:
|
|
||||||
- extensions
|
|
||||||
resourceNames:
|
|
||||||
- default-psp
|
|
||||||
resources:
|
|
||||||
- podsecuritypolicies
|
|
||||||
verbs:
|
|
||||||
- use
|
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
|
||||||
kind: RoleBinding
|
|
||||||
metadata:
|
|
||||||
name: default-psp-rolebinding
|
|
||||||
namespace: ingress-nginx
|
|
||||||
roleRef:
|
|
||||||
apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: Role
|
|
||||||
name: default-psp-role
|
|
||||||
subjects:
|
|
||||||
- apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: Group
|
|
||||||
name: system:serviceaccounts
|
|
||||||
- apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: Group
|
|
||||||
name: system:authenticated
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Namespace
|
|
||||||
metadata:
|
|
||||||
name: cattle-system
|
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
|
||||||
kind: Role
|
|
||||||
metadata:
|
|
||||||
name: default-psp-role
|
|
||||||
namespace: cattle-system
|
|
||||||
rules:
|
|
||||||
- apiGroups:
|
|
||||||
- extensions
|
|
||||||
resourceNames:
|
|
||||||
- default-psp
|
|
||||||
resources:
|
|
||||||
- podsecuritypolicies
|
|
||||||
verbs:
|
|
||||||
- use
|
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
|
||||||
kind: RoleBinding
|
|
||||||
metadata:
|
|
||||||
name: default-psp-rolebinding
|
|
||||||
namespace: cattle-system
|
|
||||||
roleRef:
|
|
||||||
apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: Role
|
|
||||||
name: default-psp-role
|
|
||||||
subjects:
|
|
||||||
- apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: Group
|
|
||||||
name: system:serviceaccounts
|
|
||||||
- apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: Group
|
|
||||||
name: system:authenticated
|
|
||||||
---
|
|
||||||
apiVersion: extensions/v1beta1
|
|
||||||
kind: PodSecurityPolicy
|
|
||||||
metadata:
|
|
||||||
name: restricted
|
|
||||||
spec:
|
|
||||||
requiredDropCapabilities:
|
|
||||||
- NET_RAW
|
|
||||||
privileged: false
|
|
||||||
allowPrivilegeEscalation: false
|
|
||||||
defaultAllowPrivilegeEscalation: false
|
|
||||||
fsGroup:
|
|
||||||
rule: RunAsAny
|
|
||||||
runAsUser:
|
|
||||||
rule: MustRunAsNonRoot
|
|
||||||
seLinux:
|
|
||||||
rule: RunAsAny
|
|
||||||
supplementalGroups:
|
|
||||||
rule: RunAsAny
|
|
||||||
volumes:
|
|
||||||
- emptyDir
|
|
||||||
- secret
|
|
||||||
- persistentVolumeClaim
|
|
||||||
- downwardAPI
|
|
||||||
- configMap
|
|
||||||
- projected
|
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
|
||||||
kind: ClusterRole
|
|
||||||
metadata:
|
|
||||||
name: psp:restricted
|
|
||||||
rules:
|
|
||||||
- apiGroups:
|
|
||||||
- extensions
|
|
||||||
resourceNames:
|
|
||||||
- restricted
|
|
||||||
resources:
|
|
||||||
- podsecuritypolicies
|
|
||||||
verbs:
|
|
||||||
- use
|
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
|
||||||
kind: ClusterRoleBinding
|
|
||||||
metadata:
|
|
||||||
name: psp:restricted
|
|
||||||
roleRef:
|
|
||||||
apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: ClusterRole
|
|
||||||
name: psp:restricted
|
|
||||||
subjects:
|
|
||||||
- apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: Group
|
|
||||||
name: system:serviceaccounts
|
|
||||||
- apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: Group
|
|
||||||
name: system:authenticated
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: ServiceAccount
|
|
||||||
metadata:
|
|
||||||
name: tiller
|
|
||||||
namespace: kube-system
|
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
|
||||||
kind: ClusterRoleBinding
|
|
||||||
metadata:
|
|
||||||
name: tiller
|
|
||||||
roleRef:
|
|
||||||
apiGroup: rbac.authorization.k8s.io
|
|
||||||
kind: ClusterRole
|
|
||||||
name: cluster-admin
|
|
||||||
subjects:
|
|
||||||
- kind: ServiceAccount
|
|
||||||
name: tiller
|
|
||||||
namespace: kube-system
|
|
||||||
ignore_docker_version: true
|
|
||||||
kubernetes_version: v1.15.6-rancher1-2
|
|
||||||
#
|
|
||||||
# If you are using calico on AWS
|
|
||||||
#
|
|
||||||
# network:
|
|
||||||
# plugin: calico
|
|
||||||
# calico_network_provider:
|
|
||||||
# cloud_provider: aws
|
|
||||||
#
|
|
||||||
# # To specify flannel interface
|
|
||||||
#
|
|
||||||
# network:
|
|
||||||
# plugin: flannel
|
|
||||||
# flannel_network_provider:
|
|
||||||
# iface: eth1
|
|
||||||
#
|
|
||||||
# # To specify flannel interface for canal plugin
|
|
||||||
#
|
|
||||||
# network:
|
|
||||||
# plugin: canal
|
|
||||||
# canal_network_provider:
|
|
||||||
# iface: eth1
|
|
||||||
#
|
|
||||||
network:
|
|
||||||
mtu: 0
|
|
||||||
plugin: canal
|
|
||||||
#
|
|
||||||
# services:
|
|
||||||
# kube-api:
|
|
||||||
# service_cluster_ip_range: 10.43.0.0/16
|
|
||||||
# kube-controller:
|
|
||||||
# cluster_cidr: 10.42.0.0/16
|
|
||||||
# service_cluster_ip_range: 10.43.0.0/16
|
|
||||||
# kubelet:
|
|
||||||
# cluster_domain: cluster.local
|
|
||||||
# cluster_dns_server: 10.43.0.10
|
|
||||||
#
|
|
||||||
services:
|
|
||||||
etcd:
|
|
||||||
backup_config:
|
|
||||||
enabled: false
|
|
||||||
interval_hours: 12
|
|
||||||
retention: 6
|
|
||||||
safe_timestamp: false
|
|
||||||
creation: 12h
|
|
||||||
extra_args:
|
|
||||||
data-dir: /var/lib/etcd
|
|
||||||
extra_binds:
|
|
||||||
- '/var/lib/etcd:/var/lib/etcd'
|
|
||||||
gid: 52034
|
|
||||||
retention: 72h
|
|
||||||
snapshot: false
|
|
||||||
uid: 52034
|
|
||||||
kube_api:
|
|
||||||
always_pull_images: false
|
|
||||||
extra_args:
|
|
||||||
admission-control-config-file: /opt/kubernetes/admission.yaml
|
|
||||||
anonymous-auth: 'false'
|
|
||||||
audit-log-format: json
|
|
||||||
audit-log-maxage: '30'
|
|
||||||
audit-log-maxbackup: '10'
|
|
||||||
audit-log-maxsize: '100'
|
|
||||||
audit-log-path: /var/log/kube-audit/audit-log.json
|
|
||||||
audit-policy-file: /opt/kubernetes/audit.yaml
|
|
||||||
enable-admission-plugins: >-
|
|
||||||
ServiceAccount,NamespaceLifecycle,LimitRanger,PersistentVolumeLabel,DefaultStorageClass,ResourceQuota,DefaultTolerationSeconds,AlwaysPullImages,DenyEscalatingExec,NodeRestriction,EventRateLimit,PodSecurityPolicy
|
|
||||||
encryption-provider-config: /opt/kubernetes/encryption.yaml
|
|
||||||
profiling: 'false'
|
|
||||||
service-account-lookup: 'true'
|
|
||||||
tls-cipher-suites: >-
|
|
||||||
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_128_GCM_SHA256
|
|
||||||
extra_binds:
|
|
||||||
- '/var/log/kube-audit:/var/log/kube-audit'
|
|
||||||
- '/opt/kubernetes:/opt/kubernetes'
|
|
||||||
pod_security_policy: true
|
|
||||||
service_node_port_range: 30000-32767
|
|
||||||
kube_controller:
|
|
||||||
extra_args:
|
|
||||||
address: 127.0.0.1
|
|
||||||
feature-gates: RotateKubeletServerCertificate=true
|
|
||||||
profiling: 'false'
|
|
||||||
terminated-pod-gc-threshold: '1000'
|
|
||||||
kubelet:
|
|
||||||
extra_args:
|
|
||||||
anonymous-auth: 'false'
|
|
||||||
event-qps: '0'
|
|
||||||
feature-gates: RotateKubeletServerCertificate=true
|
|
||||||
make-iptables-util-chains: 'true'
|
|
||||||
protect-kernel-defaults: 'true'
|
|
||||||
streaming-connection-idle-timeout: 1800s
|
|
||||||
tls-cipher-suites: >-
|
|
||||||
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_128_GCM_SHA256
|
|
||||||
fail_swap_on: false
|
|
||||||
generate_serving_certificate: true
|
|
||||||
scheduler:
|
|
||||||
extra_args:
|
|
||||||
address: 127.0.0.1
|
|
||||||
profiling: 'false'
|
|
||||||
ssh_agent_auth: false
|
|
||||||
windows_prefered_cluster: false
|
|
||||||
```
|
|
||||||
|
|
||||||
### Hardened Example Ubuntu cloud-config:
|
|
||||||
|
|
||||||
``` yaml
|
|
||||||
#cloud-config
|
|
||||||
package_update: false
|
|
||||||
packages:
|
|
||||||
- curl
|
|
||||||
- jq
|
|
||||||
runcmd:
|
|
||||||
- sysctl -w vm.overcommit_memory=1
|
|
||||||
- sysctl -w kernel.panic=10
|
|
||||||
- sysctl -w kernel.panic_on_oops=1
|
|
||||||
- curl https://releases.rancher.com/install-docker/18.09.sh | sh
|
|
||||||
- usermod -aG docker ubuntu
|
|
||||||
- return=1; while [ $return != 0 ]; do sleep 2; docker ps; return=$?; done
|
|
||||||
- addgroup --gid 52034 etcd
|
|
||||||
- useradd --comment "etcd service account" --uid 52034 --gid 52034 etcd
|
|
||||||
- mkdir -p /var/lib/etcd && chown etcd.etcd /var/lib/etcd && chmod 0700 /var/lib/etcd
|
|
||||||
- ${agent_cmd} --etcd --controlplane --worker
|
|
||||||
- mkdir /mnt/kube-bench
|
|
||||||
write_files:
|
|
||||||
- path: /etc/sysctl.d/kubelet.conf
|
|
||||||
owner: root:root
|
|
||||||
permissions: "0644"
|
|
||||||
content: |
|
|
||||||
vm.overcommit_memory=1
|
|
||||||
kernel.panic=10
|
|
||||||
kernel.panic_on_oops=1
|
|
||||||
- path: /opt/kubernetes/admission.yaml
|
|
||||||
owner: root:root
|
|
||||||
permissions: "0600"
|
|
||||||
content: |
|
|
||||||
apiVersion: apiserver.k8s.io/v1alpha1
|
|
||||||
kind: AdmissionConfiguration
|
|
||||||
plugins:
|
|
||||||
- name: EventRateLimit
|
|
||||||
path: /opt/kubernetes/event.yaml
|
|
||||||
- path: /opt/kubernetes/event.yaml
|
|
||||||
owner: root:root
|
|
||||||
permissions: "0600"
|
|
||||||
content: |
|
|
||||||
apiVersion: eventratelimit.admission.k8s.io/v1alpha1
|
|
||||||
kind: Configuration
|
|
||||||
limits:
|
|
||||||
- type: Server
|
|
||||||
qps: 5000
|
|
||||||
burst: 20000
|
|
||||||
- path: /opt/kubernetes/encryption.yaml
|
|
||||||
owner: root:root
|
|
||||||
permissions: "0600"
|
|
||||||
content: |
|
|
||||||
apiVersion: apiserver.config.k8s.io/v1
|
|
||||||
kind: EncryptionConfiguration
|
|
||||||
resources:
|
|
||||||
- resources:
|
|
||||||
- secrets
|
|
||||||
providers:
|
|
||||||
- aescbc:
|
|
||||||
keys:
|
|
||||||
- name: key1
|
|
||||||
secret: LF7YiCFyWqAa2MovOgp42rArBdLBGWdjJpX2knvYAkc=
|
|
||||||
- identity: {}
|
|
||||||
- path: /opt/kubernetes/audit.yaml
|
|
||||||
owner: root:root
|
|
||||||
permissions: "0600"
|
|
||||||
content: |
|
|
||||||
apiVersion: audit.k8s.io/v1beta1
|
|
||||||
kind: Policy
|
|
||||||
rules:
|
|
||||||
- level: Metadata
|
|
||||||
```
|
|
||||||
@@ -0,0 +1,424 @@
|
|||||||
|
---
|
||||||
|
title: Hardening Guide v2.3.5
|
||||||
|
weight: 100
|
||||||
|
---
|
||||||
|
|
||||||
|
This document provides prescriptive guidance for hardening a production installation of Rancher v2.3.5. It outlines the configurations and controls required to address Kubernetes benchmark controls from the Center for Information Security (CIS).
|
||||||
|
|
||||||
|
> This hardening guide describes how to secure the nodes in your cluster, and it is recommended to follow this guide before installing Kubernetes.
|
||||||
|
|
||||||
|
This hardening guide is intended to be used with specific versions of the CIS Kubernetes Benchmark, Kubernetes, and Rancher:
|
||||||
|
|
||||||
|
Hardening Guide Version | Rancher Version | CIS Benchmark Version | Kubernetes Version
|
||||||
|
------------------------|----------------|-----------------------|------------------
|
||||||
|
Hardening Guide v2.3.5 | Rancher v2.3.5 | Benchmark v1.5 | Kubernetes 1.15
|
||||||
|
|
||||||
|
|
||||||
|
[Click here to download a PDF version of this document](https://releases.rancher.com/documents/security/2.3.5/Rancher_Hardening_Guide.pdf)
|
||||||
|
|
||||||
|
### Overview
|
||||||
|
|
||||||
|
This document provides prescriptive guidance for hardening a production installation of Rancher v2.3.5 with Kubernetes v1.15. It outlines the configurations required to address Kubernetes benchmark controls from the Center for Information Security (CIS).
|
||||||
|
|
||||||
|
For more detail about evaluating a hardened cluster against the official CIS benchmark, refer to the [CIS Benchmark Rancher Self-Assessment Guide - Rancher v2.3.5]({{< baseurl >}}/rancher/v2.x/en/security/benchmark-2.3.5/).
|
||||||
|
|
||||||
|
### Configure Kernel Runtime Parameters
|
||||||
|
|
||||||
|
The folowing `sysctl` configuration is recommended for all nodes type in the cluster. Set the following parameters in `/etc/sysctl.d/90-kubelet.conf`:
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
vm.overcommit_memory=1
|
||||||
|
vm.panic_on_oom=0
|
||||||
|
kernel.panic=10
|
||||||
|
kernel.panic_on_oops=1
|
||||||
|
kernel.keys.root_maxbytes=25000000
|
||||||
|
```
|
||||||
|
|
||||||
|
Run `sysctl -p /etc/sysctl.d/90-kubelet.conf` to enable the settings.
|
||||||
|
|
||||||
|
### Configure `etcd` user and group
|
||||||
|
A user account and group for the **etcd** service is required to be setup prior to installing RKE. The **uid** and **gid** for the **etcd** user will be used in the RKE **config.yml** to set the proper permissions for files and directories during installation time.
|
||||||
|
|
||||||
|
#### create `etcd` user and group
|
||||||
|
To create the **etcd** group run the following console commands.
|
||||||
|
|
||||||
|
```
|
||||||
|
addgroup --gid 52034 etcd
|
||||||
|
useradd --comment "etcd service account" --uid 52034 --gid 52034 etcd
|
||||||
|
```
|
||||||
|
|
||||||
|
Update the RKE **config.yml** with the **uid** and **gid** of the **etcd** user:
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
services:
|
||||||
|
etcd:
|
||||||
|
gid: 52034
|
||||||
|
uid: 52034
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 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.
|
||||||
|
|
||||||
|
For each namespace the **default** service account must include this value:
|
||||||
|
|
||||||
|
```
|
||||||
|
automountServiceAccountToken: false
|
||||||
|
```
|
||||||
|
|
||||||
|
Save the following yaml to a file called `account_update.yaml`
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: default
|
||||||
|
automountServiceAccountToken: false
|
||||||
|
```
|
||||||
|
|
||||||
|
Create a bash script file called `account_update.sh`. Be sure to `chmod +x account_update.sh` so the script has execute permissions.
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
for namespace in $(kubectl get namespaces -A -o json | jq -r '.items[].metadata.name'); do
|
||||||
|
kubectl patch serviceaccount default -n ${namespace} -p "$(cat account_update.yaml)"
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ensure that all Namespaces have Network Policies defined
|
||||||
|
|
||||||
|
Running different applications on the same Kubernetes cluster creates a risk of one
|
||||||
|
compromised application attacking a neighboring application. Network segmentation is
|
||||||
|
important to ensure that containers can communicate only with those they are supposed
|
||||||
|
to. A network policy is a specification of how selections of pods are allowed to
|
||||||
|
communicate with each other and other network endpoints.
|
||||||
|
|
||||||
|
Network Policies are namespace scoped. When a network policy is introduced to a given
|
||||||
|
namespace, all traffic not allowed by the policy is denied. However, if there are no network
|
||||||
|
policies in a namespace all traffic will be allowed into and out of the pods in that
|
||||||
|
namespace.
|
||||||
|
|
||||||
|
> todo: add information about network policies and provide default example here:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Reference Hardened RKE `config.yml` configuration
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
# If you intened to deploy Kubernetes in an air-gapped environment,
|
||||||
|
# please consult the documentation on how to configure custom RKE images.
|
||||||
|
kubernetes_version: "v1.15.9-rancher1-1"
|
||||||
|
enable_network_policy: true
|
||||||
|
default_pod_security_policy_template_id: "restricted"
|
||||||
|
nodes:
|
||||||
|
- address: "172.16.16.9"
|
||||||
|
port: ""
|
||||||
|
internal_address: ""
|
||||||
|
role:
|
||||||
|
- controlplane
|
||||||
|
- etcd
|
||||||
|
- worker
|
||||||
|
hostname_override: ""
|
||||||
|
user: "ubuntu"
|
||||||
|
services:
|
||||||
|
etcd:
|
||||||
|
uid: 52034
|
||||||
|
gid: 52034
|
||||||
|
kube-api:
|
||||||
|
pod_security_policy: true
|
||||||
|
secrets_encryption_config:
|
||||||
|
enabled: true
|
||||||
|
audit_log:
|
||||||
|
enabled: true
|
||||||
|
admission_configuration:
|
||||||
|
event_rate_limit:
|
||||||
|
enabled: true
|
||||||
|
kube-controller:
|
||||||
|
extra_args:
|
||||||
|
feature-gates: "RotateKubeletServerCertificate=true"
|
||||||
|
scheduler:
|
||||||
|
image: ""
|
||||||
|
extra_args: {}
|
||||||
|
extra_binds: []
|
||||||
|
extra_env: []
|
||||||
|
kubelet:
|
||||||
|
generate_serving_certificate: true
|
||||||
|
extra_args:
|
||||||
|
feature-gates: "RotateKubeletServerCertificate=true"
|
||||||
|
protect-kernel-defaults: "true"
|
||||||
|
tls-cipher-suites: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_128_GCM_SHA256"
|
||||||
|
extra_binds: []
|
||||||
|
extra_env: []
|
||||||
|
cluster_domain: ""
|
||||||
|
infra_container_image: ""
|
||||||
|
cluster_dns_server: ""
|
||||||
|
fail_swap_on: false
|
||||||
|
generate_serving_certificate: true
|
||||||
|
kubeproxy:
|
||||||
|
image: ""
|
||||||
|
extra_args: {}
|
||||||
|
extra_binds: []
|
||||||
|
extra_env: []
|
||||||
|
network:
|
||||||
|
plugin: ""
|
||||||
|
options: {}
|
||||||
|
mtu: 0
|
||||||
|
node_selector: {}
|
||||||
|
authentication:
|
||||||
|
strategy: ""
|
||||||
|
sans: []
|
||||||
|
webhook: null
|
||||||
|
addons: |
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: ingress-nginx
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: Role
|
||||||
|
metadata:
|
||||||
|
name: default-psp-role
|
||||||
|
namespace: ingress-nginx
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- extensions
|
||||||
|
resourceNames:
|
||||||
|
- default-psp
|
||||||
|
resources:
|
||||||
|
- podsecuritypolicies
|
||||||
|
verbs:
|
||||||
|
- use
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: RoleBinding
|
||||||
|
metadata:
|
||||||
|
name: default-psp-rolebinding
|
||||||
|
namespace: ingress-nginx
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Role
|
||||||
|
name: default-psp-role
|
||||||
|
subjects:
|
||||||
|
- apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Group
|
||||||
|
name: system:serviceaccounts
|
||||||
|
- apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Group
|
||||||
|
name: system:authenticated
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: cattle-system
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: Role
|
||||||
|
metadata:
|
||||||
|
name: default-psp-role
|
||||||
|
namespace: cattle-system
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- extensions
|
||||||
|
resourceNames:
|
||||||
|
- default-psp
|
||||||
|
resources:
|
||||||
|
- podsecuritypolicies
|
||||||
|
verbs:
|
||||||
|
- use
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: RoleBinding
|
||||||
|
metadata:
|
||||||
|
name: default-psp-rolebinding
|
||||||
|
namespace: cattle-system
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Role
|
||||||
|
name: default-psp-role
|
||||||
|
subjects:
|
||||||
|
- apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Group
|
||||||
|
name: system:serviceaccounts
|
||||||
|
- apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Group
|
||||||
|
name: system:authenticated
|
||||||
|
---
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
kind: PodSecurityPolicy
|
||||||
|
metadata:
|
||||||
|
name: restricted
|
||||||
|
spec:
|
||||||
|
requiredDropCapabilities:
|
||||||
|
- NET_RAW
|
||||||
|
privileged: false
|
||||||
|
allowPrivilegeEscalation: false
|
||||||
|
defaultAllowPrivilegeEscalation: false
|
||||||
|
fsGroup:
|
||||||
|
rule: RunAsAny
|
||||||
|
runAsUser:
|
||||||
|
rule: MustRunAsNonRoot
|
||||||
|
seLinux:
|
||||||
|
rule: RunAsAny
|
||||||
|
supplementalGroups:
|
||||||
|
rule: RunAsAny
|
||||||
|
volumes:
|
||||||
|
- emptyDir
|
||||||
|
- secret
|
||||||
|
- persistentVolumeClaim
|
||||||
|
- downwardAPI
|
||||||
|
- configMap
|
||||||
|
- projected
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
name: psp:restricted
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- extensions
|
||||||
|
resourceNames:
|
||||||
|
- restricted
|
||||||
|
resources:
|
||||||
|
- podsecuritypolicies
|
||||||
|
verbs:
|
||||||
|
- use
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: psp:restricted
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: psp:restricted
|
||||||
|
subjects:
|
||||||
|
- apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Group
|
||||||
|
name: system:serviceaccounts
|
||||||
|
- apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: Group
|
||||||
|
name: system:authenticated
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: tiller
|
||||||
|
namespace: kube-system
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: tiller
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: cluster-admin
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: tiller
|
||||||
|
namespace: kube-system
|
||||||
|
|
||||||
|
addons_include: []
|
||||||
|
system_images:
|
||||||
|
etcd: ""
|
||||||
|
alpine: ""
|
||||||
|
nginx_proxy: ""
|
||||||
|
cert_downloader: ""
|
||||||
|
kubernetes_services_sidecar: ""
|
||||||
|
kubedns: ""
|
||||||
|
dnsmasq: ""
|
||||||
|
kubedns_sidecar: ""
|
||||||
|
kubedns_autoscaler: ""
|
||||||
|
coredns: ""
|
||||||
|
coredns_autoscaler: ""
|
||||||
|
kubernetes: ""
|
||||||
|
flannel: ""
|
||||||
|
flannel_cni: ""
|
||||||
|
calico_node: ""
|
||||||
|
calico_cni: ""
|
||||||
|
calico_controllers: ""
|
||||||
|
calico_ctl: ""
|
||||||
|
calico_flexvol: ""
|
||||||
|
canal_node: ""
|
||||||
|
canal_cni: ""
|
||||||
|
canal_flannel: ""
|
||||||
|
canal_flexvol: ""
|
||||||
|
weave_node: ""
|
||||||
|
weave_cni: ""
|
||||||
|
pod_infra_container: ""
|
||||||
|
ingress: ""
|
||||||
|
ingress_backend: ""
|
||||||
|
metrics_server: ""
|
||||||
|
windows_pod_infra_container: ""
|
||||||
|
ssh_key_path: ""
|
||||||
|
ssh_cert_path: ""
|
||||||
|
ssh_agent_auth: false
|
||||||
|
authorization:
|
||||||
|
mode: ""
|
||||||
|
options: {}
|
||||||
|
ignore_docker_version: false
|
||||||
|
private_registries: []
|
||||||
|
ingress:
|
||||||
|
provider: ""
|
||||||
|
options: {}
|
||||||
|
node_selector: {}
|
||||||
|
extra_args: {}
|
||||||
|
dns_policy: ""
|
||||||
|
extra_envs: []
|
||||||
|
extra_volumes: []
|
||||||
|
extra_volume_mounts: []
|
||||||
|
cluster_name: ""
|
||||||
|
prefix_path: ""
|
||||||
|
addon_job_timeout: 0
|
||||||
|
bastion_host:
|
||||||
|
address: ""
|
||||||
|
port: ""
|
||||||
|
user: ""
|
||||||
|
ssh_key: ""
|
||||||
|
ssh_key_path: ""
|
||||||
|
ssh_cert: ""
|
||||||
|
ssh_cert_path: ""
|
||||||
|
monitoring:
|
||||||
|
provider: ""
|
||||||
|
options: {}
|
||||||
|
node_selector: {}
|
||||||
|
restore:
|
||||||
|
restore: false
|
||||||
|
snapshot_name: ""
|
||||||
|
dns: null
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reference Hardened RKE Template configuration
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
todo:
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Hardened Reference Ubuntu **cloud-config**:
|
||||||
|
|
||||||
|
``` yaml
|
||||||
|
#cloud-config
|
||||||
|
packages:
|
||||||
|
- curl
|
||||||
|
- jq
|
||||||
|
runcmd:
|
||||||
|
- sysctl -w vm.overcommit_memory=1
|
||||||
|
- sysctl -w kernel.panic=10
|
||||||
|
- sysctl -w kernel.panic_on_oops=1
|
||||||
|
- curl https://releases.rancher.com/install-docker/18.09.sh | sh
|
||||||
|
- usermod -aG docker ubuntu
|
||||||
|
- return=1; while [ $return != 0 ]; do sleep 2; docker ps; return=$?; done
|
||||||
|
- addgroup --gid 52034 etcd
|
||||||
|
- useradd --comment "etcd service account" --uid 52034 --gid 52034 etcd
|
||||||
|
write_files:
|
||||||
|
- path: /etc/sysctl.d/kubelet.conf
|
||||||
|
owner: root:root
|
||||||
|
permissions: "0644"
|
||||||
|
content: |
|
||||||
|
vm.overcommit_memory=1
|
||||||
|
kernel.panic=10
|
||||||
|
kernel.panic_on_oops=1
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user