設定階層式安全性政策

本頁面說明如何設定階層式安全性政策,協助保護組織、資料夾或專案。設定階層式安全性政策前,請務必熟悉階層式安全性政策總覽中的資訊。

設定階層式安全性政策的身分與存取權管理權限

如要執行下列作業,您必須在目標資源階層節點上,或在政策本身 (如果已存在) 上,具備 Identity and Access Management (IAM) 角色「Compute 組織安全性政策管理員」(roles/compute.orgSecurityPolicyAdmin):

  • 建立新的階層式安全性政策
  • 新增、更新或刪除規則,修改階層式安全性政策
  • 刪除階層式安全性政策

如要執行下列作業,您必須具備目標資源階層節點的 IAM Compute 組織資源管理員角色 (roles/compute.orgSecurityResourceAdmin),以及目標資源階層節點或政策本身的 Compute 組織安全性政策管理員角色 (roles/compute.orgSecurityPolicyAdmin) 或 Compute 組織安全性政策使用者角色 (roles/compute.orgSecurityPolicyUser):

  • 將階層式安全性政策與資源階層節點建立關聯

最後,請參閱下表,瞭解具備下列任一角色時可執行的其他作業:

作業 角色
查看後端資源的所有有效 Google Cloud Armor 規則
查看 organizationSecurityPolicy 涵蓋的有效後端資源

設定階層式安全性政策

以下各節說明如何建立階層式安全性政策、將政策與資源階層節點建立關聯、在節點之間移動政策、刪除政策,以及如何查看適用於受保護資源的所有 Cloud Armor 安全性政策規則。

建立階層式安全性政策

您可以使用 gcloud compute org-security-policies create 指令建立階層式安全性政策。您可以使用 --organization 或 --folder 旗標,以及對應的 ORGANIZATION_ID 或 FOLDER_ID,在組織或資料夾下建立階層式安全性政策。請參考下列範例建立階層式安全性政策,並將 POLICY_NAME 替換為新安全性政策的名稱:

  • 建立組織層級階層式安全性政策:

    gcloud compute org-security-policies create \
        --organization=ORGANIZATION_ID \
        --type=CLOUD_ARMOR \
        --short-name=POLICY_NAME
    
  • 建立資料夾層級階層式安全性政策:

    gcloud compute org-security-policies create \ 
        --folder=FOLDER_ID \
        --type=CLOUD_ARMOR \
        --short-name=POLICY_NAME
    

將現有安全性政策與資源階層節點建立關聯

如果您已有安全性政策,可以使用 gcloud compute org-security-policies associations create 指令,將政策與資源階層節點建立關聯。

  • 將階層式安全性政策與組織建立關聯:

    gcloud compute org-security-policies associations create \
        --security-policy=POLICY_ID \
        --organization=ORGANIZATION_ID \
        --name=ASSOCIATION_NAME
    
  • 將階層式安全性政策與資料夾建立關聯:

    gcloud compute org-security-policies associations create \
        --security-policy=POLICY_ID \
        --folder=FOLDER_ID \
        --name=ASSOCIATION_NAME
    
  • 將階層式安全性政策與專案建立關聯:

    gcloud compute org-security-policies associations create \
        --security-policy=POLICY_ID \
        --project-number=PROJECT_ID \
        --name=ASSOCIATION_NAME
    

更改下列內容:

  • POLICY_ID:安全性政策的 ID
  • ORGANIZATION_ID:組織 ID
  • ASSOCIATION_NAME:關聯名稱
  • FOLDER_ID:資料夾 ID
  • PROJECT_ID:專案 ID

將專案從階層式安全性政策中排除

此外,您也可以從資料夾層級的階層式安全性政策中排除專案,以及從組織層級的階層式安全性政策中排除專案和資料夾:

  • 您可以使用 gcloud compute org-security-policies associations create 指令搭配 --excluded-projects 旗標,從階層式安全性政策中排除專案。

    下列範例指令會將安全性政策 example-policy 與組織 10000001 建立關聯,同時排除 ID 為 2000000002 的專案:

    gcloud compute org-security-policies associations create \
        --security-policy=example-policy \
        --excluded-projects="projects/2000000002" \
        --organization=10000001
    
  • 您可以使用 gcloud compute org-security-policies associations create 指令和 --excluded-folders 旗標,將資料夾從組織層級階層式安全性政策中排除。

    下列範例指令會將安全性政策 example-policy 與組織 10000001 建立關聯,同時排除 ID 為 3000000003 的資料夾:

    gcloud compute org-security-policies associations create \
        --security-policy=example-policy \
        --excluded-folders="folders/3000000003" \
        --organization=10000001
    

移動階層式安全性政策

您可以使用 gcloud compute org-security-policies move 指令,將階層式安全性政策移至其他父項資源階層節點,藉此變更階層式安全性政策的父項。您需要提供來源做為第一個旗標,目的地做為第二個旗標。移動階層式安全性政策會變更其擁有權,而非相關聯的資源。只有組織和資料夾可以擁有階層式安全性政策,因此您無法將這些政策移至專案。

在以下範例中,您會將階層式安全性政策從組織 ORGANIZATION_ID 移至資料夾 FOLDER_ID:

gcloud compute org-security-policies move policy-1 \
    --organization ORGANIZATION_ID \
    --folder FOLDER_ID

刪除階層式安全性政策

刪除階層式安全性政策前,必須先刪除該政策與資源階層節點的所有關聯。在以下範例中,您可以使用 gcloud compute org-security-policies associations delete 指令,移除階層式安全性政策 POLICY_NAME 與組織 ORGANIZATION_ID 之間名為 ASSOCIATION_NAME 的關聯:

gcloud compute org-security-policies associations delete ASSOCIATION_NAME \
    --security-policy=POLICY_NAME \
    --organization=ORGANIZATION_ID

如果安全性政策不只一個關聯,請為每個關聯重複上一個步驟。如果階層式安全性政策沒有任何關聯,您可以使用 gcloud compute org-security-policies delete 指令刪除該政策,如下例所示:

gcloud compute org-security-policies delete POLICY_NAME \
    --organization=ORGANIZATION_ID

查看受保護資源的所有有效 Cloud Armor 規則

您可以使用 gcloud compute backend-services get-effective-security-policies 指令,查看適用於受保護資源的所有 Cloud Armor 安全性政策規則。

gcloud compute backend-services get-effective-security-policies PROTECTED_RESOURCE

將 PROTECTED_RESOURCE 替換成要檢查的受保護資源名稱。

在繼承階層式安全性政策的專案中,對後端服務執行 gcloud compute backend-services get-effective-security-policies 指令時,即使階層式安全性政策不支援該特定後端服務的類型,回應仍可能包含階層式安全性政策。如需階層式安全性政策支援的後端設定清單,請參閱「階層式安全性政策總覽」。

用途

以下各節說明階層式安全性政策的用途。

拒絕從一組 IP 位址傳送至組織中所有應用程式負載平衡器的流量

您可以使用階層式安全性政策,管理禁止存取整個組織網路的 IP 位址清單,或拒絕來自特定區域或國家/地區的流量。這有助於解決公司特定的安全性問題,或協助您維持法規遵循。下列步驟說明如何建立組織層級階層式安全性政策,拒絕來自 IP 位址範圍 192.0.2.0/24 的流量:

  1. 建立名為 org-level-deny-ip-policy 的階層式安全性政策,並附加至 ID 為 1000000001 的組織:

     gcloud compute org-security-policies create \
         --organization=1000000001 \
         --type=CLOUD_ARMOR \
         --description= "this org policy denies a set of IP addresses for all resources" \
         --short-name=org-level-deny-ip-policy
    
  2. 新增優先順序為 1000 的規則,並設定 IP 位址範圍 192.0.2.0/24 的比對條件和 deny 動作:

     gcloud compute org-security-policies rules create 1000 \
         --action=deny \
         --security-policy=org-level-deny-ip-policy \
         --organization=1000000001 \
         --description "Deny traffic from 192.0.2.0/24" \
         --src-ip-ranges "192.0.2.0/24"
    
  3. 最後,將安全性政策與組織建立關聯,拒絕來自 192.0.2.0/24 IP 位址對組織中所有服務的要求:

     gcloud compute org-security-policies associations create \
         --security-policy=org-level-deny-ip-policy \
         --organization=ORGANIZATION_ID
    

將一組來源 IP 位址的存取權授予貴組織中的某些專案

您可以將組織內某些專案的存取權,授予一或多個 IP 位址。如果您有信任的上游 Proxy,且只想在部分專案中排除該 Proxy,不納入規則評估,建議您採取這種做法。在下列以 Cloud CDN 為基礎的範例中,您可以使用資料夾層級階層式安全性政策,將 IP 位址範圍 192.0.2.0/24 的存取權授予組織 10000001 中名為 project-1、project-2 和 project-3 的專案:

  1. 使用下列指令,將 project-1、project-2 和 project-3 移至 ID 為 20000002 的資料夾:

    gcloud projects move project-1 --folder=20000002
    gcloud projects move project-2 --folder=20000002
    gcloud projects move project-3 --folder=20000002
    
  2. 使用下列指令建立名為 org-level-proxy-filtering 的安全性政策:

     gcloud compute org-security-policies create \
         --folder=20000002 \
         --type=CLOUD_ARMOR \
         --short-name=org-level-proxy-filtering
    
  3. 新增優先順序為 1000 的規則,並設定 IP 位址範圍 192.0.2.0/24 的比對條件和 goto_next 規則動作。如果要求符合這項條件,Cloud Armor 就會停止評估這項安全性政策中的規則:

     gcloud compute org-security-policies rules create 1000 \
         --action=goto_next \
         --security-policy=org-level-proxy-filtering \
         --organization=10000001 \
         --src-ip-ranges="192.0.2.0/24"
    
  4. 選用:如要將安全性政策規則套用至這些專案,針對非來自 192.0.2.0/24 的要求,請新增優先順序低於 1000 的規則。您可以稍後再執行這個步驟。

  5. 使用下列指令,將政策與您在步驟 1 中將專案移至的資料夾 (ID 為 20000002) 建立關聯:

     gcloud compute org-security-policies associations create \
         --security-policy=org-level-proxy-filtering \
         --folder=20000002
    

後續步驟