Policy Controller 附带一个默认的限制条件模板库,可与 NIST SP 800-53 修订版本 5 包搭配使用,实施美国国家标准与技术研究院 (NIST) 特别出版物 (SP) 800-53 修订版本 5 中列出的控制措施。该包可实施开箱即用的安全和隐私权政策,帮助组织保护其系统和数据免受各种威胁的侵扰。
本页面包含有关手动应用政策包的说明。或者,您也可以直接应用政策包。
本页面适用于想要提供并维护自动化以进行审核或强制执行,从而确保云平台中运行的所有资源满足组织合规性要求的 IT 管理员和运维人员。如需详细了解我们在 Google Cloud 内容中提及的常见角色和示例任务,请参阅常见的 GKE 用户角色和任务。
NIST SP 800-53 修订版本 5 政策包限制条件
| 限制条件名称 | 限制条件说明 | 控制 ID | 
|---|---|---|
| nist-sp-800-53-r5-block-secrets-of-type-basic-auth | 限制使用基本-身份验证类型 Secret。 | AC-16 安全和隐私属性 | 
| nist-sp-800-53-r5-restrict-hostpath-volumes | 限制使用 HostPath 卷。 | |
| nist-sp-800-53-r5-restrict-rbac-subjects | 将 RBAC 主体中的名称限制为只能使用指定的值。 | AC-2 账号管理 | 
| nist-sp-800-53-r5-restrict-rbac-subjects | 将 RBAC 主体中的名称限制为只能使用指定的值。 | AC-3 访问权限强制执行 | 
| nist-sp-800-53-r5-block-secrets-of-type-basic-auth | 限制使用基本-身份验证类型 Secret。 | AC-4 信息流强制执行 | 
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | |
| nist-sp-800-53-r5-require-namespace-network-policies | 要求集群中定义的每个命名空间都具有一个 NetworkPolicy。 | |
| nist-sp-800-53-r5-restrict-hostpath-volumes | 限制使用 HostPath 卷。 | |
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | AC-6 最小权限 | 
| nist-sp-800-53-r5-restrict-clusteradmin-rolebindings | 限制使用“cluster-admin”角色。 | |
| nist-sp-800-53-r5-restrict-repos | 将容器映像限制为允许的“repos”列表。 | |
| nist-sp-800-53-r5-restrict-role-wildcards | 限制在“Roles”和“ClusterRoles”中使用通配符。 | |
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | AU-10 不可否认性 | 
| nist-sp-800-53-r5-nodes-have-consistent-time | 通过仅允许使用 Container-Optimized OS (COS) 或 Ubuntu 作为操作系统映像,确保节点上的时间一致且正确无误。 | AU-8 时间戳 | 
| nist-sp-800-53-r5-require-namespace-network-policies | 要求集群中定义的每个命名空间都具有一个 NetworkPolicy。 | CA-9 内部系统连接 | 
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | CM-14 签名组件 | 
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | CM-2 基准配置 | 
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-apparmor | 限制允许 Pod 使用的 AppArmor 配置文件。 | CM-3 配置更改控制 | 
| nist-sp-800-53-r5-block-secrets-of-type-basic-auth | 限制使用基本-身份验证类型 Secret。 | |
| nist-sp-800-53-r5-capabilities | 限制允许 Pod 使用的其他功能。 | |
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | |
| nist-sp-800-53-r5-host-namespaces | 限制“hostPID”或“hostIPC”设为“true”的容器。 | |
| nist-sp-800-53-r5-host-network | 限制“hostNetwork”标志设为“true”的容器运行。 | |
| nist-sp-800-53-r5-privileged-containers | 限制“securityContext.privileged”设为“true”的容器。 | |
| nist-sp-800-53-r5-proc-mount-type | 要求 Pod 使用默认的“/proc”掩码 | |
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-restrict-hostpath-volumes | 限制使用 HostPath 卷。 | |
| nist-sp-800-53-r5-restrict-volume-types | 将可装载卷的类型限制为允许列表中的类型。 | |
| nist-sp-800-53-r5-seccomp | Seccomp 配置文件不得明确设置为“Unconfined”。 | |
| nist-sp-800-53-r5-selinux | 限制 Pod 的 SELinux 配置。 | |
| nist-sp-800-53-r5-sysctls | 限制允许 Pod 使用的 Sysctls。 | |
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | CM-4 安全影响分析 | 
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-restrict-clusteradmin-rolebindings | 限制使用“cluster-admin”角色。 | |
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | CM-5 更改的访问权限限制 | 
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-restrict-clusteradmin-rolebindings | 限制使用“cluster-admin”角色。 | |
| nist-sp-800-53-r5-block-secrets-of-type-basic-auth | 限制使用基本-身份验证类型 Secret。 | CM-6 配置设置 | 
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | |
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | |
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-restrict-hostpath-volumes | 限制使用 HostPath 卷。 | |
| nist-sp-800-53-r5-restrict-volume-types | 将可装载卷的类型限制为允许列表中的类型。 | |
| nist-sp-800-53-r5-apparmor | 限制允许 Pod 使用的 AppArmor 配置文件。 | CM-7 最小功能 | 
| nist-sp-800-53-r5-capabilities | 限制允许 Pod 使用的其他功能。 | |
| nist-sp-800-53-r5-host-namespaces | 限制“hostPID”或“hostIPC”设为“true”的容器。 | |
| nist-sp-800-53-r5-host-network | 限制“hostNetwork”标志设为“true”的容器运行。 | |
| nist-sp-800-53-r5-privileged-containers | 限制“securityContext.privileged”设为“true”的容器。 | |
| nist-sp-800-53-r5-proc-mount-type | 要求 Pod 使用默认的“/proc”掩码 | |
| nist-sp-800-53-r5-restrict-clusteradmin-rolebindings | 限制使用“cluster-admin”角色。 | |
| nist-sp-800-53-r5-restrict-hostpath-volumes | 限制使用 HostPath 卷。 | |
| nist-sp-800-53-r5-restrict-volume-types | 将可装载卷的类型限制为允许列表中的类型。 | |
| nist-sp-800-53-r5-seccomp | Seccomp 配置文件不得明确设置为“Unconfined”。 | |
| nist-sp-800-53-r5-selinux | 限制 Pod 的 SELinux 配置。 | |
| nist-sp-800-53-r5-sysctls | 限制允许 Pod 使用的 Sysctls。 | |
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | CP-10 信息系统恢复和重建 | 
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | CP-9 系统备份 | 
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-restrict-rbac-subjects | 将 RBAC 主体中的名称限制为只能使用指定的值。 | IA-2 身份识别和身份验证(组织用户) | 
| nist-sp-800-53-r5-block-creation-with-default-serviceaccount | 禁止使用默认服务账号资源创建。 | IA-4 标识符管理 | 
| nist-sp-800-53-r5-restrict-rbac-subjects | 将 RBAC 主体中的名称限制为只能使用指定的值。 | |
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | IA-5 身份验证器管理 | 
| nist-sp-800-53-r5-restrict-rbac-subjects | 将 RBAC 主体中的名称限制为只能使用指定的值。 | |
| nist-sp-800-53-r5-restrict-rbac-subjects | 将 RBAC 主体中的名称限制为只能使用指定的值。 | MA-4 非本地维护 | 
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | PL-1 政策和程序 | 
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | RA-5 漏洞扫描 | 
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | SA-10 开发者配置管理 | 
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | SA-11 可信路径 | 
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | SA-3 系统开发生命周期 | 
| nist-sp-800-53-r5-block-secrets-of-type-basic-auth | 限制使用基本-身份验证类型 Secret。 | SA-8 安全和隐私工程原则 | 
| nist-sp-800-53-r5-restrict-hostpath-volumes | 限制使用 HostPath 卷。 | |
| nist-sp-800-53-r5-restrict-volume-types | 将可装载卷的类型限制为允许列表中的类型。 | |
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | SC-12 加密密钥创建和管理 | 
| nist-sp-800-53-r5-restrict-storageclass | 将“StorageClass”限制为默认情况下加密的“StorageClass”。 | SC-28 静态信息保护 | 
| nist-sp-800-53-r5-require-namespace-network-policies | 要求集群中定义的每个命名空间都具有一个 NetworkPolicy。 | SC-4 共享资源中的信息 | 
| nist-sp-800-53-r5-cpu-and-memory-limits-required | 要求 Pod 指定 CPU 和内存限制。 | SC-6 资源可用性 | 
| nist-sp-800-53-r5-block-secrets-of-type-basic-auth | 限制使用基本-身份验证类型 Secret。 | SC-7 边界保护 | 
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | |
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-require-namespace-network-policies | 要求集群中定义的每个命名空间都具有一个 NetworkPolicy。 | |
| nist-sp-800-53-r5-restrict-hostpath-volumes | 限制使用 HostPath 卷。 | |
| nist-sp-800-53-r5-restrict-volume-types | 将可装载卷的类型限制为允许列表中的类型。 | |
| nist-sp-800-53-r5-asm-peer-authn-strict-mtls | 确保 PeerAuthentication 无法覆盖严格 mTLS。 | SC-8 传输机密性和完整性 | 
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | SI-12 信息管理和保留 | 
| nist-sp-800-53-r5-restrict-storageclass | 将“StorageClass”限制为默认情况下加密的“StorageClass”。 | |
| nist-sp-800-53-r5-require-av-daemonset | 需要安装反病毒守护进程集。 | SI-3 恶意代码保护 | 
| nist-sp-800-53-r5-block-secrets-of-type-basic-auth | 限制使用基本-身份验证类型 Secret。 | SI-7 软件、固件和信息完整性 | 
| nist-sp-800-53-r5-enforce-config-management | 要求运行 Config Sync 并启用偏移预防,并且集群上至少有一个“RootSync”对象。 | |
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | |
| nist-sp-800-53-r5-require-managed-by-label | 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。 | |
| nist-sp-800-53-r5-restrict-hostpath-volumes | 限制使用 HostPath 卷。 | |
| nist-sp-800-53-r5-require-binauthz | 要求 Binary Authorization 验证准入 webhook。 | SR-4 出处 | 
须知事项
- 安装并初始化 Google Cloud CLI,它提供了以下说明中使用的 gcloud和kubectl命令。如果您使用 Cloud Shell,则系统会预安装 Google Cloud CLI。
- 在集群上安装 Policy Controller 以及默认的限制条件模板库。您还必须启用对参照限制条件的支持,因为此政策包中包含参照限制条件。
为参照限制条件配置政策控制器
- 在文件中,将以下 YAML 清单保存为 - policycontroller-config.yaml。此清单将 Policy Controller 配置为监视特定种类的对象。- apiVersion: config.gatekeeper.sh/v1alpha1 kind: Config metadata: name: config namespace: "gatekeeper-system" spec: sync: syncOnly: - group: "apps" version: "v1" kind: "DaemonSet" - group: "networking.k8s.io" version: "v1" kind: "NetworkPolicy" - group: "configsync.gke.io" version: "v1beta1" kind: "RootSync" - group: "storage.k8s.io" version: "v1" kind: "StorageClass" - group: "admissionregistration.k8s.io" version: "v1" kind: "ValidatingWebhookConfiguration"
- 应用 - policycontroller-config.yaml清单:- kubectl apply -f policycontroller-config.yaml 
配置集群和工作负载
- nist-sp-800-53-r5-enforce-config-management中要求启用和配置 Config Sync,包括偏移预防准入 webhook。
- 必须使用防病毒解决方案。 默认为 clamavnamespace中存在名为clamav的daemonset,但daemonset的名称和命名空间可以自定义以符合nist-sp-800-53-r5-require-av-daemonset限制条件中的实现。
- 容器映像限制为允许的仓库列表,但您可以根据需要在 nist-sp-800-53-r5-restrict-repos中进行自定义。
- 节点必须使用 Container-Optimized OS 或 Ubuntu 作为 nist-sp-800-53-r5-nodes-have-consistent-time中的映像。
- 可以使用的存储类别仅限于允许列表,但您可以在 nist-sp-800-53-r5-restrict-storageclass中进行自定义,添加具有默认加密的其他类别。
- 需要在 - nist-sp-800-53-r5-require-binauthz中启用和配置 Binary Authorization。
审核 NIST SP 800-53 修订版本 5 政策包
政策控制器允许您为 Kubernetes 集群强制执行政策。为了帮助测试您的工作负载及其对上表中列出的 NIST SP 800-53 政策的合规性,您可以在“审核”模式下部署这些限制条件以发现违规行为,更重要的是让您有机会在 Kubernetes 集群上强制执行之前处理这些违规行为。
您可以在 spec.enforcementAction 设置为 dryrun 的情况下,使用 kubectl、kpt 或 Config Sync 应用这些政策。
kubectl
- (可选)使用 kubectl 预览政策限制条件: - kubectl kustomize https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/nist-sp-800-53-r5 
- 使用 kubectl 应用政策限制条件: - kubectl apply -k https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/nist-sp-800-53-r5 - 输出如下所示: - asmpeerauthnstrictmtls.constraints.gatekeeper.sh/nist-sp-800-53-r5-asm-peer-authn-strict-mtls created k8sallowedrepos.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-repos created k8sblockcreationwithdefaultserviceaccount.constraints.gatekeeper.sh/nist-sp-800-53-r5-block-creation-with-default-serviceaccount created k8sblockobjectsoftype.constraints.gatekeeper.sh/nist-sp-800-53-r5-block-secrets-of-type-basic-auth created k8senforceconfigmanagement.constraints.gatekeeper.sh/nist-sp-800-53-r5-enforce-config-management created k8spspapparmor.constraints.gatekeeper.sh/nist-sp-800-53-r5-apparmor created k8spspcapabilities.constraints.gatekeeper.sh/nist-sp-800-53-r5-capabilities created k8spspforbiddensysctls.constraints.gatekeeper.sh/nist-sp-800-53-r5-sysctls created k8spsphostfilesystem.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-hostpath-volumes created k8spsphostnamespace.constraints.gatekeeper.sh/nist-sp-800-53-r5-host-namespaces created k8spsphostnetworkingports.constraints.gatekeeper.sh/nist-sp-800-53-r5-host-network created k8spspprivilegedcontainer.constraints.gatekeeper.sh/nist-sp-800-53-r5-privileged-containers created k8spspprocmount.constraints.gatekeeper.sh/nist-sp-800-53-r5-proc-mount-type created k8spspselinuxv2.constraints.gatekeeper.sh/nist-sp-800-53-r5-selinux created k8spspseccomp.constraints.gatekeeper.sh/nist-sp-800-53-r5-seccomp created k8spspvolumetypes.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-volume-types created k8sprohibitrolewildcardaccess.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-role-wildcards created k8srequirebinauthz.constraints.gatekeeper.sh/nist-sp-800-53-r5-require-binauthz created k8srequirecosnodeimage.constraints.gatekeeper.sh/nist-sp-800-53-r5-nodes-have-consistent-time created k8srequiredaemonsets.constraints.gatekeeper.sh/nist-sp-800-53-r5-require-av-daemonset created k8srequirenamespacenetworkpolicies.constraints.gatekeeper.sh/nist-sp-800-53-r5-require-namespace-network-policies created k8srequiredlabels.constraints.gatekeeper.sh/nist-sp-800-53-r5-require-managed-by-label created k8srequiredresources.constraints.gatekeeper.sh/nist-sp-800-53-r5-cpu-and-memory-limits-required created k8srestrictrbacsubjects.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-rbac-subjects created k8srestrictrolebindings.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-clusteradmin-rolebindings created k8sstorageclass.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-storageclass created 
- 验证政策限制条件是否已安装,并检查集群中是否存在违规行为: - kubectl get constraints -l policycontroller.gke.io/bundleName=nist-sp-800-53-r5 - 输出类似于以下内容: - NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spspapparmor.constraints.gatekeeper.sh/nist-sp-800-53-r5-apparmor dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8srequirebinauthz.constraints.gatekeeper.sh/nist-sp-800-53-r5-require-binauthz dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8srestrictrbacsubjects.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-rbac-subjects dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spspforbiddensysctls.constraints.gatekeeper.sh/nist-sp-800-53-r5-sysctls dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spspvolumetypes.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-volume-types dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spsphostnetworkingports.constraints.gatekeeper.sh/nist-sp-800-53-r5-host-network dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spsphostnamespace.constraints.gatekeeper.sh/nist-sp-800-53-r5-host-namespaces dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8srequiredaemonsets.constraints.gatekeeper.sh/nist-sp-800-53-r5-require-av-daemonset dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8sprohibitrolewildcardaccess.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-role-wildcards dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8sblockcreationwithdefaultserviceaccount.constraints.gatekeeper.sh/nist-sp-800-53-r5-block-creation-with-default-serviceaccount dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spsphostfilesystem.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-hostpath-volumes dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spspseccomp.constraints.gatekeeper.sh/nist-sp-800-53-r5-seccomp dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS asmpeerauthnstrictmtls.constraints.gatekeeper.sh/nist-sp-800-53-r5-asm-peer-authn-strict-mtls dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8srequiredresources.constraints.gatekeeper.sh/nist-sp-800-53-r5-cpu-and-memory-limits-required dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spspprocmount.constraints.gatekeeper.sh/nist-sp-800-53-r5-proc-mount-type dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8sblockobjectsoftype.constraints.gatekeeper.sh/nist-sp-800-53-r5-block-secrets-of-type-basic-auth dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8srequirenamespacenetworkpolicies.constraints.gatekeeper.sh/nist-sp-800-53-r5-require-namespace-network-policies dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spspcapabilities.constraints.gatekeeper.sh/nist-sp-800-53-r5-capabilities dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8sstorageclass.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-storageclass dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8srequiredlabels.constraints.gatekeeper.sh/nist-sp-800-53-r5-require-managed-by-label dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spspprivilegedcontainer.constraints.gatekeeper.sh/nist-sp-800-53-r5-privileged-containers dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8sallowedrepos.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-repos dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8spspselinuxv2.constraints.gatekeeper.sh/nist-sp-800-53-r5-selinux dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8senforceconfigmanagement.constraints.gatekeeper.sh/nist-sp-800-53-r5-enforce-config-management dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8srestrictrolebindings.constraints.gatekeeper.sh/nist-sp-800-53-r5-restrict-clusteradmin-rolebindings dryrun 0 NAME ENFORCEMENT-ACTION TOTAL-VIOLATIONS k8srequirecosnodeimage.constraints.gatekeeper.sh/nist-sp-800-53-r5-nodes-have-consistent-time dryrun 0 
kpt
- 安装并设置 kpt。 - 在这些说明中,kpt 用于自定义和部署 Kubernetes 资源。 
- 使用 kpt 从 GitHub 下载 NIST SP 800-53 修订版本 5 政策包: - kpt pkg get https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/nist-sp-800-53-r5 
- 运行 - set-enforcement-actionkpt 函数将政策的强制执行操作设置为- dryrun:- kpt fn eval nist-sp-800-53-r5 -i gcr.io/kpt-fn/set-enforcement-action:v0.1 \ -- enforcementAction=dryrun 
- 使用 kpt 初始化工作目录,此操作会创建一个资源来跟踪更改: - cd nist-sp-800-53-r5 kpt live init 
- 使用 kpt 应用政策限制条件: - kpt live apply 
- 验证政策限制条件是否已安装,并检查集群中是否存在违规行为: - kpt live status --output table --poll-until current - 状态为 - CURRENT,即表示限制条件成功安装。
Config Sync
- 安装并设置 kpt。 - 在这些说明中,kpt 用于自定义和部署 Kubernetes 资源。 - 使用 Config Sync 将政策部署到其集群的运维人员可以按照以下说明操作: 
- 更改为 Config Sync 的同步目录: - cd SYNC_ROOT_DIR - 创建 - resourcegroup.yaml或将其附加到- .gitignore:- echo resourcegroup.yaml >> .gitignore 
- 创建一个专用的 - policies目录:- mkdir -p policies 
- 使用 kpt 从 GitHub 下载 NIST SP 800-53 修订版本 5 政策包: - kpt pkg get https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/nist-sp-800-53-r5 policies/nist-sp-800-53-r5 
- 运行 - set-enforcement-actionkpt 函数将政策的强制执行操作设置为- dryrun:- kpt fn eval policies/nist-sp-800-53-r5 -i gcr.io/kpt-fn/set-enforcement-action:v0.1 -- enforcementAction=dryrun 
- (可选)预览待创建的政策限制条件: - kpt live init policies/nist-sp-800-53-r5 kpt live apply --dry-run policies/nist-sp-800-53-r5 
- 如果 Config Sync 的同步目录使用 Kustomize,请将 - policies/nist-sp-800-53-r5添加到根- kustomization.yaml。否则,请移除- policies/nist-sp-800-53-r5/kustomization.yaml文件:- rm SYNC_ROOT_DIR/policies/nist-sp-800-53-r5/kustomization.yaml 
- 将更改推送到 Config Sync 代码库: - git add SYNC_ROOT_DIR/policies/nist-sp-800-53-r5 git commit -m 'Adding NIST SP 800-53 Rev. 5 policy audit enforcement' git push 
- 验证安装状态: - watch gcloud beta container fleet config-management status --project PROJECT_ID - 状态 - SYNCED用于确认政策的安装情况。
查看违规问题
在审核模式下安装政策限制条件后,您可以使用 Policy Controller 信息中心在界面中查看集群的违规问题。
- 您还可以使用 - kubectl来通过以下命令查看针对集群的违规行为:- kubectl get constraint -l policycontroller.gke.io/bundleName=nist-sp-800-53-r5 -o json | jq -cC '.items[]| [.metadata.name,.status.totalViolations]' 
- 如果存在违规行为,您可以使用以下命令查看每个限制条件的违规消息列表: - kubectl get constraint -l policycontroller.gke.io/bundleName=nist-sp-800-53-r5 -o json | jq -C '.items[]| select(.status.totalViolations>0)| [.metadata.name,.status.violations[]?]' 
更改 NIST SP 800-53 修订版本 5 政策包强制执行操作
查看集群上的政策违规情况后,您可以考虑更改强制执行模式,以便准入控制器发出 warn,甚至 deny 屏蔽不合规资源应用于集群。
kubectl
- 使用 kubectl 将政策的强制执行操作设置为 - warn:- kubectl get constraints -l policycontroller.gke.io/bundleName=nist-sp-800-53-r5 -o name | xargs -I {} kubectl patch {} --type='json' -p='[{"op":"replace","path":"/spec/enforcementAction","value":"warn"}]'
- 验证政策限制条件强制执行措施是否已更新: - kubectl get constraints -l policycontroller.gke.io/bundleName=nist-sp-800-53-r5 
kpt
- 运行 - set-enforcement-actionkpt 函数将政策的强制执行操作设置为- warn:- kpt fn eval -i gcr.io/kpt-fn/set-enforcement-action:v0.1 -- enforcementAction=warn 
- 应用政策限制条件: - kpt live apply 
Config Sync
使用 Config Sync 将政策部署到其集群的运维人员可以按照以下说明操作:
- 更改为 Config Sync 的同步目录: - cd SYNC_ROOT_DIR 
- 运行 - set-enforcement-actionkpt 函数将政策的强制执行操作设置为- warn:- kpt fn eval policies/nist-sp-800-53-r5 -i gcr.io/kpt-fn/set-enforcement-action:v0.1 -- enforcementAction=warn 
- 将更改推送到 Config Sync 代码库: - git add SYNC_ROOT_DIR/policies/nist-sp-800-53-r5 git commit -m 'Adding NIST SP 800-53 Rev. 5 policy warn enforcement' git push 
- 验证安装状态: - nomos status - 集群应显示状态为 - SYNCED,并显示已安装的政策。
测试政策执行情况
使用以下命令在集群上创建不合规的资源:
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: wp-non-compliant
spec:
  containers:
    ‐ image: wordpress
      name: wordpress
EOF
准入控制器应生成一个警告列表,其中列出了此资源违反政策的行为,如以下示例所示:
Warning: [nist-sp-800-53-r5-cpu-and-memory-limits-required] container <wordpress> does not have <{"cpu", "memory"}> limits defined
Warning: [nist-sp-800-53-r5-restrict-repos] container <wordpress> has an invalid image repo <wordpress>, allowed repos are ["gcr.io/gke-release/", "gcr.io/anthos-baremetal-release/", "gcr.io/config-management-release/", "gcr.io/kubebuilder/", "gcr.io/gkeconnect/", "gke.gcr.io/"]
pod/wp-non-compliant created
移除 NIST SP 800-53 修订版本 5 政策包
如果需要,可以从集群中移除 NIST SP 800-53 修订版本 5 政策包。
kubectl
- 使用 kubectl 移除政策: - kubectl delete constraint -l policycontroller.gke.io/bundleName=nist-sp-800-53-r5 
kpt
- 移除政策: - kpt live destroy 
Config Sync
使用 Config Sync 将政策部署到其集群的运维人员可以按照以下说明操作:
- 将更改推送到 Config Sync 代码库: - git rm -r SYNC_ROOT_DIR/policies/nist-sp-800-53-r5 git commit -m 'Removing NIST SP 800-53 Rev. 5 policies' git push 
- 验证状态: - nomos status - 集群应显示状态为 - SYNCED,且资源已移除。