mirror of
https://github.com/rancher/rancher-docs.git
synced 2026-05-05 20:53:33 +00:00
Add v2.13 preview docs
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
---
|
||||
title: Rancher 自我评估和加固指南
|
||||
---
|
||||
|
||||
<head>
|
||||
<link rel="canonical" href="https://ranchermanager.docs.rancher.com/zh/reference-guides/rancher-security/hardening-guides"/>
|
||||
</head>
|
||||
|
||||
Rancher 为每个受支持的 Rancher 版本的 Kubernetes 发行版提供了特定的安全强化指南。
|
||||
|
||||
## Rancher Kubernetes 发行版
|
||||
|
||||
Rancher 使用以下 Kubernetes 发行版:
|
||||
|
||||
- [**RKE2**](https://docs.rke2.io/) 是一个完全合规的 Kubernetes 发行版,专注于安全和合规性。
|
||||
- [**K3s**](https://docs.k3s.io/) 是一个完全合规的,轻量级 Kubernetes 发行版。它易于安装,内存需求只有上游 Kubernetes 的一半,所有组件都在一个小于 100 MB 的二进制文件中。
|
||||
|
||||
要加固运行未列出的发行版的 Kubernetes 集群,请参阅 Kubernetes 提供商文档。
|
||||
|
||||
## 加固指南和 Benchmark 版本
|
||||
|
||||
每个自我评估指南都附有强化指南。这些指南与列出的 Rancher 版本一起进行了测试。每个自我评估指南都在特定的 Kubernetes 版本和 CIS Benchmark 版本上进行了测试。如果 CIS Benchmark 尚未针对你的 Kubernetes 版本进行验证,你可以使用现有指南,直到添加适合你的版本的指南。
|
||||
|
||||
### RKE2 指南
|
||||
|
||||
| 类型 | Kubernetes 版本 | CIS Benchmark 版本 | 自我评估指南 | 加固指南 |
|
||||
|------|--------------------|-----------------------|-----------------------|------------------|
|
||||
| Rancher provisioned RKE2 | Kubernetes v1.25/v1.26/v1.27 | CIS v1.7 | [链接](rke2-hardening-guide/rke2-self-assessment-guide-with-cis-v1.7-k8s-v1.25-v1.26-v1.27.md) | [链接](rke2-hardening-guide/rke2-hardening-guide.md) |
|
||||
| Standalone RKE2 | Kubernetes v1.27-v1.32 | CIS v1.9 | [链接](https://docs.rke2.io/security/cis_self_assessment19) | [链接](https://docs.rke2.io/security/hardening_guide) |
|
||||
|
||||
### K3s 指南
|
||||
|
||||
| 类型 | Kubernetes 版本 | CIS Benchmark 版本 | 自我评估指南 | 加固指南 |
|
||||
|------|--------------------|-----------------------|-----------------------|------------------|
|
||||
| Rancher provisioned K3s cluster | Kubernetes v1.25/v1.26/v1.27 | CIS v1.7 | [链接](k3s-hardening-guide/k3s-self-assessment-guide-with-cis-v1.7-k8s-v1.25-v1.26-v1.27.md) | [链接](k3s-hardening-guide/k3s-hardening-guide.md) |
|
||||
| Standalone K3s | Kubernetes v1.26 up to v1.29 | CIS v1.8 | [链接](https://docs.k3s.io/security/self-assessment-1.8) | [链接](https://docs.k3s.io/security/hardening-guide) |
|
||||
|
||||
## 在 SELinux 上使用 Rancher
|
||||
|
||||
[Security-Enhanced Linux (SELinux)](https://en.wikipedia.org/wiki/Security-Enhanced_Linux) 是一个内核模块,为 Linux 添加了额外的访问控制和安全工具。SELinux 过去曾被政府机构使用,现在已成为行业标准。SELinux 在 RHEL 和 CentOS 上默认启用。
|
||||
|
||||
要将 Rancher 与 SELinux 结合使用,我们建议[安装](../selinux-rpm/about-rancher-selinux.md) `rancher-selinux`。
|
||||
+744
@@ -0,0 +1,744 @@
|
||||
---
|
||||
title: K3s 加固指南
|
||||
---
|
||||
|
||||
<head>
|
||||
<link rel="canonical" href="https://ranchermanager.docs.rancher.com/zh/reference-guides/rancher-security/hardening-guides/k3s-hardening-guide"/>
|
||||
</head>
|
||||
|
||||
本文档提供了针对生产环境的 K3s 集群进行加固的具体指导,以便在使用 Rancher 部署之前进行配置。它概述了满足信息安全中心(Center for Information Security, CIS)Kubernetes benchmark controls 所需的配置和控制。
|
||||
|
||||
:::note
|
||||
这份加固指南描述了如何确保你集群中的节点安全。我们建议你在安装 Kubernetes 之前遵循本指南。
|
||||
:::
|
||||
|
||||
此加固指南适用于 K3s 集群,并与以下版本的 CIS Kubernetes Benchmark、Kubernetes 和 Rancher 相关联:
|
||||
|
||||
| Rancher 版本 | CIS Benchmark 版本 | Kubernetes 版本 |
|
||||
|-----------------|-----------------------|------------------------------|
|
||||
| Rancher v2.7 | Benchmark v1.23 | Kubernetes v1.23 |
|
||||
| Rancher v2.7 | Benchmark v1.24 | Kubernetes v1.24 |
|
||||
| Rancher v2.7 | Benchmark v1.7 | Kubernetes v1.25 至 v1.26 |
|
||||
|
||||
:::note
|
||||
在 Benchmark v1.7 中,不再需要 `--protect-kernel-defaults` (4.2.6) 参数,并已被 CIS 删除。
|
||||
:::
|
||||
|
||||
有关如何评估加固的 K3s 集群与官方 CIS benchmark 的更多细节,请参考特定 Kubernetes 和 CIS benchmark 版本的 K3s 自我评估指南。
|
||||
|
||||
K3s 在不需要修改的情况下通过了许多 Kubernetes CIS controls,因为它默认应用了几个安全缓解措施。然而,有一些值得注意的例外情况,需要手动干预才能完全符合 CIS Benchmark 要求:
|
||||
|
||||
1. K3s 不修改主机操作系统。任何主机级别的修改都需要手动完成。
|
||||
2. 某些 CIS policy controls,例如 `NetworkPolicies` 和 `PodSecurityStandards`(在 v1.24 及更早版本中为 `PodSecurityPolicies`),会限制集群功能。
|
||||
你必须选择让 K3s 配置这些策略。在你的命令行标志或配置文件中添加相应的选项(启用准入插件),并手动应用适当的策略。
|
||||
请参阅以下详细信息。
|
||||
|
||||
CIS Benchmark 的第一部分(1.1)主要关注于 Pod manifest 的权限和所有权。由于发行版中的所有内容都打包在一个二进制文件中,因此这一部分不适用于 K3s 的核心组件。
|
||||
|
||||
## 主机级别要求
|
||||
|
||||
### 确保 `protect-kernel-defaults`已经设置
|
||||
|
||||
<Tabs groupId="k3s-version">
|
||||
<TabItem value="v1.25 及更新版本" default>
|
||||
|
||||
自 CIS benchmark 1.7 开始,不再需要`protect-kernel-defaults`。
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="v1.24 及更早版本">
|
||||
|
||||
这是一个 kubelet 标志,如果所需的内核参数未设置或设置为与 kubelet 的默认值不同的值,将导致 kubelet 退出。
|
||||
|
||||
可以在 Rancher 的集群配置中设置 `protect-kernel-defaults` 标志。
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
rkeConfig:
|
||||
machineSelectorConfig:
|
||||
- config:
|
||||
protect-kernel-defaults: true
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### 设置内核参数
|
||||
|
||||
建议为集群中的所有节点类型设置以下 `sysctl` 配置。在 `/etc/sysctl.d/90-kubelet.conf` 中设置以下参数:
|
||||
|
||||
```ini
|
||||
vm.panic_on_oom=0
|
||||
vm.overcommit_memory=1
|
||||
kernel.panic=10
|
||||
kernel.panic_on_oops=1
|
||||
```
|
||||
|
||||
运行 `sudo sysctl -p /etc/sysctl.d/90-kubelet.conf` 以启用设置。
|
||||
|
||||
此配置需要在设置 kubelet 标志之前完成,否则 K3s 将无法启动。
|
||||
|
||||
## Kubernetes 运行时要求
|
||||
|
||||
CIS Benchmark 的运行时要求主要围绕 Pod 安全(通过 PSA)、网络策略和 API 服务器审计日志展开。
|
||||
|
||||
默认情况下,K3s 不包含任何 Pod 安全或网络策略。然而,K3s 附带一个控制器,可以强制执行你创建的任何网络策略。默认情况下,K3s 启用了 `PodSecurity` 和 `NodeRestriction` 等多个准入控制器。
|
||||
|
||||
### Pod 安全
|
||||
|
||||
<Tabs groupId="k3s-version">
|
||||
<TabItem value="v1.25 及更新版本" default>
|
||||
|
||||
K3s v1.25 及更新版本支持 [Pod 安全准入(PSA)](https://kubernetes.io/docs/concepts/security/pod-security-admission/),用于控制 Pod 安全性。
|
||||
|
||||
你可以在 Rancher 中通过集群配置,设置 `defaultPodSecurityAdmissionConfigurationTemplateName` 字段来指定 PSA 配置:
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
defaultPodSecurityAdmissionConfigurationTemplateName: rancher-restricted
|
||||
```
|
||||
|
||||
Rancher 提供了 `rancher-restricted` 模板,用于强制执行高度限制性的 Kubernetes 上游 [`Restricted`](https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted) 配置文件,其中包含了 Pod 加固的最佳实践。
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="v1.24 及更早版本">
|
||||
|
||||
K3s v1.24 及更早版本支持 [Pod 安全策略 (PSP)](https://github.com/kubernetes/website/blob/release-1.24/content/en/docs/concepts/security/pod-security-policy.md) 以控制 Pod 安全性。
|
||||
|
||||
你可以在 Rancher 中通过集群配置,传递以下标志来启用 PSPs:
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
rkeConfig:
|
||||
machineGlobalConfig:
|
||||
kube-apiserver-arg:
|
||||
- enable-admission-plugins=NodeRestriction,PodSecurityPolicy,ServiceAccount
|
||||
```
|
||||
|
||||
这会保留 `NodeRestriction` 插件并启用 `PodSecurityPolicy`。
|
||||
|
||||
启用 PSPs 后,你可以应用策略来满足 CIS Benchmark 第 5.2 节中描述的必要控制。
|
||||
|
||||
:::note
|
||||
这些是 CIS Benchmark 中的手动检查。CIS 扫描结果将标记为 `warning`,因为需要集群操作员进行手动检查。
|
||||
:::
|
||||
|
||||
以下是合规的 PSP 示例:
|
||||
|
||||
```yaml
|
||||
---
|
||||
apiVersion: policy/v1beta1
|
||||
kind: PodSecurityPolicy
|
||||
metadata:
|
||||
name: restricted-psp
|
||||
spec:
|
||||
privileged: false # CIS - 5.2.1
|
||||
allowPrivilegeEscalation: false # CIS - 5.2.5
|
||||
requiredDropCapabilities: # CIS - 5.2.7/8/9
|
||||
- ALL
|
||||
volumes:
|
||||
- 'configMap'
|
||||
- 'emptyDir'
|
||||
- 'projected'
|
||||
- 'secret'
|
||||
- 'downwardAPI'
|
||||
- 'csi'
|
||||
- 'persistentVolumeClaim'
|
||||
- 'ephemeral'
|
||||
hostNetwork: false # CIS - 5.2.4
|
||||
hostIPC: false # CIS - 5.2.3
|
||||
hostPID: false # CIS - 5.2.2
|
||||
runAsUser:
|
||||
rule: 'MustRunAsNonRoot' # CIS - 5.2.6
|
||||
seLinux:
|
||||
rule: 'RunAsAny'
|
||||
supplementalGroups:
|
||||
rule: 'MustRunAs'
|
||||
ranges:
|
||||
- min: 1
|
||||
max: 65535
|
||||
fsGroup:
|
||||
rule: 'MustRunAs'
|
||||
ranges:
|
||||
- min: 1
|
||||
max: 65535
|
||||
readOnlyRootFilesystem: false
|
||||
```
|
||||
|
||||
要使示例 PSP 生效,我们需要创建一个 `ClusterRole` 和 一个`ClusterRoleBinding`。我们还需要为需要额外权限的系统级 Pod 提供“系统无限制策略”,以及允许必要的 sysctls 来实现 ServiceLB 完整功能的额外策略。
|
||||
|
||||
```yaml
|
||||
---
|
||||
apiVersion: policy/v1beta1
|
||||
kind: PodSecurityPolicy
|
||||
metadata:
|
||||
name: restricted-psp
|
||||
spec:
|
||||
privileged: false
|
||||
allowPrivilegeEscalation: false
|
||||
requiredDropCapabilities:
|
||||
- ALL
|
||||
volumes:
|
||||
- 'configMap'
|
||||
- 'emptyDir'
|
||||
- 'projected'
|
||||
- 'secret'
|
||||
- 'downwardAPI'
|
||||
- 'csi'
|
||||
- 'persistentVolumeClaim'
|
||||
- 'ephemeral'
|
||||
hostNetwork: false
|
||||
hostIPC: false
|
||||
hostPID: false
|
||||
runAsUser:
|
||||
rule: 'MustRunAsNonRoot'
|
||||
seLinux:
|
||||
rule: 'RunAsAny'
|
||||
supplementalGroups:
|
||||
rule: 'MustRunAs'
|
||||
ranges:
|
||||
- min: 1
|
||||
max: 65535
|
||||
fsGroup:
|
||||
rule: 'MustRunAs'
|
||||
ranges:
|
||||
- min: 1
|
||||
max: 65535
|
||||
readOnlyRootFilesystem: false
|
||||
---
|
||||
apiVersion: policy/v1beta1
|
||||
kind: PodSecurityPolicy
|
||||
metadata:
|
||||
name: system-unrestricted-psp
|
||||
annotations:
|
||||
seccomp.security.alpha.kubernetes.io/allowedProfileNames: '*'
|
||||
spec:
|
||||
allowPrivilegeEscalation: true
|
||||
allowedCapabilities:
|
||||
- '*'
|
||||
fsGroup:
|
||||
rule: RunAsAny
|
||||
hostIPC: true
|
||||
hostNetwork: true
|
||||
hostPID: true
|
||||
hostPorts:
|
||||
- max: 65535
|
||||
min: 0
|
||||
privileged: true
|
||||
runAsUser:
|
||||
rule: RunAsAny
|
||||
seLinux:
|
||||
rule: RunAsAny
|
||||
supplementalGroups:
|
||||
rule: RunAsAny
|
||||
volumes:
|
||||
- '*'
|
||||
---
|
||||
apiVersion: policy/v1beta1
|
||||
kind: PodSecurityPolicy
|
||||
metadata:
|
||||
name: svclb-psp
|
||||
annotations:
|
||||
seccomp.security.alpha.kubernetes.io/allowedProfileNames: '*'
|
||||
spec:
|
||||
allowPrivilegeEscalation: false
|
||||
allowedCapabilities:
|
||||
- NET_ADMIN
|
||||
allowedUnsafeSysctls:
|
||||
- net.ipv4.ip_forward
|
||||
- net.ipv6.conf.all.forwarding
|
||||
fsGroup:
|
||||
rule: RunAsAny
|
||||
hostPorts:
|
||||
- max: 65535
|
||||
min: 0
|
||||
runAsUser:
|
||||
rule: RunAsAny
|
||||
seLinux:
|
||||
rule: RunAsAny
|
||||
supplementalGroups:
|
||||
rule: RunAsAny
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: psp:restricted-psp
|
||||
rules:
|
||||
- apiGroups:
|
||||
- policy
|
||||
resources:
|
||||
- podsecuritypolicies
|
||||
verbs:
|
||||
- use
|
||||
resourceNames:
|
||||
- restricted-psp
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: psp:system-unrestricted-psp
|
||||
rules:
|
||||
- apiGroups:
|
||||
- policy
|
||||
resources:
|
||||
- podsecuritypolicies
|
||||
resourceNames:
|
||||
- system-unrestricted-psp
|
||||
verbs:
|
||||
- use
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: psp:svclb-psp
|
||||
rules:
|
||||
- apiGroups:
|
||||
- policy
|
||||
resources:
|
||||
- podsecuritypolicies
|
||||
resourceNames:
|
||||
- svclb-psp
|
||||
verbs:
|
||||
- use
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: psp:svc-local-path-provisioner-psp
|
||||
rules:
|
||||
- apiGroups:
|
||||
- policy
|
||||
resources:
|
||||
- podsecuritypolicies
|
||||
resourceNames:
|
||||
- system-unrestricted-psp
|
||||
verbs:
|
||||
- use
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: psp:svc-coredns-psp
|
||||
rules:
|
||||
- apiGroups:
|
||||
- policy
|
||||
resources:
|
||||
- podsecuritypolicies
|
||||
resourceNames:
|
||||
- system-unrestricted-psp
|
||||
verbs:
|
||||
- use
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: psp:svc-cis-operator-psp
|
||||
rules:
|
||||
- apiGroups:
|
||||
- policy
|
||||
resources:
|
||||
- podsecuritypolicies
|
||||
resourceNames:
|
||||
- system-unrestricted-psp
|
||||
verbs:
|
||||
- use
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: default:restricted-psp
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: psp:restricted-psp
|
||||
subjects:
|
||||
- kind: Group
|
||||
name: system:authenticated
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: system-unrestricted-node-psp-rolebinding
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: psp:system-unrestricted-psp
|
||||
subjects:
|
||||
- apiGroup: rbac.authorization.k8s.io
|
||||
kind: Group
|
||||
name: system:nodes
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: system-unrestricted-svc-acct-psp-rolebinding
|
||||
namespace: kube-system
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: psp:system-unrestricted-psp
|
||||
subjects:
|
||||
- apiGroup: rbac.authorization.k8s.io
|
||||
kind: Group
|
||||
name: system:serviceaccounts
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: svclb-psp-rolebinding
|
||||
namespace: kube-system
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: psp:svclb-psp
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: svclb
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: svc-local-path-provisioner-psp-rolebinding
|
||||
namespace: kube-system
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: psp:svc-local-path-provisioner-psp
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: local-path-provisioner-service-account
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: svc-coredns-psp-rolebinding
|
||||
namespace: kube-system
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: psp:svc-coredns-psp
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: coredns
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: svc-cis-operator-psp-rolebinding
|
||||
namespace: cis-operator-system
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: psp:svc-cis-operator-psp
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: cis-operator-serviceaccount
|
||||
```
|
||||
|
||||
上述策略可以放置在 `/var/lib/rancher/k3s/server/manifests` 目录下名为 `policy.yaml` 的文件中。在启动 K3s 之前,必须创建策略文件和其目录结构。建议限制访问权限以避免泄露潜在的敏感信息。
|
||||
|
||||
```shell
|
||||
sudo mkdir -p -m 700 /var/lib/rancher/k3s/server/manifests
|
||||
```
|
||||
|
||||
:::note
|
||||
CNI、DNS 和 Ingress 等关键 Kubernetes 组件在 `kube-system` 命名空间中作为 Pod 运行。因此,这个命名空间的限制政策较少,从而使这些组件能够正常运行。
|
||||
:::
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### 网络策略
|
||||
|
||||
CIS 要求所有命名空间应用网络策略,合理限制进入命名空间和 Pod 的流量。
|
||||
|
||||
:::note
|
||||
这些是 CIS Benchmark 中的手动检查。CIS 扫描结果将标记为 `warning`,因为需要集群操作员进行手动检查。
|
||||
:::
|
||||
|
||||
网络策略可以放置在 `/var/lib/rancher/k3s/server/manifests` 目录下的 `policy.yaml` 文件中。如果该目录不是作为 PSP(如上所述)的一部分创建的,则必须首先创建该目录。
|
||||
|
||||
```shell
|
||||
sudo mkdir -p -m 700 /var/lib/rancher/k3s/server/manifests
|
||||
```
|
||||
|
||||
以下是合规的网络策略示例:
|
||||
|
||||
```yaml
|
||||
---
|
||||
kind: NetworkPolicy
|
||||
apiVersion: networking.k8s.io/v1
|
||||
metadata:
|
||||
name: intra-namespace
|
||||
namespace: kube-system
|
||||
spec:
|
||||
podSelector: {}
|
||||
ingress:
|
||||
- from:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
name: kube-system
|
||||
---
|
||||
kind: NetworkPolicy
|
||||
apiVersion: networking.k8s.io/v1
|
||||
metadata:
|
||||
name: intra-namespace
|
||||
namespace: default
|
||||
spec:
|
||||
podSelector: {}
|
||||
ingress:
|
||||
- from:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
name: default
|
||||
---
|
||||
kind: NetworkPolicy
|
||||
apiVersion: networking.k8s.io/v1
|
||||
metadata:
|
||||
name: intra-namespace
|
||||
namespace: kube-public
|
||||
spec:
|
||||
podSelector: {}
|
||||
ingress:
|
||||
- from:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
name: kube-public
|
||||
```
|
||||
|
||||
除非特意允许,否则活动限制会阻止 DNS。以下是允许 DNS 相关流量的网络策略示例:
|
||||
|
||||
```yaml
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: default-network-dns-policy
|
||||
namespace: <NAMESPACE>
|
||||
spec:
|
||||
ingress:
|
||||
- ports:
|
||||
- port: 53
|
||||
protocol: TCP
|
||||
- port: 53
|
||||
protocol: UDP
|
||||
podSelector:
|
||||
matchLabels:
|
||||
k8s-app: kube-dns
|
||||
policyTypes:
|
||||
- Ingress
|
||||
```
|
||||
|
||||
如果没有创建网络策略来允许访问,则默认情况下会阻止 metrics-server 和 Traefik Ingress 控制器。
|
||||
|
||||
```yaml
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-all-metrics-server
|
||||
namespace: kube-system
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
k8s-app: metrics-server
|
||||
ingress:
|
||||
- {}
|
||||
policyTypes:
|
||||
- Ingress
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-all-svclbtraefik-ingress
|
||||
namespace: kube-system
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
svccontroller.k3s.cattle.io/svcname: traefik
|
||||
ingress:
|
||||
- {}
|
||||
policyTypes:
|
||||
- Ingress
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-all-traefik-v121-ingress
|
||||
namespace: kube-system
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: traefik
|
||||
ingress:
|
||||
- {}
|
||||
policyTypes:
|
||||
- Ingress
|
||||
```
|
||||
|
||||
:::note
|
||||
你必须像平常一样管理你创建的任何其他命名空间的网络策略。
|
||||
:::
|
||||
|
||||
### API server 审计配置
|
||||
|
||||
CIS 要求 1.2.19 至 1.2.22 与配置 API server 审核日志相关。默认情况下,K3s 不会创建日志目录和审计策略,因为每个用户的审计策略要求和环境都是特定的。
|
||||
|
||||
如果你需要日志目录,则必须在启动 K3s 之前创建它。我们建议限制访问权限以避免泄露敏感信息。
|
||||
|
||||
```bash
|
||||
sudo mkdir -p -m 700 /var/lib/rancher/k3s/server/logs
|
||||
```
|
||||
|
||||
以下是用于记录请求元数据的初始审计策略。应将策略写入到 `/var/lib/rancher/k3s/server` 目录下名为 `audit.yaml` 的文件中。有关 API server 的策略配置的详细信息,请参阅 [官方 Kubernetes 文档](https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/)。
|
||||
|
||||
```yaml
|
||||
---
|
||||
apiVersion: audit.k8s.io/v1
|
||||
kind: Policy
|
||||
rules:
|
||||
- level: Metadata
|
||||
```
|
||||
|
||||
还需要进一步配置才能通过 CIS 检查。这些在 K3s 中默认不配置,因为它们根据你的环境和需求而有所不同:
|
||||
|
||||
- 确保 `--audit-log-path` 参数已经设置。
|
||||
- 确保 `--audit-log-maxage` 参数设置为 30 或适当的值。
|
||||
- 确保 `--audit-log-maxbackup` 参数设置为 10 或适当的值。
|
||||
- 确保 `--audit-log-maxsize` 参数设置为 100 或适当的值。
|
||||
|
||||
综合起来,要启用和配置审计日志,请将以下行添加到 Rancher 的 K3s 集群配置文件中:
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
rkeConfig:
|
||||
machineGlobalConfig:
|
||||
kube-apiserver-arg:
|
||||
- audit-policy-file=/var/lib/rancher/k3s/server/audit.yaml # CIS 3.2.1
|
||||
- audit-log-path=/var/lib/rancher/k3s/server/logs/audit.log # CIS 1.2.18
|
||||
- audit-log-maxage=30 # CIS 1.2.19
|
||||
- audit-log-maxbackup=10 # CIS 1.2.20
|
||||
- audit-log-maxsize=100 # CIS 1.2.21
|
||||
```
|
||||
|
||||
### Controller Manager 要求
|
||||
|
||||
CIS 要求 1.3.1 检查 Controller Manager 中的垃圾收集设置。垃圾收集对于确保资源充足可用性并避免性能和可用性下降非常重要。根据你的系统资源和测试结果,选择一个适当的阈值来激活垃圾收集。
|
||||
|
||||
你可以在 Rancher 的 K3s 集群文件中设置以下配置来解决此问题。下面的值仅是一个示例,请根据当前环境设置适当的阈值。
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
rkeConfig:
|
||||
machineGlobalConfig:
|
||||
kube-controller-manager-arg:
|
||||
- terminated-pod-gc-threshold=10 # CIS 1.3.1
|
||||
```
|
||||
|
||||
### 配置 `default` Service Account
|
||||
|
||||
Kubernetes 提供了一个名为 `default` 的 service account,供集群工作负载使用,其中没有为 Pod 分配特定的 service account。当 Pod 需要从 Kubernetes API 获取访问权限时,应为该 Pod 创建一个特定的 service account,并为该 service account 授予权限。
|
||||
|
||||
对于 CIS 5.1.5,`default` service account 应配置为不提供 service account 令牌,并且不具有任何明确的权限分配。
|
||||
|
||||
可以通过在每个命名空间中将 `default` service account 的 `automountServiceAccountToken` 字段更新为 `false` 来解决此问题。
|
||||
|
||||
对于内置命名空间(`kube-system`、`kube-public`、`kube-node-lease` 和 `default`)中的 `default` service accounts,K3s 不会自动执行此操作。
|
||||
|
||||
将以下配置保存到名为 `account_update.yaml` 的文件中。
|
||||
|
||||
```yaml
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: default
|
||||
automountServiceAccountToken: false
|
||||
```
|
||||
|
||||
创建一个名为 `account_update.sh` 的 Bash 脚本文件。确保使用 `chmod +x account_update.sh` 给脚本添加可执行权限。
|
||||
|
||||
```shell
|
||||
#!/bin/bash -e
|
||||
|
||||
for namespace in $(kubectl get namespaces -A -o=jsonpath="{.items[*]['metadata.name']}"); do
|
||||
kubectl patch serviceaccount default -n ${namespace} -p "$(cat account_update.yaml)"
|
||||
done
|
||||
```
|
||||
|
||||
每次向你的集群添加新的 service account 时,运行该脚本。
|
||||
|
||||
## 加固版 K3s 模板配置参考
|
||||
|
||||
Rancher 使用以下参考模板配置,基于本指南中的每个 CIS 控件创建加固过的自定义 K3s 集群。此参考内容不包括其他必需的**集群配置**指令,这些指令因你的环境而异。
|
||||
|
||||
<Tabs groupId="k3s-version">
|
||||
<TabItem value="v1.25 及更新的版本" default>
|
||||
|
||||
```yaml
|
||||
apiVersion: provisioning.cattle.io/v1
|
||||
kind: Cluster
|
||||
metadata:
|
||||
name: # 定义集群名称
|
||||
spec:
|
||||
defaultPodSecurityAdmissionConfigurationTemplateName: rancher-restricted
|
||||
enableNetworkPolicy: true
|
||||
kubernetesVersion: # 定义 K3s 版本
|
||||
rkeConfig:
|
||||
machineGlobalConfig:
|
||||
kube-apiserver-arg:
|
||||
- enable-admission-plugins=NodeRestriction,ServiceAccount # CIS 1.2.15, 1.2.13
|
||||
- audit-policy-file=/var/lib/rancher/k3s/server/audit.yaml # CIS 3.2.1
|
||||
- audit-log-path=/var/lib/rancher/k3s/server/logs/audit.log # CIS 1.2.18
|
||||
- audit-log-maxage=30 # CIS 1.2.19
|
||||
- audit-log-maxbackup=10 # CIS 1.2.20
|
||||
- audit-log-maxsize=100 # CIS 1.2.21
|
||||
- request-timeout=300s # CIS 1.2.22
|
||||
- service-account-lookup=true # CIS 1.2.24
|
||||
kube-controller-manager-arg:
|
||||
- terminated-pod-gc-threshold=10 # CIS 1.3.1
|
||||
secrets-encryption: true
|
||||
machineSelectorConfig:
|
||||
- config:
|
||||
kubelet-arg:
|
||||
- make-iptables-util-chains=true # CIS 4.2.7
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="v1.24 及更早的版本">
|
||||
|
||||
```yaml
|
||||
apiVersion: provisioning.cattle.io/v1
|
||||
kind: Cluster
|
||||
metadata:
|
||||
name: # 定义集群名称
|
||||
spec:
|
||||
enableNetworkPolicy: true
|
||||
kubernetesVersion: # 定义 K3s 版本
|
||||
rkeConfig:
|
||||
machineGlobalConfig:
|
||||
kube-apiserver-arg:
|
||||
- enable-admission-plugins=NodeRestriction,PodSecurityPolicy,ServiceAccount # CIS 1.2.15, 5.2, 1.2.13
|
||||
- audit-policy-file=/var/lib/rancher/k3s/server/audit.yaml # CIS 3.2.1
|
||||
- audit-log-path=/var/lib/rancher/k3s/server/logs/audit.log # CIS 1.2.18
|
||||
- audit-log-maxage=30 # CIS 1.2.19
|
||||
- audit-log-maxbackup=10 # CIS 1.2.20
|
||||
- audit-log-maxsize=100 # CIS 1.2.21
|
||||
- request-timeout=300s # CIS 1.2.22
|
||||
- service-account-lookup=true # CIS 1.2.24
|
||||
kube-controller-manager-arg:
|
||||
- terminated-pod-gc-threshold=10 # CIS 1.3.1
|
||||
secrets-encryption: true
|
||||
machineSelectorConfig:
|
||||
- config:
|
||||
kubelet-arg:
|
||||
- make-iptables-util-chains=true # CIS 4.2.7
|
||||
protect-kernel-defaults: true # CIS 4.2.6
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## 结论
|
||||
|
||||
如果你按照本指南操作,由 Rancher 提供的 K3s 自定义集群将配置为通过 CIS Kubernetes Benchmark 测试。你可以查看我们的 K3s 自我评估指南,了解我们是如何验证每个 benchmarks 的,并且你可以在你的集群上执行相同的操作。
|
||||
+3215
File diff suppressed because it is too large
Load Diff
+273
@@ -0,0 +1,273 @@
|
||||
---
|
||||
title: RKE2 加固指南
|
||||
---
|
||||
|
||||
<head>
|
||||
<link rel="canonical" href="https://ranchermanager.docs.rancher.com/zh/reference-guides/rancher-security/hardening-guides/rke2-hardening-guide"/>
|
||||
</head>
|
||||
|
||||
本文档提供了针对生产环境的 RKE2 集群进行加固的具体指导,以便在使用 Rancher 部署之前进行配置。它概述了满足信息安全中心(Center for Information Security, CIS)Kubernetes benchmark controls 制所需的配置和控制。
|
||||
|
||||
:::note
|
||||
这份加固指南描述了如何确保你集群中的节点安全。我们建议你在安装 Kubernetes 之前遵循本指南。
|
||||
:::
|
||||
|
||||
此加固指南适用于 RKE2 集群,并与以下版本的 CIS Kubernetes Benchmark、Kubernetes 和 Rancher 相关联:
|
||||
|
||||
| Rancher 版本 | CIS Benchmark 版本 | Kubernetes 版本 |
|
||||
|-----------------|-----------------------|------------------------------|
|
||||
| Rancher v2.7 | Benchmark v1.23 | Kubernetes v1.23 |
|
||||
| Rancher v2.7 | Benchmark v1.24 | Kubernetes v1.24 |
|
||||
| Rancher v2.7 | Benchmark v1.7 | Kubernetes v1.25 至 v1.26 |
|
||||
|
||||
:::note
|
||||
- 在 Benchmark v1.24 及更高版本中,由于新的文件权限要求(600 而不是 644),一些检查 ID 可能会失败。受影响的检查 ID 包括:`1.1.1`, `1.1.3`, `1.1.5`, `1.1.7`, `1.1.13`, `1.1.15`, `1.1.17`, `4.1.3`, `4.1.5` 和 `4.1.9`。
|
||||
- 在 Benchmark v1.7 中,不再需要 `--protect-kernel-defaults` (4.2.6) 参数,并已被 CIS 删除。
|
||||
:::
|
||||
|
||||
有关如何评估加固的 RKE2 集群与官方 CIS benchmark 的更多细节,请参考特定 Kubernetes 和 CIS benchmark 版本的 RKE2 自我评估指南。
|
||||
|
||||
RKE2 在不需要修改的情况下通过了许多 Kubernetes CIS controls,因为它默认应用了几个安全缓解措施。然而,有一些值得注意的例外情况,需要手动干预才能完全符合 CIS Benchmark 要求:
|
||||
|
||||
1. RKE2 不会修改主机操作系统。因此,作为运维人员,你必须进行一些主机级别的修改。
|
||||
2. 某些 CIS controls 对于网络策略和 Pod 安全标准(或 RKE2 v1.25 之前的 Pod 安全策略 (PSP))将限制集群的功能。你必须选择让 RKE2 为你配置这些功能。为了确保满足这些要求,可以启动 RKE2 并设置 profile 标志为 `cis-1.23`(适用于 v1.25 及更新版本)或 `cis-1.6`(适用于 v1.24 及更早版本)。
|
||||
|
||||
## 主机级别要求
|
||||
|
||||
主机级要求有两个方面:内核参数和 etcd 进程/目录配置。这些在本节中进行了概述。
|
||||
|
||||
### 确保 `protect-kernel-defaults` 已经设置
|
||||
|
||||
<Tabs groupId="k3s-version">
|
||||
<TabItem value="v1.25 及更新版本" default>
|
||||
|
||||
自 CIS benchmark 1.7 开始,不再需要`protect-kernel-defaults`。
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="v1.24 及更早版本">
|
||||
|
||||
这是一个 kubelet 标志,如果所需的内核参数未设置或设置为与 kubelet 的默认值不同的值,将导致 kubelet 退出。
|
||||
|
||||
可以在 Rancher 的集群配置中设置 `protect-kernel-defaults` 标志。
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
rkeConfig:
|
||||
machineSelectorConfig:
|
||||
- config:
|
||||
protect-kernel-defaults: true
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### 设置内核参数
|
||||
|
||||
建议为集群中的所有节点类型设置以下 `sysctl` 配置。在 `/etc/sysctl.d/90-kubelet.conf` 中设置以下参数:
|
||||
|
||||
```ini
|
||||
vm.panic_on_oom=0
|
||||
vm.overcommit_memory=1
|
||||
kernel.panic=10
|
||||
kernel.panic_on_oops=1
|
||||
```
|
||||
|
||||
运行 `sudo sysctl -p /etc/sysctl.d/90-kubelet.conf` 以启用设置。
|
||||
|
||||
### 确保 etcd 配置正确
|
||||
|
||||
CIS Benchmark 要求 etcd 数据目录由 `etcd` 用户和组拥有。这意味着 etcd 进程必须以主机级别的 `etcd` 用户身份运行。为了实现这一点,在使用有效的 `cis-1.xx` 配置文件启动 RKE2 时,RKE2 会采取以下几个步骤:
|
||||
|
||||
1. 检查主机上是否存在 `etcd` 用户和组。如果不存在,则显示错误并退出。
|
||||
2. 使用 `etcd` 作为用户和组所有者创建 etcd 的数据目录。
|
||||
3. 通过适当设置 etcd 静态 Pod 的 `SecurityContext`,确保 etcd 进程以 `etcd` 用户和组的身份运行。
|
||||
|
||||
为满足上述要求,你必须执行以下操作:
|
||||
|
||||
#### 创建 etcd 用户
|
||||
|
||||
在某些 Linux 发行版中,`useradd` 命令不会创建组。下面包含了 `-U` 标志来解决这个问题。这个标志告诉 `useradd` 创建一个与用户同名的组。
|
||||
|
||||
```bash
|
||||
sudo useradd -r -c "etcd user" -s /sbin/nologin -M etcd -U
|
||||
```
|
||||
|
||||
## Kubernetes 运行时要求
|
||||
|
||||
通过 CIS Benchmark 测试的运行时要求主要集中在 Pod 安全、网络策略和内核参数上。当使用有效的 `cis-1.xx` 配置文件时,大部分都会被 RKE2 自动处理,但需要一些额外的运维人员干预是。本节概述了这些内容。
|
||||
|
||||
### Pod 安全
|
||||
|
||||
RKE2 始终以一定程度的 Pod 安全性运行。
|
||||
|
||||
<Tabs groupId="rke2-version">
|
||||
<TabItem value="v1.25 及更新版本" default>
|
||||
|
||||
在 v1.25 及更高版本中,[Pod 安全准入(PSAs)](https://kubernetes.io/docs/concepts/security/pod-security-admission/)用于保证 pod 安全。
|
||||
|
||||
以下是确保加固 RKE2 通过 Rancher 中提供的 CIS v1.23 加固配置文件 `rke2-cis-1.7-hardened` 所需的最低配置。
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
defaultPodSecurityAdmissionConfigurationTemplateName: rancher-restricted
|
||||
rkeConfig:
|
||||
machineSelectorConfig:
|
||||
- config:
|
||||
profile: cis-1.23
|
||||
```
|
||||
|
||||
当同时设置了 `defaultPodSecurityAdmissionConfigurationTemplateName` 和 `profile` 标志时,Rancher 和 RKE2 会执行以下操作:
|
||||
|
||||
1. 检查是否已满足主机级要求。如果未满足,RKE2 将以致命错误退出,并描述未满足的要求。
|
||||
2. 应用允许群集传递关联 controls 的网络策略。
|
||||
3. 配置 Pod 安全准入控制器(PSA)使用 PSA 配置模板 `rancher-restricted`,以在所有命名空间中强制执行受限模式,除了模板豁免列表中的命名空间。
|
||||
这些命名空间被豁免,以允许系统 Pod 在没有限制的情况下运行,这是集群正常运行所必需的。
|
||||
|
||||
:::note
|
||||
如果你打算将一个 RKE 集群导入到 Rancher 中,请参考[文档](../../../../how-to-guides/new-user-guides/authentication-permissions-and-global-configuration/psa-config-templates.md)了解如何配置 PSA 以豁免 Rancher system 命名空间。
|
||||
:::
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="v1.24 及更早版本">
|
||||
|
||||
在 Kubernetes v1.24 及更早版本中,`PodSecurityPolicy` 准入控制器始终是启用的。
|
||||
|
||||
以下是确保 RKE2 加固以通过 Rancher 中提供的 CIS v1.23 加固配置文件 `rke2-cis-1.23-hardened` 所需的最低配置。
|
||||
|
||||
:::note
|
||||
在下面的示例中,配置文件设置为`cis-1.6`,这是在上游 RKE2 中定义的值,但集群实际上配置为传递 CIS v1.23 加固配置文件
|
||||
:::
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
defaultPodSecurityPolicyTemplateName: restricted-noroot
|
||||
rkeConfig:
|
||||
machineSelectorConfig:
|
||||
- config:
|
||||
profile: cis-1.6
|
||||
```
|
||||
|
||||
|
||||
当同时设置了 `defaultPodSecurityPolicyTemplateName` 和 `profile` 标志时,Rancher 和 RKE2 会执行以下操作:
|
||||
|
||||
1. 检查是否已满足主机级要求。如果未满足,RKE2 将以致命错误退出,并描述未满足的要求。
|
||||
2. 应用网络策略,以确保集群通过相关的 controls 要求。
|
||||
3. 配置运行时 Pod 安全策略,以确保集群通过相关的 controls 要求。
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
:::note
|
||||
Kubernetes control plane 组件以及关键的附加组件,如 CNI、DNS 和 Ingress,都作为 `kube-system` 命名空间中的 Pod 运行。因此,这个命名空间的限制政策较少,从而使这些组件能够正常运行。
|
||||
:::
|
||||
|
||||
### 网络策略
|
||||
|
||||
当使用有效的 `cis-1.xx` 配置文件运行时,RKE2 将设置适当的 `NetworkPolicies`,以满足 Kubernetes 内置命名空间的 CIS Benchmark 要求。这些命名空间包括:`kube-system`、`kube-public`、`kube-node-lease` 和 `default`。
|
||||
|
||||
所使用的 `NetworkPolicy` 仅允许同一命名空间内的 Pod 相互通信。值得注意的例外是允许 DNS 请求进行解析。
|
||||
|
||||
:::note
|
||||
运维人员必须像管理其他命名空间一样管理额外创建的命名空间的网络策略。
|
||||
:::
|
||||
|
||||
### 配置 `default` service account
|
||||
|
||||
**将 `default` service accountsSet 的 `automountServiceAccountToken` 设置为 `false`**
|
||||
|
||||
Kubernetes 提供了一个 `default` service account,用于集群工作负载,在 pod 没有分配特定 service account 时使用。如果需要从 pod 访问 Kubernetes API,则应为该 pod 创建一个特定的 service account,并授予该 service account 权限。`default` service account 应配置为不提供 service account 令牌,并且不具有任何明确的权限分配。
|
||||
|
||||
对于标准的 RKE2 安装中的每个命名空间,包括 `default` 和 `kube-system`,`default` service account 必须包含此值:
|
||||
|
||||
```yaml
|
||||
automountServiceAccountToken: false
|
||||
```
|
||||
|
||||
对于由集群操作员创建的命名空间,可以使用以下脚本和配置文件来配置 `default` service account。
|
||||
|
||||
以下配置必须保存到一个名为 `account_update.yaml` 的文件中。
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: default
|
||||
automountServiceAccountToken: false
|
||||
```
|
||||
|
||||
创建一个名为 `account_update.sh` 的 bash 脚本文件。确保运行 `sudo chmod +x account_update.sh` 命令,以便脚本具有执行权限。
|
||||
|
||||
```bash
|
||||
#!/bin/bash -e
|
||||
|
||||
for namespace in $(kubectl get namespaces -A -o=jsonpath="{.items[*]['metadata.name']}"); do
|
||||
echo -n "Patching namespace $namespace - "
|
||||
kubectl patch serviceaccount default -n ${namespace} -p "$(cat account_update.yaml)"
|
||||
done
|
||||
```
|
||||
|
||||
执行此脚本以将 `account_update.yaml` 配置应用到所有命名空间中的 `default` service account。
|
||||
|
||||
### API server 审计配置
|
||||
|
||||
CIS 要求 1.2.19 至 1.2.22 与为 API server 配置审计日志有关。当 RKE2 在设置配置文件标志的情况下启动时,它将自动在 API server 中配置加固的 `--audit-log-` 参数以通过这些 CIS 检查。
|
||||
|
||||
RKE2 的默认审计策略被配置为不记录 API server 中的请求。这样做是为了允许集群操作员灵活地定制符合其审计要求和需求的审计策略,因为这些策略是针对每个用户的环境和政策而特定的。
|
||||
|
||||
当使用 `profile` 标志启动 RKE2 时,RKE2 会创建一个默认的审计策略。该策略定义在 `/etc/rancher/rke2/audit-policy.yaml` 中。
|
||||
|
||||
```yaml
|
||||
apiVersion: audit.k8s.io/v1
|
||||
kind: Policy
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
rules:
|
||||
- level: None
|
||||
```
|
||||
|
||||
## 加固的 RKE2 模板配置参考
|
||||
|
||||
参考模板配置用于在 Rancher 中创建加固的 RKE2 自定义集群。该参考不包括其他必需的**集群配置**指令,这些指令会根据你的环境而有所不同。
|
||||
|
||||
<Tabs groupId="rke2-version">
|
||||
<TabItem value="v1.25 及更新版本" default>
|
||||
|
||||
```yaml
|
||||
apiVersion: provisioning.cattle.io/v1
|
||||
kind: Cluster
|
||||
metadata:
|
||||
name: # 定义集群名称
|
||||
spec:
|
||||
defaultPodSecurityAdmissionConfigurationTemplateName: rancher-restricted
|
||||
kubernetesVersion: # 定义 RKE2 版本
|
||||
rkeConfig:
|
||||
machineSelectorConfig:
|
||||
- config:
|
||||
profile: cis-1.23
|
||||
```
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="v1.24 及更早版本">
|
||||
|
||||
```yaml
|
||||
apiVersion: provisioning.cattle.io/v1
|
||||
kind: Cluster
|
||||
metadata:
|
||||
name: # 定义集群名称
|
||||
spec:
|
||||
defaultPodSecurityPolicyTemplateName: restricted-noroot
|
||||
kubernetesVersion: # 定义 RKE2 版本
|
||||
rkeConfig:
|
||||
machineSelectorConfig:
|
||||
- config:
|
||||
profile: cis-1.6
|
||||
protect-kernel-defaults: true
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## 结论
|
||||
|
||||
如果你按照本指南操作,由 Rancher 提供的 RKE2 自定义集群将配置为通过 CIS Kubernetes Benchmark 测试。你可以查看我们的 RKE2 自我评估指南,了解我们是如何验证每个 benchmarks 的,并且你可以在你的集群上执行相同的操作。
|
||||
+2967
File diff suppressed because it is too large
Load Diff
+11
@@ -0,0 +1,11 @@
|
||||
---
|
||||
title: Kubernetes 安全最佳实践
|
||||
---
|
||||
|
||||
## 限制云元数据 API 访问
|
||||
|
||||
AWS、Azure、DigitalOcean 或 GCP 等云提供商通常会在本地向实例公开元数据服务。默认情况下,此端点可被运行在云实例上的 pod 访问,包括在托管的 Kubernetes(如 EKS、AKS、DigitalOcean Kubernetes 或 GKE)中的 pod,并且可以包含该节点的云凭证、配置数据(如 kubelet 凭证)以及其他敏感数据。为了降低在云平台上运行的这种风险,请遵循 [Kubernetes 安全建议](https://kubernetes.io/docs/tasks/administer-cluster/securing-a-cluster/#restricting-cloud-metadata-api-access),即限制授予实例凭证的权限,使用网络策略限制 pod 对元数据 API 的访问,并避免使用配置数据来传递密文。
|
||||
|
||||
建议你参阅你使用的云提供商的安全最佳实践,获取限制对云实例元数据 API 访问的建议和详情。
|
||||
|
||||
要获取更多参考资料,请参阅 MITRE ATT&CK 知识库 - [不安全凭证:云实例元数据 API](https://attack.mitre.org/techniques/T1552/005/)。
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
---
|
||||
title: PodSecurityConfiguration 示例
|
||||
---
|
||||
|
||||
以下 PodSecurityConfiguration 包含了 `rancher-restricted` 集群正常运行所需的 Rancher 命名空间豁免。
|
||||
|
||||
```yaml
|
||||
apiVersion: apiserver.config.k8s.io/v1
|
||||
kind: AdmissionConfiguration
|
||||
plugins:
|
||||
- name: PodSecurity
|
||||
configuration:
|
||||
apiVersion: pod-security.admission.config.k8s.io/v1
|
||||
kind: PodSecurityConfiguration
|
||||
defaults:
|
||||
enforce: "restricted"
|
||||
enforce-version: "latest"
|
||||
audit: "restricted"
|
||||
audit-version: "latest"
|
||||
warn: "restricted"
|
||||
warn-version: "latest"
|
||||
exemptions:
|
||||
usernames: []
|
||||
runtimeClasses: []
|
||||
namespaces: [calico-apiserver,
|
||||
calico-system,
|
||||
cattle-alerting,
|
||||
cattle-csp-adapter-system,
|
||||
cattle-elemental-system,
|
||||
cattle-epinio-system,
|
||||
cattle-externalip-system,
|
||||
cattle-fleet-local-system,
|
||||
cattle-fleet-system,
|
||||
cattle-gatekeeper-system,
|
||||
cattle-global-data,
|
||||
cattle-global-nt,
|
||||
cattle-impersonation-system,
|
||||
cattle-istio,
|
||||
cattle-istio-system,
|
||||
cattle-logging,
|
||||
cattle-logging-system,
|
||||
cattle-monitoring-system,
|
||||
cattle-neuvector-system,
|
||||
cattle-prometheus,
|
||||
cattle-resources-system,
|
||||
cattle-sriov-system,
|
||||
cattle-system,
|
||||
cattle-ui-plugin-system,
|
||||
cattle-windows-gmsa-system,
|
||||
cert-manager,
|
||||
cis-operator-system,
|
||||
fleet-default,
|
||||
ingress-nginx,
|
||||
istio-system,
|
||||
kube-node-lease,
|
||||
kube-public,
|
||||
kube-system,
|
||||
longhorn-system,
|
||||
rancher-alerting-drivers,
|
||||
security-scan,
|
||||
tigera-operator]
|
||||
```
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
---
|
||||
title: Rancher 安全最佳实践
|
||||
---
|
||||
|
||||
<head>
|
||||
<link rel="canonical" href="https://ranchermanager.docs.rancher.com/zh/reference-guides/rancher-security/rancher-security-best-practices"/>
|
||||
</head>
|
||||
|
||||
## 限制对 /version 和 /rancherversion 的公共访问
|
||||
|
||||
上游(本地) Rancher 实例提供正在运行的 Rancher 版本和用于构建它的 Go 版本信息。这些信息可以通过 `/version` 路径访问,该路径用于诸如自动化版本升级或确认部署成功等任务。上游实例还提供了可通过 `/rancherversion` 路径访问的 Rancher 版本信息。
|
||||
|
||||
攻击者可能会滥用这些信息来识别正在运行的 Rancher 版本,并与潜在的漏洞相关联以进行利用。如果你的上游 Rancher 实例在网上是公开可访问的,请使用 7 层防火墙来阻止 `/version` 和 `/rancherversion` 路径。
|
||||
|
||||
更多关于保护服务器的详细信息,请参阅 [OWASP Web Application Security Testing - Enumerate Infrastructure and Application Admin Interfaces](https://owasp.org/www-project-web-security-testing-guide/stable/4-Web_Application_Security_Testing/02-Configuration_and_Deployment_Management_Testing/05-Enumerate_Infrastructure_and_Application_Admin_Interfaces.html)。
|
||||
|
||||
## 会话管理
|
||||
|
||||
某些环境可能需要额外的安全控制来管理会话。例如,你可能希望限制用户的并发活动会话或限制可以从哪些地理位置发起这些会话。Rancher 默认情况下不支持这些功能。
|
||||
|
||||
如果你需要此类功能,请将 7 层防火墙与[外部认证](../../how-to-guides/new-user-guides/authentication-permissions-and-global-configuration/authentication-config/authentication-config.md#外部认证与本地认证)结合使用。
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
---
|
||||
title: 安全
|
||||
---
|
||||
|
||||
<head>
|
||||
<link rel="canonical" href="https://ranchermanager.docs.rancher.com/zh/reference-guides/rancher-security"/>
|
||||
</head>
|
||||
|
||||
<table width="100%">
|
||||
<tr style={{verticalAlign: 'top'}}>
|
||||
<td width="30%" style={{border: 'none'}}>
|
||||
<h4>安全策略</h4>
|
||||
<p style={{padding: '8px'}}>Rancher Labs 会负责任地披露问题,并致力于在合理的时间内解决所有问题。 </p>
|
||||
</td>
|
||||
<td width="30%" style={{border: 'none'}}>
|
||||
<h4>报告流程</h4>
|
||||
<p style={{padding: '8px'}}>请将安全问题发送至 <a href="mailto:security-rancher@suse.com">security-rancher@suse.com</a>。</p>
|
||||
</td>
|
||||
<td width="30%" style={{border: 'none'}}>
|
||||
<h4>公告</h4>
|
||||
<p style={{padding:'8px'}}>订阅 <a href="https://forums.rancher.com/c/announcements">Rancher 公告论坛</a>以获取版本更新。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
安全是 Rancher 全部功能的基础。Rancher 集成了全部主流认证工具和服务,并提供了企业级的 [RBAC 功能](../../how-to-guides/new-user-guides/authentication-permissions-and-global-configuration/manage-role-based-access-control-rbac/manage-role-based-access-control-rbac.md),让你的 Kubernetes 集群更加安全。
|
||||
|
||||
本文介绍了安全相关的文档以及资源,让你的 Rancher 安装和下游 Kubernetes 集群更加安全。
|
||||
|
||||
## NeuVector 与 Rancher 的集成
|
||||
|
||||
NeuVector 是一个开源的、以容器为中心的安全应用程序,现已集成到 Rancher 中。NeuVector 提供生产安全、DevOps 漏洞保护和容器防火墙等功能。请参阅 [Rancher 文档](../../integrations-in-rancher/neuvector/neuvector.md) 和 [NeuVector 文档](https://open-docs.neuvector.com/)了解更多信息。
|
||||
|
||||
## 在 Kubernetes 集群上运行 CIS 安全扫描
|
||||
|
||||
Rancher 使用 [kube-bench](https://github.com/aquasecurity/kube-bench) 来运行安全扫描,从而检查 Kubernetes 是否按照 [CIS](https://www.cisecurity.org/cis-benchmarks/)(Center for Internet Security,互联网安全中心)Kubernetes Benchmark 中定义的安全最佳实践进行部署。
|
||||
|
||||
CIS Kubernetes Benchmark 是一个参考文档,用于为 Kubernetes 建立安全配置基线。
|
||||
|
||||
CIS 是一个 501(c\)(3) 非营利组织,成立于 2000 年 10 月,其使命是识别、开发、验证、促进和维持网络防御的最佳实践方案,并建立和指导社区,以在网络空间中营造信任的环境。
|
||||
|
||||
CIS Benchmark 是目标系统安全配置的最佳实践。CIS Benchmark 是由安全专家、技术供应商、公开和私人社区成员,以及 CIS Benchmark 开发团队共同志愿开发的。
|
||||
|
||||
Benchmark 提供两种类型的建议,分别是自动(Automated)和手动(Manual)。我们只运行 Automated 相关的测试。
|
||||
|
||||
Rancher 在集群上运行 CIS 安全扫描时会生成一份报告,该报告会显示每个测试的结果,包括测试概要以及 `passed`、`skipped` 和 `failed` 的测试数量。报告还包括失败测试的修正步骤。
|
||||
|
||||
有关详细信息,请参阅[安全扫描](../../how-to-guides/advanced-user-guides/cis-scan-guides/cis-scan-guides.md)。
|
||||
|
||||
## SELinux RPM
|
||||
|
||||
[安全增强型 Linux (SELinux)](https://en.wikipedia.org/wiki/Security-Enhanced_Linux) 是对 Linux 的安全增强。被政府机构使用之后,SELinux 已成为行业标准,并在 CentOS 7 和 8 上默认启用。
|
||||
|
||||
我们提供了 `rancher-selinux` 和 `rke2-selinux` 两个 RPM(Red Hat 软件包),让 Rancher 产品能够在 SELinux 主机上正常运行。有关详细信息,请参阅[此页面](selinux-rpm/selinux-rpm.md)。
|
||||
|
||||
## Rancher 加固指南
|
||||
|
||||
Rancher 加固指南基于 <a href="https://www.cisecurity.org/benchmark/kubernetes/" target="_blank">CIS Kubernetes Benchmark</a>。
|
||||
|
||||
加固指南为加固 Rancher 的生产安装提供了说明性指导。有关安全管控的完整列表,请参阅 Rancher 的 [CIS Kubernetes Benchmark 自我评估](#cis-benchmark-和自我评估)指南。
|
||||
|
||||
> 加固指南描述了如何保护集群中的节点,建议在安装 Kubernetes 之前参考加固指南中的步骤。
|
||||
|
||||
每个加固指南版本都针对特定的 CIS Kubernetes Benchmark、Kubernetes 和 Rancher 版本。
|
||||
|
||||
## CIS Benchmark 和自我评估
|
||||
|
||||
Benchmark 自我评估是 Rancher 安全加固指南的辅助。加固指南展示了如何加固集群,而 Benchmark 指南旨在帮助你评估加固集群的安全级别。
|
||||
|
||||
本指南将介绍各种 controls,并提供更新的示例命令来审计 Rancher 创建的集群的合规性。你可以前往 [CIS 网站](https://www.cisecurity.org/benchmark/kubernetes/)下载原始的 Benchmark 文档。
|
||||
|
||||
Rancher 自我评估指南的每个版本都对应于强化指南、Rancher、Kubernetes 和 CIS Benchmark 的特定版本。
|
||||
|
||||
## 第三方渗透测试报告
|
||||
|
||||
Rancher 会定期聘请第三方对 Rancher 软件栈进行安全审计和渗透测试。被测环境遵循 Rancher 在测试时提供的强化指南。以前的渗透测试报告如下。
|
||||
|
||||
结果:
|
||||
|
||||
- [Cure53 渗透测试 - 2019 年 7 月](https://releases.rancher.com/documents/security/pen-tests/2019/RAN-01-cure53-report.final.pdf)
|
||||
- [Untamed Theory 渗透测试 - 2019 年 3 月](https://releases.rancher.com/documents/security/pen-tests/2019/UntamedTheory-Rancher_SecurityAssessment-20190712_v5.pdf)
|
||||
|
||||
请注意,新报告不再共享或公开发布。
|
||||
|
||||
## Rancher 安全公告和 CVE
|
||||
|
||||
Rancher 致力于向社区通报我们产品中的安全问题。有关我们已解决的问题的 CVE(常见漏洞和暴露)列表,请参阅[此页](security-advisories-and-cves.md)。
|
||||
|
||||
## Kubernetes 安全最佳实践
|
||||
|
||||
有关保护 Kubernetes 集群的建议,请参阅 [Kubernetes 安全最佳实践](kubernetes-security-best-practices.md)指南。
|
||||
|
||||
## Rancher 安全最佳实践
|
||||
|
||||
有关保护 Rancher Manager 部署的建议,请参阅 [Rancher 安全最佳实践](rancher-security-best-practices.md)指南。
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
---
|
||||
title: 加固 Rancher Webhook
|
||||
---
|
||||
|
||||
<head>
|
||||
<link rel="canonical" href="https://ranchermanager.docs.rancher.com/zh/reference-guides/rancher-security/rancher-webhook-hardening"/>
|
||||
</head>
|
||||
|
||||
Rancher Webhook 是 Rancher 中的一个重要组件,它在强制执行 Rancher 及其工作负载的安全要求方面发挥着重要的作用。为了减少其攻击面,对它的访问应限制为唯一有效的调用方:Kubernetes API server。这可以通过单独使用网络策略和认证,或相互结合使用以加固 webhook 免受攻击。
|
||||
|
||||
## 使用网络策略阻止外部流量
|
||||
|
||||
webhook 只应接受来自 Kubernetes API server 的请求。但是默认情况下,webhook 可以接受来自任何源的流量。如果你使用的是支持网络策略的 CNI,则可以创建一个策略来阻止来源不是 API server 的流量。
|
||||
|
||||
Kubernetes 中内置的网络策略资源无法阻止或允许来自集群主机的流量,并且 `kube-apiserver` 进程在主机网络上运行。因此你必须使用当前集群正在使用的 CNI 的高级网络策略资源。以下是 Calico 和 Cilium 的示例。更多详细的信息,请参阅你使用的 CNI 的文档。
|
||||
|
||||
### Calico
|
||||
|
||||
使用 `crd.projectcalico.org/v1` API 组中的网络策略资源。使用 `app == 'rancher-webhook'` selector 为 webhook 创建一个规则,并且将 control plane 主机的 CIDR 设置为入口源:
|
||||
|
||||
```yaml
|
||||
apiVersion: crd.projectcalico.org/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-k8s
|
||||
namespace: cattle-system
|
||||
spec:
|
||||
selector: app == 'rancher-webhook'
|
||||
types:
|
||||
- Ingress
|
||||
ingress:
|
||||
- action: Allow
|
||||
protocol: TCP
|
||||
source:
|
||||
nets:
|
||||
- 192.168.42.0/24 # control plane 主机的 CIDR。如果主机位于不同的子网中,则可能会列出多个。
|
||||
destination:
|
||||
selector:
|
||||
app == 'rancher-webhook'
|
||||
```
|
||||
|
||||
### Cilium
|
||||
|
||||
使用 `cilium.io/v2` API 组中的 CiliumNetworkPolicy 资源。将 `host` 和 `remote-node` 键添加到 `fromEntities` 入口规则。这会阻止集群内和外部流量,同时允许来自主机的流量。
|
||||
|
||||
```yaml
|
||||
apiVersion: "cilium.io/v2"
|
||||
kind: CiliumNetworkPolicy
|
||||
metadata:
|
||||
name: allow-k8s
|
||||
namespace: cattle-system
|
||||
spec:
|
||||
endpointSelector:
|
||||
matchLabels:
|
||||
app: rancher-webhook
|
||||
ingress:
|
||||
- fromEntities:
|
||||
- host
|
||||
- remote-node
|
||||
```
|
||||
|
||||
## 要求 Kubernetes API Server 对 Webhook 进行认证
|
||||
|
||||
Webhook 应仅接受来自 Kubernetes API server 的请求。默认情况下,webhook 不要求客户端对其进行认证。它可以接受任何请求。你可以配置 webhook 验证凭据,以便只有 API server 可以访问它。更多信息可以在 [Kubernetes 文档](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#authenticate-apiservers)中找到。
|
||||
|
||||
1. 配置 API server 向 webhook 提供证书,指向 AdmissionConfiguration 文件以配置 ValidatingAdmissionWebhook 和 MutatingAdmissionWebhook 插件:
|
||||
|
||||
```yaml
|
||||
# /etc/rancher/admission/admission.yaml
|
||||
apiVersion: apiserver.config.k8s.io/v1
|
||||
kind: AdmissionConfiguration
|
||||
plugins:
|
||||
- name: ValidatingAdmissionWebhook
|
||||
configuration:
|
||||
apiVersion: apiserver.config.k8s.io/v1
|
||||
kind: WebhookAdmissionConfiguration
|
||||
kubeConfigFile: "/etc/rancher/admission/kubeconfig"
|
||||
- name: MutatingAdmissionWebhook
|
||||
configuration:
|
||||
apiVersion: apiserver.config.k8s.io/v1
|
||||
kind: WebhookAdmissionConfiguration
|
||||
kubeConfigFile: "/etc/rancher/admission/kubeconfig"
|
||||
```
|
||||
|
||||
这也是配置其他准入插件的同一配置文件,例如 PodSecurity。如果你的发行版或设置使用了额外的准入插件,请将它们也配置在这里。例如,将 [RKE2 的 PodSecurity 配置](https://docs.rke2.io/security/pod_security_standards)添加到这个文件中。
|
||||
|
||||
2. 创建准入插件引用的 kubeconfig 文件。Rancher Webhook 仅支持客户端证书认证,因此请生成一个 TLS 密钥对,并且将 kubeconfig 设置为使用 `client-certificate` 和 `client-key` 或者使用 `client-certificate-data` 和 `client-key-data`。 例如:
|
||||
|
||||
```yaml
|
||||
# /etc/rancher/admission/kubeconfig
|
||||
apiVersion: v1
|
||||
kind: Config
|
||||
users:
|
||||
- name: 'rancher-webhook.cattle-system.svc'
|
||||
user:
|
||||
client-certificate: /path/to/client/cert
|
||||
client-key: /path/to/client/key
|
||||
```
|
||||
|
||||
3. 使用 `--admission-control-config-file` 参数启动 kube-apiserver 服务,并将该参数值指向你的 AdmissionConfiguration 文件。具体的操作方式因发行版而异,并不受普遍支持,例如在托管的 Kubernetes 提供商中可能不支持。请查阅你的 Kubernetes 发行版的文档以获取详细的信息。
|
||||
|
||||
对于 RKE2,可以使用这样的配置文件启动 `rke2-server`:
|
||||
|
||||
```yaml
|
||||
# /etc/rancher/rke2/config.yaml
|
||||
kube-apiserver-arg:
|
||||
- admission-control-config-file=/etc/rancher/admission/admission.yaml
|
||||
kube-apiserver-extra-mount:
|
||||
- /etc/rancher/admission:/etc/rancher/admission:ro
|
||||
```
|
||||
|
||||
:::danger
|
||||
某些发行版会默认设置此参数。如果你的发行版预配置了它自己的 AdmissionConfiguration,则必须将其包含在你自定义的准入控制的配置文件中。例如,RKE2 在 `/etc/rancher/rke2/rke2-pss.yaml` 安装了一个 AdmissionConfiguration 文件,该文件配置了 PodSecurity 准入插件。在 config.yaml 中设置 `admission-control-config-file` 将会覆盖这个重要的安全设置。要包含两个插件,请参阅 [Default Pod Security Standards 文档](https://docs.rke2.io/security/pod_security_standards)并将相应的插件配置复制到你的 admission.yaml 中。
|
||||
:::
|
||||
|
||||
4. 如果你使用 Rancher 通过现有节点来配置你的集群,请在配置集群之前在节点上创建这些文件。
|
||||
|
||||
如果你使用 Rancher 在新节点上配置你的集群,请先允许集群配置完成,然后使用 Rancher 提供的 SSH key 和 IP 地址连接到节点,并将 RKE2 的配置文件放在 `/etc/rancher/rke2/config.yaml.d/` 目录下。
|
||||
|
||||
5. 使用这些凭证配置集群后,配置 Rancher cluster agent 以在 webhook 中启用认证。创建一个包含以下内容的 chart values 的文件:
|
||||
|
||||
```yaml
|
||||
# values.yaml
|
||||
auth:
|
||||
clientCA: <base64-encoded certificate authority that signed the kube-apiserver's client certificates>
|
||||
allowedCNs:
|
||||
- <list of Common Names identifying the kube-apiserver's client certificates.>
|
||||
- <if not provided, any cert signed by the given CA will be accepted.>
|
||||
```
|
||||
|
||||
6. 在配置的集群中的 `cattle-system` 命名空间下创建一个 configmap,并包含这些 values 配置:
|
||||
|
||||
```
|
||||
kubectl --namespace cattle-system create configmap rancher-config --from-file=rancher-webhook=values.yaml
|
||||
```
|
||||
|
||||
webhook 将会使用这些 values 配置重新启动。
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: 安全公告和 CVE
|
||||
---
|
||||
|
||||
<head>
|
||||
<link rel="canonical" href="https://ranchermanager.docs.rancher.com/zh/reference-guides/rancher-security/security-advisories-and-cves"/>
|
||||
</head>
|
||||
|
||||
Rancher 致力于向社区披露我们产品的安全问题。我们会针对已解决的问题发布安全公告和 CVE(Common Vulnerabilities and Exposures,通用漏洞披露)。Rancher GitHub 上的[安全页面](https://github.com/rancher/rancher/security/advisories)也会发布新的安全公告。
|
||||
|
||||
| ID | 描述 | 日期 | 解决 |
|
||||
|----|-------------|------|------------|
|
||||
| [CVE-2023-32199](https://github.com/rancher/rancher/security/advisories/GHSA-j4vr-pcmw-hx59) | Rancher now removes the corresponding ClusterRoleBindings whenever the admin GlobalRole or its GlobalRoleBindings are deleted. Previously orphaned ClusterRoleBindings were marked with the annotation `authz.cluster.cattle.io/admin-globalrole-missing=true`. | 23 Oct 2025 | Rancher [v2.12.3](https://github.com/rancher/rancher/releases/tag/v2.12.3) and [v2.11.7](https://github.com/rancher/rancher/releases/tag/v2.11.7) |
|
||||
| [CVE-2024-58269](https://github.com/rancher/rancher/security/advisories/GHSA-mw39-9qc2-f7mg) | The Rancher audit log redaction process has changed to the following: <br/><br/><ul><li> It now redacts `kubectl.kubernetes.io/last-applied-configuration` annotations on both Response and Request body contents. Previously it did not redact Response body content.</li><li> It now redacts Cluster Import URLs on both Request URLs and Referer headers. Previously it did not redact Referer headers.</li></ul> | 23 Oct 2025 | Rancher [v2.12.3](https://github.com/rancher/rancher/releases/tag/v2.12.3) |
|
||||
| [CVE-2024-58260](https://github.com/rancher/rancher/security/advisories/GHSA-q82v-h4rq-5c86) | Setting the username of one user as the same username of another user causes an error when either user attempts to log in. Therefore, a user with the `Manage Users` permission could potentially deny any user, including admins, from logging in. To prevent this, usernames have been made immutable once set, and it is not possible to update or create a user with a username that is already in use. | 25 Sep 2025 | Rancher [v2.12.2](https://github.com/rancher/rancher/releases/tag/v2.12.2), [v2.11.6](https://github.com/rancher/rancher/releases/tag/v2.11.6), [v2.10.10](https://github.com/rancher/rancher/releases/tag/v2.10.10), and [v2.9.12](https://github.com/rancher/rancher/releases/tag/v2.9.12) |
|
||||
| [CVE-2024-58267](https://github.com/rancher/rancher/security/advisories/GHSA-v3vj-5868-2ch2) | The Rancher CLI is modified to print the `requestId` more visibly than as part of the login URL. It also adds a `cli=true` origin marker to the URL. The dashboard is modified to recognize the presence of the `requestId` and uses that to show a warning message to the user, asking for verification that they initiated a CLI login with the related Id. The non-presence of the origin marker enables the dashboard to distinguish between the modified CLI and older CLI’s, and adjust the message accordingly. | 25 Sep 2025 | Rancher [v2.12.2](https://github.com/rancher/rancher/releases/tag/v2.12.2), [v2.11.6](https://github.com/rancher/rancher/releases/tag/v2.11.6), [v2.10.10](https://github.com/rancher/rancher/releases/tag/v2.10.10), and [v2.9.12](https://github.com/rancher/rancher/releases/tag/v2.9.12) |
|
||||
| [CVE-2025-54468](https://github.com/rancher/rancher/security/advisories/GHSA-mjcp-rj3c-36fr) | `Impersonate-*` headers are removed for requests made through the `/meta/proxy` Rancher endpoint (e.g. when cloud credentials are being created) as the headers may contain identifiable and/or sensitive information. | 25 Sep 2025 | Rancher [v2.12.2](https://github.com/rancher/rancher/releases/tag/v2.12.2), [v2.11.6](https://github.com/rancher/rancher/releases/tag/v2.11.6), [v2.10.10](https://github.com/rancher/rancher/releases/tag/v2.10.10), and [v2.9.12](https://github.com/rancher/rancher/releases/tag/v2.9.12) |
|
||||
| [CVE-2024-58259](https://github.com/rancher/rancher/security/advisories/GHSA-4h45-jpvh-6p5j) | POSTs to the Rancher API endpoints are now limited to 1 Mi; this is configurable through the settings if you need a larger limit. The Rancher authentication endpoints are configured independently of the main public API (as you might need bigger payloads in the other API endpoints). Suppose you need to increase the maximum allowed payload for authentication. In that case, you can set the environment variable `CATTLE_AUTH_API_BODY_LIMIT` to a quantity, e.g., 2 Mi, which would allow larger payloads for the authentication endpoints. | 28 Aug 2025 | Rancher [v2.12.1](https://github.com/rancher/rancher/releases/tag/v2.12.1), [v2.11.5](https://github.com/rancher/rancher/releases/tag/v2.11.5), [v2.10.9](https://github.com/rancher/rancher/releases/tag/v2.10.9) and [v2.9.11](https://github.com/rancher/rancher/releases/tag/v2.9.11) |
|
||||
| [CVE-2024-52284](https://github.com/rancher/fleet/security/advisories/GHSA-6h9x-9j5v-7w9h) | Following a recent [change](https://github.com/rancher/fleet/pull/3403) excluding Helm values files from bundles, an edge case subsisted where the values files referenced in `fleet.yaml` with your directory name (e.g., `my-dir/values.yaml` instead of `values.yaml`) would not be excluded, which would potentially expose confidential data in bundle resources. Helm values files are now excluded from bundle resources regardless of how you reference them. | 28 Aug 2025 | Rancher [v2.12.1](https://github.com/rancher/rancher/releases/tag/v2.12.1), [v2.11.5](https://github.com/rancher/rancher/releases/tag/v2.11.5) and [v2.10.9](https://github.com/rancher/rancher/releases/tag/v2.10.9) |
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
---
|
||||
title: 关于 rancher-selinux
|
||||
---
|
||||
|
||||
要让 Rancher 使用 SELinux,你必须手动为 SELinux 节点启用一些功能。为了解决这个问题,Rancher 提供了一个 SELinux RPM。
|
||||
|
||||
The `rancher-selinux` RPM contains a set of SELinux policies designed to grant the necessary privileges to various Rancher components running on Linux systems with SELinux enabled.
|
||||
|
||||
`rancher-selinux` 的 GitHub 仓库在[这里](https://github.com/rancher/rancher-selinux)。
|
||||
|
||||
## 安装 rancher-selinux RPM
|
||||
|
||||
:::note 要求
|
||||
|
||||
rancher-selinux RPM 已在 CentOS 7 和 8 上进行了测试。
|
||||
|
||||
:::
|
||||
|
||||
### 1. 设置 yum 仓库
|
||||
|
||||
设置 yum 仓库,从而直接在集群中的所有主机上安装 `rancher-selinux`。
|
||||
|
||||
要使用 RPM 仓库,在 CentOS 7 或 RHEL 7 系统上运行以下 bash 代码片段:
|
||||
|
||||
```
|
||||
# cat << EOF > /etc/yum.repos.d/rancher.repo
|
||||
[rancher]
|
||||
name=Rancher
|
||||
baseurl=https://rpm.rancher.io/rancher/production/centos/7/noarch
|
||||
enabled=1
|
||||
gpgcheck=1
|
||||
gpgkey=https://rpm.rancher.io/public.key
|
||||
EOF
|
||||
```
|
||||
|
||||
要使用 RPM 仓库,在 CentOS 8 或 RHEL 8 系统上运行以下 bash 代码片段:
|
||||
|
||||
```
|
||||
# cat << EOF > /etc/yum.repos.d/rancher.repo
|
||||
[rancher]
|
||||
name=Rancher
|
||||
baseurl=https://rpm.rancher.io/rancher/production/centos/8/noarch
|
||||
enabled=1
|
||||
gpgcheck=1
|
||||
gpgkey=https://rpm.rancher.io/public.key
|
||||
EOF
|
||||
```
|
||||
### 2. 安装 RPM
|
||||
|
||||
安装 RPM:
|
||||
|
||||
```
|
||||
yum -y install rancher-selinux
|
||||
```
|
||||
|
||||
## 配置 Logging 应用程序以使用 SELinux
|
||||
|
||||
:::note 要求
|
||||
|
||||
Logging v2 已在 RHEL/CentOS 7 和 8 上使用 SELinux 进行了测试。
|
||||
|
||||
:::
|
||||
|
||||
在主机上安装 `rancher-selinux` RPM 后,应用程序不会自动运行。它们需要在 RPM 提供的允许的 SELinux 容器域中运行。
|
||||
|
||||
要将 `rancher-logging` Chart 配置为支持 SELinux,请在安装 Chart 时将 `values.yaml` 中的 `global.seLinux.enabled` 更改为 true。
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: 关于 rke2-selinux
|
||||
---
|
||||
|
||||
`rke2-selinux` 为 RKE2 提供策略。如果 RKE2 安装程序脚本检测到它运行在基于 RPM 的发行版上,它会自动安装。
|
||||
|
||||
`rke2-selinux` 的 GitHub 仓库在[这里](https://github.com/rancher/rke2-selinux)。
|
||||
|
||||
有关在启用 SELinux 的主机上安装 RKE2 的更多信息,请参阅 [RKE2 文档](https://docs.rke2.io/install/methods#rpm)。
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
---
|
||||
title: SELinux RPM
|
||||
---
|
||||
|
||||
<head>
|
||||
<link rel="canonical" href="https://ranchermanager.docs.rancher.com/zh/reference-guides/rancher-security/selinux-rpm"/>
|
||||
</head>
|
||||
|
||||
[安全增强型 Linux (SELinux)](https://en.wikipedia.org/wiki/Security-Enhanced_Linux) 是对 Linux 的安全增强。
|
||||
|
||||
它由 Red Hat 开发,是 Linux 上 MAC(mandatory access controls,强制访问控制)的实现。系统管理员可以使用 MAC 设置应用程序和用户是如何访问不同资源的,例如文件、设备、网络和进程间的通信。SELinux 还通过默认限制操作系统来增强安全性。
|
||||
|
||||
被政府机构使用之后,SELinux 已成为行业标准,并在 CentOS 7 和 8 上默认启用。要检查 SELinux 是否在你的系统上启用和执行,请使用 `getenforce`:
|
||||
|
||||
```
|
||||
# getenforce
|
||||
Enforcing
|
||||
```
|
||||
|
||||
我们提供了 [`rancher-selinux`](about-rancher-selinux.md) 和 [`rke2-selinux`](about-rke2-selinux.md) 两个 RPM(Red Hat 软件包),让 Rancher 产品能够在 SELinux 主机上正常运行。
|
||||
Reference in New Issue
Block a user