本页包含有关分析组织政策设置的信息,可帮助您了解哪些资源受哪些组织政策的约束。借助组织政策的政策分析器,您可以创建分析查询,以获取有关自定义组织政策和预定义组织政策的信息。
分析查询由范围和限制条件组成。
- 限制条件:指定限制条件的资源名称。
范围:指定组织以限定分析范围。此范围内定义的所有具有指定限制条件的组织政策都将纳入分析范围。
如需详细了解组织政策,请参阅组织政策服务简介。
如需详细了解如何创建自定义限制条件,请参阅创建和管理自定义限制条件。
如需详细了解托管式限制,请参阅使用限制条件。
准备工作
Enable the Cloud Asset API.
您必须在用于发送查询的项目中启用该 API。此资源不必与您将查询范围限定到的资源相同。
可选:如果您希望每个组织每天执行 20 个以上的政策分析查询,请确保您已在组织级层激活 Security Command Center 的高级层级或企业层级。如需了解详情,请参阅结算问题。
所需的角色和权限
如需获得运行组织政策分析所需的权限,请让管理员向您授予您要进行分析的组织资源的以下 IAM 角色:
-
如需进行分析,请执行以下操作:
Cloud Asset Viewer (
roles/cloudasset.viewer
) -
查看限制:
Organization Policy Viewer (
roles/orgpolicy.policyViewer
)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
这些预定义角色包含运行组织政策分析所需的权限。如需查看所需的确切权限,请展开所需权限部分:
所需权限
如需运行组织政策分析,您需要具备以下权限:
-
如需进行分析,请执行以下操作:
-
cloudasset.assets.analyzeOrgPolicy
-
cloudasset.assets.searchAllResources
-
cloudasset.assets.searchAllIamPolicies
-
-
如需查看自定义限制条件和受管理的限制条件,请执行以下操作:
orgpolicy.customConstraints.get
价格和配额
大规模使用组织政策的 Policy Analyzer(每个组织每天超过 20 个查询)和继承可视化图表仅适用于在组织级层激活 Security Command Center 的客户。
组织政策的 Policy Analyzer 配额在所有 Policy Analyzer 工具之间共享。如需了解详情,请参阅结算问题。
分析已配置的政策
组织政策由限制条件以及强制执行该限制条件的可选条件构成。您可以使用政策分析器返回具有特定限制条件的组织政策的列表,以及附加了这些政策的资源。
对于在查询范围内检测到的每项组织政策,政策分析器都会返回一个结果条目。结果条目包含以下字段:
consolidatedPolicy
:组织政策所附加到的资源,以及根据层次结构评估规则对该资源强制执行的有效政策。project
:相应合并后政策所属的项目资源的 ID。folders
:组织政策所关联的资源的任何文件夹祖先资源的 ID。organization
:组织政策所关联的资源的祖先组织资源的 ID。policyBundle
:附加到上述资源的全套已配置组织政策,以及在资源层次结构中为该资源的祖先定义的组织政策。
如果您的资源受 VPC Service Controls 服务边界保护,您必须在组织资源的边界中创建出站流量规则,以允许访问 cloudasset.googleapis.com
服务和 google.cloud.asset.v1.AssetService.SearchAllResources
方法。如果您没有出口规则,则请求将失败并显示 NETWORK_NOT_IN_SAME_SERVICE_PERIMETER
错误。如需了解详情,请参阅调试被 VPC Service Controls 阻止的请求。
控制台
在 Google Cloud 控制台中,前往政策分析器页面。
在分析组织政策部分中,找到标记为在何处配置特定的组织政策?的窗格,然后点击该窗格中的创建查询。
在选择查询组织框中,选择要分析组织政策的组织。
选择要分析的限制条件类型。对于预定义或受管理的约束条件,请选择内置约束条件。 对于自定义限制条件,请选择自定义限制条件。
输入要分析的限制的名称。已包含您要分析的限制条件类型的前缀。例如,对于预定义的网域限制限制,请输入
iam.allowedPolicyMemberDomains
;对于服务账号创建受管理限制,请输入iam.managed.disableServiceAccountKeyCreation
;对于自定义限制,请输入其名称,例如disableGkeAutoUpgrade
。点击分析,然后点击运行查询。报告页面会显示您输入的查询参数,以及直接应用此限制的所有资源的结果表。
您可以点击复制查询网址来保存此查询,以便日后再次查看。 如需查看此查询,请前往生成的网址。
您可以直观呈现所分析的限制条件的继承情况,方法是从列表中选择至少一项资源,然后点击查看继承情况。您还可以在创建分析查询时立即前往可视化图表视图,只需依次点击分析和可视化图表即可。如需了解详情,请参阅直观呈现继承关系。
gcloud
如需获取组织政策限制条件在组织内的强制执行情况分析,请使用 gcloud asset analyze-org-policies
命令:
gcloud asset analyze-org-policies \
--constraint=CONSTRAINT_NAME \
--scope=organizations/ORGANIZATION_ID \
--limit=LIMIT_POLICIES \
--filter=FILTER_QUERY
替换以下内容:
CONSTRAINT_NAME:您要分析的组织政策限制的名称。如需查看限制条件列表,请参阅组织政策限制条件。
ORGANIZATION_ID:组织资源的 ID。如需详细了解如何查找组织 ID,请参阅创建和管理组织。
LIMIT_POLICIES:您要查看的结果条目数。如需查看无限数量的条目,请输入
unlimited
。FILTER_QUERY:过滤查询,用于仅查看与过滤表达式匹配的政策。唯一可用于过滤的字段是
consolidated_policy.attached_resource
。例如,consolidated_policy.attached_resource="//cloudresourcemanager.googleapis.com/projects/1234567890"
只会返回附加到项目 ID 为1234567890
的项目的政策。
YAML 响应类似于以下内容:
YAML 响应示例
--- consolidatedPolicy: appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621 attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621 rules: - enforce: true policyBundle: - appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621 attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621 reset: true - appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 rules: - enforce: true --- consolidatedPolicy: appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 rules: - enforce: true policyBundle: - appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 rules: - enforce: true
REST
如需分析组织政策限制条件在组织内的强制执行情况,请使用 Cloud Asset API 的 analyzeOrgPolicies
方法。
HTTP 方法和网址:
GET https://cloudasset.googleapis.com/v1/organizations/ORGANIZATION_ID:analyzeOrgPolicies
请求 JSON 正文:
JSON_REQUEST="{ 'constraint': 'CONSTRAINT_NAME', 'filter': 'FILTER_QUERY', 'page_size': PAGE_SIZE, 'page_token': PAGE_TOKEN }"
替换以下内容:
ORGANIZATION_ID:组织资源的 ID。如需详细了解如何查找组织 ID,请参阅创建和管理组织。
CONSTRAINT_NAME:您要分析的组织政策限制的名称。如需查看限制条件列表,请参阅组织政策限制条件。
FILTER_QUERY:过滤查询,用于仅查看与过滤表达式匹配的政策。唯一可用于过滤的字段是
consolidated_policy.attached_resource
。例如,consolidated_policy.attached_resource="//cloudresourcemanager.googleapis.com/projects/1234567890"
只会返回附加到项目 ID 为1234567890
的项目的政策。PAGE_SIZE:您希望每页显示的结果条目数。如需查看无限数量的条目,请输入
unlimited
。如果结果条目的总数大于 PAGE_SIZE,则设置了此标志的请求会返回nextPageToken
值。PAGE_TOKEN:仅在包含
page_size
标志的第一个请求之后的请求中设置。您可以使用从之前响应中收到的nextPageToken
值来返回特定页面的结果。
JSON 响应类似于以下内容:
JSON 响应示例
{ "orgPolicyResults": [ { "consolidatedPolicy": { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/123456789012", "rules": [ { "values": { "allowedValues": [ "C0265whk2" ] } }, { "values": { "allowedValues": [ "C03kd36xr" ] } } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/123456789012" }, "policyBundle": [ { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/123456789012", "rules": [ { "values": { "allowedValues": [ "C03kd36xr" ] } } ], "inheritFromParent": true, "appliedResource": "//cloudresourcemanager.googleapis.com/folders/123456789012" }, { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123", "rules": [ { "values": { "allowedValues": [ "C0265whk2" ] } } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123" } ] }, { "consolidatedPolicy": { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123", "rules": [ { "values": { "allowedValues": [ "C0265whk2" ] } } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123" }, "policyBundle": [ { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123", "rules": [ { "values": { "allowedValues": [ "C0265whk2" ] } } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123" } ] } ] "constraint": { "googleDefinedConstraint": { "name": "constraints/iam.allowedPolicyMemberDomains", "displayName": "Domain restricted sharing", "description": "This list constraint defines one or more Cloud Identity or Google Workspace customer IDs whose principals can be added to IAM policies. \u003cbr\u003eBy default, all user identities are allowed to be added to IAM policies. Only allowed values can be defined in this constraint, denied values are not supported. \u003cbr\u003eIf this constraint is active, only principals that belong to the allowed customer IDs can be added to IAM policies.", "constraintDefault": "ALLOW", "listConstraint": {} } } }
分析容器
在此上下文中,容器是指项目、文件夹或组织资源。您可以使用政策分析器返回所有容器的列表,这些容器具有组织政策并且强制执行了特定限制条件。政策分析器还会返回每个容器的全名、容器在层次结构中的父级,以及容器继承或附加的标记。
对于查询范围内检测到的每个容器,政策分析器都会返回一个结果条目。结果条目包含以下字段:
consolidatedPolicy
:组织政策所附加到的容器,以及根据层次结构评估规则对该容器强制执行的有效政策。conditionEvaluation
:如果包含的条件导致组织政策强制执行,则evaluationValue
为TRUE
。如果条件导致组织政策未强制执行,则evaluationValue
为FALSE
。如果组织政策所强制执行的一个或多个资源不支持相应条件,则返回该条件本身。effectiveTags
:直接附加到容器或由容器及其在层次结构中的父级容器继承的所有标记。folders
:包含组织政策所附加到的容器的任何文件夹资源的 ID。fullResourceName
:容器的全名。organization
:组织政策所附加到的容器的祖先组织资源的 ID。parent
:相应容器父级的完整资源名称。policyBundle
:直接在容器上配置的组织政策(如果存在)以及在资源层次结构中容器的祖先上定义的组织政策。project
:组织政策所附加到的容器的 ID(如果它是项目资源)。
如果您的资源受 VPC Service Controls 服务边界保护,您必须在组织资源的边界中创建出站流量规则,以允许访问 cloudasset.googleapis.com
服务和 google.cloud.asset.v1.AssetService.SearchAllResources
方法。如果您没有出口规则,则请求将失败并显示 NETWORK_NOT_IN_SAME_SERVICE_PERIMETER
错误。如需了解详情,请参阅调试被 VPC Service Controls 阻止的请求。
控制台
在 Google Cloud 控制台中,前往政策分析器页面。
在分析组织政策部分,找到标签为哪些项目或文件夹受组织政策限制条件的影响?的窗格,然后点击该窗格中的创建查询。
在选择查询组织框中,选择要分析组织政策的组织。
选择要分析的限制条件类型。对于预定义或受管理的限制条件,请选择内置限制条件。对于自定义限制条件,请选择自定义限制条件。
输入要分析的限制的名称。已包含您要分析的限制条件类型的前缀。例如,对于预定义的网域限制约束,请输入
iam.allowedPolicyMemberDomains
;对于服务账号创建受管理约束,请输入iam.managed.disableServiceAccountKeyCreation
;对于自定义约束,请输入其名称,例如disableGkeAutoUpgrade
。点击运行查询。报告页面会显示您输入的查询参数,以及此限制所强制执行或继承的所有容器的结果表。
您可以点击复制查询网址来保存此查询,以便日后再次查看。 如需查看此查询,请前往生成的网址。
您可以直观呈现所分析的限制的继承情况,方法是选择列表中的至少一个容器,然后点击查看继承情况。您还可以在创建分析查询时立即前往可视化图表视图,只需依次点击分析和可视化图表即可。如需了解详情,请参阅直观呈现继承关系。
gcloud
如需分析组织政策限制条件在组织内容器中的强制执行情况,请使用 gcloud asset analyze-org-policy-governed-containers
命令:
gcloud asset analyze-org-policy-governed-containers \
--constraint=CONSTRAINT_NAME \
--scope=organizations/ORGANIZATION_ID \
--limit=LIMIT_CONTAINERS \
--filter=FILTER_QUERY
替换以下内容:
CONSTRAINT_NAME:您要分析的组织政策限制的名称。如需查看限制条件列表,请参阅组织政策限制条件。
ORGANIZATION_ID:组织资源的 ID。如需详细了解如何查找组织 ID,请参阅创建和管理组织。
LIMIT_CONTAINERS:您要查看的结果条目数。如需查看无限数量的条目,请输入
unlimited
。FILTER_QUERY:过滤查询,用于仅查看与过滤表达式匹配的容器。唯一可用于过滤的字段是
parent
。例如,parent="//cloudresourcemanager.googleapis.com/organizations/012345678901"
将仅返回组织 ID 为012345678901
的组织的子容器。
YAML 响应类似于以下内容:
YAML 响应示例
--- consolidatedPolicy: appliedResource: //cloudresourcemanager.googleapis.com/projects/donghe-project1 attachedResource: //cloudresourcemanager.googleapis.com/projects/donghe-project1 rules: - values: allowedValues: - projects/donghe-project1/zones/us-central1-a/instances/instance-1 fullResourceName: //cloudresourcemanager.googleapis.com/projects/donghe-project1 parent: //cloudresourcemanager.googleapis.com/folders/86513245445 policyBundle: - appliedResource: //cloudresourcemanager.googleapis.com/projects/donghe-project1 attachedResource: //cloudresourcemanager.googleapis.com/projects/donghe-project1 inheritFromParent: true rules: - values: allowedValues: - projects/donghe-project1/zones/us-central1-a/instances/instance-1 --- consolidatedPolicy: appliedResource: //cloudresourcemanager.googleapis.com/projects/jeffreyai-prj01-on-ipa1 attachedResource: //cloudresourcemanager.googleapis.com/projects/jeffreyai-prj01-on-ipa1 rules: - denyAll: true fullResourceName: //cloudresourcemanager.googleapis.com/projects/jeffreyai-prj01-on-ipa1 parent: //cloudresourcemanager.googleapis.com/organizations/474566717491 policyBundle: - appliedResource: //cloudresourcemanager.googleapis.com/projects/jeffreyai-prj01-on-ipa1 attachedResource: //cloudresourcemanager.googleapis.com/projects/jeffreyai-prj01-on-ipa1 inheritFromParent: true rules: - denyAll: true --- consolidatedPolicy: appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621 attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621 rules: - values: allowedValues: - projects/opa-test-project-1-364621/zones/us-central1-a/instances/instance-1 fullResourceName: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621 parent: //cloudresourcemanager.googleapis.com/folders/666681422980 policyBundle: - appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621 attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621 rules: - values: allowedValues: - projects/opa-test-project-1-364621/zones/us-central1-a/instances/instance-1
REST
如需分析组织政策限制条件在组织内的容器上的强制执行情况,请使用 Cloud Asset API 的 analyzeOrgPolicyGovernedContainers
方法。
HTTP 方法和网址:
GET https://cloudasset.googleapis.com/v1/organizations/ORGANIZATION_ID:analyzeOrgPolicyGovernedContainers
请求 JSON 正文:
JSON_REQUEST="{ 'constraint': 'CONSTRAINT_NAME', 'filter': '"FILTER_QUERY"', 'page_size': PAGE_SIZE, 'page_token': PAGE_TOKEN }"
替换以下内容:
ORGANIZATION_ID:组织资源的 ID。如需详细了解如何查找组织 ID,请参阅创建和管理组织。
CONSTRAINT_NAME:您要分析的组织政策限制的名称。如需查看限制条件列表,请参阅组织政策限制条件。
FILTER_QUERY:过滤查询,用于仅查看与过滤表达式匹配的容器。唯一可用于过滤的字段是
parent
。例如,parent="//cloudresourcemanager.googleapis.com/organizations/012345678901"
将仅返回组织 ID 为012345678901
的组织的子容器。PAGE_SIZE:您要查看的结果条目页数。如需查看无限数量的条目,请输入
unlimited
。如果结果条目的总数大于 PAGE_SIZE,则设置了此标志的请求会返回nextPageToken
值。PAGE_TOKEN:仅在包含
page_size
标志的第一个请求之后的请求中设置。您可以使用从之前响应中收到的nextPageToken
值来返回特定页面的结果。
JSON 响应类似于以下内容:
JSON 响应示例
{ "governedContainers": [ { "fullResourceName": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-2", "parent": "//cloudresourcemanager.googleapis.com/folders/513502730678", "consolidatedPolicy": { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678", "rules": [ { "enforce": false } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678" }, "policyBundle": [ { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678", "rules": [ { "enforce": false } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678" }, { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/666681422980", "rules": [ { "enforce": true } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/666681422980" } ] }, { "fullResourceName": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-1", "parent": "//cloudresourcemanager.googleapis.com/folders/513502730678", "consolidatedPolicy": { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678", "rules": [ { "enforce": false } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678" }, "policyBundle": [ { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678", "rules": [ { "enforce": false } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678" }, { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/666681422980", "rules": [ { "enforce": true } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/666681422980" } ] } ] "constraint": { "googleDefinedConstraint": { "name": "constraints/compute.requireOsLogin", "displayName": "Require OS Login", "description": "This boolean constraint, when set to \u003ccode\u003etrue\u003c/code\u003e, enables OS Login on all newly created Projects. All VM instances created in new projects will have OS Login enabled. On new and existing projects, this constraint prevents metadata updates that disable OS Login at the project or instance level. \u003cbr\u003eBy default, the OS Login feature is disabled on Compute Engine projects.\u003cbr\u003eGKE instances in private clusters running node pool versions 1.20.5-gke.2000 and later support OS Login. GKE instances in public clusters do not currently support OS Login. If this constraint is applied to a Project running public clusters, GKE instances running in that Project may not function properly.", "constraintDefault": "ALLOW", "booleanConstraint": {} } } }
分析资产
在此上下文中,资产是指 Google Cloud 资源或 Identity and Access Management (IAM) 允许政策。您可以使用政策分析器返回具有组织政策并且强制执行了特定限制条件的所有资源的列表。支持自定义限制条件、受管理的限制条件和以下预定义的限制条件:
constraints/ainotebooks.accessMode
constraints/ainotebooks.disableFileDownloads
constraints/ainotebooks.disableRootAccess
constraints/ainotebooks.disableTerminal
constraints/ainotebooks.environmentOptions
constraints/ainotebooks.requireAutoUpgradeSchedule
constraints/ainotebooks.restrictVpcNetworks
constraints/compute.disableGuestAttributesAccess
constraints/compute.disableInstanceDataAccessApis
constraints/compute.disableNestedVirtualization
constraints/compute.disableSerialPortAccess
constraints/compute.disableSerialPortLogging
constraints/compute.disableVpcExternalIpv6
constraints/compute.requireOsLogin
constraints/compute.requireShieldedVm
constraints/compute.restrictLoadBalancerCreationForTypes
constraints/compute.restrictProtocolForwardingCreationForTypes
constraints/compute.restrictXpnProjectLienRemoval
constraints/compute.setNewProjectDefaultToZonalDNSOnly
constraints/compute.skipDefaultNetworkCreation
constraints/compute.trustedImageProjects
constraints/compute.vmCanIpForward
constraints/compute.vmExternalIpAccess
constraints/gcp.detailedAuditLoggingMode
constraints/gcp.resourceLocations
constraints/iam.allowedPolicyMemberDomains
constraints/iam.automaticIamGrantsForDefaultServiceAccounts
constraints/iam.disableServiceAccountCreation
constraints/iam.disableServiceAccountKeyCreation
constraints/iam.disableServiceAccountKeyUpload
constraints/iam.restrictCrossProjectServiceAccountLienRemoval
constraints/iam.serviceAccountKeyExpiryHours
constraints/resourcemanager.accessBoundaries
constraints/resourcemanager.allowedExportDestinations
constraints/sql.restrictAuthorizedNetworks
constraints/sql.restrictNoncompliantDiagnosticDataAccess
constraints/sql.restrictNoncompliantResourceCreation
constraints/sql.restrictPublicIp
constraints/storage.publicAccessPrevention
constraints/storage.restrictAuthTypes
constraints/storage.uniformBucketLevelAccess
政策分析器会返回每项资产的全名、层次结构中该资产的父级,以及层次结构中位于该资产之上的任何祖先项目、文件夹和组织资源。
对于查询范围内检测到的每项媒体资源,政策分析器都会返回一个结果条目。
资源的搜索结果条目包含以下字段:
consolidatedPolicy
:组织政策所附加到的资源,以及根据层次结构评估规则对该资源强制执行的有效政策。conditionEvaluation
:如果包含的条件导致组织政策强制执行,则evaluationValue
为TRUE
。如果条件导致组织政策未强制执行,则evaluationValue
为FALSE
。如果组织政策所强制执行的一个或多个资源不支持相应条件,则返回该条件本身。assetType
:相应资产的资源类型。effectiveTags
:直接附加到或由组织政策所附加到的资源以及层次结构中该资源的父级资源继承的所有标记。folders
:包含组织政策所附加到的资源的任何文件夹资源的 ID。fullResourceName
:资源的完整资源名称。organization
:包含相应资源的组织的相对资源名称。parent
:资源的父级的完整资源名称。project
:包含相应资源的项目的 ID。policyBundle
:附加到上述资源的全套已配置组织政策,以及在资源层次结构中为该资源的祖先定义的组织政策。
允许政策的结果条目包含以下字段:
consolidatedPolicy
:组织政策所附加到的资源,以及根据层次结构评估规则对该资源强制执行的有效政策。assetType
:附加了允许政策的资源的资源类型。attachedResource
:附加了允许政策的资源的完整名称。folders
:包含许可政策的任何文件夹的相对资源名称。organization
:包含允许政策的组织的相对资源名称。policy
:允许政策。project
:包含许可政策的项目的相对资源名称。policyBundle
:附加到上述资源的全套已配置组织政策,以及在资源层次结构中为该资源的祖先定义的组织政策。
如果您的资源受 VPC Service Controls 服务边界保护,您必须在组织资源的边界中创建出站流量规则,以允许访问 cloudasset.googleapis.com
服务和 google.cloud.asset.v1.AssetService.SearchAllResources
方法。如果您没有出口规则,则请求将失败并显示 NETWORK_NOT_IN_SAME_SERVICE_PERIMETER
错误。如需了解详情,请参阅调试被 VPC Service Controls 阻止的请求。
控制台
在 Google Cloud 控制台中,前往政策分析器页面。
在分析组织政策部分中,找到标记为哪些资源受组织政策限制条件的影响?的窗格,然后点击该窗格中的创建查询。
在选择查询组织框中,选择要分析组织政策的组织。
选择要分析的限制条件类型。对于预定义或受管理的约束条件,请选择内置约束条件。对于自定义限制条件,请选择自定义限制条件。
输入要分析的限制的名称。已包含您要分析的限制条件类型的前缀。例如,对于预定义的存储桶级访问权限限制,请输入
storage.uniformBucketLevelAccess
;对于服务账号创建受管限制,请输入iam.managed.disableServiceAccountKeyCreation
;对于自定义限制,请输入其名称,例如disableGkeAccess
。点击运行查询。报告页面会显示您输入的查询参数,以及此限制所强制执行或继承的所有资产的结果表。
您可以点击复制查询网址来保存此查询,以便日后再次查看。 如需查看此查询,请前往生成的网址。
您可以直观呈现所分析的限制的继承情况,方法是选择列表中的至少一项资产,然后点击查看继承情况。您还可以在创建分析查询时立即前往可视化图表视图,只需依次点击分析和可视化图表即可。如需了解详情,请参阅直观呈现继承关系。
gcloud
如需分析组织政策限制条件在组织内资产上的强制执行情况,请使用 gcloud asset analyze-org-policy-governed-assets
命令:
gcloud asset analyze-org-policy-governed-assets \
--constraint=CONSTRAINT_NAME \
--scope=organizations/ORGANIZATION_ID \
--limit=LIMIT_ASSETS \
--filter=FILTER_QUERY
替换以下内容:
CONSTRAINT_NAME:您要分析的组织政策限制的名称。如需查看限制条件列表,请参阅组织政策限制条件。
ORGANIZATION_ID:组织资源的 ID。如需详细了解如何查找组织 ID,请参阅创建和管理组织。
LIMIT_ASSETS:您要查看的结果条目数。如需查看无限数量的条目,请输入
unlimited
。FILTER_QUERY:过滤查询,用于仅查看与过滤表达式匹配的素材资源。可用于过滤的字段包括
governed_resource.folders
、governed_resource.project
、governed_iam_policy.folders
和governed_iam_policy.project
。例如,governed_resource.project="projects/1234567890"
将仅返回附加到项目 ID 为1234567890
的项目的资源。
YAML 响应类似于以下内容:
YAML 响应示例
--- consolidatedPolicy: appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-2 attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-2 rules: - enforce: false governedResource: folders: - folders/513502730678 - folders/666681422980 fullResourceName: //container.googleapis.com/projects/opa-test-project-2/zones/us-central1-c/clusters/opa-test-project-2-cluster-1/nodePools/default-pool organization: organizations/474566717491 parent: //container.googleapis.com/projects/opa-test-project-2/zones/us-central1-c/clusters/opa-test-project-2-cluster-1 project: projects/892625391619 policyBundle: - appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-2 attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-2 reset: true - appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 attachedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 rules: - enforce: true --- consolidatedPolicy: appliedResource: //cloudresourcemanager.googleapis.com/projects/project2-244918 attachedResource: //cloudresourcemanager.googleapis.com/projects/project2-244918 rules: - enforce: false governedResource: folders: - folders/800636178739 - folders/408342778736 fullResourceName: //container.googleapis.com/projects/project2-244918/zones/us-central1-c/clusters/cluster-1/nodePools/default-pool organization: organizations/474566717491 parent: //container.googleapis.com/projects/project2-244918/zones/us-central1-c/clusters/cluster-1 project: projects/761097189269 policyBundle: - appliedResource: //cloudresourcemanager.googleapis.com/projects/project2-244918 attachedResource: //cloudresourcemanager.googleapis.com/projects/project2-244918 rules: - enforce: false - appliedResource: //cloudresourcemanager.googleapis.com/folders/408342778736 attachedResource: //cloudresourcemanager.googleapis.com/folders/408342778736 rules: - condition: description: cond-desc1 expression: resource.matchTag("474566717491/env", "prod") title: cond-title1 enforce: false - enforce: true - appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 attachedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 rules: - enforce: true --- consolidatedPolicy: appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 attachedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 rules: - enforce: true governedResource: fullResourceName: //container.googleapis.com/projects/probe-per-rt-project/zones/us-west1-a/clusters/test-cluster-for-backup/nodePools/default-pool organization: organizations/474566717491 parent: //container.googleapis.com/projects/probe-per-rt-project/zones/us-west1-a/clusters/test-cluster-for-backup project: projects/896190383908 policyBundle: - appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 attachedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491 rules: - enforce: true
REST
如需分析组织政策限制条件在组织内资产上的强制执行情况,请使用 Cloud Asset API 的 analyzeOrgPolicyGovernedAssets
方法。
HTTP 方法和网址:
GET https://cloudasset.googleapis.com/v1/organizations/ORGANIZATION_ID:analyzeOrgPolicyGovernedAssets
请求 JSON 正文:
JSON_REQUEST="{ 'constraint': 'CONSTRAINT_NAME', 'filter': 'FILTER_QUERY', 'page_size': PAGE_SIZE, 'page_token': PAGE_TOKEN }"
替换以下内容:
ORGANIZATION_ID:组织资源的 ID。如需详细了解如何查找组织 ID,请参阅创建和管理组织。
CONSTRAINT_NAME:您要分析的组织政策限制的名称。如需查看限制条件列表,请参阅组织政策限制条件。
FILTER_QUERY:过滤查询,用于仅查看与过滤表达式匹配的素材资源。可用于过滤的字段包括
governed_resource.folders
、governed_resource.project
、governed_iam_policy.folders
和governed_iam_policy.project
。例如,governed_resource.project="projects/1234567890"
将仅返回附加到项目 ID 为1234567890
的项目的资源。PAGE_SIZE:您要查看的结果条目页数。如需查看无限数量的条目,请输入
unlimited
。如果结果条目的总数大于 PAGE_SIZE,则设置了此标志的请求会返回nextPageToken
值。PAGE_TOKEN:仅在包含
page_size
标志的第一个请求之后的请求中设置。您可以使用从之前响应中收到的nextPageToken
值来返回特定页面的结果。
JSON 响应类似于以下内容:
JSON 响应示例
{ "governedAssets": [ { "governedResource": { "fullResourceName": "//container.googleapis.com/projects/opa-test-project-2/zones/us-central1-c/clusters/opa-test-project-2-cluster-1/nodePools/default-pool", "parent": "//container.googleapis.com/projects/opa-test-project-2/zones/us-central1-c/clusters/opa-test-project-2-cluster-1", "project": "projects/892625391619", "folders": [ "folders/513502730678", "folders/666681422980" ], "organization": "organizations/474566717491" }, "consolidatedPolicy": { "attachedResource": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-2", "rules": [ { "enforce": false } ], "appliedResource": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-2" }, "policyBundle": [ { "attachedResource": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-2", "reset": true, "appliedResource": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-2" }, { "attachedResource": "//cloudresourcemanager.googleapis.com/organizations/474566717491", "rules": [ { "enforce": true } ], "appliedResource": "//cloudresourcemanager.googleapis.com/organizations/474566717491" } ] }, { "governedResource": { "fullResourceName": "//container.googleapis.com/projects/project2-244918/zones/us-central1-c/clusters/cluster-1/nodePools/default-pool", "parent": "//container.googleapis.com/projects/project2-244918/zones/us-central1-c/clusters/cluster-1", "project": "projects/761097189269", "folders": [ "folders/800636178739", "folders/408342778736" ], "organization": "organizations/474566717491" }, "consolidatedPolicy": { "attachedResource": "//cloudresourcemanager.googleapis.com/projects/project2-244918", "rules": [ { "enforce": false } ], "appliedResource": "//cloudresourcemanager.googleapis.com/projects/project2-244918" }, "policyBundle": [ { "attachedResource": "//cloudresourcemanager.googleapis.com/projects/project2-244918", "rules": [ { "enforce": false } ], "appliedResource": "//cloudresourcemanager.googleapis.com/projects/project2-244918" }, { "attachedResource": "//cloudresourcemanager.googleapis.com/folders/408342778736", "rules": [ { "enforce": false, "condition": { "expression": "resource.matchTag(\"474566717491/env\", \"prod\")", "title": "cond-title1", "description": "cond-desc1" } }, { "enforce": true } ], "appliedResource": "//cloudresourcemanager.googleapis.com/folders/408342778736" }, { "attachedResource": "//cloudresourcemanager.googleapis.com/organizations/474566717491", "rules": [ { "enforce": true } ], "appliedResource": "//cloudresourcemanager.googleapis.com/organizations/474566717491" } ] } ] "constraint": { "customConstraint": { "name": "organizations/474566717491/customConstraints/custom.disableGkeAutoUpgrade", "resourceTypes": [ "container.googleapis.com/NodePool" ], "methodTypes": [ "CREATE", "UPDATE" ], "condition": "resource.management.autoUpgrade == false", "actionType": "ALLOW", "displayName": "Disable GKE auto upgrade", "description": "Only allow GKE NodePool resource create or updates if AutoUpgrade is not enabled" } } }
直观呈现继承关系
如果您在组织级层激活了 Security Command Center 的高级方案或 Enterprise 方案,则可以使用 Google Cloud 控制台直观呈现您分析过的组织政策的继承情况。
如需查看继承可视化图表,请为已配置的政策、容器或资产创建组织政策分析查询。在运行查询分析页面上,点击分析,然后选择可视化。
您还可以前往已保存查询的网址,选择要突出显示的资源,然后点击
查看继承关系。资源继承页面会直观显示分析查询中所选资源的资源层次结构:
指明资源是组织、文件夹还是项目。
蓝色圆点表示资源已在查询中选中。
表示资源会替换其父级资源的政策。
表示资源将组织政策重置为 Google 管理的相应政策默认值。将政策重置为默认值的资源通过虚线与其父级相关联。
表示资源会与其父级合并政策。
表示相应资源上的组织政策强制执行布尔值限制条件或具有允许值的列表限制条件。
表示相应资源的组织政策是具有被拒绝值的列表限制条件。
表示相应资源上的组织政策是不强制执行的布尔值限制。
后续步骤
- 详细了解使用限制条件。
- 了解如何创建和管理自定义限制条件。