查看密钥用量

本页面介绍了如何查看组织内受 Cloud KMS 密钥保护的 Google Cloud 资源。密钥使用情况跟踪仅适用于组织资源。

您可以从两个层面查看有关密钥所保护资源的信息:

  • 每个密钥的密钥使用情况摘要信息包括使用该密钥的受保护资源、项目和唯一 Google Cloud 产品的数量。任何对密钥具有 Cloud KMS Viewer 角色的用户都可以查看此级别的详细信息。
  • 密钥使用情况详细信息会指明哪些资源受此密钥保护并依赖于此密钥。此级别的详细信息属于特权信息,只有在组织中具有 Cloud KMS Protected Resources Viewer 角色的账号才能查看。

准备工作

本页假定您在Google Cloud 组织资源中使用 Cloud KMS。

  1. 让组织管理员向您的 Cloud KMS 服务账号授予组织资源上的 Cloud KMS Organization Service Agent (roles/cloudkms.orgServiceAgent) 角色。此角色无法在 Google Cloud 控制台中获得,因此您必须使用 gcloud CLI 授予该角色:

    gcloud CLI

    gcloud organizations add-iam-policy-binding ORGANIZATION_ID \
        --member=serviceAccount:service-org-ORGANIZATION_ID@gcp-sa-cloudkms.iam.gserviceaccount.com \
        --role=roles/cloudkms.orgServiceAgent
    

    ORGANIZATION_ID 替换为您组织的数字 ID。

  2. 向需要查看密钥使用情况摘要的任何人授予 Cloud KMS Viewer (roles/cloudkms.viewer) 角色。如需了解如何授予角色,请参阅管理访问权限

  3. 向需要查看密钥使用情况详情的任何人授予组织资源的 Cloud KMS Protected Resources Viewer (roles/cloudkms.protectedResourcesViewer) 角色。此角色无法在 Google Cloud 控制台中获得,因此您必须使用 gcloud CLI 授予该角色:

    gcloud CLI

    gcloud organizations add-iam-policy-binding ORGANIZATION_ID \
        --member=user:USER_EMAIL \
        --role=roles/cloudkms.protectedResourcesViewer
    

    替换以下内容:

    • ORGANIZATION_ID:贵组织的数字 ID。
    • USER_EMAIL:用户的电子邮件地址。
  4. 启用 Cloud KMS Inventory API。

    启用 API

查看密钥使用情况信息

控制台

  1. 在 Google Cloud 控制台中,前往密钥清单页面。

    前往“密钥清单”

  2. 可选:如需过滤密钥列表,请在 filter_list 过滤框中输入搜索字词,然后按 Enter 键。例如,您可以按密钥的位置、密钥环、状态或其他属性进行过滤。

  3. 点击您要查看使用情况信息的密钥的名称。

  4. 点击使用情况跟踪标签页。

  5. 可选:如需过滤受保护资源的列表,请在 filter_list 过滤框中输入搜索字词,然后按 Enter 键。

系统会显示所选密钥的使用情况摘要和详细信息。

gcloud CLI

如需在命令行上使用 Cloud KMS,请先安装或升级到最新版本的 Google Cloud CLI

如需查看密钥使用情况摘要,请使用 get-protected-resources-summary 方法:

gcloud kms inventory get-protected-resources-summary \
    --keyname  projects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/KEY_NAME \

替换以下内容:

  • PROJECT_ID:包含密钥环的项目的 ID。
  • LOCATION:密钥环的 Cloud KMS 位置。
  • KEY_RING:包含密钥的密钥环的名称。
  • KEY_NAME:您要查看使用情况摘要的密钥的名称。

如需查看密钥使用情况详情,请使用 search-protected-resources 方法:

gcloud kms inventory search-protected-resources \
    --keyname  projects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/KEY_NAME \
    --scope=organizations/ORGANIZATION_ID

替换以下内容:

  • PROJECT_ID:包含密钥环的项目的 ID。
  • LOCATION:密钥环的 Cloud KMS 位置。
  • KEY_RING:包含密钥的密钥环的名称。
  • KEY_NAME:您要查看使用情况详细信息的密钥的名称。
  • ORGANIZATION_ID:贵组织的数字 ID。

API

这些示例使用 curl 作为 HTTP 客户端来演示如何使用 API。如需详细了解访问权限控制,请参阅访问 Cloud KMS API

如需查看密钥使用情况摘要,请使用 cryptoKeys.getProtectedResourcesSummary 方法:

curl  "https://kmsinventory.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/KEY_NAME/protectedResourcesSummary"
    --request "GET" \
    --header "x-goog-user-project: CALLING_PROJECT_ID"
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer TOKEN"

替换以下内容:

  • PROJECT_ID:包含密钥环的项目的 ID。
  • LOCATION:密钥环的 Cloud KMS 位置。
  • KEY_RING:包含密钥的密钥环的名称。
  • KEY_NAME:您要查看使用情况摘要的密钥的名称。
  • CALLING_PROJECT_ID:您从中调用 KMS Inventory API 的项目的 ID。

如需查看密钥使用情况详情,请使用 protectedResources.search 方法:

curl "https://kmsinventory.googleapis.com/v1/organizations/ORGANIZATION_ID/protectedResources:search?crypto_key=projects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/KEY_NAME"
    --request "GET" \
    --header "x-goog-user-project: CALLING_PROJECT_ID"
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer TOKEN"

替换以下内容:

  • ORGANIZATION_ID:贵组织的数字 ID。
  • PROJECT_ID:包含密钥环的项目的 ID。
  • LOCATION:密钥环的 Cloud KMS 位置。
  • KEY_RING:包含密钥的密钥环的名称。
  • KEY_NAME:您要查看使用情况详细信息的密钥的名称。
  • CALLING_PROJECT_ID:您从中调用 KMS Inventory API 的项目的 ID。

密钥使用情况详细信息

使用情况详细信息(关于使用所选密钥加密的受保护资源)包括以下内容:

  • 名称:受所选密钥保护的 Google Cloud 资源名称。
  • 项目:包含受保护资源的项目的名称。
  • 加密密钥版本:用于加密此资源的密钥版本。 某些受保护的资源不会报告加密密钥版本。
  • 云产品:与此资源关联的 Google Cloud 产品。
  • 资源类型:受保护的资源类型,例如存储分区 (Cloud Storage) 或磁盘 (Compute Engine)。
  • 位置:与资源关联的 Google Cloud 区域。
  • 创建日期:资源的创建时间。
  • 标签:与资源关联的一组键值对。

列出保护资源的密钥版本

如果某资源受多个密钥版本保护,您可能无法在使用情况跟踪标签页中看到完整的密钥版本列表。

如需列出保护资源的密钥版本,请使用 gcloud CLI 运行以下命令:

gcloud beta kms inventory search-protected-resources \
  --keyname=KEY_NAME \
  --scope=organizations/ORGANIZATION_ID \
  --filter="name:RESOURCE_NAME" \
  --flatten="cryptoKeyVersions" \
  --format="value(cryptoKeyVersions)"

替换以下内容:

  • KEY_NAME:您要列出密钥版本的密钥的名称。
  • ORGANIZATION_ID:贵组织的数字 ID。
  • RESOURCE_NAME:您要列出密钥版本的资源的名称。

限制

使用密钥使用情况跟踪功能时,请注意以下事项:

  • 密钥使用情况跟踪仅适用于 CMEK 密钥使用情况。如果您在 Google Cloud内外的应用中使用密钥版本,则该用量不会显示在用量跟踪标签页中。
  • 某些 CMEK 资源未被跟踪。对于未在受跟踪的资源类型中列出的资源类型,密钥使用情况详细信息中可能不包含密钥使用情况信息。例如,Datastream 使用密钥加密 ConnectionProfile (datastream.googleapis.com/ConnectionProfile) 资源的用量不会显示在用量跟踪标签页上。
  • 数据可能会延迟。例如,如果您创建新的受保护资源,受保护资源和关联的密钥版本不会立即添加到使用情况跟踪标签页中。
  • Cloud Storage 密钥使用情况数据还受以下限制:
    • 密钥使用情况数据会从对象汇总到存储分区。不显示对象名称。如果存储桶至少有一个对象使用某个密钥,则该存储桶会显示为正在使用该密钥。
    • 如果存储分区包含使用超过 4,000 个唯一密钥版本保护的对象,则密钥使用情况跟踪可能不完整。
  • 密钥使用情况跟踪详情仅供参考。在进行可能会导致服务中断或数据丢失的更改之前,请使用其他来源自行开展尽职调查。请勿仅根据密钥使用情况跟踪信息停用或销毁密钥版本。

跟踪的资源类型

支持以下资源类型:

    服务 资源
    AI Applications discoveryengine.googleapis.com/DataStore
    AlloyDB for PostgreSQL alloydb.googleapis.com/Backup
    AlloyDB for PostgreSQL alloydb.googleapis.com/Cluster
    Apigee API Hub apihub.googleapis.com/ApiHubInstance
    Artifact Registry artifactregistry.googleapis.com/Repository
    BigQuery bigquery.googleapis.com/Dataset
    BigQuery bigquery.googleapis.com/Model
    BigQuery bigquery.googleapis.com/Table
    BigQuery bigquerydatatransfer.googleapis.com/TransferConfig
    Bigtable bigtableadmin.googleapis.com/Backup
    Bigtable bigtableadmin.googleapis.com/Cluster
    Bigtable bigtableadmin.googleapis.com/Table
    Cloud Composer composer.googleapis.com/Environment
    Cloud Data Fusion datafusion.googleapis.com/Instance
    Cloud Healthcare API healthcare.googleapis.com/Dataset
    Cloud Logging logging.googleapis.com/LogBucket
    Cloud Run run.googleapis.com/Revision
    Cloud Run functions cloudfunctions.googleapis.com/CloudFunction
    Cloud Run functions cloudfunctions.googleapis.com/Function
    Cloud SQL sqladmin.googleapis.com/BackupRun
    Cloud SQL sqladmin.googleapis.com/Instance
    Cloud Storage storage.googleapis.com/Bucket
    Cloud Workstations workstations.googleapis.com/Workstation
    Cloud Workstations workstations.googleapis.com/WorkstationConfig
    Compute Engine compute.googleapis.com/Disk
    Compute Engine compute.googleapis.com/Image
    Compute Engine compute.googleapis.com/MachineImage
    Compute Engine compute.googleapis.com/Snapshot
    Database Migration Service datamigration.googleapis.com/MigrationJob
    Database Migration Service datamigration.googleapis.com/ConnectionProfile
    Dataflow dataflow.googleapis.com/Job
    Dataproc dataproc.googleapis.com/Cluster
    Dataproc dataproc.googleapis.com/Batch
    Dataproc Metastore metastore.googleapis.com/Service
    Datastream datastream.googleapis.com/Stream
    Document AI documentai.googleapis.com/HumanReviewConfig
    Document AI documentai.googleapis.com/Processor
    Document AI documentai.googleapis.com/ProcessorVersion
    Filestore file.googleapis.com/Instance
    Filestore file.googleapis.com/Backup
    Firestore firestore.googleapis.com/Database
    Firestore datastore.googleapis.com/Database
    Google Agentspace Enterprise discoveryengine.googleapis.com/DataStore
    Google Kubernetes Engine container.googleapis.com/Cluster
    Looker (Google Cloud Core) looker.googleapis.com/Instance
    Memorystore for Redis redis.googleapis.com/Instance
    Migrate to Virtual Machines vmmigration.googleapis.com/Source
    Pub/Sub pubsub.googleapis.com/Topic
    Secret Manager secretmanager.googleapis.com/Secret
    Secret Manager secretmanager.googleapis.com/SecretVersion
    Secure Source Manager securesourcemanager.googleapis.com/Instance
    Spanner spanner.googleapis.com/Database
    Vertex AI aiplatform.googleapis.com/Dataset
    Vertex AI aiplatform.googleapis.com/Featurestore
    Vertex AI aiplatform.googleapis.com/Tensorboard
    Vertex AI aiplatform.googleapis.com/BatchPredictionJob
    Vertex AI aiplatform.googleapis.com/CustomJob
    Vertex AI aiplatform.googleapis.com/Endpoint
    Vertex AI aiplatform.googleapis.com/Model
    Vertex AI aiplatform.googleapis.com/TrainingPipeline
    Vertex AI aiplatform.googleapis.com/PipelineJob
    Vertex AI aiplatform.googleapis.com/MetadataStore
    Vertex AI Workbench 实例 notebooks.googleapis.com/Instance
    Workflows workflows.googleapis.com/Workflow