Context
针对 kubeadm 创建的 cluster 运行 CIS 基准测试工具时,发现了多个必须立即办理的问题。 Task
通过设置修复所有问题并重新启动受影响的组件以确保新的设置收效。
修复针对 API 服务器发现的所有以下违规行为:
1.2.7 Ensure that the --authorization-mode argument is not set to AlwaysAllow FAIL
1.2.8 Ensure that the --authorization-mode argument includes Node FAIL
1.2.9 Ensure that the --authorization-mode argument includes RBAC FAIL
1.2.18 Ensure that the --insecure-bind-address argument is not set FAIL (v1.28 考题中这项没给出,但最好也检查一下,模拟环境是里需要改的)
修复针对 kubelet 发现的所有以下违规行为:
Fix all of the following violations that were found against the kubelet:
4.2.1 Ensure that the anonymous-auth argument is set to false FAIL
4.2.2 Ensure that the --authorization-mode argument is not set to AlwaysAllow FAIL
留意:尽可能使用 Webhook 身份验证/授权。
修复针对 etcd 发现的所有以下违规行为:
Fix all of the following violations that were found against etcd:
2.2 Ensure that the --client-cert-auth argument is set to true FAIL
模拟环境里,初始化这道题的脚本为 kube-bench.sh
candidate@node01:~$ kubectl label pod products-service environment=testing -n dev-team
复制代码
2 创建 NetworkPolicy
candidate@node01:~$ vi /cks/net/po.yaml
# 查networkpolicy,根据官网,修改为如下内容:
……
metadata:
name: pod-restriction #修改
namespace: dev-team #修改
spec:
podSelector:
matchLabels:
environment: testing
policyTypes:
- Ingress #注意,这里只写 - Ingress,不要将 - Egress 也复制进来!
ingress:
- from: #第一个 from
- namespaceSelector:
matchLabels:
name: qaqa #命名空间有 name: qaqa 标签的
- from: #第二个 from
- namespaceSelector: {} #修改为这样,所有命名空间
podSelector: #注意,这个 podSelector 前面的“-” 要删除。
matchLabels:
environment: testing #有 environment: testing 标签的 Pod,这个地方是根据题目要求“Pods with label environment: testing , in any namespace”,这句话里的 pod 标签写的。不要和上面 spec 里的混淆。