k8s-CKS真题-k8s安全策略PodSecurityPolicy

简介: k8s-CKS真题-k8s安全策略PodSecurityPolicy

题目

context
A PodsecurityPolicy shall prevent the creati on of privileged Pods in a specific namespace.
Task
Create a new PodSecurityPolicy named prevent-psp-policy, which prevents the creation of privileged Pods.
Create a new ClusterRole named restrict-access-role, which uses the newly created PodSecurityPolicy prevent-psp-policy.
Create a new serviceAccount named psp-denial-sa in the existing namespace development.
Finally, create a new clusterRoleBinding named deny-access-bind, which binds the newly created ClusterRole restrict-access-role to the newly created serviceAccount psp-denial-sa.
  1. 创建一个新的PodSecurityPolicy,名称为prevent-psp-policy,防止创建特权容器。
  2. 创建一个新的ClusterRole,名称为restrict-access-role,使用prevent-psp-policy
  3. 在已存在的命名空间development中创建一个新的serviceAccount,名称为psp-denial-sa
  4. 创建一个新的clusterRoleBinding,名称为deny-access-bind,把restrict-access-role绑定到psp-denial-sa

环境搭建

1.开启PSP

vim /etc/kubernetes/manifests/kube-apiserver.yaml
systemctl restart kubelet

2.创建命名空间

kubectl create ns development

namespace/development created

解题

任务一

apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: prevent-psp-policy
spec:
  privileged: false  # 不允许提权的 Pod!
  # 以下内容负责填充一些必需字段。
  seLinux:
    rule: RunAsAny
  supplementalGroups:
    rule: RunAsAny
  runAsUser:
    rule: RunAsAny
  fsGroup:
    rule: RunAsAny
  volumes:
  - '*'

任务二

命令

kubectl create clusterrole restrict-access-role --verb=use --resource=psp --resource-name=prevent-psp-policy

或者使用yaml文件

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: restrict-access-role
rules:
- apiGroups: ['policy']
  resources: ['podsecuritypolicies']
  verbs:     ['use']
  resourceNames:
  - prevent-psp-policy

任务三

kubectl create sa psp-denial-sa -n development

任务四

kubectl create clusterrolebinding deny-access-bind --clusterrole=restrict-access-role --serviceaccount=development:psp-denial-sa -n development

结果截图

可以看到有个Warning提示,1.25版本之后就没有psp了,之后这个考题可能变动。

参考

k8s-v1.24-pod-security-policy/

k8s-v1.24-admission-controllers

相关实践学习
容器服务Serverless版ACK Serverless 快速入门:在线魔方应用部署和监控
通过本实验,您将了解到容器服务Serverless版ACK Serverless 的基本产品能力,即可以实现快速部署一个在线魔方应用,并借助阿里云容器服务成熟的产品生态,实现在线应用的企业级监控,提升应用稳定性。
云原生实践公开课
课程大纲 开篇:如何学习并实践云原生技术 基础篇: 5 步上手 Kubernetes 进阶篇:生产环境下的 K8s 实践 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
相关文章
|
5天前
|
Kubernetes 安全 调度
提升CKA认证成功率,CKA真题中的节点维护全攻略!
提升CKA认证成功率,CKA真题中的节点维护全攻略!
30 0
|
5天前
|
运维 Ubuntu Linux
k8s-CKS真题-故障排查Sysdig & falco
k8s-CKS真题-故障排查Sysdig & falco
110 0
|
5天前
|
Kubernetes 容器
k8s学习-CKS真题-日志审计 log audit
k8s学习-CKS真题-日志审计 log audit
91 0
|
5天前
|
Kubernetes 安全 Ubuntu
k8s学习-CKS真题-Dockerfile和deployment优化
k8s学习-CKS真题-Dockerfile和deployment优化
77 0
|
5天前
|
Kubernetes 监控 容器
k8s学习-CKA真题-监控Pod日志
k8s学习-CKA真题-监控Pod日志
79 0
|
5天前
|
Kubernetes 安全 容器
k8s学习-CKS真题-TLS安全配置
k8s学习-CKS真题-TLS安全配置
78 0
|
5天前
|
Kubernetes 安全 Linux
k8s学习-CKS真题-Trivy扫描镜像安全漏洞
k8s学习-CKS真题-Trivy扫描镜像安全漏洞
61 0
|
5天前
|
Kubernetes 数据安全/隐私保护 容器
k8s学习-CKS真题-RoleBinding
k8s学习-CKS真题-RoleBinding
40 0
|
5天前
|
Kubernetes 安全 测试技术
k8s-CKS真题-CIS基准测试与安全扫描
k8s-CKS真题-CIS基准测试与安全扫描
40 0
|
5天前
|
Kubernetes 容器 Perl
k8s学习-CKA真题-网络策略NetworkPolicy
k8s学习-CKA真题-网络策略NetworkPolicy
40 0