gpt4 book ai didi

kubernetes - 如何在 AKS 的 K8S 集群中强制执行 MustRunAsNonRoot 策略

转载 作者:行者123 更新时间:2023-12-04 13:29:12 24 4
gpt4 key购买 nike

我有一个在 Azure AKS 服务中运行的 K8S 集群。
我要强制执行 MustRunAsNonRoot 政策。怎么做?
创建了以下策略:

apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: restrict-root
spec:
privileged: false
allowPrivilegeEscalation: false
runAsUser:
rule: MustRunAsNonRoot
seLinux:
rule: RunAsAny
fsGroup:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
volumes:
- '*'
它部署在集群中:
$ kubectl get psp
NAME PRIV CAPS SELINUX RUNASUSER FSGROUP SUPGROUP READONLYROOTFS VOLUMES
restrict-root false RunAsAny MustRunAsNonRoot RunAsAny RunAsAny false *
准入 Controller 在集群中运行:
$ kubectl get pods -n gatekeeper-system
NAME READY STATUS RESTARTS AGE
gatekeeper-audit-7b4bc6f977-lvvfl 1/1 Running 0 32d
gatekeeper-controller-5948ddcd54-5mgsm 1/1 Running 0 32d
gatekeeper-controller-5948ddcd54-b59wg 1/1 Running 0 32d
无论如何,可以在 root 下运行一个简单的 pod:
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mypod
image: busybox
args: ["sleep", "10000"]
securityContext:
runAsUser: 0
Pod 正在运行:
$ kubectl describe po mypod
Name: mypod
Namespace: default
Priority: 0
Node: aks-default-31327534-vmss000001/10.240.0.5
Start Time: Mon, 08 Feb 2021 23:10:46 +0100
Labels: <none>
Annotations: <none>
Status: Running
为什么 MustRunAsNonRoot 不适用?如何强制执行?
编辑:看起来 AKS 引擎不支持 PodSecurityPolicy ( list of supported policies )。那么问题还是一样的:如何对工作负载强制执行 MustRunAsNonRoot 规则?

最佳答案

你不应该使用 PodSecurityPolicy Azure AKS 群集 因为它已被设置为从 2021 年 5 月 31 日起弃用 Azure Policy for AKS .查询 the official docs欲知更多详情:

Warning

The feature described in this document, pod security policy (preview), is set for deprecation and will no longer be availableafter May 31st, 2021 in favor of Azure Policy forAKS.The deprecation date has been extended from the previous date ofOctober 15th, 2020.


所以目前你应该使用 Azure Policy for AKS ,其中 among other built-in policies分组为计划(Azure Policy 中的计划是为实现单一的总体目标而量身定制的策略定义的集合),您可以找到目标是 disallow running of privileged containers 的策略。在您的 AKS 集群 .
至于 PodSecurityPolicy ,暂时它应该仍然有效。请查收 here如果你没有忘记任何事情,例如确保您 set up the corresponding ClusterRole and ClusterRoleBinding 允许使用该策略。

关于kubernetes - 如何在 AKS 的 K8S 集群中强制执行 MustRunAsNonRoot 策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66110317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com