Cloud Asset Inventory 總覽

Cloud Asset Inventory 是全球中繼資料資產管理服務,可讓您查看、搜尋、匯出、監控及分析 Google Cloud 資產中繼資料。這項功能適用於法規遵循追蹤、排定稽核和數據分析等工作。

Cloud Asset Inventory 可用於下列工作:

  • 資源探索和管理:依據中繼資料屬性 (例如位置、建立時間、標記和狀態) 篩選。
  • 安全性和成本稽核:找出權限過高、公開或未使用的資源,盡可能縮小攻擊面並降低成本。

素材資源的建立、更新和刪除記錄最多會保留 35 天。過去 35 天內未變更的資產會傳回最新狀態。

在 Google Cloud中使用素材資源

以下說明如何使用素材資源:

資產中繼資料來源

資產中繼資料可能來自下列位置:

  • Google Cloud 資源,例如 Compute Engine VM 執行個體、Cloud Storage bucket 和 App Engine 執行個體。

  • 在 Google Cloud 資源上設定的政策,例如 IAM 政策、組織政策和 Access Context Manager 政策。

  • OS 庫存管理服務中的執行階段資訊。

素材資源類型、素材資源名稱和內容類型

Cloud Asset Inventory 提供多種與資產互動的方法。視您使用的方法和所需的回應詳細資料而定,您可能需要在要求中指定資產類型、資產名稱和內容類型。

資產類型

部分 Cloud Asset Inventory 方法會根據資產類型傳回結果。資產類型包括 Google Cloud 資源、政策、OS 清單執行階段資訊和關係。如要進一步瞭解可用的資產類型,以及支援這些類型的 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。如果是組織政策第 2 版,請嘗試使用 resource 內容類型和 orgpolicy.googleapis.com/Policy 資源類型。
RESOURCE resource 資源的中繼資料。

回覆如何隨內容類型變化

下列範例說明透過 Cloud Asset Inventory 列出專案中的 VM 執行個體時,回應如何隨著內容類型而變化。

沒有內容類型

如果列出 VM 執行個體時未指定內容類型,則只會收到執行個體名稱、上次更新時間,以及所屬的專案、資料夾和組織。

展開查看回應範例

---
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 內容類型,您也會收到 VM 上的 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'

RESOURCE 內容類型

如果指定 RESOURCE 內容類型,您也會收到與 VM 相關聯的所有中繼資料。

展開查看回應範例

---
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.
      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 會定期同步處理資料。因此,新佈建或修改的資源可能無法立即查詢。索引作業可能會延遲,因此狀態變更可能需要一段時間,才會套用至搜尋查詢、動態饋給和匯出作業。

  • 資料/事件可能遺失:從其他Google Cloud 服務接收資訊時,可能會暫時遺失、延遲或未按順序傳送。

如要進一步瞭解如何設計使用 Cloud Asset Inventory 資料的服務,請參閱 Cloud Asset Inventory 最佳做法。

後續步驟