總覽
本指南說明如何設定包含資源位置限制的機構政策。
您可以使用機構政策服務資源位置限制,限制新資源的實際位置,也可以使用資源的位置屬性來識別服務部署和維護該資源的位置。對於某些 Google Cloud 服務中包含資料的資源,此屬性也反映了資料的儲存位置。這項限制可讓您定義允許的位置 Google Cloud ,以便在階層中建立支援服務的資源。
定義資源位置後,這項限制只會套用至新建立的資源。在設定資源位置限制之前,您建立的資源將繼續存在並執行其功能。
對於某些服務如 Cloud Storage 和 Dataproc 的子資源建立,不會強制執行包含此限制的政策。
限制
資源位置機構政策服務限制會控管是否能建立可選取位置的資源。這項限制不會影響建立全域資源 (例如 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
。
設定地點時,請使用 in:
前置字元和值群組。使用 Google 精選的值組,即可選擇地理位置,不必指定目前或未來的 Cloud 位置。 Google 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 values」(政策值) 底下,選取 [Custom] (自訂)。
在「政策類型」下方,選取「允許」建立允許的位置清單,或選取「拒絕」建立拒絕的位置清單。
在「Policy value」(政策值) 方塊中,輸入前置字串
in
以及值群組位置字串,然後按一下 Enter 鍵。例如
in:us-locations
或in:us-west1-locations
。按一下「新增政策值」,即可輸入多個位置字串。您還可以將特定區域、地區或多地區位置輸入為位置字串。如需可用位置的清單,請參閱資源位置支援的服務頁面。
如要強制執行這項政策,請按一下「設定政策」。
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
錯誤訊息示例
如果服務支援資源位置限制,就無法在違反限制的位置建立新資源。如果服務嘗試在違反限制的位置建立資源,系統會產生錯誤訊息,並拒絕該要求。
這則錯誤訊息的格式如下:
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 收錄的群組和位置的集合,提供簡易定義資源位置的方法。值組搭配包含許多相關位置,並且會隨著時間的演進而不斷擴展,所以無需更改您的機構政策來配合新位置。
如要在機構政策中使用值組,請先輸入 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 |
群組:
值:
|
杜林 | 杜林所有位置: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-west1-locations |
值:
|
低碳南美洲 | 碳排放量較低的南美洲所有位置:in:southamerica-low-carbon-locations |
群組:
|
聖保羅 | 聖保羅所有位置:in:southamerica-east1-locations |
值:
|
美國低碳 | 美國境內所有低碳影響位置:in:us-low-carbon-locations |
群組:
|
北美洲 | 北美洲所有位置:in:northamerica-locations |
群組:
值:
|
加拿大 | 加拿大境內的所有地點。in:canada-locations |
群組:
值:
|
墨西哥 | 墨西哥境內所有地點:in:northamerica-south1-locations |
值:
|
美國 | 美國境內所有地點:in:us-locations |
群組:
值:
|
奧克拉荷馬州 | 奧克拉荷馬州所有地點:in:us-central2-locations |
值:
|
南卡羅來納州 | 南卡羅來納州所有區域:in:us-east1-locations |
值:
|
北維吉尼亞州 | 北維吉尼亞州所有位置:in:us-east4-locations |
值:
|
哥倫布 | 哥倫布所有位置:in:us-east5-locations |
值:
|
達拉斯 | 達拉斯境內的所有地點:in:us-south1-locations |
值:
|
洛杉磯 | 洛杉磯境內的所有地點:in:us-west2-locations |
值:
|
鹽湖城 | 鹽湖城的所有位置:in:us-west3-locations |
值:
|
拉斯維加斯 | 拉斯維加斯所有位置:in:us-west4-locations |
值:
|
南美洲 | 南美洲所有位置:in:southamerica-locations |
群組:
|
巴西 | 巴西境內所有地點:in:br-locations |
群組:
值:
|
智利 | 智利境內所有地點:in:cl-locations |
群組:
值:
|
聖地牙哥 | 聖地牙哥所有位置:in:southamerica-west1-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」ACCESS_TOKEN是可用於 API 授權的 OAuth 2.0 不記名憑證字串。