Google Cloud 機構政策可讓您透過程式以集中方式控管機構的資源。身為機構政策管理員,您可以定義機構政策,也就是一組稱為限制的限制,適用於Google Cloud 資源和Google Cloud 資源階層中這些資源的子系。您可以在機構、資料夾或專案層級強制執行機構政策。
機構政策提供各種Google Cloud 服務的預先定義限制。不過,如要進一步控管機構政策中受限制的特定欄位,您也可以建立自訂限制,並在自訂機構政策中強制執行這些限制。
政策繼承
根據預設,機構政策會由您強制執行政策的資源子系繼承。舉例來說,如果您對資料夾強制執行政策, Google Cloud 系統會對該資料夾中的所有專案強制執行政策。如要進一步瞭解這項行為及如何變更,請參閱「階層評估規則」。
Google Cloud Armor 支援的資源
對於 Google Cloud Armor 資源,您可以對下列資源和欄位設定自訂限制。
安全政策:
compute.googleapis.com/SecurityPolicy
- 名稱:
resource.name
- 說明:
resource.description
- 規則:
resource.rules[]
- 標頭動作:
resource.headerAction
- 要新增的要求標頭:
resource.headerAction.requestHeadersToAdds[]
- 標題名稱:
resource.requestHeadersToAdds.requestHeadersToAdds[].headerName
- 標頭值:
resource.requestHeadersToAdds.requestHeadersToAdds[].headerValue
- 標題名稱:
- 比對器:
resource.rules[].match
- 版本化運算式:
resource.rules[].versionedExpr
- 設定:
resource.rules[].config
- 來源 IP 範圍:
resource.rules[].config.srcIpRanges[]
- 來源 IP 範圍:
- 運算式:
resource.rules[].expr
- 運算式選項:
resource.rules[].exprOptions
- reCAPTCHA 選項:
resource.rules[].exprOption.recaptchaOptions
- 動作符記網站金鑰:
resource.rules[].exprOption.recaptchaOptions.actionTokenSiteKeys
- 工作階段符記網站金鑰:
resource.rules[].exprOption.recaptchaOptions.sessionTokenSiteKeys
- reCAPTCHA 選項:
- 聯播網比對器:
resource.rules[].networkMatch
- 使用者定義的欄位相符:
resource.rules[].userDefinedFieldMatch
- 名稱:
resource.rules[].userDefinedFieldMatch.name
- 值:
resource.rules[].userDefinedFieldMatch.values
- 名稱:
- 來源 IP 範圍:
resource.rules[].srcIpRanges
- 目的地 IP 範圍:
resource.rules[].destIpRanges
- IP 通訊協定:
resource.rules[].ipProtocols
- 來源通訊埠:
resource.rules[].srcPorts
- 目的地通訊埠:
resource.rules[].destPorts
- 來源區碼:
resource.rules[].srcRegionCodes
- 來源 ASN:
resource.rules[].srcAsns
- 預先設定的 WAF 設定:
resource.rules[].preconfiguredWafConfig
- 排除條件:
resource.rules[].preconfiguredWafConfig.exclusions[]
- 目標規則集:
resource.rules[].preconfiguredWafConfig.exclusions[].targetRuleSet
- 目標規則 ID:
resource.rules[].preconfiguredWafConfig.exclusions[].targetRuleIds[]
- 要排除的要求標頭:
resource.rules[].preconfiguredWafConfig.exclusions[].requestHeadersToExclude[]
- 值:
resource.rules[].preconfiguredWafConfig.exclusions[].requestHeadersToExclude[].val
- 作業:
resource.rules[].preconfiguredWafConfig.exclusions[].requestHeadersToExclude[].op
- 要求排除的 Cookie:
resource.rules[].preconfiguredWafConfig.exclusions[].requestCookiesToExclude[]
- 值:
resource.rules[].preconfiguredWafConfig.exclusions[].requestCookiesToExclude[].val
- 作業:
resource.rules[].preconfiguredWafConfig.exclusions[].requestCookiesToExclude[].op
- 要排除的查詢參數:
resource.rules[].preconfiguredWafConfig.exclusions[].requestQueryParamsToExclude[]
- 值:
resource.rules[].preconfiguredWafConfig.exclusions[].requestQueryParamsToExclude[].val
- 作業:
resource.rules[].preconfiguredWafConfig.exclusions[].requestQueryParamsToExclude[].op
- 要排除的要求 URI:
resource.rules[].preconfiguredWafConfig.exclusions[].requestUrisToExclude[]
- 值:
resource.rules[].preconfiguredWafConfig.exclusions[].requestUrisToExclude[].val
- 作業:
resource.rules[].preconfiguredWafConfig.exclusions[].requestUrisToExclude[].op
- 目標規則集:
- 重新導向選項:
resource.rules[].redirectOptions[]
- 類型:
resource.rules[].redirectOptions[].type
- 目標:
resource.rules[].redirectOptions[].target
- 速率限制選項:
resource.rules[].rateLimitOptions[]
- 頻率限制門檻:
resource.rules[].rateLimitOptions[].rateLimitThreshold
- 數量:
resource.rules[].rateLimitOptions[].rateLimitThreshold.count
- 間隔 (秒):
resource.rules[].rateLimitOptions[].rateLimitThreshold.intervalSec
- 數量:
- 確認動作:
resource.rules[].rateLimitOptions[].conformAction
- 超過門檻後的動作:
resource.rules[].rateLimitOptions[].exceedAction
- 超出重新導向選項:
resource.rules[].rateLimitOptions[].exceedRedirectOptions
- 類型:
resource.rules[].rateLimitOptions[].exceedRedirectOptions.type
- 目標:
resource.rules[].rateLimitOptions[].exceedRedirectOptions.target
- 類型:
- 超過門檻後的動作 RPC 狀態:
resource.rules[].rateLimitOptions[].exceedActionRpcStatus
- 錯誤代碼:
resource.rules[].rateLimitOptions[].exceedActionRpcStatus.code
- 郵件:
resource.rules[].rateLimitOptions[].exceedActionRpcStatus.message
- 錯誤代碼:
- 對下列金鑰強制執行:
resource.rules[].rateLimitOptions[].enforceOnKey
- 強制啟用金鑰名稱:
resource.rules[].rateLimitOptions[].enforceOnKeyName
- 強制啟用金鑰設定:
resource.rules[].rateLimitOptions[].enforceOnKeyConfigs
- 對下列金鑰類型強制執行:
resource.rules[].rateLimitOptions[].enforceOnKeyConfigs.enforceOnKeyType
- 強制啟用金鑰名稱:
resource.rules[].rateLimitOptions[].enforceOnKeyConfigs.enforceOnKeyName
- 對下列金鑰類型強制執行:
- 停權門檻:
resource.rules[].rateLimitOptions[].banThreshold
- 數量:
resource.rules[].rateLimitOptions[].banThreshold.count
- 間隔 (秒):
resource.rules[].rateLimitOptions[].banThreshold.intervalSec
- 數量:
- 停權時間長度 (秒):
resource.rules[].rateLimitOptions[].banDurationSec
- 重新導向目標:
resource.rules[].redirectTarget
- 規則編號:
resource.rules[].ruleNumber
- 標頭動作:
- 可調整的防護設定:
resource.adaptiveProtectionConfig
- 第 7 層分散式阻斷服務防禦設定:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig
- 啟用:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.enable
- 規則顯示設定:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.ruleVisibility
- 門檻設定:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[]
- 名稱:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].name
- 自動部署負載門檻:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].autoDeployLoadThreshold
- 自動部署可信度門檻:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].autoDeployConfidenceThreshold
- 自動部署受影響的基準門檻:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].autoDeployImpactedBaselineThreshold
- 自動部署期限 (秒):
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].autoDeployExpirationSec
- 偵測負載門檻:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].detectionLoadThreshold
- 偵測絕對 QPS:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].detectionAbsoluteQps
- 偵測到的基準 QPS 倍數:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].detectionRelativeToBaselineQps
- 流量精細程度設定:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].trafficGranularityConfigs[]
- 類型:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].trafficGranularityConfigs[].type
- 值:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].trafficGranularityConfigs[].value
- 啟用每個不重複的值:
resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.thresholdConfigs[].trafficGranularityConfigs[].enableEachUniqueValue
- 名稱:
- 自動部署設定:
resource.adaptiveProtectionConfig.autoDeployConfig
- 載入門檻:
resource.adaptiveProtectionConfig.autoDeployConfig.loadThreshold
- 可信度門檻:
resource.adaptiveProtectionConfig.autoDeployConfig.confidenceThreshold
- 受影響的基準門檻:
resource.adaptiveProtectionConfig.autoDeployConfig.impactedBaselineThreshold
- 期限 (秒):
resource.adaptiveProtectionConfig.autoDeployConfig.expirationSec
- 第 7 層分散式阻斷服務防禦設定:
- 進階選項設定:
resource.advancedOptionsConfig
- JSON 剖析:
resource.advancedOptionsConfig,jsonParsing
- JSON 自訂設定:
resource.advancedOptionsConfig,jsonCustomConfig
- 內容類型:
resource.advancedOptionsConfig,jsonCustomConfig.contentTypes[]
- 記錄層級:
resource.advancedOptionsConfig.logLevel
- 使用者 IP 要求標頭:
resource.advancedOptionsConfig.userIpRequestHeaders[]
- JSON 剖析:
- DDoS 防護設定:
resource.ddosProtectionConfig
- 分散式阻斷服務攻擊防護:
resource.ddosProtectionConfig.ddosProtection
- 分散式阻斷服務攻擊防護:
- reCAPTCHA 選項設定:
resource.recaptchaOptionsConfig
- 重新導向網站金鑰:
resource.recaptchaOptionsConfig.redirectSiteKey
- 重新導向網站金鑰:
- 類型:
resource.type
- 使用者定義的欄位:
resource.userDefinedFields[]
- 名稱:
resource.userDefinedFields[].name
- 底數:
resource.userDefinedFields[].base
- 位移:
resource.userDefinedFields[].offset
- 大小:
resource.userDefinedFields[].size
- 遮罩:
resource.userDefinedFields[].mask
- 名稱:
- 名稱:
網路邊緣安全服務:
compute.googleapis.com/NetworkEdgeSecurityService
- 名稱:
resource.name
- 說明:
resource.description
- 安全性政策:
resource.securityPolicy
- 名稱:
定義自訂限制
自訂限制是由資源、方法、條件和動作所定義,這些項目受到您要強制執行機構政策的服務支援。自訂限制的條件是使用一般運算語言 (CEL) 定義。如要進一步瞭解如何使用 CEL 在自訂限制中建立條件,請參閱「建立及管理機構政策」一文的 CEL 專區。
事前準備
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
-
機構政策管理員 (
roles/orgpolicy.policyAdmin
) 機構資源 -
如要測試限制條件,請執行下列操作:
-
專案的Compute 安全管理員 (
roles/compute.securityAdmin
) -
專案的服務帳戶使用者 (
roles/iam.serviceAccountUser
)
-
專案的Compute 安全管理員 (
-
orgpolicy.constraints.list
-
orgpolicy.policies.create
-
orgpolicy.policies.delete
-
orgpolicy.policies.list
-
orgpolicy.policies.update
-
orgpolicy.policy.get
-
orgpolicy.policy.set
前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。
選取頁面頂端的「專案挑選器」。
在專案選擇工具中,選取要設定機構政策的資源。
按一下「自訂限制」
。在「顯示名稱」方塊中,輸入容易理解的限制名稱。這個欄位的長度上限為 200 個字元。 請勿在限制名稱中輸入 PII 或機密資料,因為錯誤訊息可能會顯示上述資訊。
在「Constraint ID」(限制條件 ID) 方塊中,輸入新自訂限制條件的名稱。自訂限制必須以
custom.
開頭,且只能包含大寫英文字母、小寫英文字母或數字,例如custom.requireSecurityPolicyWithStandardJsonParsing
。這個欄位的長度上限為 70 個字元,不含前置字元,例如organizations/123456789/customConstraints/custom.
。在「Description」方塊中,輸入限制的易讀說明,違反政策時會以錯誤訊息形式顯示。 這個欄位的長度上限為 2,000 個字元。
在「Resource type」方塊中,選取包含要限制物件和欄位的 Google Cloud REST 資源名稱。例如:
compute.googleapis.com/SecurityPolicy
。在「強制執行方式」下方,選取要僅對 REST
CREATE
方法強制執行限制,還是對 RESTCREATE
和UPDATE
方法都強制執行限制。如要定義條件,請按一下「編輯條件」
。在「Add condition」(新增條件) 面板中,建立參照支援服務資源的 CEL 條件。這個欄位的長度上限為 1,000 個字元。
按一下 [儲存]。
在「動作」下方,選取是否要在符合上述條件時允許或拒絕評估方法。
按一下「建立限制」。
ORGANIZATION_ID
:您的機構 ID,例如123456789
。CONSTRAINT_NAME
:新自訂限制的名稱。自訂限制必須以custom.
開頭,且只能包含大寫英文字母、小寫英文字母或數字,例如custom.requireSecurityPolicyWithStandardJsonParsing
。這個欄位的長度上限為 70 個字元,不含前置字元,例如organizations/123456789/customConstraints/custom
。RESOURCE_NAME
:包含要限制物件和欄位的 Compute Engine API REST 資源名稱 (而非 URI)。例如:SecurityPolicy
。METHOD1,METHOD2,...
:要強制執行限制的 RESTful 方法清單。可以是CREATE
或CREATE
和UPDATE
。CONDITION
:針對支援服務資源的代表項目編寫的 CEL 條件。這個欄位的長度上限為 1,000 個字元。如要進一步瞭解可編寫條件的資源,請參閱「支援的資源」。ACTION
:如果符合condition
,則要採取的動作。可以是ALLOW
或DENY
。DISPLAY_NAME
:限制條件的易記名稱。這個欄位的長度上限為 200 個字元。DESCRIPTION
:違反政策時,要以錯誤訊息形式顯示的限制說明,方便使用者閱讀。這個欄位的長度上限為 2,000 個字元。- 前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。
- 在專案選擇工具中,選取要設定機構政策的專案。
- 在「Organization policies」(機構政策) 頁面上的清單中選取限制條件,即可查看該限制條件的「Policy details」(政策詳情) 頁面。
- 如要設定這項資源的機構政策,請按一下「管理政策」。
- 在「編輯政策」頁面中,選取「覆寫上層政策」。
- 按一下「新增規則」。
- 在「Enforcement」(強制執行) 區段中,選取是否要強制執行這項機構政策。
- 選用:如要根據標記設定機構政策條件,請按一下「新增條件」。請注意,如果為組織政策新增條件式規則,您必須至少新增一項無條件規則,否則無法儲存政策。詳情請參閱「使用標記設定組織政策」。
- 按一下「測試變更」,模擬機構政策的影響。舊版受管理限制不支援政策模擬。詳情請參閱「 使用 Policy Simulator 測試組織政策變更」。
- 如要完成並套用機構政策,請按一下「設定政策」。這項政策最多需要 15 分鐘才會生效。
-
PROJECT_ID
:要強制執行限制的專案。 -
CONSTRAINT_NAME
:您為自訂限制定義的名稱。例如:
。custom.requireSecurityPolicyWithStandardJsonParsing
建立
requireStandardJsonParsing.yaml
限制檔案,並加入下列資訊。name: organizations/ORGANIZATION_ID/customConstraints/custom.requireStandardJsonParsing resource_types: compute.googleapis.com/SecurityPolicy condition: "resource.advancedOptionsConfig.jsonParsing != 'STANDARD'" action_type: DENY method_types: [CREATE, UPDATE] display_name: Security policies must have standard JSON parsing enabled.
將
ORGANIZATION_ID
替換為機構 ID。設定自訂限制。
gcloud org-policies set-custom-constraint requireStandardJsonParsing.yaml
使用下列範例提供的資訊建立
requireStandardJsonParsing-policy.yaml
政策檔案,並在專案層級強制執行限制。您也可以在機構或資料夾層級設定這項限制。name: projects/PROJECT_ID/policies/custom.requireStandardJsonParsing spec: rules: – enforce: true
將
PROJECT_ID
替換為您的專案 ID。強制執行政策。
gcloud org-policies set-policy requireStandardJsonParsing-policy.yaml
如要測試限制,請建立安全性政策,但不要設定 JSON 剖析欄位。
gcloud compute security-policies create my-policy \ --type=CLOUD_ARMOR
輸出結果會與下列內容相似:
ERROR: (gcloud.compute.securityPolicies.create) Could not fetch resource: - Operation denied by custom org policy: [customConstraints/custom.requireStandardJsonParsing] : Security policies must have standard JSON parsing enabled.
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。
必要的角色
如要取得管理 Google Cloud Armor 資源機構政策所需的權限,請要求管理員授予下列 IAM 角色:
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這些預先定義的角色具備管理 Google Cloud Armor 資源組織政策所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要管理 Google Cloud Armor 資源的組織政策,必須具備下列權限:
設定自訂限制
您可以使用 Google Cloud 控制台或 Google Cloud CLI 建立自訂限制,並設定在機構政策中使用。
控制台
在每個欄位中輸入值後,右側會顯示這個自訂限制的對等 YAML 設定。
gcloud
如要使用 Google Cloud CLI 建立自訂限制,請建立 YAML 檔案。
name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME resource_types: compute.googleapis.com/RESOURCE_NAME method_types: – METHOD1 – METHOD2 condition: "CONDITION" action_type: ACTION display_name: DISPLAY_NAME description: DESCRIPTION
更改下列內容:
如要進一步瞭解如何建立自訂限制,請參閱「定義自訂限制」。
為新的自訂限制建立 YAML 檔案後,您必須進行設定,才能在貴機構的機構政策中使用該檔案。如要設定自訂限制,請使用gcloud org-policies set-custom-constraint
指令: 將gcloud org-policies set-custom-constraint CONSTRAINT_PATH
CONSTRAINT_PATH
替換為自訂限制檔案的完整路徑。例如:/home/user/customconstraint.yaml
。 完成後,自訂限制就會顯示在 Google Cloud 機構政策清單中,做為機構政策使用。如要確認自訂限制存在,請使用gcloud org-policies list-custom-constraints
指令: 將gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
ORGANIZATION_ID
替換為機構資源的 ID。 詳情請參閱「查看機構政策」。強制執行自訂限制
如要強制執行限制,請建立參照該限制的機構政策,然後將該政策套用至 Google Cloud 資源。控制台
gcloud
如要建立含有布林值規則的機構政策,請建立參照限制的政策 YAML 檔案:
name: projects/PROJECT_ID/policies/CONSTRAINT_NAME spec: rules: - enforce: true
取代下列項目:
如要強制執行包含限制的機構政策,請執行下列指令:
gcloud org-policies set-policy POLICY_PATH
將
POLICY_PATH
替換為機構政策 YAML 檔案的完整路徑。這項政策最多需要 15 分鐘才會生效。範例:建立限制,規定所有安全性政策都必須啟用標準 JSON 剖析功能
如果安全性政策未啟用標準 JSON 剖析功能,這項限制會禁止建立該政策。
gcloud
定價
機構政策服務 (包括預先定義和自訂機構政策) 免費提供。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-11 (世界標準時間)。
-