本主题介绍了如何查看 Google Cloud 贵组织中受 Cloud KMS 密钥保护的资源。
您可以通过以下两种级别查看密钥保护的资源的相关信息:
- 每个密钥的密钥使用情况摘要信息包括受保护资源、项目和使用该密钥的唯一 Google Cloud 产品的数量。具有密钥的 Cloud KMS 查看者角色的任何人都可以查看此级别的详细信息。
- 密钥使用情况详细信息可确定哪些资源受此密钥保护以及依赖于此密钥。此级别的详细信息是特权信息,仅适用于在组织中具有 Cloud KMS Protected Resources Viewer 角色的账号。
准备工作
本主题假定您是在Google Cloud 组织资源中使用 Cloud KMS。
请让组织管理员为您的 Cloud KMS 服务账号授予组织资源的 Cloud KMS Organization Service Agent (
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。向需要查看密钥使用情况摘要的任何用户授予 Cloud KMS Viewer (
roles/cloudkms.viewer
) 角色。如需了解如何授予角色,请参阅管理访问权限。向需要查看密钥使用情况详情的任何人授予贵组织资源的 Cloud KMS Protected Resources Viewer (
roles/cloudkms.protectedResourcesViewer
) 角色。此角色无法在控制台中获得,因此您必须使用 gcloud CLI 授予此角色: Google Cloudgcloud CLI
gcloud organizations add-iam-policy-binding ORGANIZATION_ID \ --member=user:USER_EMAIL \ --role=roles/cloudkms.protectedResourcesViewer
替换以下内容:
ORGANIZATION_ID
:您的组织的数字 ID。USER_EMAIL
:用户的电子邮件地址。
启用 Cloud KMS Inventory API。
查看密钥使用情况信息
控制台
在 Google Cloud 控制台中,前往密钥目录页面。
可选:如需过滤按键列表,请在 filter_list Filter 框中输入搜索字词,然后按 Enter 键。例如,您可以按位置、钥匙圈、状态或钥匙的其他属性进行过滤。
点击您要查看其使用情况信息的密钥的名称。
点击使用情况跟踪标签页。
可选:如需过滤受保护资源列表,请在 filter_list Filter 框中输入搜索字词,然后按 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 由所选密钥保护的资源的名称。
- Project:包含受保护资源的项目的名称。
- 加密密钥版本:用于加密此资源的密钥版本。某些受保护资源不会报告加密密钥版本。
- Cloud 产品:与此资源关联的 Google Cloud 产品。
- 资源类型:受保护的资源类型,例如存储分区 (Cloud Storage) 或磁盘 (Compute Engine)。
- Location:与资源关联的 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 |