總覽
本指南說明如何設定包含資源位置限制的組織政策。
您可以使用組織政策服務資源位置限制,限制新資源的實體位置。也可以使用資源的位置屬性來識別服務部署和維護該資源的位置。對於某些 Google Cloud 服務中含有資料的資源,這項屬性也會反映資料的儲存位置。這項限制可讓您定義允許的 Google Cloud 位置,以便在階層中建立支援服務的資源。
定義資源位置後,這項限制只會套用至新建立的資源。在設定資源位置限制之前建立的資源,將繼續存在並執行其功能。
如果政策包含這項限制,則在為特定服務 (例如 Cloud Storage 和 Managed Service for Apache Spark) 建立子資源時,不會強制執行該政策。
限制
資源位置組織政策服務限制可控管建立資源的能力,並可選取資源的位置。這項限制不會影響全域資源 (例如 Compute Engine 全域位址) 或不支援選取位置的資源建立位置。
為避免破壞現有的服務基礎架構,請在非正式環境專案和資料夾中測試任何新政策,然後在組織內逐步套用政策。
如要瞭解資料儲存承諾,請參閱《Google Cloud 服務條款》和《服務專屬條款》。包含資源位置限制的組織政策並非資料儲存承諾。
此限制適用於部分特定的產品和資源類型。如需支援的服務清單和各項服務行為的詳細資料,請參閱「支援限制資源位置的服務」頁面。
位置類型
您可以在代表不同大小類別的位置類型中部署 Google Cloud 資源。最大的位置類型是 multi-region,其中包含多個 region。每個 region 會進一步細分為 zones。如要進一步瞭解區域和可用區,請參閱「區域和可用區總覽」。
Multi-region位置由多個region中的實體資源支援,通常僅供儲存空間資源使用。例如us、asia、europe和global。Region位置在地理上彼此隔離。例如us-west1(奧勒岡州)、asia-northeast1(東京) 和europe-west1(比利時)。Zone位置是最精細且獨立的位置類型,用於部署資源。zone是region內的獨立故障域。例如us-east1-b、us-west1-b和asia-northeast1-a。 Google Cloud 也提供專為 AI 和機器學習工作負載量身打造的 AI 可用區,例如us-central1-ai1a。
設定位置時,請使用 in: 前置字元和值組。使用 Google Cloud彙整的值組,即可選擇地理位置,不必指定目前或未來的 Cloud 位置。
值組的 in: 前置字元,指定值組內的所有值都視為政策的一部分。如果您輸入群組值或不含前置字串的 Google Cloud 區域,系統會根據下列規則自動新增 in: 前置字串:
- 如果輸入的位置使用
in:前置字元,且包含任何無效群組,政策變更就會失敗。 - 如果您輸入的地區是區域 (例如
us-east1),系統會在前面加上in:前置字串,在本例中為in:us-east1-locations。 - 如果輸入區域或多區域值組 (例如
us-locations),系統會在前面加上in:前置字元,在本例中為in:us-locations。 - 如果輸入可用區或多區域 (例如
us-east1-b或us),值不會變更。
設定組織政策
資源位置限制是一種舊版代管限制,具有清單規則。您可以從資源位置限制的 allowed_values 或 denied_values 清單新增或移除位置。為避免組織政策在可用清單中新增位置時,意外限制服務行為,請使用值組或 allowed_values 清單,代表您要定義的整個地理邊界。
如要設定包含資源位置限制的組織政策,請按照下列步驟操作:
控制台
前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。
在專案挑選器中,選取要設定組織政策的組織、資料夾或專案。
選取「Google Cloud Platform - Resource Location Restriction」限制,開啟「Policy details」(政策詳細資料) 頁面。
按一下「Manage Policy」(管理政策)。
在「Edit policy」(編輯政策) 頁面,選取「Override parent's policy」(覆寫上層政策)。
在「Policy enforcement」(政策強制執行) 下方,選取「Replace」(取代)。
按一下「Add rule」(新增規則)。
在「Policy values」(政策值) 底下,選取「Custom」(自訂)。
在「Policy type」(政策類型) 下方,選取「Allow」(允許) 建立允許的位置清單,或選取「Deny」(拒絕) 建立拒絕的位置清單。
在「Policy value」(政策值) 方塊中,輸入
in前置字元和值組位置字串,然後按下 Enter 鍵。例如
in:us-locations或in:us-west1-locations。按一下「新增值」,即可輸入多個位置字串。您還可以將特定區域、地區或多地區位置輸入為位置字串。如需可用位置清單,請參閱「支援限制資源位置的服務」頁面。
如要強制執行政策,請按一下「Set policy」(設定政策)。
gcloud
如要建立強制執行資源位置限制的組織政策,請建立參照該限制的政策 YAML 檔案:
name: organizations/ORGANIZATION_ID/policies/gcp.resourceLocations
spec:
rules:
- values:
deniedValues:
- in:us-east1-locations
- in:northamerica-northeast1-locations
如要強制執行包含限制的組織政策,請執行下列指令:
gcloud org-policies set-policy POLICY_PATH
更改下列內容:
ORGANIZATION_ID:組織 ID,例如 01234567890。POLICY_PATH:含有組織政策的 YAML 檔案完整路徑。
系統會傳回包含新機構政策結果的回應:
name: organizations/01234567890/policies/gcp.resourceLocations
spec:
rules:
- values:
deniedValues:
- in:us-east1-locations
- in:northamerica-northeast1-locations
您還可以將特定區域、地區或多地區位置輸入為位置字串。如要查看可用位置清單,請參閱「資源位置支援的服務」頁面。
API
您可以使用 Resource Manager API 設定資源的組織政策。您需要 OAuth 2.0 不記名權杖,才能進行驗證和授權。
如要使用資源位置限制設定組織政策,請按照下列步驟操作:
curl -X POST -H "Content-Type: application/json" -H "Authorization: \
Bearer ${bearer_token}" -d '{policy: {etag: "BwVtXec438Y=", constraint: \
"constraints/gcp.resourceLocations", list_policy: {denied_values: \
["in:europe-locations", "in:southamerica-locations"] }}}' \
https://cloudresourcemanager.googleapis.com/v1/organizations/123456789:setOrgPolicy
系統會傳回回應,其中包含新組織政策的結果:
name: organizations/01234567890/policies/gcp.resourceLocations
spec:
rules:
- values:
deniedValues:
- in:europe-locations
- in:southamerica-locations
您還可以將特定區域、地區或多地區位置輸入為位置字串。如要查看可用位置清單,請參閱「資源位置支援的服務」頁面。
如要瞭解如何在組織政策中使用限制,請參閱「建立組織政策」。
使用組織政策的沿用機制
您可以調整組織政策,從資源的父節點繼承組織政策。繼承可讓您精細控管整個資源階層中使用的組織政策。
如要在資源節點上啟用繼承功能,請在組織政策 YAML 檔案中設定 inheritFromParent = true。例如:
name: organizations/01234567890/policies/gcp.resourceLocations
spec:
inheritFromParent: true
rules:
- values:
deniedValues:
- in:us-west1
允許或禁止在 AI 可用區建立 VM
您可以在自訂組織政策中建立及強制執行自訂限制,允許或禁止在 AI 區域建立 VM。
AI 可用區的名稱中會包含 ai 字串。例如,us-west4-ai2b 是 us-west4 區域中的 AI 可用區,us-west4-b 則是父項可用區。建立自訂限制時,請在條件中使用字串 -ai。如要進一步瞭解 AI 可用區,請參閱「關於 AI 可用區」。
如要瞭解管理組織政策所需的權限,請參閱「建立及管理自訂限制」頁面的「必要角色」一節。
如要設定自訂組織政策,允許或禁止在 AI 區域建立 VM,請完成下列步驟:
建立 AI 可用區的自訂限制
視您要允許或禁止在 AI 區域中建立 VM 而定,請使用下列其中一項限制建立 YAML 檔案。
如要限制只能在 AI 可用區建立 VM,請使用下列限制:
name: organizations/ORGANIZATION_ID/customConstraints/custom.allowOnlyAiZones resource_types: - compute.googleapis.com/Instance method_types: - CREATE - UPDATE actionType: ALLOW condition: "resource.zone.contains('-ai')" displayName: allowOnlyAiZones description: Allow VMs to be created in AI zones only.如要禁止在 AI 區域建立 VM,請使用下列限制:
name: organizations/ORGANIZATION_ID/customConstraints/custom.denyAiZones resource_types: - compute.googleapis.com/Instance method_types: - CREATE - UPDATE actionType: DENY condition: "resource.zone.contains('-ai')" displayName: denyAiZones description: Deny VMs from being created in AI zones.將
ORGANIZATION_ID替換為組織 ID,例如01234567890。
設定自訂限制
為自訂限制建立 YAML 檔案後,您必須設定自訂限制,才能用於組織政策。
如要設定自訂限制,請使用
gcloud org-policies set-custom-constraint指令:gcloud org-policies set-custom-constraint CONSTRAINT_PATH將
CONSTRAINT_PATH替換為自訂限制 YAML 檔案的完整路徑,例如/home/user/customconstraint.yaml。建立組織政策
如要建立強制執行自訂限制的組織政策,請建立參照限制的政策 YAML 檔案:
name: projects/PROJECT_ID/policies/CONSTRAINT_NAME spec: rules: - enforce: true更改下列內容:
PROJECT_ID:要強制執行限制的專案。CONSTRAINT_NAME:自訂限制的名稱,例如custom.allowOnlyAiZones或custom.denyAiZones。
對專案強制執行自訂組織政策
如要強制執行包含自訂限制的組織政策,請執行下列指令:
gcloud org-policies set-policy POLICY_PATH請將
POLICY_PATH替換為組織政策 YAML 檔案的完整路徑。組織政策變更最多可能需要 15 分鐘才會全面生效。
如要進一步瞭解自訂限制,請參閱「建立自訂限制」。如要排解問題,請參閱「排解自訂限制問題」。
錯誤訊息示例
如果服務支援資源位置限制,就無法在違反限制的位置建立新資源。如果服務嘗試在違反限制的位置建立資源,則會失敗並產生錯誤訊息。
這則錯誤訊息的格式如下:
LOCATION_IN_REQUEST violates constraint
constraints/gcp.resourceLocations on the resource RESOURCE_TESTED.
在以下範例中,Compute Engine 資源因政策強制執行而無法建立新的執行個體:
Location ZONE:us-east1-b violates constraint constraints/gcp.resourceLocations
on the resource
projects/policy-violation-test/zones/us-east1-b/instances/instance-3.
Google Cloud Observability 和 Cloud 稽核記錄項目:
{
insertId: "5u759gdngec"
logName: "projects/policy-violation-test/logs/cloudaudit.googleapis.com%2Factivity"
protoPayload: {
@type: "type.googleapis.com/google.cloud.audit.AuditLog"
authenticationInfo: {…}
authorizationInfo: [6]
methodName: "beta.compute.instances.insert"
request: {…}
requestMetadata: {…}
resourceLocation: {…}
resourceName: "projects/policy-violation-test/zones/us-east1-b/instances/instance-3"
response: {
@type: "type.googleapis.com/error"
error: {
code: 412
errors: [
0: {
domain: "global"
location: "If-Match"
locationType: "header"
message: "Location ZONE:us-east1-b violates constraint constraints/gcp.resourceLocations on the resource projects/policy-violation-test/zones/us-east1-b/instances/instance-3."
reason: "conditionNotMet"
}
]
message: "Location ZONE:us-east1-b violates constraint constraints/gcp.resourceLocations on the resource projects/policy-violation-test/zones/us-east1-b/instances/instance-3."
}
}
serviceName: "compute.googleapis.com"
status: {
code: 3
message: "INVALID_ARGUMENT"
}
}
receiveTimestamp: "2019-06-14T03:04:23.660988360Z"
resource: {
labels: {…}
type: "gce_instance"
}
severity: "ERROR"
timestamp: "2019-06-14T03:04:22.783Z"
}
安全漏洞發現項目和修復
資源位置限制會限制在執行階段建立資源。這項功能有助於防止位置違規,但不會識別或修正現有的違規。您可以使用 Security Command Center 的內建服務安全狀態分析,找出資源階層中的位置違規事項。詳情請參閱「組織政策安全漏洞發現項目」。
如果安全狀態分析發現位置違規,請參閱「修復安全狀態分析發現項目」,瞭解修復步驟。
值組搭配
值組是 Google 彙整的群組和位置集合,您只要指定值組,即可輕鬆定義資源位置。值組包含許多相關位置,Google 會隨著時間擴充值組,您不必變更組織政策來納入新位置。
如要在組織政策使用值組,請以「in:」做為值組的前置字串。如要進一步瞭解如何使用值前置字串,請參閱「建立組織政策」。系統會在呼叫設定組織政策時驗證群組名稱。如果使用無效的群組名稱,政策設定將會失敗。
下表包含目前可用群組的清單:
| 群組 | 說明 | 直接成員 |
|---|---|---|
| 約翰尼斯堡 | 約翰尼斯堡內的所有地點:in:africa-south1-locations |
值:
|
| 亞洲 | 亞洲境內的所有位置:in:asia-locations |
群組:
值:
|
| 香港 | 香港境內所有地點:in:asia-east2-locations |
值:
|
| 印尼 | 印尼境內所有地點:in:id-locations |
群組:
值:
|
| 雅加達 | 雅加達境內所有地點:in:asia-southeast2-locations |
值:
|
| 以色列 | 以色列境內所有地點:in:il-locations |
群組:
值:
|
| 以色列 | 以色列境內所有地點:in:me-west1-locations |
值:
|
| 印度 | 印度境內所有地點:in:in-locations |
群組:
值:
|
| 孟買 | 孟買境內的所有地點:in:asia-south1-locations |
值:
|
| 德里 | 德里境內的所有地點:in:asia-south2-locations |
值:
|
| 日本 | 日本境內所有地點:in:jp-locations |
群組:
值:
|
| 東京 | 東京境內的所有地點:in:asia-northeast1-locations |
值:
|
| 大阪 | 大阪境內的所有位置:in:asia-northeast2-locations |
值:
|
| 韓國 | 韓國境內所有地點:in:kr-locations |
群組:
值:
|
| 首爾 | 首爾境內的所有地點:in:asia-northeast3-locations |
值:
|
| 杜哈 | 杜哈境內所有地點:in:me-central1-locations |
值:
|
| 沙烏地阿拉伯 | 沙烏地阿拉伯境內所有地點:in:sa-locations |
群組:
值:
|
| 達曼 | 達曼境內的所有地點:in:me-central2-locations |
值:
|
| 新加坡 | 新加坡境內所有地點:in:sg-locations |
群組:
值:
|
| 新加坡 | 新加坡境內所有地點:in:asia-southeast1-locations |
值:
|
| 台灣 | 臺灣境內所有地點:in:tw-locations |
群組:
值:
|
| 台灣 | 臺灣境內所有地點:in:asia-east1-locations |
值:
|
| 澳洲 | 澳洲境內所有地點:in:australia-locations |
群組:
值:
|
| 雪梨 | 雪梨境內的所有地點:in:australia-southeast1-locations |
值:
|
| 墨爾本 | 墨爾本內的所有地點:in:australia-southeast2-locations |
值:
|
| AWS | 所有 AWS 位置:in:aws-locations |
值:
|
| Azure | 所有 Azure 位置:in:azure-locations |
值:
|
| 歐盟 | 歐盟境內的所有位置:in:eu-locations |
群組:
值:
|
| 德國 | 德國境內所有地點:in:de-locations |
群組:
值:
|
| 柏林 | 柏林境內的所有地點:in:europe-west10-locations |
值:
|
| 法蘭克福 | 法蘭克福境內的所有位置:in:europe-west3-locations |
值:
|
| 華沙 | 華沙境內的所有地點:in:europe-central2-locations |
值:
|
| 芬蘭 | 芬蘭境內所有地點:in:europe-north1-locations |
值:
|
| 斯德哥爾摩 | 斯德哥爾摩境內的所有地點:in:europe-north2-locations |
值:
|
| 馬德里 | 馬德里境內的所有地點:in:europe-southwest1-locations |
值:
|
| 比利時 | 比利時境內所有地點:in:europe-west1-locations |
值:
|
| 荷蘭 | 荷蘭境內所有地點:in:europe-west4-locations |
值:
|
| 巴黎 | 巴黎境內的所有地點:in:europe-west9-locations |
值:
|
| 義大利 | 義大利境內所有地點:in:it-locations |
群組:
值:
|
| Turin | 杜林的所有地點:in:europe-west12-locations |
值:
|
| 米蘭 | 米蘭境內的所有地點:in:europe-west8-locations |
值:
|
| 歐洲 | 歐洲境內的所有位置:in:europe-locations |
群組:
值:
|
| 瑞士 | 瑞士境內所有地點:in:ch-locations |
群組:
值:
|
| 蘇黎世 | 蘇黎世內的所有地點:in:europe-west6-locations |
值:
|
| 英國 | 英國境內所有地點:in:gb-locations |
群組:
值:
|
| 倫敦 | 倫敦境內的所有地點:in:europe-west2-locations |
值:
|
| 低碳位置 | 所有低碳影響區域:in:low-carbon-locations |
群組:
|
| 低碳加拿大 | 加拿大境內所有低碳影響地點:in:canada-low-carbon-locations |
群組:
|
| 蒙特婁 | 蒙特婁境內的所有地點:in:northamerica-northeast1-locations |
值:
|
| 多倫多 | 多倫多境內的所有地點:in:northamerica-northeast2-locations |
值:
|
| 低碳歐盟 | 歐盟境內所有低碳影響位置:in:eu-low-carbon-locations |
群組:
|
| 低碳歐洲 | 歐洲境內所有低碳影響的位置:in:europe-low-carbon-locations |
群組:
|
| 低碳北美 | 北美洲所有低碳影響位置:in:northamerica-low-carbon-locations |
群組:
|
| 愛荷華州 | 愛荷華州內的所有地點:in:us-central1-locations |
值:
|
| 奧克拉荷馬州 | 奧克拉荷馬州境內的所有地點:in:us-central2-locations |
值:
|
| 達拉斯 | 達拉斯境內的所有地點:in:us-south1-locations |
值:
|
| 奧勒岡州 | 奧勒岡州境內的所有地點:in:us-west1-locations |
值:
|
| 低碳南美洲 | 南美洲所有低碳影響地點:in:southamerica-low-carbon-locations |
群組:
|
| 聖保羅 | 聖保羅內的所有地點:in:southamerica-east1-locations |
值:
|
| 聖地牙哥 | 聖地牙哥內的所有地點:in:southamerica-west1-locations |
值:
|
| 低碳美國 | 美國境內所有低碳影響的位置:in:us-low-carbon-locations |
群組:
|
| 北美洲 | 北美洲境內的所有位置:in:northamerica-locations |
群組:
值:
|
| 加拿大 | 加拿大境內的所有地點。in:canada-locations |
群組:
值:
|
| 墨西哥 | 墨西哥境內所有地點:in:northamerica-south1-locations |
值:
|
| 美國 | 美國境內所有地點:in:us-locations |
群組:
值:
|
| 南卡羅來納州 | 南卡羅來納州內的所有可用區:in:us-east1-locations |
值:
|
| 北維吉尼亞州 | 北維吉尼亞州內的所有位置:in:us-east4-locations |
值:
|
| 哥倫布 | 哥倫布市內的所有地點:in:us-east5-locations |
值:
|
| 洛杉磯 | 洛杉磯境內的所有地點:in:us-west2-locations |
值:
|
| 鹽湖城 | 鹽湖城內的所有地點:in:us-west3-locations |
值:
|
| 拉斯維加斯 | 拉斯維加斯的所有地點:in:us-west4-locations |
值:
|
| 南美洲 | 南美洲境內的所有位置:in:southamerica-locations |
群組:
|
| 巴西 | 巴西境內所有地點:in:br-locations |
群組:
值:
|
| 智利 | 智利境內所有地區:in:cl-locations |
群組:
值:
|
| 泰國 | 泰國境內所有地點:in:th-locations |
群組:
值:
|
| 曼谷 | 曼谷境內的所有地點:in:asia-southeast3-locations |
值:
|
驗證
組織政策服務使用 OAuth 2.0 進行 API 驗證和授權。如要取得 OAuth 2.0 不記名權杖,請按照下列步驟操作:
在「Step 1」所列的範圍中,選取 [Cloud Resource Manager API v2] > [https://www.googleapis.com/auth/cloud-platform],然後點選 [Authorize APIs]。
在「Sign in with Google」(使用 Google 帳戶登入) 頁面上,選擇您的帳戶並登入。
如要提供 Google OAuth 2.0 Playground 的存取權,請在顯示的提示中按一下「Allow」(允許)。
在「Step 2」,點選 [Exchange authorization code for tokens]。
在右側「Request / Response」窗格的底部,會顯示您的存取憑證字串。
{ "access_token": "ACCESS_TOKEN", "token_type": "Bearer", "expires_in": 3600 }其中 ACCESS_TOKEN 是可用於 API 授權的 OAuth 2.0 不記名權杖字串。