AWS Builder Center: Learn, Build and Connect with builders in the AWS community
AWS Builder Center is the official home for builders on AWS. Share and read what others are working on, follow people who inspire you, explore training and workshops, and find tools to support what you're building.
常见问题解答: Amazon EKS 容器组中的容器组安全标准和容器组安全准入
我对 Amazon Elastic Kubernetes Service (Amazon EKS) 容器组 (pod) 中的容器组安全标准和容器组安全准入有一些疑问。
**问:**如何为我的 Amazon EKS 集群开启或关闭容器组安全标准和容器组安全准入?
默认情况下,Kubernetes 版本 1.23 及更高版本会在集群级别为特权容器组安全标准配置文件启用所有容器组安全准入模式。容器组安全准入允许在所有命名空间中使用具有特权容器组安全标准配置文件的部署或容器组。
**问:**如何在 Kubernetes 命名空间级别应用特定的容器组安全准入模式和容器组安全标准配置文件?
要在 Kubernetes 命名空间级别应用特定的容器组安全准入模式和容器组安全标准配置文件,请配置命名空间标签。
例如,运行以下命令,将 Baseline 容器组安全标准的 enforce 模式应用于单个命名空间:
kubectl label --overwrite ns test-namespace pod-security.kubernetes.io/enforce=baseline
或者,运行以下命令,将 Baseline 容器组安全标准的 enforce 模式应用于所有可用的命名空间:
kubectl label --overwrite ns --all pod-security.kubernetes.io/enforce=baseline
**注意:**将 test-namespace 替换为您的命名空间的名称,将 enforce 替换为您的容器组安全准入模式,将 baseline 替换为您的容器组安全标准策略配置文件。有关详细信息,请参阅 Kubernetes 网站上的 Pod Security Admission labels for namespaces(命名空间的容器组安全准入标签)和 Pod Security Standards(容器组安全标准)。
**问:**当我修改命名空间以使用更严格的容器组安全标准配置文件时,它会影响命名空间中现有容器组的功能吗?
不会。如果您使用现有容器组修改命名空间以使用 audit 或 warn 模式,您会在终端上收到消息。您还可以在容器组 YAML 输出的 status.message 部分看到该消息。如果您修改命名空间以使用 enforce 模式,Kubernetes 不会删除命名空间中的现有容器组。但是,您收到的消息与以下示例类似:
“Warning: existing pods in namespace "policy-test" violate the new PodSecurity enforce level "restricted:latest”
“Warning: test-688f68dc87-htm8x: allowPrivilegeEscalation != false, unrestricted capabilities, runAsNonRoot != true, seccompProfilenamespace/policy-test configured”
容器组 YAML 输出中的 enforce 模式消息示例:
lastTransitionTime: "2022-11-24T05:10:49Z" lastUpdateTime: "2022-11-24T05:10:49Z" message: 'pods "test-67d5fc995b-8r9t2" is forbidden: violates PodSecurity "baseline:latest": privileged (container "assets" must not set securityContext.privileged=true)' reason: FailedCreate status: "True" type: ReplicaFailure
如果容器组不遵守命名空间的容器组安全标准配置文件策略或容器组安全准入模式,请更新其部署清单。
**问:**如何自定义容器组安全准入控制器在我的命名空间级别应用的容器组安全策略?
您无法通过容器组安全准入控制器直接自定义应用的容器组安全策略。请使用验证准入策略来实施和强制执行您的自定义规则,或者使用带有外部代码的 Webhook 准入控制。
**问:**我能否将多个容器组安全准入模式和容器组安全标准配置文件应用于单个 Kubernetes 命名空间?
不可以。但是,您可以使用标签在任何命名空间上配置多个容器组安全标准检查。
例如,根据最新版本,以下命令将 enforce 模式应用于 Baseline 容器组安全标准,将 warn 和 audit 模式应用于 Restricted 容器组安全标准:
kubectl label --overwrite ns test \\ pod-security.kubernetes.io/enforce=baseline \\ pod-security.kubernetes.io/enforce-version=latest \\ pod-security.kubernetes.io/warn=restricted \\ pod-security.kubernetes.io/warn-version=latest \\ pod-security.kubernetes.io/audit=restricted \\ pod-security.kubernetes.io/audit-version=latest
**问:**我能否在托管式 Kubernetes 集群的集群级别应用容器组安全准入模式和容器组安全标准配置文件?
不能。对于托管式集群,您只能在命名空间级别应用容器组安全准入模式和容器组安全标准配置文件。
**问:**我能否在我的 Amazon EKS 集群中使用容器组安全准入 Webhook?
可以。您可以在您的 Amazon EKS 集群中安装容器组安全准入 Webhook。有关详细信息,请参阅 GitHub 网站上的 pod-security-admission webhook。
**问:**我为什么应该在我的 Amazon EKS 集群中使用容器组安全准入 Webhook?
借助容器组安全准入 Webhook,您可以在所有 Kubernetes 命名空间中应用相同的容器组安全准入模式和容器组安全标准配置文件。您也可以免除命名空间。如果没有容器组安全准入 Webhook,则必须在单个命名空间级别应用更改。
- 语言
- 中文 (简体)

相关内容
AWS 官方已更新 2 年前