Policy Controller 隨附預設的限制範本庫,可以與NIST SP 800-53 修訂版 5 套裝組合搭配使用,該套裝組合會實作美國國家標準與技術研究院 (NIST) 特別出版品 (SP) 800-53 修訂版 5 中列出的控管措施。機構可透過套裝組合實作現成的安全性和隱私權政策,保護系統和資料免受各種威脅。
本頁說明如何手動套用政策組合。 或者,您也可以直接套用政策組合。
如果您是 IT 管理員和營運人員,想確保雲端平台中執行的所有資源都符合機構的法規遵循規定,請參閱本頁面,瞭解如何提供及維護自動化稽核或強制執行功能。如要進一步瞭解我們在內容中提及的常見角色和範例工作,請參閱「常見的 GKE Enterprise 使用者角色和工作」。 Google Cloud
NIST SP 800-53 修訂版 5 政策套裝組合限制
限制名稱 | 限制說明 | 控制項 ID |
---|---|---|
nist-sp-800-53-r5-block-secrets-of-type-basic-auth | 限制使用 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 | 限制使用 basic-auth 類型的 Secret。 | AC-4 強制執行資訊流程 |
nist-sp-800-53-r5-require-binauthz | 需要二進位授權驗證准入 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 | 需要二進位授權驗證准入 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 | 需要二進位授權驗證准入 Webhook。 | AU-10 不可否認性 |
nist-sp-800-53-r5-nodes-have-consistent-time | 只允許 Container-Optimized OS (COS) 或 Ubuntu 做為 OS 映像檔,確保節點上的時間一致且正確。 | AU-8 時間戳記 |
nist-sp-800-53-r5-require-namespace-network-policies | 叢集中定義的每個命名空間都必須有 NetworkPolicy。 | CA-9 內部系統連線 |
nist-sp-800-53-r5-require-binauthz | 需要二進位授權驗證准入 Webhook。 | CM-14 簽署元件 |
nist-sp-800-53-r5-enforce-config-management | 必須執行 Config Sync,並在叢集上啟用 Drift Prevention,且至少有一個 `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 | 限制使用 basic-auth 類型的 Secret。 | |
nist-sp-800-53-r5-capabilities | 限制 Pod 可使用的其他功能。 | |
nist-sp-800-53-r5-enforce-config-management | 必須執行 Config Sync,並在叢集上啟用 Drift Prevention,且至少有一個 `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 可用的 Sysctl。 | |
nist-sp-800-53-r5-enforce-config-management | 必須執行 Config Sync,並在叢集上啟用 Drift Prevention,且至少有一個 `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,並在叢集上啟用 Drift Prevention,且至少有一個 `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 | 限制使用 basic-auth 類型的 Secret。 | CM-6 設定 |
nist-sp-800-53-r5-enforce-config-management | 必須執行 Config Sync,並在叢集上啟用 Drift Prevention,且至少有一個 `RootSync` 物件。 | |
nist-sp-800-53-r5-require-binauthz | 需要二進位授權驗證准入 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 可用的 Sysctl。 | |
nist-sp-800-53-r5-enforce-config-management | 必須執行 Config Sync,並在叢集上啟用 Drift Prevention,且至少有一個 `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,並在叢集上啟用 Drift Prevention,且至少有一個 `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 | 需要二進位授權驗證准入 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,並在叢集上啟用 Drift Prevention,且至少有一個 `RootSync` 物件。 | PL-1 政策與程序 |
nist-sp-800-53-r5-require-managed-by-label | 所有應用程式都必須具備有效的 `app.kubernetes.io/managed-by` 標籤。 | |
nist-sp-800-53-r5-require-binauthz | 需要二進位授權驗證准入 Webhook。 | RA-5 安全漏洞掃描 |
nist-sp-800-53-r5-enforce-config-management | 必須執行 Config Sync,並在叢集上啟用 Drift Prevention,且至少有一個 `RootSync` 物件。 | SA-10 開發人員設定管理 |
nist-sp-800-53-r5-require-managed-by-label | 所有應用程式都必須具備有效的 `app.kubernetes.io/managed-by` 標籤。 | |
nist-sp-800-53-r5-require-binauthz | 需要二進位授權驗證准入 Webhook。 | SA-11 Trusted Path |
nist-sp-800-53-r5-require-binauthz | 需要二進位授權驗證准入 Webhook。 | SA-3 系統開發生命週期 |
nist-sp-800-53-r5-block-secrets-of-type-basic-auth | 限制使用 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 | 需要二進位授權驗證准入 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 | 限制使用 basic-auth 類型的 Secret。 | SC-7 邊界防護 |
nist-sp-800-53-r5-enforce-config-management | 必須執行 Config Sync,並在叢集上啟用 Drift Prevention,且至少有一個 `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 | 確保 PeerAuthentications 無法覆寫嚴格的 mTLS。 | SC-8 傳輸機密性和完整性 |
nist-sp-800-53-r5-require-binauthz | 需要二進位授權驗證准入 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 | 限制使用 basic-auth 類型的 Secret。 | SI-7 軟體、韌體和資訊完整性 |
nist-sp-800-53-r5-enforce-config-management | 必須執行 Config Sync,並在叢集上啟用 Drift Prevention,且至少有一個 `RootSync` 物件。 | |
nist-sp-800-53-r5-require-binauthz | 需要二進位授權驗證准入 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 | 需要二進位授權驗證准入 Webhook。 | SR-4 出處 |
事前準備
- 安裝並初始化 Google Cloud CLI,其中提供這些操作說明中使用的
gcloud
和kubectl
指令。如果您使用 Cloud Shell,Google Cloud CLI 會預先安裝。 - 在叢集上安裝 Policy Controller,並使用預設的限制範本庫。此外,您也必須啟用對參照限制條件的支援,因為這個套件含有參照限制條件。
設定 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 ,包括 Drift Prevention 許可控制 Webhook。 - 必須安裝防毒解決方案。預設值是存在名為
daemonset
的clamav
,位於clamav
namespace
中,不過daemonset
的名稱和命名空間可在nist-sp-800-53-r5-require-av-daemonset
限制中自訂,以符合您的實作項目。 - 容器映像檔僅限於允許的存放區清單,如需自訂清單,請前往
nist-sp-800-53-r5-restrict-repos
。 - 節點必須在
nist-sp-800-53-r5-nodes-have-consistent-time
中使用 Container-Optimized OS 或 Ubuntu 做為映像檔。 - 儲存空間類別的使用僅限於允許清單,您可以在
nist-sp-800-53-r5-restrict-storageclass
中自訂允許清單,新增具有預設加密功能的其他類別。 您必須在
nist-sp-800-53-r5-require-binauthz
中啟用及設定二進位授權。
稽核 NIST SP 800-53 修訂版 5 政策套裝組合
您可以透過 Policy Controller,對 Kubernetes 叢集強制執行政策。如要測試工作負載是否符合上表列出的 NIST SP 800-53 政策,您可以「稽核」模式部署這些限制,找出違規事項,更重要的是,在 Kubernetes 叢集強制執行限制前,有機會修正這些問題。
您可以使用 kubectl、kpt 或 Config Sync,將 spec.enforcementAction
設為 dryrun
,套用這些政策。
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 Rev. 5 政策套裝組合:
kpt pkg get https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/nist-sp-800-53-r5
執行
set-enforcement-action
kpt 函式,將政策的強制執行動作設為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
如要建立或附加
.gitignore
(使用resourcegroup.yaml
):echo resourcegroup.yaml >> .gitignore
建立專屬的
policies
目錄:mkdir -p policies
使用 kpt 從 GitHub 下載 NIST SP 800-53 Rev. 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-action
kpt 函式,將政策的強制執行動作設為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 資訊主頁,在 UI 中查看叢集的違規情形。
您也可以使用
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 政策套裝組合的強制執行動作
審查叢集中的政策違規事項後,您可以考慮變更強制執行模式,讓 Admission Controller 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-action
kpt 函式,將政策的強制執行動作設為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-action
kpt 函式,將政策的強制執行動作設為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 Rev. 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
狀態,且資源已移除。