迁移到 Security Command Center API v2

本页介绍了 Security Command Center API 版本 1 (v1) 和版本 2 (v2) 之间的区别。还介绍了如何将 v1 Security Command Center Management API 与 v2 Security Command Center API 结合使用,从而迁移到 v2 Security Command Center API。

自 2024 年 12 月 9 日起,如果您首次在组织中激活 Security Command Center,则必须仅在该组织中使用 Security Command Center API 版本 2。不支持早期版本。

如果您在 2024 年 12 月 9 日之前在项目级层激活了 Security Command Center,那么您在同一组织中激活的任何项目都将支持所有可用的 Security Command Center API 版本。

对于与 Security Command Center 的所有集成,我们建议您采用 v2 Security Command Center API 和 v1 Security Command Center Management API。我们建议使用 Cloud 客户端库或 Google Cloud Terraform 提供程序来调用这些 API。详情请参阅以下内容:

v1 和 v2 API 之间的差异

在迁移到 v2 Security Command Center API 时,请注意与 v1 API 之间的以下差异。

数据驻留

v2 Security Command Center API 支持数据驻留,可让您更好地控制 Security Command Center 数据的位置:

即使您尚未为贵组织启用数据驻留,我们也建议您调用每个方法的位置感知版本并指定 global 位置。这样做有助于日后更轻松地采用数据驻留。

如果您为组织启用了数据驻留,则必须使用感知位置的方法,并根据您选择的位置使用区域性服务端点(如果适用)。

如需使用每个方法的位置感知版本,请执行以下操作:

控制台

Google Cloud 控制台会在必要时使用每个方法的位置感知版本。

gcloud

运行允许您指定位置的 gcloud CLI 命令(例如 gcloud scc findings list)时,请始终提供位置。您可以通过以下几种方式来执行此操作:

  • 使用 --location 标志。
  • 如果您提供资源名称的完整路径,请使用指定位置的格式,例如 projects/123/sources/456/locations/global/findings/a1b2c3

Terraform

请务必为支持 location 的实例提供 location 实参,例如 google_scc_v2_organization_mute_config

REST

调用名称中包含 locations 的方法版本。例如,调用 organizations.locations.findings.bulkMute,而不是 organizations.findings.bulkMute

客户端库

请参阅 Security Command Center 的代码示例或客户端库的 API 参考文档

通知配置和 BigQuery Export 配置

借助 v1 Security Command Center API,您可以创建和管理以下类型的导出配置:

您还可以使用 v2 Security Command Center API 创建和管理这些导出配置。不过,如果您使用 v1 Security Command Center API 创建导出配置,则该配置不会显示在 v2 Security Command Center API 中。同样,如果您使用 v2 Security Command Center API 创建导出配置,则该配置不会显示在 v1 Security Command Center API 中。

此外,您使用 v2 Security Command Center API 创建的导出配置无法使用 source_properties 字段来过滤发现结果。您必须改用其他字段。

控制台

在 Google Cloud 控制台中,如果导出配置是使用 v1 Security Command Center API 创建的,则会带有旧版标签。您可以使用 Google Cloud 控制台管理这些资源。

如果您在 Google Cloud 控制台中创建新的导出配置,则该配置始终是使用 v2 Security Command Center API 创建的。

gcloud

如需管理使用 v1 Security Command Center API 创建的导出配置,请在运行 gcloud CLI 命令(例如 gcloud scc notifications describe)时不要指定位置:

  • 请勿使用 --location 标志。
  • 如果您要提供配置 ID 的完整路径,请使用不指定位置的格式,例如 organizations/123/notificationConfigs/456。请勿使用 organizations/123/locations/global/notificationConfigs/456 等格式。

同样,如需使用 v2 Security Command Center API 创建或管理导出配置,请在运行 gcloud CLI 命令时指定位置。创建新配置时,我们建议您使用 v2 Security Command Center API。

Terraform

Terraform 配置文件会将导出配置定义为 v1 或 v2 资源。例如,请参阅有关通知配置的资源:

创建新配置时,我们建议您创建 v2 资源。

REST

如需管理使用 v1 Security Command Center API 创建的导出配置,您必须使用 v1 Security Command Center API。

创建新配置时,我们建议您使用 v2 Security Command Center API。

客户端库

如需管理使用 v1 Security Command Center API 创建的导出配置,您必须使用适用于 v1 Security Command Center API 的 Cloud 客户端库。

创建新配置时,我们建议您使用 v2 Security Command Center API。

内置服务和自定义模块

借助 v1 Security Command Center API,您可以查看和更新以下资源类型:

如需管理这些资源类型,请使用 Security Command Center Management API 及其客户端库。v2 Security Command Center API 无法管理这些资源类型。

如果您的组织在 2023 年 6 月 20 日之前激活了 Security Command Center,则可以使用 v1 Security Command Center API 查看组织、文件夹或项目中的资产。这些 Security Command Center 资产管理功能已废弃,并且 v2 Security Command Center API 中不提供。这些功能将于 2024 年 6 月 20 日当天或之后从 v1 Security Command Center API 中移除。

不过,您可以使用 Cloud Asset Inventory 查看资产,包括其安全标记。如需了解详情,请参阅列出素材资源

您还可以使用 v2 Security Command Center API 更新资产的安全标记。用于更新安全标记的 Security Command Center API 方法并未被弃用。

更新了客户端库和 Terraform 提供程序

如需更新代码以使用 v2 Security Command Center API,请执行以下操作:

Terraform

安装适用于 Google Cloud的 Terraform 提供程序的当前版本。如需了解详情,请参阅提供程序文档

此外,请更新 Terraform 配置文件,以创建以 google_scc_v2_google_scc_management_ 开头的资源。请注意,以下资源不会在 v1 API 和 v2 API 之间共享

如果您应用的 Terraform 执行计划会将这些资源替换为其 v2 等效项,则 Terraform 会删除 v1 配置并创建新的 v2 配置。

C++

更新应用以添加客户端库的 v2 头文件:

#include "google/cloud/securitycenter/v2/security_center_client.h"

此外,请更新您的应用以使用 v2 命名空间中的类:

namespace securitycenter = ::google::cloud::securitycenter_v2;

C#

安装 v2 客户端库,然后更新您的应用以使用该库:

Install-Package Google.Cloud.SecurityCenter.V2

Go

安装 v2 客户端库,然后更新您的应用以使用该库:

go get cloud.google.com/go/securitycenter/apiv2

Java

安装当前版本的客户端库。如需了解详情,请参阅安装客户端库

此外,请更新您的应用以使用 com.google.cloud.securitycenter.v2 软件包中的类、接口和枚举。

Node.js

安装当前版本的客户端库。如需了解详情,请参阅安装客户端库

此外,请更新您的应用以使用 v2.SecurityCenterClient 以及 protos.google.cloud.securitycenter.v2 命名空间中的类、接口和枚举。

PHP

安装当前版本的客户端库。如需了解详情,请参阅安装客户端库

此外,请更新您的应用以使用 Google \ Cloud \ SecurityCenter \ V2 命名空间中的类和枚举。

Python

安装当前版本的客户端库。如需了解详情,请参阅安装客户端库

此外,请更新您的应用以使用 google.cloud.securitycenter_v2 软件包中的类。

Ruby

安装当前版本的客户端库。如需了解详情,请参阅安装客户端库

此外,请更新您的应用,以便在创建客户端对象时将 version 参数设置为 :v2

如果您需要以编程方式管理 Security Command Center 内置服务及其启用状态,或者 Event Threat Detection 或 Security Health Analytics 的自定义模块,则还必须安装 Security Command Center Management API 的客户端库,并更新您的应用以使用该客户端库。