按照這些操作說明建立 Google Cloud Armor 安全性政策,以篩選傳入應用程式的流量。如要瞭解安全性政策的概念資訊,請參閱 Google Cloud Armor 安全性政策總覽。
事前準備
設定安全性政策前,請先完成下列步驟:
請務必熟悉外部應用程式負載平衡器概念。
檢查現有的後端服務,判斷哪些服務尚未附加安全性政策。這些後端服務及其相關聯的後端不會受到 Google Cloud Armor 保護。如要新增 Google Cloud Armor 提供的保護措施,請按照本文中的操作說明,將新建立或現有的安全性政策附加至後端服務。
設定 Google Cloud Armor 安全性政策的 IAM 權限
下列作業需要 Identity and Access Management (IAM) 的
Compute Security Admin 角色 (roles/compute.securityAdmin
):
- 設定、修改、更新及刪除 Google Cloud Armor 安全性政策
- 使用下列 API 方法:
SecurityPolicies insert
SecurityPolicies delete
SecurityPolicies patch
SecurityPolicies addRule
SecurityPolicies patchRule
SecurityPolicies removeRule
具備 Compute 網路管理員角色 (roles/compute.networkAdmin
) 的使用者可以執行下列作業:
- 為後端服務設定 Google Cloud Armor 安全性政策
- 使用下列 API 方法:
BackendServices setSecurityPolicy
BackendServices list
(僅限gcloud
)
具有安全管理員角色 (roles/iam.securityAdmin
) 和 Compute Network 管理員角色的使用者,可以使用 SecurityPolicies
API 方法 get
、list
和 getRule
查看 Google Cloud Armor 安全性政策。
設定自訂角色的 IAM 權限
下表列出 IAM 角色的基本權限和相關聯的 API 方法。
IAM 權限 | API 方法 |
---|---|
compute.securityPolicies.create |
SecurityPolicies insert |
compute.securityPolicies.delete |
SecurityPolicies delete |
compute.securityPolicies.get |
SecurityPolicies get SecurityPolicies getRule |
compute.securityPolicies.list |
SecurityPolicies list |
compute.securityPolicies.use |
BackendServices setSecurityPolicy |
compute.securityPolicies.update |
SecurityPolicies patch SecurityPolicies addRule SecurityPolicies patchRule SecurityPolicies removeRule |
compute.backendServices.setSecurityPolicy |
BackendServices setSecurityPolicy |
建立安全性政策
您可以使用 Google Cloud 控制台、Google Cloud CLI 或 REST API,設定 Google Cloud Armor 安全性政策、規則和運算式。使用 gcloud CLI 建立安全性政策時,請使用 --type
旗標指定安全性政策是後端安全性政策還是邊緣安全性政策。
如果您不熟悉安全性政策設定,建議查看安全性政策範例。
運算式範例
以下是運算式範例。如要進一步瞭解運算式,請參閱 Google Cloud Armor 自訂規則語言參考資料。
如果您要設定使用 ISO 3166-1 alpha 2 國家/地區或區域代碼的規則或運算式,Google Cloud Armor 會個別處理每個代碼。Google Cloud Armor 規則和運算式會明確使用這些地區代碼,允許或拒絕要求。
下列運算式會比對來自 IP 位址
1.2.3.4
的要求,並在使用者代理程式標頭中包含字串example
:inIpRange(origin.ip, '1.2.3.4/32') && has(request.headers['user-agent']) && request.headers['user-agent'].contains('example')
或者,您也可以使用
origin.user_ip
屬性,比對自訂用戶端 IP 位址標頭的 IP 位址範圍:inIpRange(origin.user_ip, '1.2.3.4/32') && has(request.headers['user-agent']) && request.headers['user-agent'].contains('example')
下列運算式會比對含有特定值的 Cookie 的要求:
has(request.headers['cookie']) && request.headers['cookie'].contains('cookie_name=cookie_value')
下列運算式會比對來自
AU
區域的要求:origin.region_code == 'AU'
下列運算式會比對來自
AU
區域的要求,但不在指定的 IP 範圍內:origin.region_code == "AU" && !inIpRange(origin.ip, '1.2.3.0/24')
如果 URI 符合規則運算式,下列運算式會比對要求,並提供特定檔案的編號變數路徑:
request.path.matches('/path/[0-9]+/target_file.html')
如果
user-id
標頭的 Base64 解碼值包含特定值,下列運算式就會比對要求:has(request.headers['user-id']) && request.headers['user-id'].base64Decode().contains('myValue')
下列運算式使用預先設定的運算式集,比對 SQLi 攻擊:
evaluatePreconfiguredWaf('sqli-stable')
管理安全性政策
請參閱下列各節,瞭解如何列出專案中的安全性政策、更新安全性政策、刪除安全性政策,或測試安全性政策。
列出安全性政策
按照這些操作說明,列出目前專案或指定專案中的所有 Google Cloud Armor 安全性政策。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
如要查看特定政策,請前往「安全政策」頁面,然後在政策清單中點選政策名稱。
gcloud
gcloud compute security-policies list
例如:
gcloud compute security-policies list
NAME my-policy
更新安全性政策
按照這些操作說明更新 Google Cloud Armor 安全性政策。 舉例來說,您可以修改政策說明、修改預設規則的行為、變更目標後端服務,或是新增規則。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
如要更新特定政策,請前往「安全政策」頁面,在政策清單中,點按要更新政策的「選單」圖示
。- 如要更新預設規則動作的政策說明,請選取「編輯」,進行變更,然後按一下「更新」。
- 如要新增規則,請選取「新增規則」,然後按照「在安全性政策中新增規則」一文中的操作說明進行。
- 如要變更政策的目標後端服務,請選取「將政策套用至目標」,按一下「新增目標」,選取目標,然後按一下「新增」。
gcloud
如要更新安全性政策,請按照下列 Google Cloud CLI 指示操作:
- 如要更新安全性政策中的規則,請參閱「更新安全性政策中的單一規則」。
- 如要將規則新增至安全性政策,請參閱「將規則新增至安全性政策」。
- 如要從安全性政策中刪除規則,請參閱「從安全性政策中刪除規則」。
- 如要透過單一更新 (不可分割的更新) 更新多項規則,請參閱「在安全性政策中不可分割地更新多項規則」。
- 如要更新安全性政策中非規則的欄位 (例如說明欄位),請參閱「匯出安全性政策」和「匯入安全性政策」。
刪除安全性政策
按照這些操作說明刪除 Google Cloud Armor 安全性政策。您必須先從政策中移除所有後端服務,才能刪除政策。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
在「安全性政策」頁面中,找到要刪除的安全性政策,然後選取名稱旁邊的核取方塊。
按一下頁面右上角的「刪除」
。
gcloud
使用 gcloud compute security-policies delete NAME
。
將 NAME
替換為安全政策的名稱:
gcloud compute security-policies delete NAME
測試安全性政策
建議您先在預覽模式中部署所有新規則,然後檢查要求記錄,確認政策和規則的運作方式符合預期。
管理安全性政策規則
請參閱下列各節,瞭解如何列出、新增、更新或刪除安全性政策規則。
列出安全性政策中的規則
按照這些操作說明,列出 Google Cloud Armor 安全性政策中的規則。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
在「安全性政策」頁面中,按一下安全性政策名稱。系統會顯示「政策詳細資料」頁面,政策規則則會列在頁面中間的「規則」分頁標籤中。
gcloud
使用下列 gcloud
指令,列出單一安全性政策中的所有規則,以及政策說明:
gcloud compute security-policies describe NAME \
使用下列 gcloud
指令,說明指定安全政策中具有指定優先順序的規則:
gcloud compute security-policies rules describe PRIORITY \ --security-policy POLICY_NAME
舉例來說,下列指令會說明安全性政策 my-policy
中優先順序為 1000 的規則:
gcloud compute security-policies rules describe 1000 \ --security-policy my-policy
輸出:
action: deny(403) description: block traffic from 192.0.2.0/24 and 198.51.100.0/24 kind: compute#securityPolicyRule match: srcIpRanges: - '192.0.2.0/24' - '198.51.100.0/24' preview: false priority: 1000
在安全性政策中新增規則
按照這些操作說明,在 Google Cloud Armor 安全性政策中新增規則。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
在「安全性政策」頁面中,按一下安全性政策名稱。系統隨即會顯示「政策詳細資料」頁面。
按一下頁面中間的「規則」分頁標籤。
按一下 [新增規則]。
選用:輸入規則說明。
選取模式:
- 基本模式:根據 IP 位址或 IP 範圍允許或拒絕流量。
- 進階模式:根據規則運算式允許或拒絕流量。
在「比對」欄位中,指定規則的適用條件:
基本模式:輸入 1 到 10 個 IP 位址範圍,以符合規則。最多可新增 10 個 IP 位址範圍。如需限制,請參閱「Google Cloud Armor 配額與限制」。
進階模式:輸入運算式或子運算式,根據傳入的要求進行評估。如要瞭解如何編寫運算式及解讀下列範例,請參閱自訂規則語言參考資料。
下列運算式會比對來自 IP 位址
1.2.3.4
的要求,並在使用者代理程式標頭中包含字串example
:inIpRange(origin.ip, '1.2.3.4/32') && has(request.headers['user-agent']) && request.headers['user-agent'].contains('example')
下列運算式會比對含有特定值的 Cookie 的要求:
has(request.headers['cookie']) && request.headers['cookie'].contains('cookie_name=cookie_value')
下列運算式會比對來自
AU
區域的要求:origin.region_code == 'AU'
下列運算式會比對來自
AU
區域的要求,但不在指定的 IP 範圍內:origin.region_code == "AU" && !inIpRange(origin.ip, '1.2.3.0/24')
如果 URI 符合規則運算式,下列運算式就會比對要求:
request.path.matches('/example_path/')
如果
user-id
標頭的 Base64 解碼值包含特定值,下列運算式就會比對要求:has(request.headers['user-id']) && request.headers['user-id'].base64Decode().contains('myValue')
下列運算式使用預先設定的運算式集,比對 SQLi 攻擊:
evaluatePreconfiguredWaf('sqli-stable')
在「動作」中選取「允許」或「拒絕」。
如果您要設定拒絕規則,請選取「拒絕狀態」訊息。
如要啟用規則的預覽模式,請選取「啟用」核取方塊。
在「Priority」欄位中輸入正整數。
按一下「新增」。
gcloud
使用 gcloud compute security-policies rules create PRIORITY
指令。將 PRIORITY
替換為政策中規則的優先順序:
gcloud compute security-policies rules create PRIORITY \ --security-policy POLICY_NAME \ --description DESCRIPTION \ --src-ip-ranges IP_RANGES | --expression EXPRESSION \ --action=[ allow | deny-403 | deny-404 | deny-502 ] \ --preview
舉例來說,下列指令會新增規則,封鎖來自 IP 位址範圍 192.0.2.0/24 和 198.51.100.0/24 的流量。規則的優先順序為 1000,且是名為「my-policy
」政策中的規則:
gcloud compute security-policies rules create 1000 \ --security-policy my-policy \ --description "block traffic from 192.0.2.0/24 and 198.51.100.0/24" \ --src-ip-ranges "192.0.2.0/24","198.51.100.0/24" \ --action "deny-403"
使用 --expression
旗標在自訂規則語言參考資料中指定條件。下列指令會新增規則,允許來自 IP 位址 1.2.3.4
的流量,且使用者代理程式標頭中包含字串 example
:
gcloud compute security-policies rules create 1000 \ --security-policy my-policy \ --expression "inIpRange(origin.ip, '1.2.3.4/32') && has(request.headers['user-agent']) && request.headers['user-agent'].contains('example')" \ --action allow \ --description "Block User-Agent 'example'"
下列指令會新增規則,在要求的 Cookie 含有特定值時封鎖要求:
gcloud compute security-policies rules create 1000 \ --security-policy my-policy \ --expression "has(request.headers['cookie']) && request.headers['cookie'].contains('80=BLAH')" \ --action deny-403 \ --description "Cookie Block"
下列指令會新增規則,封鎖來自 AU
區域的要求:
gcloud compute security-policies rules create 1000 \ --security-policy my-policy \ --expression "origin.region_code == 'AU'" \ --action deny-403 \ --description "AU block"
下列指令會新增規則,封鎖來自 AU
區域且不在指定 IP 範圍內的請求:
gcloud compute security-policies rules create 1000 \ --security-policy my-policy \ --expression "origin.region_code == "AU" && !inIpRange(origin.ip, '1.2.3.0/24')" \ --action deny-403 \ --description "country and IP block"
下列指令會新增規則,封鎖 URI 符合規則運算式的要求:
gcloud compute security-policies rules create 1000 \ --security-policy my-policy \ --expression "request.path.matches('/example_path/')" \ --action deny-502 \ --description "regex block"
如果 user-id
標頭的 Base64 解碼值包含特定值,下列指令會新增規則來封鎖要求:
gcloud compute security-policies rules create 1000 \ --security-policy my-policy \ --expression "has(request.headers['user-id']) && request.headers['user-id'].base64Decode().contains('myValue')" \ --action deny-403 \ --description "country and IP block"
下列指令會新增規則,使用預先設定的運算式集來防範 SQLi 攻擊:
gcloud compute security-policies rules create 1000 \ --security-policy my-policy \ --expression "evaluatePreconfiguredWaf('sqli-stable')" \ --action deny-403
更新安全性政策中的單一規則
按照這些操作說明更新 Google Cloud Armor 安全性政策中的單一規則。如要以原子方式更新多項規則,請參閱「以原子方式更新安全性政策中的多項規則」。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
在「安全性政策」頁面中,按一下安全性政策名稱。系統隨即會顯示「政策詳細資料」頁面。
按一下頁面中間的「規則」分頁標籤。
找到要更新的規則,然後按一下「編輯」
。系統會顯示「編輯規則」頁面。進行變更,然後按一下「更新」。
gcloud
使用這項指令,更新指定安全性政策中具有指定優先順序的規則。您一次只能使用這個指令更新一項安全性政策:
gcloud compute security-policies rules update PRIORITY [ \ --security-policy POLICY_NAME \ --description DESCRIPTION \ --src-ip-ranges IP_RANGES | --expression EXPRESSION \ --action=[ allow | deny-403 | deny-404 | deny-502 ] \ --preview ]
舉例來說,下列指令會更新優先順序為 1111 的規則,允許來自 IP 位址範圍 192.0.2.0/24 的流量:
gcloud compute security-policies rules update 1111 \ --security-policy my-policy \ --description "allow traffic from 192.0.2.0/24" \ --src-ip-ranges "192.0.2.0/24" \ --action "allow"
如要進一步瞭解這個指令,請參閱 gcloud compute security-policies rules update
。
如要更新規則的優先順序,請使用 REST API。詳情請參閱 securityPolicies.patchRule
。
以原子方式更新安全性政策中的多項規則
原子更新會在單一更新中對多項規則套用變更。如果逐一更新規則,舊規則和新規則可能會在短時間內同時運作,導致出現非預期的行為。
如要以原子方式更新多項規則,請將目前的安全性政策匯出至 JSON 或 YAML 檔案,然後進行修改。使用修改後的檔案建立新的安全性政策,然後切換相關後端服務的安全性政策。
gcloud
匯出要更新的政策,如下列範例所示:
gcloud compute security-policies export my-policy \ --file-name my-file \ --file-format yaml
匯出的政策會類似以下範例:
description: my description fingerprint: PWfLGDWQDLY= id: '123' name: my-policy rules: - action: deny(404) description: my-rule-1 match: expr: expression: evaluatePreconfiguredWaf('xss-stable') versionedExpr: SRC_IPS_V1 preview: false priority: 1 - action: allow description: my-rule-2 match: config: srcIpRanges: - '1.2.3.4' versionedExpr: SRC_IPS_V1 preview: false priority: 2 - action: deny description: default rule kind: compute#securityPolicyRule match: config: srcIpRanges: - '*' versionedExpr: SRC_IPS_V1 preview: false priority: 2147483647 selfLink: https://www.googleapis.com/compute/v1/projects/my-project/global/securityPolicies/my-policy
使用任何文字編輯器修改政策。舉例來說,您可以修改現有規則的優先順序,並新增規則:
description: my description fingerprint: PWfLGDWQDLY= id: '123' name: my-policy rules: - action: deny(404) description: my-rule-1 match: expr: expression: evaluatePreconfiguredWaf('xss-stable') versionedExpr: SRC_IPS_V1 preview: false priority: 1 - action: allow description: my-new-rule match: config: srcIpRanges: - '1.2.3.1' versionedExpr: SRC_IPS_V1 preview: false priority: 10 - action: allow description: my-rule-2 match: config: srcIpRanges: - '1.2.3.4' versionedExpr: SRC_IPS_V1 preview: false priority: 11 - action: deny description: default rule kind: compute#securityPolicyRule match: config: srcIpRanges: - '*' versionedExpr: SRC_IPS_V1 preview: false priority: 2147483647 selfLink: https://www.googleapis.com/compute/v1/projects/my-project/global/securityPolicies/my-policy
建立新的 Google Cloud Armor 安全性政策,並指定修改後的檔案名稱和格式,如下列範例所示:
gcloud compute security-policies create new-policy \ --file-name modified-policy \ --file-format yaml
從相關後端服務中移除舊的安全性政策,如下列範例所示:
gcloud compute backend-services update my-backend \ --security-policy ""
將新的安全性政策新增至後端服務,如下例所示:
gcloud compute backend-services update my-backend \ --security-policy new-policy
如果未使用舊政策,請刪除:
gcloud compute security-policies delete my-policy
從安全性政策中刪除規則
按照這些操作說明,從 Google Cloud Armor 安全性政策中刪除規則。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
按一下安全政策的名稱。系統隨即會顯示「政策詳細資料」頁面。
在頁面中間的「規則」分頁中,找出要刪除的規則,勾選旁邊的核取方塊。
按一下
「Delete」(刪除)。
gcloud
使用這項指令,從指定安全性政策中移除具有指定優先順序的規則。一次只能修改一項安全性政策,但可以一次刪除多項規則:
gcloud compute security-policies rules delete PRIORITY [...] [ --security-policy POLICY_NAME \ ]
例如:
gcloud compute security-policies rules delete 1000 \ --security-policy my-policy
附加及移除安全性政策
請參閱下列章節,瞭解如何將安全性政策附加至後端服務和後端值區,以及如何從中移除。
將安全性政策附加至後端服務
按照這些操作說明,將 Google Cloud Armor 安全性政策附加至後端服務。安全性政策可附加至多個後端服務,但每個後端服務只能附加一項安全性政策。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
在「安全性政策」頁面中,按一下安全性政策名稱。系統隨即會顯示「政策詳細資料」頁面。
按一下頁面中央的「目標」分頁標籤。
按一下「對新目標套用政策」。
點選「新增目標」。
在「目標」清單中選取目標,然後按一下「新增」。
gcloud
將後端安全政策附加至後端服務時,請使用 gcloud compute backend-services
指令和 --security-policy
標記:
gcloud compute backend-services update my-backend \ --security-policy my-policy
將邊緣安全政策附加至後端服務時,請使用 gcloud compute backend-services
指令和 --edge-security-policy
旗標:
gcloud compute backend-services update my-backend \ --edge-security-policy my-policy
從後端服務移除安全性政策
按照這些操作說明,從後端服務中移除 Google Cloud Armor 後端安全性政策或邊緣安全性政策。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
在「安全性政策」頁面中,按一下安全性政策名稱。系統隨即會顯示「政策詳細資料」頁面。
按一下頁面中央的「目標」分頁標籤。
選取要移除政策的目標後端服務。
按一下 [移除]。
在「移除目標」訊息中,按一下「移除」。
gcloud
如要移除後端安全政策,請使用 gcloud compute
backend-services
指令和 --security-policy
旗標:
gcloud compute backend-services update my-backend \ --security-policy ""
如要移除邊緣安全政策,請使用 gcloud compute
backend-services
指令和 --edge-security-policy
旗標:
gcloud compute backend-services update my-backend \ --edge-security-policy ""
將安全性政策附加至後端 bucket
按照這些操作說明,將 Google Cloud Armor 邊緣安全性政策附加至後端值區。邊緣安全政策可附加至多個後端值區。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
在「安全性政策」頁面中,按一下安全性政策名稱。系統隨即會顯示「政策詳細資料」頁面。
按一下頁面中央的「目標」分頁標籤。
按一下「對新目標套用政策」。
點選「新增目標」。
在「目標」清單中選取目標,然後按一下「新增」。
gcloud
將邊緣安全政策附加至後端 bucket 時,請使用 cloud compute backend-buckets
指令和 --edge-security-policy
標記:
gcloud compute backend-services update my-bucket \ --edge-security-policy my-edge-policy
從後端 bucket 移除安全性政策
按照這些操作說明,從後端 bucket 移除 Google Cloud Armor 邊緣安全性政策。
主控台
在 Google Cloud 控制台中,前往「Google Cloud Armor policies」(Google Cloud Armor 政策) 頁面。
在「安全性政策」頁面中,按一下安全性政策名稱。系統隨即會顯示「政策詳細資料」頁面。
按一下頁面中央的「目標」分頁標籤。
選取要移除政策的目標後端服務。
按一下 [移除]。
在「移除目標」訊息中,按一下「移除」。
gcloud
從後端 bucket 移除邊緣安全政策時,請使用 cloud compute backend-buckets
指令和 --edge-security-policy
旗標:
gcloud compute backend-services update my-bucket \ --edge-security-policy ""
匯入及匯出安全性政策
請參閱下列章節,以 YAML 或 JSON 檔案格式匯入及匯出安全性政策。
匯入安全性政策
您可以使用 Google Cloud CLI,從 YAML 或 JSON 檔案匯入 Google Cloud Armor 安全性政策。您無法使用 import
指令更新現有政策的規則。您必須改用「更新安全性政策中的單一規則」程序逐一更新規則,或使用「以原子方式更新安全性政策中的多項規則」程序一次更新所有規則。
gcloud
如要匯入安全性政策,請使用 gcloud compute security-policies import NAME
指令。將 NAME
替換為要匯入的安全政策名稱。如未提供檔案格式,系統會根據檔案結構判斷正確格式。如果結構無效,系統會顯示錯誤。
gcloud compute security-policies import NAME \ --file-name FILE_NAME \ [--file-format FILE_FORMAT]
舉例來說,下列指令會匯入 my-file
檔案,藉此更新 my-policy
政策。
gcloud compute security-policies import my-policy \ --file-name my-file \ --file-format json
如果匯入政策時,政策的指紋已過期,Google Cloud Armor 會顯示錯誤。這表示政策在您上次匯出後已修改。如要修正這個問題,請對政策使用 describe
指令,取得最新指紋。合併所述政策與您的政策之間的差異,然後以最新指紋取代過時的指紋。
匯出安全性政策
您可以使用 Google Cloud CLI,將 Google Cloud Armor 安全性政策匯出為 YAML 或 JSON 檔案。匯出政策後,您就能取得政策副本,以便修改或儲存在來源控管中。
gcloud
在下列指令中,
NAME
是安全政策的名稱。有效檔案格式為 YAML 和 JSON。如未提供檔案格式,Google Cloud Armor 會使用預設 YAML。gcloud compute security-policies export NAME \ --file-name FILE_NAME \ --file-format FILE_FORMAT
以下範例會以 YAML 格式將
my-policy
安全性政策匯出至my-file
檔案:gcloud compute security-policies export my-policy \ --file-name my-file \ --file-format yaml
以下範例顯示匯出的安全性政策:
description: my description fingerprint: PWfLGDWQDLY= id: '123' name: my-policy rules: - action: allow description: default rule match: config: srcIpRanges: - '*' versionedExpr: SRC_IPS_V1 preview: false priority: 2147483647 selfLink: https://www.googleapis.com/compute/v1/projects/my-project/global/securityPolicies/my-policy
您可以使用任何文字編輯器修改匯出的檔案,然後使用
import
指令將檔案匯入 Google Cloud 。
列出可用的預先設定規則
列出預先設定的規則,查看預先定義的應用程式保護規則和簽章,例如 Google Cloud Armor 提供的 OWASP 核心規則集。這些預先設定的規則包含多個內建簽章,Google Cloud Armor 會用來評估傳入的要求。您可以使用自訂規則語言參考資料,將這些預先設定的規則新增至現有或新的規則。
詳情請參閱預先設定的規則。
gcloud
執行
gcloud compute security-policies list-preconfigured-expression-sets
指令:gcloud compute security-policies list-preconfigured-expression-sets
以下範例顯示指令的輸出格式:
EXPRESSION_SET expression-set-1 RULE_ID SENSITIVITY expression-set-1-id-1 sensitivity-value-1 expression-set-1-id-2 sensitivity-value-2 expression-set-2 alias-1 RULE_ID SENSITIVITY expression-set-2-id-1 sensitivity-value-1 expression-set-2-id-2 sensitivity-value-2
以下範例包含指令的實際輸出內容樣本。請注意,實際輸出內容會包含「調整 Google Cloud Armor 網路應用程式防火牆規則」中列出的所有規則。
gcloud compute security-policies list-preconfigured-expression-sets
EXPRESSION_SET sqli-canary RULE_ID SENSITIVITY owasp-crs-v030001-id942110-sqli 2 owasp-crs-v030001-id942120-sqli 2 … xss-canary RULE_ID SENSITIVITY owasp-crs-v030001-id941110-xss 1 owasp-crs-v030001-id941120-xss 1 … sourceiplist-fastly sourceiplist-cloudflare sourceiplist-imperva