This page describes how to use the Security Command Center API notifications feature, including the following examples:
- Create a
NotificationConfig - Get a
NotificationConfig - Update a
NotificationConfig - Delete a
NotificationConfig - List
NotificationConfig - Receive Pub/Sub notifications
Alternatively, you can set up continuous exports for Pub/Sub in Security Command Center.
Before you begin
To use the examples on this page, you need to complete the guide to set up finding notifications.
To execute the following examples, you need an Identity and Access Management (IAM) role with appropriate permissions:
- Create
NotificationConfig: Security Center Notification Configurations Editor (roles/securitycenter.notificationConfigEditor) - Get and List
NotificationConfig: Security Center Notification Configurations Viewer (roles/securitycenter.notificationConfigViewer) or Security Center Notification Configurations Editor (roles/securitycenter.notificationConfigEditor) - Update and Delete
NotificationConfig: Security Center Notification Configurations Editor (roles/securitycenter.notificationConfigEditor)
To grant appropriate roles to a principal that accesses a notificationConfig,
you must have one of the following IAM roles:
- Organization Administrator (
roles/resourcemanager.organizationAdmin) - Folder IAM Admin (
roles/resourcemanager.folderIamAdmin) - Project IAM Admin (
roles/resourcemanager.projectIamAdmin)
The IAM roles for Security Command Center can be granted at the organization, folder, or project level. Your ability to view, edit, create, or update findings, assets, and security sources depends on the level that you're granted access for. To learn more about Security Command Center roles, see Access control.
Data residency and notifications
If data residency
is enabled for Security Command Center, the configurations that define
continuous exports to
Pub/Sub—notificationConfig resources—are subject
to data residency control and are stored in your
Security Command Center location.
To export findings in a Security Command Center location to Pub/Sub, you must configure the continuous export in the same Security Command Center location as the findings.
Because the filters that are used in continuous exports can contain data that is subject to residency controls, make sure you specify the correct location before you create them. Security Command Center does not restrict which location you create exports in.
Continuous exports are stored only in the location in which they are created and cannot be viewed or edited in other locations.
After you create a continuous export, you can't change its location. To change the location, you need to delete the continuous export and recreate it in the new location.
To learn how to use Security Command Center when data residency is enabled, see Security Command Center regional endpoints.
Creating a NotificationConfig
To create a NotificationConfig, you must have:
- An existing Pub/Sub topic that you want to send notifications to.
- Required IAM roles for the principal that creates the
notificationConfig.
For more information, see the step to set up a Pub/Sub topic in the guide to set up finding notifications.
Before you create a NotificationConfig, note that each organization can have a
limited number of NotificationConfig files. For more information, see
Quotas and limits.
The NotificationConfig includes a filter field that limits notifications to
useful events. This field accepts all of the filters that are available in the
Security Command Center API findings.list
method.
When you create a NotificationConfig, you specify a parent for the
NotificationConfig from the Google Cloud resource hierarchy, either an
organization, a folder, or a project. If you need to retrieve, update, or delete
the NotificationConfig later, you need to include the numerical ID of the
parent organization, folder, or project when you reference it.
To create the NotificationConfig using the language or platform of your
choice:
gcloud
gcloud scc notifications create NOTIFICATION_NAME \ --PARENT=PARENT_ID \ --location=LOCATION \ --description="NOTIFICATION_DESCRIPTION" \ --pubsub-topic=PUBSUB_TOPIC \ --filter="FILTER"
Replace the following:
NOTIFICATION_NAME: the name of the notification. Must be between 1 and 128 characters and contain alphanumeric characters, underscores, or hyphens only.PARENT: the scope in the resource hierarchy to which the notification applies,organization,folder, orproject.PARENT_ID: the ID of the parent organization, folder, or project, specified in the format oforganizations/123,folders/456, orprojects/789.LOCATION: the Security Command Center location in which to create aNotificationConfig; if data residency is enabled, useeu,sa, orus; otherwise, use the valueglobal.NOTIFICATION_DESCRIPTION: a description of the notification of no more than 1,024 characters.PUBSUB_TOPIC: The Pub/Sub topic that will receive notifications. Its format isprojects/PROJECT_ID/topics/TOPIC.FILTER: the expression you define to select which findings get sent to Pub/Sub. For example,state=\"ACTIVE\".
Terraform
Create a NotificationConfig for an organization:
Create a NotificationConfig for a folder:
Create a NotificationConfig for a project: