Google Cloud 組織政策服務可讓您透過程式輔助,集中控管組織的資源。組織政策管理員可以定義組織政策,也就是一組稱為「限制」的限制,適用於Google Cloud 資源和這些資源在Google Cloud 資源階層中的子系。您可以在組織、資料夾或專案層級強制執行組織政策。
組織政策提供各種Google Cloud 服務的預先定義限制。不過,如要更精細地自訂組織政策中受限的特定欄位,您也可以建立「自訂限制」,並用於組織政策。
政策繼承
根據預設,您強制執行政策的資源子系會繼承組織政策。舉例來說,如果您對資料夾強制執行政策, Google Cloud 會對該資料夾中的所有專案強制執行政策。如要進一步瞭解這項行為以及如何變更,請參閱「階層評估規則」。
Google Cloud Armor 支援的資源
針對 Cloud Armor 資源,您可以對下列資源和欄位設定自訂限制。
-
安全性政策:
compute.googleapis.com/SecurityPolicy- 名稱:
resource.name - 說明:
resource.description -
規則:
resource.rules[]-
標頭動作:
resource.rules[].headerAction-
要新增的要求標頭:
resource.rules[].headerAction.requestHeadersToAdds[]-
標頭名稱:
resource.rules[].headerAction.requestHeadersToAdds[].headerName -
標頭值:
resource.rules[].headerAction.requestHeadersToAdds[].headerValue
-
標頭名稱:
-
要新增的要求標頭:
-
比對器:
resource.rules[].match-
版本化運算式:
resource.rules[].match.versionedExpr -
設定:
resource.rules[].match.config-
來源 IP 範圍:
resource.rules[].match.config.srcIpRanges[]
-
來源 IP 範圍:
- 運算式:
resource.rules[].match.expr -
運算式選項:
resource.rules[].match.exprOptions-
reCAPTCHA 選項:
resource.rules[].match.exprOptions.recaptchaOptions-
動作符記網站金鑰:
resource.rules[].match.exprOptions.recaptchaOptions.actionTokenSiteKeys[] -
工作階段符記網站金鑰:
resource.rules[].match.exprOptions.recaptchaOptions.sessionTokenSiteKeys[]
-
動作符記網站金鑰:
-
reCAPTCHA 選項:
-
版本化運算式:
-
網路比對器:
resource.rules[].networkMatch-
使用者定義欄位比對:
resource.rules[].networkMatch.userDefinedFieldMatch-
名稱:
resource.rules[].networkMatch.userDefinedFieldMatch.name -
值:
resource.rules[].networkMatch.userDefinedFieldMatch.values
-
名稱:
-
來源 IP 範圍:
resource.rules[].networkMatch.srcIpRanges -
目的地 IP 範圍:
resource.rules[].networkMatch.destIpRanges -
IP 通訊協定:
resource.rules[].networkMatch.ipProtocols -
來源通訊埠:
resource.rules[].networkMatch.srcPorts -
目的地通訊埠:
resource.rules[].networkMatch.destPorts -
來源區域代碼:
resource.rules[].networkMatch.srcRegionCodes -
來源 ASN:
resource.rules[].networkMatch.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
-
標頭動作:
-
Adaptive Protection 設定:
resource.adaptiveProtectionConfig-
第 7 層 DDoS 防禦設定:
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 層 DDoS 防禦設定:
-
進階選項設定:
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-
DDoS 防護:
resource.ddosProtectionConfig.ddosProtection
-
DDoS 防護:
-
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 進行驗證:
請根據您打算如何使用本頁範例,選取對應的分頁標籤:
控制台
使用 Google Cloud 控制台存取 Google Cloud 服務和 API 時,不需要設定驗證機制。
gcloud
-
安裝 Google Cloud CLI。 安裝完成後, 請執行下列指令,初始化 Google Cloud CLI:
gcloud init如果採用外部識別資訊提供者 (IdP),必須先 使用聯合身分登入 gcloud CLI。
-
- 設定預設區域和可用區。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI。
如果採用外部識別資訊提供者 (IdP),必須先 使用聯合身分登入 gcloud CLI。
詳情請參閱 Google Cloud 驗證說明文件中的「使用 REST 進行驗證」一節。
必要的角色
如要取得管理 Cloud Armor 資源組織政策所需的權限,請要求管理員授予您下列 IAM 角色:
- 組織資源的組織政策管理員 (
roles/orgpolicy.policyAdmin) -
如要測試限制,請按照下列步驟操作:
- 專案的 Compute 安全管理員 (
roles/compute.securityAdmin) - 專案的服務帳戶使用者 (
roles/iam.serviceAccountUser)
- 專案的 Compute 安全管理員 (
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
這些預先定義的角色具備管理 Cloud Armor 資源組織政策所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:
所需權限
必須具備下列權限,才能管理 Cloud Armor 資源的組織政策:
-
orgpolicy.constraints.list -
orgpolicy.policies.create -
orgpolicy.policies.delete -
orgpolicy.policies.list -
orgpolicy.policies.update -
orgpolicy.policy.get -
orgpolicy.policy.set
設定自訂限制
您可以使用 Google Cloud 控制台或 Google Cloud CLI,建立自訂限制並設定用於組織政策。控制台
前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。
選取頁面頂端的「Project picker」(專案挑選器)。
在專案挑選器中,選取要設定組織政策的資源。
按一下「 自訂限制」。
在「Display name」(顯示名稱) 方塊中,輸入限制的易記名稱。這個欄位的長度上限為 200 個字元。 請勿在限制名稱中使用 PII 或機密資料,因為錯誤訊息可能會顯示上述資訊。
在「Constraint ID」(限制 ID) 方塊中,輸入新自訂限制的名稱。自訂限制必須以
custom.開頭,且只能包含大/小寫英文字母或數字,例如 custom.requireSecurityPolicyWithStandardJsonParsing。這個欄位的長度上限為 70 個字元,不含前置字元,例如organizations/123456789/customConstraints/custom.。在「Description」(說明) 方塊中,輸入違反政策時,要以錯誤訊息形式顯示且易於理解的限制說明。這個欄位的長度上限為 2,000 個字元。
在「Resource type」(資源類型) 方塊中,選取 Google CloudREST 資源的名稱,其中包含您要限制的物件和欄位。例如:
compute.googleapis.com/SecurityPolicy。在「Enforcement method」(強制執行方法) 下方,選取要僅對 REST
CREATE方法強制執行限制,還是對 RESTCREATE和UPDATE方法強制執行限制。如要定義條件,請按一下 「Edit condition」(編輯條件)。
在「Add condition」(新增條件) 面板中,建立參照支援服務資源的 CEL 條件。這個欄位的長度上限為 1,000 個字元。
按一下 [儲存]。
在「Action」(動作) 下方,選取是否要在符合條件時允許或拒絕評估的方法。
按一下「Create constraint」(建立限制)。
在每個欄位中輸入值後,右側會顯示這項自訂限制的對等 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
更改下列內容:
ORGANIZATION_ID:組織 ID,例如123456789。CONSTRAINT_NAME:新自訂限制的名稱。自訂限制必須以custom.開頭,且只能包含大/小寫英文字母或數字,例如 custom.requireSecurityPolicyWithStandardJsonParsing。這個欄位的長度上限為 70 個字元,不含前置字元,例如organizations/123456789/customConstraints/custom。RESOURCE_NAME:Compute Engine API REST 資源的名稱 (而非 URI),內含要限制的物件和欄位。例如 compute.googleapis.com/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」(組織政策) 頁面。
- 在專案挑選器中,選取要設定組織政策的專案。
- 按一下「 Custom constraint」(自訂限制)。
- 在「Display name」(顯示名稱) 方塊中,輸入人類可讀的限制名稱。這個名稱會用於錯誤訊息,可用於識別和偵錯。請勿在顯示名稱中使用個人識別資訊 (PII) 或機密資料,因為這類名稱可能會在錯誤訊息中曝光。這個欄位最多可包含 200 個字元。
-
在「Constraint ID」(限制 ID) 方塊中,輸入新自訂限制的 ID。自訂限制只能包含英文字母 (包括大小寫) 或數字,例如
custom.requireSecurityPolicyWithStandardJsonParsing。這個欄位最多可包含 70 個字元,不含前置字元 (custom.),例如organizations/123456789/customConstraints/custom。請勿在限制 ID 中輸入 PII 或機密資料,因為錯誤訊息可能會顯示上述資訊。 - 在「Description」(說明) 方塊中,輸入人類可讀的限制說明。違反政策時,系統會將這段說明做為錯誤訊息顯示。請詳細說明違反政策的原因,以及如何解決違規問題。請勿在說明中輸入 PII 或機密資料,因為錯誤訊息可能會顯示上述資訊。這個欄位最多可輸入 2000 個字元。
-
在「Resource type」(資源類型) 方塊中,選取包含要限制的物件和欄位的 Google Cloud REST 資源名稱,例如
container.googleapis.com/Cluster。大多數資源類型最多支援 20 項自訂限制。如果嘗試建立更多自訂限制,作業會失敗。 -
這項限制只能在 REST
CREATE方法上強制執行。 - 如要定義條件,請按一下 「Edit condition」(編輯條件)。
-
在「Add condition」(新增條件) 面板中,建立參照支援服務資源的 CEL 條件,例如
resource.management.autoUpgrade == false。這個欄位最多可輸入 1000 個字元。如要進一步瞭解 CEL 的用法,請參閱 一般運算語言。如要進一步瞭解可在自訂限制中使用的服務資源,請參閱「 支援自訂限制的服務」。 - 按一下 [儲存]。
- 在「Action」下方,選取是否要在符合條件時允許或拒絕評估的方法。
- 按一下「Create constraint」(建立限制)。
如要查看各項服務支援的方法,請在「 支援自訂限制的服務」中找到該服務。
「拒絕」動作表示如果條件評估為 true,系統會禁止建立或更新資源。
「允許」動作表示只有在條件評估為 true 時,才允許建立或更新資源。除了條件中明確列出的情況外,其他所有情況都會遭到封鎖。
在每個欄位中輸入值後,右側會顯示這項自訂限制的對等 YAML 設定。
gcloud
- 如要建立自訂限制,請使用下列格式建立 YAML 檔案:
-
ORGANIZATION_ID:組織 ID,例如123456789。 -
CONSTRAINT_NAME:新自訂限制的名稱。自訂限制只能包含英文字母 (包括大小寫) 或數字,例如custom.requireSecurityPolicyWithStandardJsonParsing。這個欄位最多可包含 70 個字元,不含前置字元 (custom.),例如organizations/123456789/customConstraints/custom。請勿在限制 ID 中輸入 PII 或機密資料,因為錯誤訊息可能會顯示上述資訊。 -
RESOURCE_NAME:內含要限制的物件和欄位的 Google Cloud資源完整名稱,例如:compute.googleapis.com/SecurityPolicy。大多數資源類型最多支援 20 項自訂限制。如果嘗試建立更多自訂限制,作業會失敗。 -
methodTypes:強制執行限制的 REST 方法。只能是CREATE。 -
CONDITION:針對支援服務資源表示法所撰寫的 CEL 條件。這個欄位最多可輸入 1000 個字元。例如:"resource.advancedOptionsConfig.jsonParsing != 'STANDARD'"。 -
ACTION:符合condition時採取動作。只能是ALLOW。 -
DISPLAY_NAME:人類可讀的限制名稱。這個名稱會用於錯誤訊息,可用於識別和偵錯。請勿在顯示名稱中使用 PII 或機密資料,因為這類名稱可能會在錯誤訊息中顯示。這個欄位最多可輸入 200 個字元。 -
DESCRIPTION:違反政策時,會以錯誤訊息形式顯示且易於理解的限制說明。這個欄位最多可包含 2000 個字元。 -
為新的自訂限制建立 YAML 檔案後,您必須加以設定,才能用於組織的組織政策。如要設定自訂限制,請使用
gcloud org-policies set-custom-constraint指令: -
如要確認是否存在自訂限制,請使用
gcloud org-policies list-custom-constraints指令:
name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME resourceTypes: RESOURCE_NAME methodTypes: - CREATE condition: "CONDITION" actionType: ACTION displayName: DISPLAY_NAME description: DESCRIPTION
更改下列內容:
如要查看各項服務支援的方法,請在「 支援自訂限制的服務」中找到該服務。
如要進一步瞭解可編寫條件的資源,請參閱「支援的資源」。
「允許」動作代表如果條件評估為 true,則允許建立或更新資源。這也表示除了條件中明確列出的情況外,其他所有情況都會遭到封鎖。
gcloud org-policies set-custom-constraint CONSTRAINT_PATH
請將 CONSTRAINT_PATH 替換成自訂限制檔案的完整路徑,例如:/home/user/customconstraint.yaml。
這項作業完成後,自訂限制會顯示在 Google Cloud 組織政策清單中,供組織政策使用。
gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
將 ORGANIZATION_ID 替換為組織資源的 ID。
詳情請參閱「 查看組織政策」。
強制執行自訂限制
如要強制執行限制,請建立參照該限制的組織政策,然後將該政策套用至 Google Cloud 資源。控制台
- 前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。
- 在專案挑選器中,選取要設定組織政策的專案。
- 在「Organization policies」(組織政策) 頁面的清單中選取限制,即可查看該限制的「Policy details」(政策詳細資料) 頁面。
- 如要為這項資源設定組織政策,請按一下「Manage policy」(管理政策)。
- 在「Edit policy」(編輯政策) 頁面,選取「Override parent's policy」(覆寫上層政策)。
- 按一下「Add a rule」(新增規則)。
- 在「Enforcement」(強制執行) 部分,選取是否要強制執行這項組織政策。
- 選用:如要根據標記設定組織政策的條件,請按一下「Add condition」(新增條件)。請注意,如果為組織政策新增條件式規則,您必須至少新增一項無條件規則,否則無法儲存政策。詳情請參閱「 使用標記設定組織政策範圍」。
- 按一下「Test changes」(測試變更),模擬組織政策的影響。詳情請參閱「 使用 Policy Simulator 測試組織政策變更」。
- 如要在模擬測試模式下強制執行組織政策,請按一下「Set dry run policy」(設定模擬測試政策)。詳情請參閱「 測試組織政策」。
- 確認組織政策在模擬測試模式下運作正常後,請按一下「Set policy」(設定政策),設定正式政策。
gcloud
- 如要建立含有布林值規則的組織政策,請建立參照限制的政策 YAML 檔案:
-
PROJECT_ID:要強制執行限制的專案。 -
CONSTRAINT_NAME:要為自訂限制定義的名稱,例如:custom.requireSecurityPolicyWithStandardJsonParsing。 -
如要在模擬測試模式中強制執行組織政策,請執行下列指令並加上
dryRunSpec旗標: -
確認模擬測試模式中的組織政策運作正常後,請使用
org-policies set-policy指令和spec旗標設定正式政策:
name: projects/PROJECT_ID/policies/CONSTRAINT_NAME spec: rules: - enforce: true dryRunSpec: rules: - enforce: true
更改下列內容:
gcloud org-policies set-policy POLICY_PATH --update-mask=dryRunSpec
請將 POLICY_PATH 替換為組織政策 YAML 檔案的完整路徑。政策最多需要 15 分鐘才會生效。
gcloud org-policies set-policy POLICY_PATH --update-mask=spec
請將 POLICY_PATH 替換為組織政策 YAML 檔案的完整路徑。政策最多需要 15 分鐘才會生效。
範例:建立限制,要求所有安全性政策都啟用標準 JSON 剖析功能
這項限制會禁止建立未啟用標準 JSON 剖析功能的安全性政策。
gcloud
建立
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.
定價
組織政策 (包括預先定義和自訂組織政策) 免費提供。