Cloud Asset Inventory 概览

Cloud Asset Inventory 是一种全球元数据目录服务,可让您查看、搜索、导出、监控和分析 Google Cloud 资产元数据。您可能会使用 Cloud Asset Inventory 执行的任务包括:

  • 资源发现和管理:按元数据属性(例如位置、创建时间、标记和状态)进行过滤。
  • 资源监控:跟踪资源随时间的变化,以创建审核轨迹、调试问题和管理合规性漂移。
  • 安全和费用审核:查找权限过高、公开泄露或未使用的资源,以最大限度地缩小攻击面并优化费用。

资产的创建、更新和删除历史记录最多保留 35 天。过去 35 天内未发生变化的资源会返回其最新状态。

使用 Google Cloud中的素材资源

您可以按以下方式处理素材资源:

资产元数据来源

资产元数据可能来自以下位置:

  • 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 层级,或者 Gemini Cloud Assist

许多 Google Cloud 资产通过关系相互关联。例如,Compute 实例组可以包含 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 方案,或者 Gemini Cloud Assist

如果您指定 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 可能会遗漏一些数据更新。

除非资源类型表格中另有说明,否则几乎所有素材资源更新都会在几分钟内生效。

后续步骤