[CKS] 执行Pod安全标准

[复制链接]
发表于 2025-3-6 17:30:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
目前的全部标题为2024年10月后更新的最新题库,测验的k8s版本为1.31.1
   ​ 专栏其他文章:
  

  • [CKS] K8S Admission Set Up
  • [CKS] CIS基准测试,修复kubelet和etcd不安全项
  • [CKS] K8S NetworkPolicy Set Up
  • [CKS] 使用Trivy对image进行扫描
  • [CKS] 使用falco进行容器日记捕捉和安全监控监控
  • [CKS] Audit Log Policy
  • [CKS] Create/Read/Mount a Secret in K8S
  • [CKS] K8S Dockerfile和yaml文件安全检测
  • [CKS] K8S RuntimeClass SetUp
  • [CKS] TLS Secrets创建与挂载
  • [CKS] falco扫描发现访问指定文件pod
  • [CKS] 使用ingress公开https服务
  • [CKS] bom工具天生SPDX文档
  • [CKS] 执行Pod安全标准
  • [CKS] Docker保卫进程
  • [CKS]启用apiserver身份验证
  BackGround

为了符合要求,全部用户命名空间都逼迫执行受限的Pod安全标准。
Task

在confidential namespace中包含一个不符合限制性的Pod安全标准的Deployment。因此,其Pod无法被调度。
修改这个Deployment以符合标准,并验证Pod可以正常运行。
   部署的清单文件可以在 ~/nginx-unprivileged.yaml找到。
  Practice

Step 1: 尝试部署deployment,检察此中问题

  1. kubectl create -f nginx-unprivileged.yaml
复制代码
通过这个下令我们可以可以看到有一段Warning
  1. Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "nginx" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "nginx" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "nginx" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "nginx" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
复制代码
针对这个Warning,我们可以对资源做出以下修改
Step 2:修改Deployment

将deployment.yml文件中添加如下内容:
  1. ...
  2. spec:
  3.   template:
  4.     spec:
  5.       containers:
  6.         securityContext:
  7.           allowPrivilegeEscalation: false
  8.           runAsNonRoot: true
  9.           capabilities:
  10.             drop: ["ALL"]
  11.           seccompProfile:
  12.             type: RuntimeDefault
  13. ...
复制代码
应用更改

  1. kubectl apply -f nginx-unprivileged.yaml
复制代码
验证

  1. kubectl get deployment nginx-unprivileged-deployment -n confidential
复制代码

回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表