使用 NIST SP 800-190 政策限制条件

Policy Controller 附带默认的限制条件模板库,可与 NIST SP 800-190 包搭配使用,实施美国国家标准与技术研究院 (NIST) 特别出版物 (SP) 800-190 应用容器安全指南中列出的控制措施。该包旨在帮助组织实施应用容器安全,包括映像安全、容器运行时安全、网络安全和主机系统安全等。

NIST SP 800-190 政策包限制条件

限制条件名称 限制条件说明 控制 ID
nist-sp-800-190-restrict-rbac-subjects 将 RBAC 主体中的名称限制为只能使用指定的值。 AC-2 账号管理
nist-sp-800-190-restrict-rbac-subjects 将 RBAC 主体中的名称限制为只能使用指定的值。 AC-3 访问权限强制执行
nist-sp-800-190-block-secrets-of-type-basic-auth 限制使用基本-身份验证类型 Secret。 AC-4 信息流强制执行
nist-sp-800-190-require-binauthz 要求 Binary Authorization 验证准入 webhook。
nist-sp-800-190-require-namespace-network-policies 要求集群中定义的每个命名空间都具有一个 NetworkPolicy。
nist-sp-800-190-restrict-hostpath-volumes 限制使用 HostPath 卷。
nist-sp-800-190-require-binauthz 要求 Binary Authorization 验证准入 webhook。 AC-6 最小权限
nist-sp-800-190-restrict-clusteradmin-rolebindings 限制使用“cluster-admin”角色。
nist-sp-800-190-restrict-repos 将容器映像限制为允许的“repos”列表。
nist-sp-800-190-restrict-role-wildcards 限制在“Roles”和“ClusterRoles”中使用通配符。
nist-sp-800-190-nodes-have-consistent-time 通过仅允许使用 Container-Optimized OS (COS) 或 Ubuntu 作为操作系统映像,确保节点上的时间一致且正确无误。 AU-8 时间戳
nist-sp-800-190-require-namespace-network-policies 要求集群中定义的每个命名空间都具有一个 NetworkPolicy。 CA-9 内部系统连接
nist-sp-800-190-enforce-config-management 要求 Config Sync 正在运行且必须启用 Drift Prevention,且集群上至少要有一个“RootSync”对象。 CM-2 基准配置
nist-sp-800-190-require-managed-by-label 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。
nist-sp-800-190-apparmor 限制允许 Pod 使用的 AppArmor 配置文件。 CM-3 配置更改控制
nist-sp-800-190-block-secrets-of-type-basic-auth 限制使用基本-身份验证类型 Secret。
nist-sp-800-190-capabilities 限制允许 Pod 使用的其他功能。
nist-sp-800-190-enforce-config-management 要求 Config Sync 正在运行且必须启用 Drift Prevention,且集群上至少要有一个“RootSync”对象。
nist-sp-800-190-host-namespaces 限制“hostPID”或“hostIPC”设为“true”的容器。
nist-sp-800-190-host-network 限制“hostNetwork”标志设为“true”的容器运行。
nist-sp-800-190-privileged-containers 限制“securityContext.privileged”设为“true”的容器。
nist-sp-800-190-proc-mount-type 要求 Pod 使用默认的“/proc”掩码
nist-sp-800-190-require-managed-by-label 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。
nist-sp-800-190-restrict-hostpath-volumes 限制使用 HostPath 卷。
nist-sp-800-190-restrict-volume-types 将可装载卷的类型限制为允许列表中的类型。
nist-sp-800-190-seccomp Seccomp 配置文件不得明确设置为“Unconfined”。
nist-sp-800-190-selinux 限制 Pod 的 SELinux 配置。
nist-sp-800-190-sysctls 限制允许 Pod 使用的 Sysctls。
nist-sp-800-190-enforce-config-management 要求 Config Sync 正在运行且必须启用 Drift Prevention,且集群上至少要有一个“RootSync”对象。 CM-4 安全影响分析
nist-sp-800-190-require-managed-by-label 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。
nist-sp-800-190-restrict-clusteradmin-rolebindings 限制使用“cluster-admin”角色。
nist-sp-800-190-enforce-config-management 要求 Config Sync 正在运行且必须启用 Drift Prevention,且集群上至少要有一个“RootSync”对象。 CM-5 更改的访问权限限制
nist-sp-800-190-require-managed-by-label 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。
nist-sp-800-190-restrict-clusteradmin-rolebindings 限制使用“cluster-admin”角色。
nist-sp-800-190-block-secrets-of-type-basic-auth 限制使用基本-身份验证类型 Secret。 CM-6 配置设置
nist-sp-800-190-enforce-config-management 要求 Config Sync 正在运行且必须启用 Drift Prevention,且集群上至少要有一个“RootSync”对象。
nist-sp-800-190-require-binauthz 要求 Binary Authorization 验证准入 webhook。
nist-sp-800-190-require-managed-by-label 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。
nist-sp-800-190-restrict-hostpath-volumes 限制使用 HostPath 卷。
nist-sp-800-190-restrict-volume-types 将可装载卷的类型限制为允许列表中的类型。
nist-sp-800-190-apparmor 限制允许 Pod 使用的 AppArmor 配置文件。 CM-7 最小功能
nist-sp-800-190-capabilities 限制允许 Pod 使用的其他功能。
nist-sp-800-190-host-namespaces 限制“hostPID”或“hostIPC”设为“true”的容器。
nist-sp-800-190-host-network 限制“hostNetwork”标志设为“true”的容器运行。
nist-sp-800-190-privileged-containers 限制“securityContext.privileged”设为“true”的容器。
nist-sp-800-190-proc-mount-type 要求 Pod 使用默认的“/proc”掩码
nist-sp-800-190-restrict-clusteradmin-rolebindings 限制使用“cluster-admin”角色。
nist-sp-800-190-restrict-hostpath-volumes 限制使用 HostPath 卷。
nist-sp-800-190-restrict-volume-types 将可装载卷的类型限制为允许列表中的类型。
nist-sp-800-190-seccomp Seccomp 配置文件不得明确设置为“Unconfined”。
nist-sp-800-190-selinux 限制 Pod 的 SELinux 配置。
nist-sp-800-190-sysctls 限制允许 Pod 使用的 Sysctls。
nist-sp-800-190-enforce-config-management 要求 Config Sync 正在运行且必须启用 Drift Prevention,且集群上至少要有一个“RootSync”对象。 CP-9 系统备份
nist-sp-800-190-require-managed-by-label 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。
nist-sp-800-190-enforce-config-management 要求 Config Sync 正在运行且必须启用 Drift Prevention,且集群上至少要有一个“RootSync”对象。 CP-10 信息系统恢复和重建
nist-sp-800-190-require-managed-by-label 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。
nist-sp-800-190-restrict-rbac-subjects 将 RBAC 主体中的名称限制为只能使用指定的值。 IA-2 身份识别和身份验证(组织用户)
nist-sp-800-190-block-creation-with-default-serviceaccount 禁止使用默认服务账号资源创建。 IA-4 标识符管理
nist-sp-800-190-restrict-rbac-subjects 将 RBAC 主体中的名称限制为只能使用指定的值。
nist-sp-800-190-require-binauthz 要求 Binary Authorization 验证准入 webhook。 IA-5 身份验证器管理
nist-sp-800-190-restrict-rbac-subjects 将 RBAC 主体中的名称限制为只能使用指定的值。
nist-sp-800-190-restrict-rbac-subjects 将 RBAC 主体中的名称限制为只能使用指定的值。 MA-4 非本地维护
nist-sp-800-190-enforce-config-management 要求 Config Sync 正在运行且必须启用 Drift Prevention,且集群上至少要有一个“RootSync”对象。 SA-10 开发者配置管理
nist-sp-800-190-require-managed-by-label 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。
nist-sp-800-190-require-namespace-network-policies 要求集群中定义的每个命名空间都具有一个 NetworkPolicy。 SC-4 共享资源中的信息
nist-sp-800-190-cpu-and-memory-limits-required 要求 Pod 指定 CPU 和内存限制。 SC-6 资源可用性
nist-sp-800-190-asm-peer-authn-strict-mtls 确保 PeerAuthentication 无法覆盖严格 mTLS。 SC-8 传输机密性和完整性
nist-sp-800-190-block-secrets-of-type-basic-auth 限制使用基本-身份验证类型 Secret。 SI-7 软件、固件和信息完整性
nist-sp-800-190-enforce-config-management 要求 Config Sync 正在运行且必须启用 Drift Prevention,且集群上至少要有一个“RootSync”对象。
nist-sp-800-190-require-binauthz 要求 Binary Authorization 验证准入 webhook。
nist-sp-800-190-require-managed-by-label 要求所有应用都具有有效的“app.kubernetes.io/managed-by”标签。
nist-sp-800-190-restrict-hostpath-volumes 限制使用 HostPath 卷。

准备工作

  1. 安装并初始化 Google Cloud CLI,它提供了以下说明中使用的 gcloudkubectl 命令。如果您使用 Cloud Shell,则系统会预安装 Google Cloud CLI。
  2. 在集群上安装 Policy Controller v1.15.2 或更高版本以及默认的限制条件模板库。您还必须启用对参照限制条件的支持,因为此捆绑包包含参照限制条件。

为参照限制条件配置政策控制器

  1. 在文件中,将以下 YAML 清单保存为 policycontroller-config.yaml。清单将政策控制器配置为监视特定种类的对象。

    apiVersion: config.gatekeeper.sh/v1alpha1
    kind: Config
    metadata:
      name: config
      namespace: "gatekeeper-system"
    spec:
      sync:
        syncOnly:
          - group: "networking.k8s.io"
            version: "v1"
            kind: "NetworkPolicy"
          - group: "configsync.gke.io"
            version: "v1beta1"
            kind: "RootSync"
          - group: "admissionregistration.k8s.io"
            version: "v1"
            kind: "ValidatingWebhookConfiguration"
    
  2. 应用 policycontroller-config.yaml 清单:

    kubectl apply -f policycontroller-config.yaml
    

配置集群和工作负载

  1. nist-sp-800-190-enforce-config-management 中要求启用和配置 Config Sync,包括偏移预防准入 webhook
  2. 容器映像限制为允许的仓库列表,但您可以根据需要在 nist-sp-800-190-restrict-repos 中进行自定义。
  3. 节点必须使用 Container-Optimized OS 或 Ubuntu 作为 nist-sp-800-190-nodes-have-consistent-time 中的映像。
  4. 需要在 nist-sp-800-190-require-binauthz 中启用和配置 Binary Authorization

审核 NIST SP 800-190 政策包

政策控制器允许您为 Kubernetes 集群强制执行政策。为了帮助测试您的工作负载及其对上表中列出的 NIST 政策的合规性,您可以在“审核”模式下部署这些限制条件以发现违规行为,更重要的是让您有机会在 Kubernetes 集群上强制执行之前处理这些违规行为。

您可以在 spec.enforcementAction 设置为 dryrun 的情况下,使用 kubectl、kptConfig Sync 应用这些政策。

kubectl

  1. (可选)使用 kubectl 预览政策限制条件:

    kubectl kustomize https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/nist-sp-800-190
    
  2. 使用 kubectl 应用政策限制条件:

    kubectl apply -k https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/nist-sp-800-190
    

    输出如下所示:

    asmpeerauthnstrictmtls.constraints.gatekeeper.sh/nist-sp-800-190-asm-peer-authn-strict-mtls created
    k8sallowedrepos.constraints.gatekeeper.sh/nist-sp-800-190-restrict-repos created
    k8sblockcreationwithdefaultserviceaccount.constraints.gatekeeper.sh/nist-sp-800-190-block-creation-with-default-serviceaccount created
    k8sblockobjectsoftype.constraints.gatekeeper.sh/nist-sp-800-190-block-secrets-of-type-basic-auth created
    k8senforceconfigmanagement.constraints.gatekeeper.sh/nist-sp-800-190-enforce-config-management created
    k8spspapparmor.constraints.gatekeeper.sh/nist-sp-800-190-apparmor created
    k8spspcapabilities.constraints.gatekeeper.sh/nist-sp-800-190-capabilities created
    k8spspforbiddensysctls.constraints.gatekeeper.sh/nist-sp-800-190-sysctls created
    k8spsphostfilesystem.constraints.gatekeeper.sh/nist-sp-800-190-restrict-hostpath-volumes created
    k8spsphostnamespace.constraints.gatekeeper.sh/nist-sp-800-190-host-namespaces created
    k8spsphostnetworkingports.constraints.gatekeeper.sh/nist-sp-800-190-host-network created
    k8spspprivilegedcontainer.constraints.gatekeeper.sh/nist-sp-800-190-privileged-containers created
    k8spspprocmount.constraints.gatekeeper.sh/nist-sp-800-190-proc-mount-type created
    k8spspselinuxv2.constraints.gatekeeper.sh/nist-sp-800-190-selinux created
    k8spspseccomp.constraints.gatekeeper.sh/nist-sp-800-190-seccomp created
    k8spspvolumetypes.constraints.gatekeeper.sh/nist-sp-800-190-restrict-volume-types created
    k8sprohibitrolewildcardaccess.constraints.gatekeeper.sh/nist-sp-800-190-restrict-role-wildcards created
    k8srequirebinauthz.constraints.gatekeeper.sh/nist-sp-800-190-require-binauthz created
    k8srequirecosnodeimage.constraints.gatekeeper.sh/nist-sp-800-190-nodes-have-consistent-time created
    k8srequirenamespacenetworkpolicies.constraints.gatekeeper.sh/nist-sp-800-190-require-namespace-network-policies created
    k8srequiredlabels.constraints.gatekeeper.sh/nist-sp-800-190-require-managed-by-label created
    k8srequiredresources.constraints.gatekeeper.sh/nist-sp-800-190-cpu-and-memory-limits-required created
    k8srestrictrbacsubjects.constraints.gatekeeper.sh/nist-sp-800-190-restrict-rbac-subjects created
    k8srestrictrolebindings.constraints.gatekeeper.sh/nist-sp-800-190-restrict-clusteradmin-rolebindings created
    
  3. 验证政策限制条件是否已安装,并检查集群中是否存在违规行为:

    kubectl get constraints -l policycontroller.gke.io/bundleName=nist-sp-800-190
    

    输出类似于以下内容:

    NAME                                                            ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spspapparmor.constraints.gatekeeper.sh/nist-sp-800-190-apparmor   dryrun               0
    
    NAME                                                                        ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequirebinauthz.constraints.gatekeeper.sh/nist-sp-800-190-require-binauthz   dryrun               0
    
    NAME                                                                                   ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srestrictrbacsubjects.constraints.gatekeeper.sh/nist-sp-800-190-restrict-rbac-subjects   dryrun               0
    
    NAME                                                                   ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spspforbiddensysctls.constraints.gatekeeper.sh/nist-sp-800-190-sysctls   dryrun               0
    
    NAME                                                                            ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spspvolumetypes.constraints.gatekeeper.sh/nist-sp-800-190-restrict-volume-types   dryrun               0
    
    NAME                                                                           ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spsphostnetworkingports.constraints.gatekeeper.sh/nist-sp-800-190-host-network   dryrun               0
    
    NAME                                                                        ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spsphostnamespace.constraints.gatekeeper.sh/nist-sp-800-190-host-namespaces   dryrun               0
    
    NAME                                                                                          ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8sprohibitrolewildcardaccess.constraints.gatekeeper.sh/nist-sp-800-190-restrict-role-wildcards   dryrun               0
    
    NAME                                                                                                                         ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8sblockcreationwithdefaultserviceaccount.constraints.gatekeeper.sh/nist-sp-800-190-block-creation-with-default-serviceaccount   dryrun               0
    
    NAME                                                                                   ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spsphostfilesystem.constraints.gatekeeper.sh/nist-sp-800-190-restrict-hostpath-volumes   dryrun               0
    
    NAME                                                          ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spspseccomp.constraints.gatekeeper.sh/nist-sp-800-190-seccomp   dryrun               0
    
    NAME                                                                                      ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    asmpeerauthnstrictmtls.constraints.gatekeeper.sh/nist-sp-800-190-asm-peer-authn-strict-mtls   dryrun               0
    
    NAME                                                                                        ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequiredresources.constraints.gatekeeper.sh/nist-sp-800-190-cpu-and-memory-limits-required   dryrun               0
    
    NAME                                                                    ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spspprocmount.constraints.gatekeeper.sh/nist-sp-800-190-proc-mount-type   dryrun               0
    
    NAME                                                                                           ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8sblockobjectsoftype.constraints.gatekeeper.sh/nist-sp-800-190-block-secrets-of-type-basic-auth   dryrun               0
    
    NAME                                                                                                          ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequirenamespacenetworkpolicies.constraints.gatekeeper.sh/nist-sp-800-190-require-namespace-network-policies   dryrun               0
    
    NAME                                                                    ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spspcapabilities.constraints.gatekeeper.sh/nist-sp-800-190-capabilities   dryrun               0
    
    NAME                                                                               ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequiredlabels.constraints.gatekeeper.sh/nist-sp-800-190-require-managed-by-label   dryrun               0
    
    NAME                                                                                    ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spspprivilegedcontainer.constraints.gatekeeper.sh/nist-sp-800-190-privileged-containers   dryrun               0
    
    NAME                                                                   ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8sallowedrepos.constraints.gatekeeper.sh/nist-sp-800-190-restrict-repos   dryrun               0
    
    NAME                                                            ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8spspselinuxv2.constraints.gatekeeper.sh/nist-sp-800-190-selinux   dryrun               0
    
    NAME                                                                                         ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8senforceconfigmanagement.constraints.gatekeeper.sh/nist-sp-800-190-enforce-config-management   dryrun               0
    
    NAME                                                                                               ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srestrictrolebindings.constraints.gatekeeper.sh/nist-sp-800-190-restrict-clusteradmin-rolebindings   dryrun               0
    

kpt

  1. 安装并设置 kpt

    在这些说明中,kpt 用于自定义和部署 Kubernetes 资源。

  2. 使用 kpt 从 GitHub 下载 NIST SP 800-190 政策包:

    kpt pkg get https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/nist-sp-800-190
    
  3. 运行 set-enforcement-action kpt 函数将政策的强制执行操作设置为 dryrun

    kpt fn eval nist-sp-800-190 -i gcr.io/kpt-fn/set-enforcement-action:v0.1 \
    -- enforcementAction=dryrun
    
  4. 使用 kpt 初始化工作目录,此操作会创建一个资源来跟踪更改:

    cd nist-sp-800-190 kpt live init
    
  5. 使用 kpt 应用政策限制条件:

    kpt live apply
    
  6. 验证政策限制条件是否已安装,并检查集群中是否存在违规行为:

    kpt live status --output table --poll-until current
    

    状态为 CURRENT,即表示限制条件成功安装。

Config Sync

  1. 安装并设置 kpt

    在这些说明中,kpt 用于自定义和部署 Kubernetes 资源。

    使用 Config Sync 将政策部署到其集群的运维人员可以按照以下说明操作:

  2. 更改为 Config Sync 的同步目录:

    cd SYNC_ROOT_DIR
    

    创建 resourcegroup.yaml 或将其附加到 .gitignore

    echo resourcegroup.yaml >> .gitignore
    
  3. 创建一个专用的 policies 目录:

    mkdir -p policies
    
  4. 使用 kpt 从 GitHub 下载 NIST SP 800-190 政策包:

    kpt pkg get https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/nist-sp-800-190 policies/nist-sp-800-190
    
  5. 运行 set-enforcement-action kpt 函数将政策的强制执行操作设置为 dryrun

    kpt fn eval policies/nist-sp-800-190 -i gcr.io/kpt-fn/set-enforcement-action:v0.1 -- enforcementAction=dryrun
    
  6. (可选)预览待创建的政策限制条件:

    kpt live init policies/nist-sp-800-190 kpt live apply --dry-run policies/nist-sp-800-190
    
  7. 如果 Config Sync 的同步目录使用 Kustomize,请将 policies/nist-sp-800-190 添加到根 kustomization.yaml。否则,请移除 policies/nist-sp-800-190/kustomization.yaml 文件:

    rm SYNC_ROOT_DIR/policies/nist-sp-800-190/kustomization.yaml
    
  8. 将更改推送到 Config Sync 代码库:

    git add SYNC_ROOT_DIR/policies/nist-sp-800-190 git commit -m 'Adding NIST SP 800-190 policy audit enforcement'
    git push
    
  9. 验证安装状态:

    watch gcloud beta container fleet config-management status --project PROJECT_ID
    

    状态 SYNCED 用于确认政策的安装情况。

查看违规问题

在审核模式下安装政策限制条件后,您可以使用 Policy Controller 信息中心在界面中查看集群的违规问题。

  1. 您还可以使用 kubectl 来通过以下命令查看针对集群的违规行为:

    kubectl get constraint -l policycontroller.gke.io/bundleName=nist-sp-800-190 -o json | jq -cC '.items[]| [.metadata.name,.status.totalViolations]'
    
  2. 如果存在违规行为,您可以使用以下命令查看每个限制条件的违规消息列表:

    kubectl get constraint -l policycontroller.gke.io/bundleName=nist-sp-800-190 -o json | jq -C '.items[]| select(.status.totalViolations>0)| [.metadata.name,.status.violations[]?]'
    

更改 NIST SP 800-190 政策包强制执行操作

查看集群上的政策违规情况后,您可以考虑更改强制执行模式,以便准入控制器发出 warn,甚至 deny 屏蔽不合规资源应用于集群。

kubectl

  1. 使用 kubectl 将政策的强制执行操作设置为 deny

    kubectl get constraints -l policycontroller.gke.io/bundleName=nist-sp-800-190 -o name | xargs -I {} kubectl patch {} --type='json' -p='[{"op":"replace","path":"/spec/enforcementAction","value":"warn"}]'
    
  2. 验证政策限制条件强制执行措施是否已更新:

    kubectl get constraints -l policycontroller.gke.io/bundleName=nist-sp-800-190
    

kpt

  1. 运行 set-enforcement-action kpt 函数将政策的强制执行操作设置为 deny

    kpt fn eval -i gcr.io/kpt-fn/set-enforcement-action:v0.1 -- enforcementAction=deny
    
  2. 应用政策限制条件:

    kpt live apply
    

Config Sync

使用 Config Sync 将政策部署到其集群的运维人员可以按照以下说明操作:

  1. 更改为 Config Sync 的同步目录:

    cd SYNC_ROOT_DIR
    
  2. 运行 set-enforcement-action kpt 函数将政策的强制执行操作设置为 deny

    kpt fn eval policies/nist-sp-800-190 -i gcr.io/kpt-fn/set-enforcement-action:v0.1 -- enforcementAction=deny
    
  3. 将更改推送到 Config Sync 代码库:

    git add SYNC_ROOT_DIR/policies/nist-sp-800-190
    git commit -m 'Adding NIST SP 800-190 policy warn enforcement'
    git push
    
  4. 验证安装状态:

    gcloud alpha anthos config sync repo list --project PROJECT_ID
    

    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-190-cpu-and-memory-limits-required] container <wordpress> does not have <{"cpu", "memory"}> limits defined
Warning: [nist-sp-800-190-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-190 政策包

如果需要,您可以从集群中移除 NIST SP 800-190 政策包。

kubectl

  • 使用 kubectl 移除政策:

    kubectl delete constraint -l policycontroller.gke.io/bundleName=nist-sp-800-190
    

kpt

  • 移除政策:

    kpt live destroy
    

Config Sync

使用 Config Sync 将政策部署到其集群的运维人员可以按照以下说明操作:

  1. 将更改推送到 Config Sync 代码库:

    git rm -r SYNC_ROOT_DIR/policies/nist-sp-800-190
    git commit -m 'Removing NIST SP 800-190 policies'
    git push
    
  2. 验证状态:

    gcloud alpha anthos config sync repo list --project PROJECT_ID
    

    SYNCED 列中显示您的代码库即表示政策移除成功。