使用 NIST SP 800-190 政策限制

Policy Controller 隨附預設的限制範本庫,可以與NIST SP 800-190 套裝組合搭配使用,該套裝組合會實作美國國家標準與技術研究院 (NIST) 特殊出版品 (SP) 800-190 (應用程式容器安全指南) 中列出的控管措施。這個套件旨在協助機構組織確保應用程式容器安全,包括映像檔安全、容器執行階段安全、網路安全和主機系統安全等。

如果您是 IT 管理員和營運人員,想確保雲端平台中執行的所有資源都符合機構的法規遵循規定,請參閱本頁面,瞭解如何提供及維護自動化稽核或強制執行功能。如要進一步瞭解我們在內容中提及的常見角色和範例工作,請參閱「常見的 GKE Enterprise 使用者角色和工作」。 Google Cloud

本頁說明如何手動套用政策組合。 或者,您也可以直接套用政策組合

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 限制使用 basic-auth 類型的 Secret。 AC-4 強制執行資訊流程
nist-sp-800-190-require-binauthz 需要二進位授權驗證准入 Webhook。
nist-sp-800-190-require-namespace-network-policies 叢集中定義的每個命名空間都必須有 NetworkPolicy。
nist-sp-800-190-restrict-hostpath-volumes 限制使用 HostPath 磁碟區。
nist-sp-800-190-require-binauthz 需要二進位授權驗證准入 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 做為 OS 映像檔,確保節點上的時間一致且正確。 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 限制使用 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 可用的 Sysctl。
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 限制使用 basic-auth 類型的 Secret。 CM-6 設定
nist-sp-800-190-enforce-config-management 必須執行 Config Sync,並在叢集上啟用 Drift Prevention,且至少有一個 `RootSync` 物件。
nist-sp-800-190-require-binauthz 需要二進位授權驗證准入 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 可用的 Sysctl。
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 需要二進位授權驗證准入 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 確保 PeerAuthentications 無法覆寫嚴格的 mTLS。 SC-8 傳輸機密性和完整性
nist-sp-800-190-block-secrets-of-type-basic-auth 限制使用 basic-auth 類型的 Secret。 SI-7 軟體、韌體和資訊完整性
nist-sp-800-190-enforce-config-management 必須執行 Config Sync,並在叢集上啟用 Drift Prevention,且至少有一個 `RootSync` 物件。
nist-sp-800-190-require-binauthz 需要二進位授權驗證准入 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,並使用預設的限制範本庫。此外,您也必須啟用對參照限制條件的支援,因為這個套件含有參照限制條件。

設定 Policy Controller 的參照限制

  1. 將下列 YAML 資訊清單儲存為 policycontroller-config.yaml 檔案。 資訊清單會設定 Policy Controller,監控特定種類的物件。

    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 ,包括 Drift Prevention 許可控制 Webhook
  2. 容器映像檔僅限於允許的存放區清單,如需自訂清單,請前往 nist-sp-800-190-restrict-repos
  3. 節點必須在 nist-sp-800-190-nodes-have-consistent-time 中使用 Container-Optimized OS 或 Ubuntu 做為映像檔。
  4. 您必須在 nist-sp-800-190-require-binauthz 中啟用及設定二進位授權

稽核 NIST SP 800-190 政策套裝組合

您可以透過 Policy Controller,對 Kubernetes 叢集強制執行政策。如要測試工作負載,以及工作負載是否符合上表列出的 NIST 政策,您可以「稽核」模式部署這些限制,找出違規事項,更重要的是,在 Kubernetes 叢集強制執行限制前,有機會修正這些事項。

您可以使用 kubectl、kptConfig Sync,將 spec.enforcementAction 設為 dryrun,套用這些政策。

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
    

    如要建立或附加 .gitignore (使用 resourcegroup.yaml):

    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 資訊主頁,在 UI 中查看叢集的違規情形。

  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 政策套裝組合的強制執行動作

審查叢集中的政策違規事項後,您可以考慮變更強制執行模式,讓 Admission Controller warndeny 阻止不符規定的資源套用至叢集。

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. 驗證安裝狀態:

    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-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. 確認狀態:

    nomos status
    

    叢集應會顯示 SYNCED 狀態,且資源已移除。