限制资源位置

概览

本指南介绍如何设置包含资源位置限制条件组织政策

您可以使用组织政策服务资源的位置限制条件来限制新资源的物理位置,还可以使用资源的位置属性来标识服务部署和维护该资源的位置。对于某些 Google Cloud 服务的包含数据的资源,此属性还反映了数据的存储位置。通过此限制条件,您可以定义允许为层次结构中受支持的服务创建资源的 Google Cloud 位置。

定义资源位置后,此限制将仅应用于新创建的资源。您在设置资源位置限制条件之前创建的资源将继续存在并执行其功能。

对于 Cloud Storage 和 Dataproc 等某些服务,系统不会在创建子资源时强制执行包含此限制条件的政策。

限制

组织政策服务的资源位置限制条件可控制创建能够为其选择位置的资源的能力。此限制条件不会影响全局资源(例如 Compute Engine 全局地址)或不支持选择位置的资源的创建位置。

为避免破坏现有的服务基础架构,您应该在非生产项目和文件夹上测试任何新政策,然后在组织内逐步应用政策。

如需了解数据存储承诺,请参阅 Google Cloud 服务条款服务专用条款。包含资源位置限制条件的组织政策不是数据存储承诺。

该限制适用于一部分特定的产品和资源类型。如需查看支持的服务列表以及每项服务的行为详情,请参阅支持资源位置的服务页面。

位置类型

您可以在代表不同大小类别的位置类型中部署 Google Cloud 资源。最大的位置类型是 multi-region,其中包括多个 region。每个 region 可进一步划分为多个 zones。如需详细了解区域和地区,请参阅区域和地区概览

  • Multi-region 位置以多个 region 中的物理资源为支持,通常仅由存储资源使用。一些示例包括 usasiaeuropeglobal

  • Region 位置在地理上彼此隔离。一些示例包括 us-west1(俄勒冈)、asia-northeast1(东京)和 europe-west1(比利时)。

  • Zone 位置是用于部署资源的最精细独立位置类型。zoneregion 内的独立故障域。一些示例包括 us-east1-aus-west1-basia-northeast1-a

设置位置时,应使用 in: 前缀和值组。使用 Google Cloud 精心挑选的值组,您可以选择地理位置,而无需指定当前或未来的 Cloud 位置。

值组的前缀 in: 指定该值组内存在的所有值均被视为政策的一部分。如果您输入组值或不带前缀的 Google Cloud 区域,系统将根据以下规则自动添加 in: 前缀:

  • 如果输入的是使用前缀 in: 的位置,并且该位置包含任何无效的组,则政策更改将失败。
  • 如果输入的位置是一个区域(例如 us-east1),则该位置的前缀为 in:,在此示例中为 in:us-east1-locations
  • 如果输入单区域或多区域值组(例如 us-locations),则该值组将带有 in: 前缀,在此示例中为 in:us-locations
  • 如果输入单地区或多区域,例如 us-east1-aus,则这些值将不会更改。

设置组织政策

资源位置限制条件是一种列表限制条件。 您可以通过资源位置限制条件的 allowed_valuesdenied_values 列表添加和移除位置。将新位置添加到可用列表时,为防止组织政策意外限制服务行为,请使用表示要定义的整个地理边界的值组allowed_values 列表。

如需设置包含资源位置限制条件的组织政策,请执行以下操作:

控制台

  1. 在 Google Cloud 控制台中,转到组织政策页面。

    转到“组织政策”

  2. 从项目选择器中,选择要为其设置组织政策的组织、文件夹或项目。

  3. 选择 Google Cloud Platform - 资源位置限制限制条件,以打开其政策详细信息页面。

  4. 点击管理政策

  5. 修改政策页面上,选择覆盖父级政策

  6. 强制执行政策下,选择替换

  7. 点击添加规则

  8. 政策值下方,选择自定义

  9. 政策类型下,选择允许以创建允许位置的列表,或者选择拒绝以创建拒绝位置列表。

  10. 政策值框中,输入 in 前缀和值组位置字符串,然后按 Enter 键。

    例如 in:us-locationsin:us-west1-locations。 您可以通过点击新建政策值输入多个位置字符串。

    您还可以位置字符串形式输入特定地区、区域或多区域位置。如需查看可用位置的列表,请参阅支持资源位置的服务页面。

  11. 如需强制执行政策,请点击设置政策

gcloud

如需创建强制执行资源位置限制条件的组织政策,请创建一个引用该限制条件的政策 YAML 文件:

constraint: constraints/gcp.resourceLocations
listPolicy:
    deniedValues:
    - in:us-east1-locations
    - in:northamerica-northeast1-locations

如需强制执行包含限制条件的组织政策,请运行以下命令:

gcloud org-policies set-policy \
    --organization 'ORGANIZATION_ID' \
    POLICY_PATH

替换以下内容:

  • ORGANIZATION_ID:您的组织 ID,例如 01234567890。
  • POLICY_PATH:包含组织政策的 YAML 文件的完整路径。

系统返回的响应将包含新组织政策的结果:

name: organizations/01234567890/policies/gcp.resourceLocations
spec:
  rules:
  - values:
      allowedValues:
      - 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 Audit Logs 日志条目:

{
 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(Security Health Analytics 的一项内置服务)来发现资源层次结构中的位置违规。如需了解详情,请参阅组织政策漏洞和发现结果

如果存在 Security Health Analytics 针对位置违规的发现结果,请参阅针对 Security Health Analytics 的发现结果进行补救,了解针对这些发现结果进行补救的步骤。

值组

值组是由 Google 精心挑选的组和位置的集合,可让您轻松定义资源位置。值组包含许多相关位置。Google 会不断扩充值组,您无需更改组织政策即可适应新的位置。

如需在组织政策中使用值组,请在您的条目前面添加 in: 字符串作为前缀。如需详细了解如何使用值前缀,请参阅使用限制条件。调用以设置组织政策时,将不验证组名称。如果提供的组名称不存在,则不在有效组织政策中添加新值,除非 Google 稍后创建该组名称。

下表包含最新的可用组列表:

详情 直接成员
约翰内斯堡 约翰内斯堡境内的所有位置:
in:africa-south1-locations
值:
  • africa-south1
  • africa-south1-a
  • africa-south1-b
  • africa-south1-c
亚洲 亚洲境内的所有位置:
in:asia-locations
组:
  • asia-east1-locations
  • asia-east2-locations
  • asia-northeast1-locations
  • asia-northeast2-locations
  • asia-northeast3-locations
  • asia-south1-locations
  • asia-south2-locations
  • asia-southeast1-locations
  • asia-southeast2-locations
  • me-central1-locations
  • me-central2-locations
  • me-west1-locations

值:
  • asia
  • asia1
  • aws-ap-northeast-2
台湾 台湾境内的所有位置:
in:asia-east1-locations
值:
  • asia-east1
  • asia-east1-a
  • asia-east1-b
  • asia-east1-c
香港 香港境内的所有位置:
in:asia-east2-locations
值:
  • asia-east2
  • asia-east2-a
  • asia-east2-b
  • asia-east2-c
东京 东京境内的所有位置:
in:asia-northeast1-locations
值:
  • asia-northeast1
  • asia-northeast1-a
  • asia-northeast1-b
  • asia-northeast1-c
大阪 大阪境内的所有位置:
in:asia-northeast2-locations
值:
  • asia-northeast2
  • asia-northeast2-a
  • asia-northeast2-b
  • asia-northeast2-c
首尔 首尔境内的所有位置:
in:asia-northeast3-locations
值:
  • asia-northeast3
  • asia-northeast3-a
  • asia-northeast3-b
  • asia-northeast3-c
孟买 孟买境内的所有位置:
in:asia-south1-locations
值:
  • asia-south1
  • asia-south1-a
  • asia-south1-b
  • asia-south1-c
德里 德里境内的所有位置:
in:asia-south2-locations
值:
  • asia-south2
  • asia-south2-a
  • asia-south2-b
  • asia-south2-c
新加坡 新加坡境内的所有位置:
in:asia-southeast1-locations
值:
  • asia-southeast1
  • asia-southeast1-a
  • asia-southeast1-b
  • asia-southeast1-c
雅加达 雅加达境内的所有位置:
in:asia-southeast2-locations
值:
  • asia-southeast2
  • asia-southeast2-a
  • asia-southeast2-b
  • asia-southeast2-c
多哈 多哈境内的所有位置:
in:me-central1-locations
值:
  • me-central1
  • me-central1-a
  • me-central1-b
  • me-central1-c
达曼 达曼境内的所有位置:
in:me-central2-locations
值:
  • me-central2
  • me-central2-a
  • me-central2-b
  • me-central2-c
以色列 以色列境内的所有位置:
in:me-west1-locations
值:
  • me-west1
  • me-west1-a
  • me-west1-b
  • me-west1-c
澳大利亚 澳大利亚境内的所有位置:
in:australia-locations
组:
  • australia-southeast1-locations
  • australia-southeast2-locations
悉尼 悉尼境内的所有位置:
in:australia-southeast1-locations
值:
  • australia-southeast1
  • australia-southeast1-a
  • australia-southeast1-b
  • australia-southeast1-c
墨尔本 墨尔本境内的所有位置:
in:australia-southeast2-locations
值:
  • australia-southeast2
  • australia-southeast2-a
  • australia-southeast2-b
  • australia-southeast2-c
AWS 所有 AWS 位置:
in:aws-locations
值:
  • aws-ap-northeast-2
  • aws-ap-southeast-2
  • aws-eu-central-1
  • aws-us-east-1
Azure 所有 Azure 位置:
in:azure-locations
值:
  • azure-eastus2
  • azure-westus2
欧盟 欧盟境内的所有位置:
in:eu-locations
组:
  • europe-central2-locations
  • europe-north1-locations
  • europe-southwest1-locations
  • europe-west1-locations
  • europe-west10-locations
  • europe-west12-locations
  • europe-west3-locations
  • europe-west4-locations
  • europe-west8-locations
  • europe-west9-locations

值:
  • EU
  • eu
  • eur3
  • eur4
  • eur8
  • europe-west
华沙 华沙境内的所有位置:
in:europe-central2-locations
值:
  • europe-central2
  • europe-central2-a
  • europe-central2-b
  • europe-central2-c
芬兰 芬兰境内的所有位置:
in:europe-north1-locations
值:
  • europe-north1
  • europe-north1-a
  • europe-north1-b
  • europe-north1-c
马德里 马德里境内的所有位置:
in:europe-southwest1-locations
值:
  • europe-southwest1
  • europe-southwest1-a
  • europe-southwest1-b
  • europe-southwest1-c
比利时 比利时境内的所有位置:
in:europe-west1-locations
值:
  • europe-west1
  • europe-west1-b
  • europe-west1-c
  • europe-west1-d
柏林 柏林境内的所有位置:
in:europe-west10-locations
值:
  • europe-west10
  • europe-west10-a
  • europe-west10-b
  • europe-west10-c
都灵 都灵境内的所有位置:
in:europe-west12-locations
值:
  • europe-west12
  • europe-west12-a
  • europe-west12-b
  • europe-west12-c
法兰克福 法兰克福境内的所有位置:
in:europe-west3-locations
值:
  • europe-west3
  • europe-west3-a
  • europe-west3-b
  • europe-west3-c
荷兰 荷兰境内的所有位置:
in:europe-west4-locations
值:
  • europe-west4
  • europe-west4-a
  • europe-west4-b
  • europe-west4-c
米兰 米兰境内的所有位置:
in:europe-west8-locations
值:
  • europe-west8
  • europe-west8-a
  • europe-west8-b
  • europe-west8-c
巴黎 巴黎境内的所有位置:
in:europe-west9-locations
值:
  • europe-west9
  • europe-west9-a
  • europe-west9-b
  • europe-west9-c
欧洲 欧洲境内的所有位置:
in:europe-locations
组:
  • europe-central2-locations
  • europe-north1-locations
  • europe-southwest1-locations
  • europe-west1-locations
  • europe-west10-locations
  • europe-west12-locations
  • europe-west2-locations
  • europe-west3-locations
  • europe-west4-locations
  • europe-west6-locations
  • europe-west8-locations
  • europe-west9-locations

值:
  • EU
  • eu
  • eur3
  • eur4
  • eur5
  • eur7
  • eur8
  • europe
  • europe-west
伦敦 伦敦境内的所有位置:
in:europe-west2-locations
值:
  • europe-west2
  • europe-west2-a
  • europe-west2-b
  • europe-west2-c
苏黎世 苏黎世境内的所有位置:
in:europe-west6-locations
值:
  • europe-west6
  • europe-west6-a
  • europe-west6-b
  • europe-west6-c
日本 日本境内的所有位置:
in:jp-locations
组:
  • asia-northeast1-locations
  • asia-northeast2-locations
低碳地点 所有低碳影响地点:
in:low-carbon-locations
组:
  • canada-low-carbon-locations
  • eu-low-carbon-locations
  • europe-low-carbon-locations
  • northamerica-low-carbon-locations
  • southamerica-low-carbon-locations
  • us-low-carbon-locations
低碳加拿大 加拿大境内所有低碳影响地点:
in:canada-low-carbon-locations
组:
  • northamerica-northeast1-locations
  • northamerica-northeast2-locations
蒙特利尔 蒙特利尔境内的所有位置:
in:northamerica-northeast1-locations
值:
  • northamerica-northeast1
  • northamerica-northeast1-a
  • northamerica-northeast1-b
  • northamerica-northeast1-c
多伦多 多伦多境内的所有位置:
in:northamerica-northeast2-locations
值:
  • northamerica-northeast2
  • northamerica-northeast2-a
  • northamerica-northeast2-b
  • northamerica-northeast2-c
低碳欧盟 欧盟境内所有低碳影响地点:
in:eu-low-carbon-locations
组:
  • europe-north1-locations
  • europe-southwest1-locations
  • europe-west1-locations
  • europe-west9-locations
低碳(欧洲) 欧洲境内所有低碳影响地点:
in:europe-low-carbon-locations
组:
  • europe-north1-locations
  • europe-southwest1-locations
  • europe-west1-locations
  • europe-west6-locations
  • europe-west9-locations
低碳(北美洲) 北美洲境内所有低碳影响地点:
in:northamerica-low-carbon-locations
组:
  • northamerica-northeast1-locations
  • northamerica-northeast2-locations
  • us-central1-locations
  • us-west1-locations
爱荷华州 爱荷华境内的所有位置:
in:us-central1-locations
值:
  • us-central1
  • us-central1-a
  • us-central1-b
  • us-central1-c
  • us-central1-f
俄勒冈州 俄勒冈境内的所有位置:
in:us-west1-locations
值:
  • us-west1
  • us-west1-a
  • us-west1-b
  • us-west1-c
低碳南美洲 南美洲境内所有低碳影响地点:
in:southamerica-low-carbon-locations
组:
  • southamerica-east1-locations
圣保罗 圣保罗境内的所有位置:
in:southamerica-east1-locations
值:
  • southamerica-east1
  • southamerica-east1-a
  • southamerica-east1-b
  • southamerica-east1-c
美国低碳 美国境内低碳影响的所有地点:
in:us-low-carbon-locations
组:
  • us-central1-locations
  • us-west1-locations
北美洲 北美境内的所有位置:
in:northamerica-locations
组:
  • canada-locations
  • us-locations

值:
  • nam14
加拿大 加拿大境内的所有位置。
in:canada-locations
组:
  • northamerica-northeast1-locations
  • northamerica-northeast2-locations

值:
  • ca
美国 美国境内的所有位置:
in:us-locations
组:
  • us-central1-locations
  • us-central2-locations
  • us-east1-locations
  • us-east4-locations
  • us-east5-locations
  • us-south1-locations
  • us-west1-locations
  • us-west2-locations
  • us-west3-locations
  • us-west4-locations

值:
  • US
  • aws-us-east-1
  • azure-eastus2
  • nam10
  • nam11
  • nam12
  • nam13
  • nam15
  • nam3
  • nam4
  • nam5
  • nam6
  • nam7
  • nam8
  • nam9
  • us
  • us-central
俄克拉何马州 俄克拉何马州境内的所有位置:
in:us-central2-locations
值:
  • us-central2
  • us-central2-a
  • us-central2-b
  • us-central2-c
  • us-central2-d
南卡罗来纳州 南卡罗来纳境内的所有可用区:
in:us-east1-locations
值:
  • us-east1
  • us-east1-a
  • us-east1-b
  • us-east1-c
  • us-east1-d
北弗吉尼亚 北弗吉尼亚境内的所有位置:
in:us-east4-locations
值:
  • us-east4
  • us-east4-a
  • us-east4-b
  • us-east4-c
哥伦布 哥伦布境内的所有位置:
in:us-east5-locations
值:
  • us-east5
  • us-east5-a
  • us-east5-b
  • us-east5-c
达拉斯 达拉斯境内的所有位置:
in:us-south1-locations
值:
  • us-south1
  • us-south1-a
  • us-south1-b
  • us-south1-c
洛杉矶 洛杉矶境内的所有位置:
in:us-west2-locations
值:
  • us-west2
  • us-west2-a
  • us-west2-b
  • us-west2-c
盐湖城 盐湖城境内的所有位置:
in:us-west3-locations
值:
  • us-west3
  • us-west3-a
  • us-west3-b
  • us-west3-c
拉斯维加斯 拉斯维加斯境内的所有位置:
in:us-west4-locations
值:
  • us-west4
  • us-west4-a
  • us-west4-b
  • us-west4-c
南美洲 南美洲境内的所有位置:
in:southamerica-locations
组:
  • southamerica-east1-locations
  • southamerica-west1-locations
圣地亚哥 圣地亚哥境内的所有位置:
in:southamerica-west1-locations
值:
  • southamerica-west1
  • southamerica-west1-a
  • southamerica-west1-b
  • southamerica-west1-c

Authentication

组织政策服务使用 OAuth 2.0 进行 API 身份验证和授权。要获取 OAuth 2.0 不记名令牌,请执行以下操作:

  1. 转到 OAuth 2.0 Playground 页面

  2. 第 1 步范围列表中,选择 Cloud Resource Manager API v2 > https://www.googleapis.com/auth/cloud-platform,然后点击授权 API (Authorize APIs)。

  3. 在显示的使用 Google 账号登录页面上,选择您的账号并登录。

  4. 如需提供对 Google Oauth 2.0 Playground 的访问权限,请在出现的提示上点击允许

  5. 第 2 步中,点击以授权代码交换令牌 (Exchange authorization code for tokens)。

  6. 在右侧的请求/响应窗格底部,将显示您的访问令牌字符串:

     {
       "access_token": "ACCESS_TOKEN",
       "token_type": "Bearer",
       "expires_in": 3600
     }
    

    其中,ACCESS_TOKEN 是可用于 API 授权的 OAuth 2.0 不记名令牌字符串。