Cloud Asset Inventory 是一项全球元数据目录服务,可让您查看、搜索、导出、监控和分析 Google Cloud 资产元数据。它专为合规性跟踪、定期审核和分析等任务而设计。
您可以使用 Cloud Asset Inventory 执行的任务包括:
- 资源发现和管理:按位置、创建时间、标记和状态等元数据属性进行过滤。
- 资源监控:跟踪资源随时间发生的变化,以创建审计跟踪记录、调试问题和管理合规性偏差。
- 安全和费用审核:查找权限过高、公开暴露或未使用的资源,以最大限度地缩小攻击面并优化费用。
素材资源的创建、更新和删除历史记录最多可保留 35 天。过去 35 天内未发生更改的资源会返回其最新状态。
在 Google Cloud中使用素材资源
您可以通过以下方式使用素材资源:
列出特定项目、文件夹或组织中的资产及其关系,并获取过去最多 35 天的资产历史记录。
使用自定义查询语言搜索您的资源及其 IAM 允许政策,或使用 BigQuery SQL 查询您的资产。
将资产元数据导出到 BigQuery 或 Cloud Storage。
分析资源的 IAM 和组织政策,并查看资源的有效 IAM 政策,以了解谁有权访问哪些资源。
通过设置和订阅 Feed,监控资产的变化。
从您的资产中生成数据分析,以帮助改善您的安全状况。
资产元数据来源
资产元数据可能来自以下位置:
Google Cloud 资源,例如 Compute Engine 虚拟机实例、Cloud Storage 存储桶和 App Engine 实例。
在 Google Cloud 资源上设置的政策,例如 IAM 政策、组织政策和 Access Context Manager 政策。
来自 OS Inventory Management 的运行时信息。
素材资源类型、素材资源名称和内容类型
Cloud Asset Inventory 提供了多种与资产交互的方法。根据您使用的方法和所需的响应详细信息,您可能需要在请求中指定资产类型、资产名称和内容类型。
资产类型
某些 Cloud Asset Inventory 方法会根据资产类型返回结果。资产类型包括 Google Cloud 资源、政策、操作系统资产清单运行时信息和关系。资产类型中详细介绍了可用的资产类型以及支持这些类型的 Cloud Asset Inventory 方法。
素材资源名称
某些 Cloud Asset Inventory 方法会根据资产名称返回结果。指定资产名称时,您必须使用其完整资源名称。如需查看完整资源名称的列表,请参阅资产名称。
内容类型
您可以通过指定元数据内容类型来请求资源的额外元数据。如果您未指定内容类型,则系统只会返回基本响应,其中包含资产名称、上次更新时间以及资产所属的项目、文件夹和组织等信息。
内容类型名称因您与 Cloud Asset Inventory 的交互方式而异。RPC 和 REST API 名称相同。不过,gcloud CLI 内容类型名称遵循不同的模式。为保持一致性和便于说明,本文档的其余部分将通过其 RPC 和 REST 名称来引用内容类型。
下表详细介绍了内容类型及其说明:
| 内容类型 | 说明 | |
|---|---|---|
| RPC 和 REST 名称 | gcloud CLI 名称 | |
ACCESS_POLICY |
access-policy |
在资产上设置的 Access Context Manager 政策。 |
IAM_POLICY |
iam-policy |
绑定到资源的 IAM 政策元数据。 |
ORG_POLICY |
org-policy |
在资产上设置的组织政策元数据。此内容类型会输出旧版组织政策 v1。对于组织政策 v2,请尝试使用 resource 内容类型和 orgpolicy.googleapis.com/Policy 资源类型。
|
OS_INVENTORY |
os-inventory |
运行时操作系统清单信息。如需启用操作系统资产清单,请完成设置虚拟机管理器中的相关步骤。 |
RELATIONSHIP |
relationship |
需要访问 Security Command Center 高级方案或 Enterprise 方案。 许多 Google Cloud 资源通过关系相互连接。例如,Compute 实例组可以包含 计算实例,或者 GKE 集群可以包含节点。 关系数据从 2022 年 5 月 30 日开始提供。关系可能有自己的更新时间戳,因为其推断时间可能与源资产更新时间不同。 如需查看支持的关系列表,请参阅关系类型。 |
RESOURCE |
resource |
资源的元数据。 |
回答如何随内容类型而变化
以下示例展示了通过 Cloud Asset Inventory 列出项目中的虚拟机实例时,响应如何因内容类型不同而发生变化。
无内容类型
如果您在列出虚拟机实例时未指定内容类型,则只会收到实例名称、上次更新时间以及它们所属的项目、文件夹和组织。
展开即可查看回答示例
--- ancestors: - projects/PROJECT_NUMBER - folders/FOLDER_NUMBER - organizations/ORGANIZATION_ID assetType: compute.googleapis.com/Instance name: //compute.googleapis.com/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME updateTime: '2023-11-15T12:28:30.087825Z'
IAM_POLICY 内容类型
如果您指定 IAM_POLICY 内容类型,则还会收到虚拟机上的 IAM 绑定(如果有)。
展开即可查看回答示例
---
ancestors:
- projects/PROJECT_NUMBER
- folders/FOLDER_NUMBER
- organizations/ORGANIZATION_ID
assetType: compute.googleapis.com/Instance
iamPolicy:
bindings:
- members:
- user:USER_EMAIL_ADDRESS
role: roles/compute.securityAdmin
etag: ETAG
name: //compute.googleapis.com/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME
updateTime: '2023-12-19T23:35:42.673842Z'RELATIONSHIP 内容类型
关系需要访问 Security Command Center 高级方案或 Enterprise 方案。
如果您指定 RELATIONSHIP 内容类型,则还会收到与虚拟机实例的相关资产关联的元数据。
展开即可查看回答示例
--- ancestors: - projects/PROJECT_NUMBER - folders/FOLDER_NUMBER - organizations/ORGANIZATION_ID assetType: compute.googleapis.com/Instance name: //compute.googleapis.com/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME relatedAsset: ancestors: - projects/PROJECT_NUMBER - folders/FOLDER_NUMBER - organizations/ORGANIZATION_ID asset: //compute.googleapis.com/projects/PROJECT_ID/zones/ZONE/disks/INSTANCE_NAME assetType: compute.googleapis.com/Disk relationshipType: COMPUTE_INSTANCE_USE_DISK updateTime: '2023-12-19T23:35:42.673842Z'
使用 RELATIONSHIP 内容类型时,您可以请求特定关系类型,而不是请求所有关系。
RESOURCE 内容类型
如果您指定 RESOURCE 内容类型,则还会收到与虚拟机关联的所有元数据。
展开即可查看回答示例
---
ancestors:
- projects/PROJECT_NUMBER
- folders/FOLDER_NUMBER
- organizations/ORGANIZATION_ID
assetType: compute.googleapis.com/Instance
name: //compute.googleapis.com/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME
resource:
data:
allocationAffinity:
consumeAllocationType: ANY_ALLOCATION
canIpForward: false
confidentialInstanceConfig:
enableConfidentialCompute: true
cpuPlatform: AMD Rome
creationTimestamp: '2023-11-14T14:35:37.059-08:00'
deletionProtection: false
description: ''
disks:
- architecture: X86_64
autoDelete: true
boot: true
deviceName: INSTANCE_NAME
diskSizeGb: '10'
guestOsFeatures:
- type: VIRTIO_SCSI_MULTIQUEUE
- type: SEV_CAPABLE
- type: SEV_SNP_CAPABLE
- type: SEV_LIVE_MIGRATABLE
- type: UEFI_COMPATIBLE
- type: GVNIC
index: 0
interface: NVME
licenses:
- https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/licenses/ubuntu-2004-lts
mode: READ_WRITE
shieldedInstanceInitialState:
dbx:
- content: DATA
fileType: BIN
dbxs:
- content: DATA
fileType: BIN
source: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks/INSTANCE_NAME
type: PERSISTENT
displayDevice:
enableDisplay: false
fingerprint: FINGERPRINT
id: 'ID'
keyRevocationActionType: NONE_ON_KEY_REVOCATION
labelFingerprint: LABEL_FINGERPRINT
lastStartTimestamp: '2023-11-15T04:28:30.005-08:00'
machineType: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/machineTypes/n2d-standard-2
name: INSTANCE_NAME
networkInterfaces:
- accessConfigs:
- name: External NAT
natIP: 34.27.105.222
networkTier: PREMIUM
type: ONE_TO_ONE_NAT
fingerprint: jKU51FdTluk=
name: nic0
network: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks/default
networkIP: 10.128.15.212
nicType: GVNIC
stackType: IPV4_ONLY
subnetwork: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/subnetworks/default
reservationAffinity:
consumeReservationType: ANY_ALLOCATION
resourceStatus: {}
scheduling:
automaticRestart: true
onHostMaintenance: TERMINATE
preemptible: false
provisioningModel: STANDARD
selfLink: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME
serviceAccounts:
- email: PROJECT_NUMBER-compute@developer.gserviceaccount.com
scopes:
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring.write
- https://www.googleapis.com/auth/servicecontrol
- https://www.googleapis.com/auth/service.management.readonly
- https://www.googleapis.com/auth/trace.append
shieldedInstanceConfig:
enableIntegrityMonitoring: true
enableSecureBoot: false
enableVtpm: true
shieldedInstanceIntegrityPolicy:
updateAutoLearnPolicy: true
startRestricted: false
status: RUNNING
tags:
fingerprint: FINGERPRINT
zone: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE
discoveryDocumentUri: https://www.googleapis.com/discovery/v1/apis/compute/v1/rest
discoveryName: Instance
location: ZONE
parent: //cloudresourcemanager.googleapis.com/projects/PROJECT_NUMBER
version: v1
updateTime: '2023-11-15T12:28:30.087825Z'一致性模型
在设计涉及 Cloud Asset Inventory 的解决方案之前,了解其一致性模型有助于您构建强大的软件:
最终一致性:Cloud Asset Inventory 使用定期数据同步。因此,新预配或修改的资源可能无法立即查询。可能会出现索引编制延迟;因此,状态更改可能需要一些时间才能在搜索查询、Feed 和导出内容中传播。
可能丢失数据/事件:从其他Google Cloud 服务接收信息时,可能会出现暂时性丢包、延迟或乱序传送。
如需详细了解如何设计使用 Cloud Asset Inventory 数据的服务,请参阅 Cloud Asset Inventory 最佳实践。