本页面介绍如何使用 Security Command Center API 通知功能,包括以下示例:
- 创建
NotificationConfig
- 获取
NotificationConfig
- 更新
NotificationConfig
- 删除
NotificationConfig
- 列出
NotificationConfig
- 接收 Pub/Sub 通知
或者,Security Command Center Premium 客户可以在 Security Command Center 信息中心为 Pub/Sub 设置持续导出。
准备工作
要使用此页面上的示例,您需要完成设置发现结果通知指南。
要执行以下示例,您需要具有适当权限的 Identity and Access Management (IAM) 角色:
- 创建
NotificationConfig
:Security Center Notification Configurations Editor (roles/securitycenter.notificationConfigEditor
) - 获取并列出
NotificationConfig
:Security Center Notification Configurations Viewer (roles/securitycenter.notificationConfigViewer
) 或 Security Center Notification Configurations Editor (roles/securitycenter.notificationConfigEditor
) - 更新和删除
NotificationConfig
:Security Center Notification Configurations Editor (roles/securitycenter.notificationConfigEditor
)
如需向访问 notificationConfig
的主账号授予适当的角色,您必须具有以下 IAM 角色之一:
- Organization Administrator (
roles/resourcemanager.organizationAdmin
) - Folder IAM Admin (
roles/resourcemanager.folderIamAdmin
) - Project IAM Admin (
roles/resourcemanager.projectIamAdmin
)
Security Command Center 的 IAM 角色可以在组织、文件夹或项目级层授予。您能否查看、修改、创建或更新发现结果、资产和安全来源,取决于您获授予的访问权限级别。如需详细了解 Security Command Center 角色,请参阅访问权限控制。
数据驻留和通知
如果 Security Command Center 启用了数据驻留,则用于定义持续导出到 Pub/Sub(notificationConfig
资源)的配置受数据驻留控制,并存储在您的 Security Command Center 位置。
如需将某个 Security Command Center 位置中的发现结果导出到 Pub/Sub,您必须在发现结果所在的 Security Command Center 位置配置持续导出。
由于持续导出中使用的过滤条件可能包含受驻留控制措施约束的数据,因此在创建它们之前,请务必指定正确的位置。Security Command Center 不限制您在哪个位置创建导出作业。
持续导出仅存储在创建它们的位置,无法在其他位置查看或修改。
创建持续导出后,便无法更改其位置。如需更改位置,您需要删除持续导出,然后在新位置重新创建。
如需使用 API 调用检索连续导出,您需要在 notificationConfig
的完整资源名称中指定位置。例如:
GET https://securitycenter.googleapis.com/v2/{name=organizations/123/locations/eu/notificationConfigs/my-pubsub-export-01}
同样,如需使用 gcloud CLI 检索连续导出,您需要在配置的完整资源名称中或使用 --locations
标志指定位置。例如:
gcloud scc notifications describe myContinuousExport organizations/123 \ --location=locations/us
创建 NotificationConfig
要创建 NotificationConfig
,您必须具有:
- 您要向其发送通知的现有 Pub/Sub 主题。
- 创建
notificationConfig
的主账号所需的 IAM 角色。
如需了解详情,请参阅设置发现结果通知指南中的设置 Pub/Sub 主题步骤。
创建 NotificationConfig
之前,请注意每个组织只能有一定数量的 NotificationConfig
文件。如需了解详情,请参阅配额和限制。
NotificationConfig
包含一个 filter
字段,用于限制对有用事件的通知。此字段接受 Security Command Center API findings.list
方法中提供的所有过滤条件。
创建 NotificationConfig
时,您需要为 Google Cloud 资源层次结构中的 NotificationConfig
指定一个父项,可以是组织、文件夹或项目。如果您稍后需要检索、更新或删除 NotificationConfig
,则需要在引用时添加父级组织、文件夹或项目的数字 ID。
使用您选择的语言或平台创建 NotificationConfig
:
gcloud
gcloud scc notifications create NOTIFICATION_NAME \ --PARENT=PARENT_ID \ --location=LOCATION --description="NOTIFICATION_DESCRIPTION" \ --pubsub-topic=PUBSUB_TOPIC \ --filter="FILTER"
替换以下内容:
NOTIFICATION_NAME
:通知的名称。长度必须介于 1 到 128 个字符之间,并且只能包含字母数字字符、下划线或连字符。PARENT
:通知适用的资源层次结构中的范围,即organization
、folder
或project
。PARENT_ID
:父级组织、文件夹或项目的 ID,采用organizations/123
、folders/456
或projects/789
格式指定。LOCATION
:如果启用了数据驻留,请指定要在其中创建通知的 Security Command Center 位置。生成的notificationConfig
资源仅存储在此位置。系统仅会将在此位置发布的发现结果发送到 Pub/Sub。如果未启用数据驻留,则指定
--location
标志会使用 Security Command Center API v2 创建通知,并且该标志的唯一有效值为global
。NOTIFICATION_DESCRIPTION
:不超过 1024 个字符的通知说明。PUBSUB_TOPIC
:将接收通知的 Pub/Sub 主题。其格式为projects/PROJECT_ID/topics/TOPIC
。FILTER
:您定义的表达式,用于选择将哪些发现结果发送到 Pub/Sub。例如state="ACTIVE"
。
Python
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Java
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Go
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Node.js
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
PHP
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Ruby
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
C#
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
通知现已发布到您指定的 Pub/Sub 主题。
如需发布通知,系统会以 service-org-ORGANIZATION_ID@gcp-sa-scc-notification.iam.gserviceaccount.com
的形式为您创建一个服务账号。此服务账号是在您创建第一个 NotificationConfig
时由系统创建的,并在创建通知配置时被自动授予 PUBSUB_TOPIC 的 IAM 政策上的 securitycenter.notificationServiceAgent
角色。需要此服务账号角色才能接收通知。
获取 NotificationConfig
如需获取 NotificationConfig
,您必须具有包含 securitycenter.notification.get
权限的 IAM 角色。
gcloud
gcloud scc notifications describe PARENT_TYPE/PARENT_ID/locations/LOCATION/notificationConfigs/NOTIFICATION_NAME
替换以下内容:
- 将
PARENT_TYPE
替换为organizations
、folders
或projects
,具体取决于在通知配置中指定的资源层次结构的级别。 - 将
PARENT_ID
替换为父资源的数字 ID。 LOCATION
:如果已启用数据驻留,或者notificationConfig
资源是使用 API v2 创建的,则为必需。如果启用了数据驻留,请指定存储通知的 Security Command Center 位置。
如果未启用数据驻留,请仅在
notificationConfig
资源是使用 Security Command Center API v2 创建的情况下添加/locations/LOCATION
(在这种情况下,唯一有效的位置是global
)。NOTIFICATION_NAME
:通知的名称。
Python
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Java
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Go
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Node.js
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
PHP
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Ruby
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
C#
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
更新 NotificationConfig
要更新 NotificationConfig
,您必须具有包含 securitycenter.notification.update
权限的 IAM 角色。
使用字段掩码更新时,只有指定的字段才会更新。如果您不使用字段掩码,则 NotificationConfig
中的所有可变字段都将替换为新值。您可以使用字段掩码来更新 Pub/Sub 主题和说明。
如需完成此示例,您必须订阅新主题,并且您的通知服务账号必须具有该主题的 pubsub.topics.setIamPolicy
权限。
授予必要的权限后,使用您选择的语言更新 NotificationConfig
说明、Pub/Sub 主题和过滤条件:
gcloud
gcloud scc notifications update PARENT_TYPE/PARENT_ID/locations/LOCATION/notificationConfigs/NOTIFICATION_NAME
--description="NOTIFICATION_DESCRIPTION" \
--pubsub-topic=PUBSUB_TOPIC \
--filter="FILTER"
替换以下内容:
- 将
PARENT_TYPE
替换为organizations
、folders
或projects
,具体取决于在通知配置中指定的资源层次结构的级别。 - 将
PARENT_ID
替换为父资源的数字 ID。 LOCATION
:如果启用了数据驻留或notificationConfig
是使用 API v2 创建的,则需要。如果启用了数据驻留,请指定存储通知的 Security Command Center 位置。
如果未启用数据驻留,则仅当
notificationConfig
资源是使用 Security Command Center API v2 创建时,才在全名中包含/locations/LOCATION
或指定--location
标志(在这种情况下,唯一有效的位置是global
)。NOTIFICATION_NAME
:通知的名称。NOTIFICATION_DESCRIPTION
:不超过 1024 个字符的通知说明。PUBSUB_TOPIC
:将接收通知的 Pub/Sub 主题。其格式为projects/PROJECT_ID/topics/TOPIC
。FILTER
:您定义的表达式,用于选择将哪些发现结果发送到 Pub/Sub。例如state="ACTIVE"
。
Python
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Java
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Go
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Node.js
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
PHP
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Ruby
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
C#
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
删除 NotificationConfig
要删除 NotificationConfig
,您必须具有包含 securitycenter.notification.delete
权限的 IAM 角色。
删除 NotificationConfig
时,securitycenter.notificationServiceAgent
角色将保留在 Pub/Sub 主题上。如果您在任何其他 NotificationConfig
中使用 Pub/Sub 主题,请从主题中移除该角色。如需了解详情,请参阅访问控制。
使用您选择的语言删除 NotificationConfig
:
gcloud
gcloud scc notifications delete PARENT_TYPE/PARENT_ID/locations/LOCATION/notificationConfigs/NOTIFICATION_NAME
替换以下内容:
- 将
PARENT_TYPE
替换为organizations
、folders
或projects
,具体取决于在通知配置中指定的资源层次结构的级别。 - 将
PARENT_ID
替换为父资源的数字 ID。 LOCATION
:如果启用了数据驻留或notificationConfig
是使用 API v2 创建的,则需要。如果启用了数据驻留,请指定存储通知的 Security Command Center 位置。
如果未启用数据驻留,则仅当
notificationConfig
是使用 Security Command Center API v2 创建时,才在全名中包含/locations/LOCATION
或指定--location
标志(在这种情况下,唯一有效的位置是global
)。NOTIFICATION_NAME
:通知的名称。
Python
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Java
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Go
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Node.js
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
PHP
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Ruby
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
C#
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
列出 NotificationConfig
要列出 NotificationConfigs
,您必须拥有一个包含 securitycenter.notification.list
权限的 IAM 角色。
所有 Security Command Center API 列表均已分页。每个响应都会返回一个结果页面和一个返回下一页的令牌。默认 pageSize
为 10。您可以将页面大小配置为最小值 1,最大值 1000。
使用您选择的语言列出 NotificationConfigs
:
gcloud
gcloud scc notifications list PARENT_TYPE/PARENT_ID/locations/LOCATION
替换以下内容:
- 将
PARENT_TYPE
替换为organizations
、folders
或projects
,具体取决于您列出通知的范围。 - 将
PARENT_ID
替换为父资源的数字 ID。 LOCATION
:如果已启用数据驻留,或者notificationConfig
资源是使用 API v2 创建的,则为必需。如果启用了数据驻留,请指定存储通知的 Security Command Center 位置。
如果未启用数据驻留,则在名称中包含
/locations/LOCATION
或命令中的--location
标志只会列出使用 Security Command Center API v2 创建的notificationConfig
资源,并且唯一有效的位置是global
。
Python
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Java
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Go
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Node.js
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
PHP
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
Ruby
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
C#
以下示例使用 v1 API。如需修改 v2 的示例,请将 v1
替换为 v2
,并将 /locations/LOCATION
添加到资源名称中。
对于大多数资源,请在资源名称的 /PARENT/PARENT_ID
后添加 /locations/LOCATION
,其中 PARENT
为 organizations
、folders
或 projects
。
对于发现结果,请在资源名称的 /sources/SOURCE_ID
后添加 /locations/LOCATION
,其中 SOURCE_ID
是发出发现结果的 Security Command Center 服务的 ID。
接收 Pub/Sub 通知
本部分提供了一个示例通知消息和示例,展示如何将 Pub/Sub 消息转换为包含发现结果的 NotificationMessage
。
通知以 JSON
格式发布到 Pub/Sub。以下是通知消息的示例:
{
"notificationConfigName": "organizations/ORGANIZATION_ID/notificationConfigs/CONFIG_ID",
"finding": {
"name": "organizations/ORGANIZATION_ID/sources/SOURCE_ID/findings/FINDING_ID",
"parent": "organizations/ORGANIZATION_ID/sources/SOURCE_ID",
"state": "ACTIVE",
"category": "TEST-CATEGORY",
"securityMarks": {
"name": "organizations/ORGANIZATION_ID/sources/SOURCE_ID/findings/FINDING_ID/securityMarks"
},
"eventTime": "2019-07-26T07:32:37Z",
"createTime": "2019-07-29T18:45:27.243Z"
}
}
使用您选择的语言将 Pub/Sub 消息转换为 NotificationMessage
:
gcloud
gcloud CLI 不支持将 Pub/Sub 消息转换为 NotificationMessage
。您可以使用 gcloud CLI 获取 NotificationMessage
并直接在终端中输出 JSON
:
# The subscription used to receive published messages from a topic
PUBSUB_SUBSCRIPTION="projects/PROJECT_ID/subscriptions/SUBSCRIPTION_ID"
gcloud pubsub subscriptions pull $PUBSUB_SUBSCRIPTION
替换以下内容:
- PROJECT_ID 替换为您的项目 ID。
- 将 SUBSCRIPTION_ID 替换为您的订阅 ID。
Python
Java
Go
Node.js
PHP
后续步骤
- 了解如何过滤通知。