使用 PCI-DSS v4.0 政策限制

Policy Controller 隨附預設的限制範本庫,可以與 PCI-DSS v4.0 套裝組合搭配使用,評估叢集資源是否符合支付卡產業資料安全標準 (PCI-DSS) v4.0 的某些部分。

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

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

PCI-DSS v4.0 政策套裝組合限制

限制名稱 限制說明 控制項 ID
pci-dss-v4.0-require-apps-annotations 叢集中的所有應用程式都必須有 network-controls/date 註解。 2.2.5
pci-dss-v4.0-require-av-daemonset 必須安裝防毒軟體。DaemonSet 5.2.1、5.2.2、5.2.3、5.3.1、5.3.2、5.3.5
pci-dss-v4.0-require-binauthz 需要二進位授權驗證許可控制器 Webhook。 2.2.1、2.2.4、6.2.3、6.3.1、6.3.2
pci-dss-v4.0-require-cloudarmor-backendconfig BackendConfig 資源強制執行 Google Cloud Armor 設定。 6.4.1、6.4.2
pci-dss-v4.0-require-config-management 必須啟用 Config Management,並在叢集上啟用 Drift Prevention,且叢集上至少有一個 RootSync 物件。 1.2.8、2.2.6、5.3.5、6.3.2、6.5.1
pci-dss-v4.0-require-default-deny-network-policies 要求叢集中定義的每個命名空間,針對輸出都必須有預設的拒絕 NetworkPolicy 1.3.2、1.4.4
pci-dss-v4.0-require-managed-by-label 所有應用程式都必須有有效的 app.kubernetes.io/managed-by 標籤。 1.2.8、2.2.6、5.3.5、6.3.2、6.5.1
pci-dss-v4.0-require-namespace-network-policies 叢集中定義的每個 Namespace 都必須有 NetworkPolicy 1.2.5、1.2.6、1.4.1、1.4.4
pci-dss-v4.0-require-peer-authentication-strict-mtls 確保 PeerAuthentications 無法覆寫嚴格的 mTLS。 2.2.7、4.2.1、8.3.2
pci-dss-v4.0-require-valid-network-ranges 限制允許用於輸入和輸出的 CIDR 範圍。 1.3.1、1.3.2、1.4.2、1.4.4
pci-dss-v4.0-resources-have-required-labels 所有應用程式都必須包含指定標籤,才能符合防火牆規定。 1.2.7
pci-dss-v4.0-restrict-cluster-admin-role 限制使用 cluster-admin 角色。 7.2.1、7.2.2、7.2.5、8.2.4
pci-dss-v4.0-restrict-creation-with-default-serviceaccount 限制使用預設服務帳戶建立資源。稽核期間無效。 2.2.2
pci-dss-v4.0-restrict-default-namespace 禁止 Pod 使用預設命名空間。 2.2.3
pci-dss-v4.0-restrict-ingress 限制 Ingress 物件的建立作業。 1.3.1、1.4.2、1.4.4
pci-dss-v4.0-restrict-node-image 只允許 Container-Optimized OS 或 Ubuntu 做為 OS 映像檔,確保節點時間一致且正確。 10.6.1、10.6.2、10.6.3
pci-dss-v4.0-restrict-pods-exec 限制在 RolesClusterRoles 中使用 pods/exec 8.6.1
pci-dss-v4.0-restrict-rbac-subjects 限制 RBAC 主體只能使用允許值。 7.3.2、8.2.1、8.2.2、8.2.4
pci-dss-v4.0-restrict-role-wildcards 限制在 RolesClusterRoles 中使用萬用字元。 7.3.3、8.2.4
pci-dss-v4.0-restrict-storageclass StorageClass 限制為預設加密的 StorageClass 清單。 3.3.2、3.3.3

事前準備

  1. 安裝並初始化 Google Cloud CLI,其中提供這些操作說明中使用的 gcloudkubectl 指令。如果您使用 Cloud Shell,Google Cloud CLI 會預先安裝。
  2. 在叢集上安裝 Policy Controller 1.16.0 以上版本,並使用預設的限制範本庫。此外,由於這個套件組合包含參照限制,您也必須啟用參照限制的支援功能

設定 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: "admissionregistration.k8s.io"
            version: "v1"
            kind: "ValidatingWebhookConfiguration"
          - group: "storage.k8s.io"
            version: "v1"
            kind: "StorageClass"
    
  2. 套用 policycontroller-config.yaml 資訊清單:

    kubectl apply -f policycontroller-config.yaml
    

為 PCI-DSS v4.0 設定叢集的工作負載

  1. 所有應用程式 (ReplicaSetDeploymentStatefulSetDaemonSet) 都必須包含 network-controls/date 註解,並使用 YYYY-MM-DD 的架構。
  2. 必須安裝防毒解決方案。預設值是 clamav Namespace 中存在名為 clamavdaemonset,不過 daemonset 的名稱和命名空間可在 pci-dss-v4.0-require-av-daemonset 限制中自訂,以符合您的實作項目。
  3. 您必須在 pci-dss-v4.0-require-binauthz 中啟用並設定二進位授權
  4. 必須為 CloudArmor 設定所有 BackendConfig
  5. 必須啟用 Config Sync
  6. 叢集中定義的每個 Namespace 都有預設的拒絕 NetworkPolicy,允許的例外狀況可在 pci-dss-v4.0-require-namespace-network-policies 中指定。
  7. 根據預設,configmanagement.gke.io 必須使用 Config Sync,但您可以在 pci-dss-v4.0-enforce-managed-by-configmanagement-label 限制中自訂允許的 app.kubernetes.io/managed-by 值。
  8. 叢集中定義的每個 Namespace 都必須有 NetworkPolicy
  9. 如果使用 Cloud Service Mesh,ASM PeerAuthentication 必須使用嚴格的 mTLS spec.mtls.mode: STRICT
  10. 只有允許的 IP 範圍可用於 Ingress 和 Express,這些範圍可在 pci-dss-v4.0-require-valid-network-ranges 中指定。
  11. 所有應用程式 (ReplicaSetDeploymentStatefulSetDaemonSet) 都必須包含 pci-dss-[0-9]{4}q[1-4] 結構定義的 pci-dss-firewall-audit label
  12. 不得使用叢集管理員 ClusterRole
  13. 無法使用預設服務帳戶建立資源。
  14. 預設 Namespace 無法用於 Pod。
  15. 只能建立允許的 Ingress 物件 (NodePortLoadBalancerIngressGatewayService 類型),這些物件可在 pci-dss-v4.0-restrict-ingress 中指定。
  16. 所有節點都必須使用 Container-Optimized OS 或 Ubuntu 做為映像檔,以確保時間一致。
  17. 不允許在 RolesClusterRoles 中使用萬用字元或 pods/exec 權限。
  18. RBAC 繫結只能使用允許的主體,網域名稱可在 pci-dss-v4.0-restrict-rbac-subjects 中指定。
  19. pci-dss-v4.0-restrict-storageclass 中,必須使用預設加密機制 StorageClass

稽核 PCI-DSS v4.0 政策套裝組合

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

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

kubectl

  1. (選用) 使用 kubectl 預覽政策限制:

    kubectl kustomize https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/pci-dss-v4.0
    
  2. 使用 kubectl 套用政策限制:

    kubectl apply -k https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/pci-dss-v4.0
    

    輸出內容如下:

    asmpeerauthnstrictmtls.constraints.gatekeeper.sh/pci-dss-v4.0-require-peer-authentication-strict-mtls created
    k8sblockallingress.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-ingress created
    k8sblockcreationwithdefaultserviceaccount.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-creation-with-default-serviceaccount created
    k8senforcecloudarmorbackendconfig.constraints.gatekeeper.sh/pci-dss-v4.0-require-cloudarmor-backendconfig created
    k8senforceconfigmanagement.constraints.gatekeeper.sh/pci-dss-v4.0-require-config-management created
    k8sprohibitrolewildcardaccess.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-role-wildcards created
    k8srequirebinauthz.constraints.gatekeeper.sh/pci-dss-v4.0-require-binauthz created
    k8srequirecosnodeimage.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-node-image created
    k8srequiredaemonsets.constraints.gatekeeper.sh/pci-dss-v4.0-require-av-daemonset created
    k8srequiredefaultdenyegresspolicy.constraints.gatekeeper.sh/pci-dss-v4.0-require-default-deny-network-policies created
    k8srequirenamespacenetworkpolicies.constraints.gatekeeper.sh/pci-dss-v4.0-require-namespace-network-policies created
    k8srequirevalidrangesfornetworks.constraints.gatekeeper.sh/pci-dss-v4.0-require-valid-network-ranges created
    k8srequiredannotations.constraints.gatekeeper.sh/pci-dss-v4.0-require-apps-annotations created
    k8srequiredlabels.constraints.gatekeeper.sh/pci-dss-v4.0-require-managed-by-label created
    k8srequiredlabels.constraints.gatekeeper.sh/pci-dss-v4.0-resources-have-required-labels created
    k8srestrictnamespaces.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-default-namespace created
    k8srestrictrbacsubjects.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-rbac-subjects created
    k8srestrictrolebindings.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-cluster-admin-role created
    k8srestrictrolerules.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-pods-exec created
    k8sstorageclass.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-storageclass created
    
  3. 確認已安裝政策限制,並檢查叢集是否發生違規情形:

    kubectl get constraints -l policycontroller.gke.io/bundleName=pci-dss-v4.0
    

    輸出結果會與下列內容相似:

    NAME                                                                                                    ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    asmpeerauthnstrictmtls.constraints.gatekeeper.sh/pci-dss-v4.0-require-peer-authentication-strict-mtls   dryrun               0
    
    NAME                                                                         ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8sblockallingress.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-ingress   dryrun               0
    
    NAME                                                                                                                             ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8sblockcreationwithdefaultserviceaccount.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-creation-with-default-serviceaccount   dryrun               0
    
    NAME                                                                                                        ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8senforcecloudarmorbackendconfig.constraints.gatekeeper.sh/pci-dss-v4.0-require-cloudarmor-backendconfig   dryrun               0
    
    NAME                                                                                          ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8senforceconfigmanagement.constraints.gatekeeper.sh/pci-dss-v4.0-require-config-management   dryrun               0
    
    NAME                                                                                           ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8sprohibitrolewildcardaccess.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-role-wildcards   dryrun               0
    
    NAME                                                                         ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequirebinauthz.constraints.gatekeeper.sh/pci-dss-v4.0-require-binauthz   dryrun               0
    
    NAME                                                                                ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequirecosnodeimage.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-node-image   dryrun               0
    
    NAME                                                                               ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequiredaemonsets.constraints.gatekeeper.sh/pci-dss-v4.0-require-av-daemonset   dryrun               0
    
    NAME                                                                                     ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequiredannotations.constraints.gatekeeper.sh/pci-dss-v4.0-require-apps-annotations   dryrun               0
    
    NAME                                                                                                             ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequiredefaultdenyegresspolicy.constraints.gatekeeper.sh/pci-dss-v4.0-require-default-deny-network-policies   dryrun               0
    
    NAME                                                                                      ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequiredlabels.constraints.gatekeeper.sh/pci-dss-v4.0-require-managed-by-label         dryrun               0
    k8srequiredlabels.constraints.gatekeeper.sh/pci-dss-v4.0-resources-have-required-labels   dryrun               0
    
    NAME                                                                                                           ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequirenamespacenetworkpolicies.constraints.gatekeeper.sh/pci-dss-v4.0-require-namespace-network-policies   dryrun               0
    
    NAME                                                                                                   ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srequirevalidrangesfornetworks.constraints.gatekeeper.sh/pci-dss-v4.0-require-valid-network-ranges   dryrun               0
    
    NAME                                                                                      ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srestrictnamespaces.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-default-namespace   dryrun               0
    
    NAME                                                                                    ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srestrictrbacsubjects.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-rbac-subjects   dryrun               0
    
    NAME                                                                                         ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srestrictrolebindings.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-cluster-admin-role   dryrun               0
    
    NAME                                                                             ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8srestrictrolerules.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-pods-exec   dryrun               0
    
    NAME                                                                           ENFORCEMENT-ACTION   TOTAL-VIOLATIONS
    k8sstorageclass.constraints.gatekeeper.sh/pci-dss-v4.0-restrict-storageclass   dryrun               0
    

KPT

  1. 安裝及設定 kpt。這些操作說明會使用 kpt 自訂及部署 Kubernetes 資源。

  2. 使用 kpt 從 GitHub 下載 PCI-DSS 4.0 版政策套裝組合:

    kpt pkg get https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/pci-dss-v4.0
    
  3. 執行 set-enforcement-action kpt 函式,將政策的強制執行動作設為 dryrun

    kpt fn eval pci-dss-v4.0 -i gcr.io/kpt-fn/set-enforcement-action:v0.1 \
      -- enforcementAction=dryrun
    
  4. 使用 kpt 初始化工作目錄,這會建立資源來追蹤變更:

    cd pci-dss-v4.0
    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 將政策部署至叢集,可以按照下列指示操作:

  1. 變更為 Config Sync 的同步目錄:

    cd SYNC_ROOT_DIR
    

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

    echo resourcegroup.yaml >> .gitignore
    

  2. 建立專屬的 policies 目錄:

    mkdir -p policies
    
  3. 使用 kpt 從 GitHub 下載 PCI-DSS 4.0 版政策套裝組合:

    kpt pkg get https://github.com/GoogleCloudPlatform/gke-policy-library.git/anthos-bundles/pci-dss-v4.0 policies/pci-dss-v4.0
    
  4. 執行 set-enforcement-action kpt 函式,將政策的強制執行動作設為 dryrun

    kpt fn eval policies/pci-dss-v4.0 -i gcr.io/kpt-fn/set-enforcement-action:v0.1 -- enforcementAction=dryrun
    
  5. (選用) 預覽要建立的政策限制:

    kpt live init policies/pci-dss-v4.0
    kpt live apply --dry-run policies/pci-dss-v4.0
    
  6. 如果 Config Sync 的同步目錄使用 Kustomize,請將 policies/pci-dss-v4.0 新增至根目錄 kustomization.yaml。否則請移除 policies/pci-dss-v4.0/kustomization.yaml 檔案:

    rm SYNC_ROOT_DIR/policies/pci-dss-v4.0/kustomization.yaml
    
  7. 將變更推送至 Config Sync 存放區:

    git add SYNC_ROOT_DIR/policies/pci-dss-v4.0
    git commit -m 'Adding PCI-DSS v4.0 policy audit enforcement'
    git push
    
  8. 驗證安裝狀態:

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

    如果狀態為 SYNCED,表示政策已安裝完成。

查看政策違規事項

在稽核模式下安裝政策限制後,您可以使用 Policy Controller 資訊主頁,在 UI 中查看叢集違規情形。

您也可以使用 kubectl,透過下列指令查看叢集上的違規事項:

kubectl get constraint -l policycontroller.gke.io/bundleName=pci-dss-v4.0 -o json | jq -cC '.items[]| [.metadata.name,.status.totalViolations]'

如有違規事項,您可以透過下列方式查看每個限制的違規訊息清單:

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

變更 PCI-DSS v4.0 政策套裝組合的強制執行動作

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

kubectl

  1. 使用 kubectl 將政策的強制執行動作設為 warn

    kubectl get constraint -l policycontroller.gke.io/bundleName=pci-dss-v4.0 -o name | xargs -I {} kubectl patch {} --type='json' -p='[{"op":"replace","path":"/spec/enforcementAction","value":"warn"}]'
    
  2. 確認政策限制強制執行動作已更新:

    kubectl get constraint -l policycontroller.gke.io/bundleName=pci-dss-v4.0
    

KPT

  1. 執行 set-enforcement-action kpt 函式,將政策的強制執行動作設為 warn

    kpt fn eval -i gcr.io/kpt-fn/set-enforcement-action:v0.1 -- enforcementAction=warn
    
  2. 套用政策限制:

    kpt live apply
    

Config Sync

如果運算子使用 Config Sync 將政策部署至叢集,可以按照下列指示操作:

  1. 變更為 Config Sync 的同步目錄:

    cd SYNC_ROOT_DIR
    
  2. 執行 set-enforcement-action kpt 函式,將政策的強制執行動作設為 warn

    kpt fn eval policies/pci-dss-v4.0 -i gcr.io/kpt-fn/set-enforcement-action:v0.1 -- enforcementAction=warn
    
  3. 將變更推送至 Config Sync 存放區:

    git add SYNC_ROOT_DIR/policies/pci-dss-v4.0
    git commit -m 'Adding PCI-DSS v4.0 policy bundle warn enforcement'
    git push
    
  4. 驗證安裝狀態:

    nomos status
    

    叢集應顯示 SYNCED 狀態,並列出已安裝的政策。

測試政策強制執行

使用下列指令在叢集上建立不符規定的資源:

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  namespace: default
  name: wp-non-compliant
  labels:
    app: wordpress
spec:
  containers:
    - image: wordpress
      name: wordpress
      ports:
      - containerPort: 80
        name: wordpress
EOF

准入控制器應會產生警告,列出這項資源違反的政策,如下列範例所示:

Warning: [pci-dss-v4.0-restrict-default-namespace] <default> namespace is restricted
pod/wp-non-compliant created

移除 PCI-DSS v4.0 政策組合

如有需要,可以從叢集中移除 PCI-DSS v4.0 政策套裝組合。

kubectl

  • 使用 kubectl 移除政策:

    kubectl delete constraint -l policycontroller.gke.io/bundleName=pci-dss-v4.0
    

KPT

  • 移除政策:

    kpt live destroy
    

Config Sync

如果運算子使用 Config Sync 將政策部署至叢集,可以按照下列指示操作:

  1. 將變更推送至 Config Sync 存放區:

    git rm -r SYNC_ROOT_DIR/policies/pci-dss-v4.0
    git commit -m 'Removing PCI-DSS v4.0 policies'
    git push
    
  2. 確認狀態:

    nomos status
    

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