This page explains how to create, view, update, and delete custom modules for Security Health Analytics by using either the Google Cloud console or Google Cloud CLI.
For more introductory information, see Overview of custom modules for Security Health Analytics.
Before you begin
Before you can work with custom modules, you need the following prerequisites:
- Security Health Analytics must be enabled. For information about enabling Security Health Analytics, see Enable or disable a built-in service.
- Your user account must be granted one or more Identity and Access Management (IAM) roles that contain the required permissions. For more information, see Required IAM permissions.
- If you intend to write your own custom modules and upload them to
Security Command Center by using
gcloudcommands, you need the Google Cloud CLI. For information about installing the gcloud CLI, see Install the gcloud CLI. - If the Security Command Center API is not already enabled, you need to enable it before you can use custom modules for Security Health Analytics. You can enable the Security Command Center API on the API Library page in the Google Cloud console.
- To understand the usage limits for Security Health Analytics, see Custom module quotas.
Required IAM permissions
To work with custom modules, you need the following Identity and Access Management (IAM) permissions:
| Permission | Role |
|---|---|
| securitycenter.securityhealthanalyticscustommodules.create securitycenter.securityhealthanalyticscustommodules.update securitycenter.securityhealthanalyticscustommodules.delete |
roles/securitycenter.settingsEditor roles/securitycenter.admin |
| securitycenter.securityhealthanalyticscustommodules.get securitycenter.securityhealthanalyticscustommodules.list |
roles/securitycenter.settingsViewer roles/securitycenter.adminViewer roles/securitycenter.admin |
| securitycenter.securityhealthanalyticscustommodules.test | roles/securitycenter.securityHealthAnalyticsCustomModulesTester roles/securitycenter.adminViewer roles/securitycenter.adminEditor roles/securitycenter.admin |
For more information about IAM permissions and roles and how to grant them, see Grant an IAM role by using the Google Cloud console.
Create a custom module
This section explains how to create custom modules using the Google Cloud console, the gcloud CLI, or Terraform.
To test your custom module as a step in the creation process, you need to prepare test resource definitions in a YAML file. For instructions, see Create test resources in a YAML file.
To create a custom module, select the method that you want to use from the following tabs:
Google Cloud console
To create a custom module in the Google Cloud console, complete the following steps:
Go to the Security Command Center Settings page in the Google Cloud console.
If prompted, select the organization, folder, or project in which you need to create the custom module.
On the Security Health Analytics card, click Manage Settings.
Click the Modules tab.
Click Create module. The Create module for Security Health Analytics page opens.
On the Configure module panel, define the display name, resources to scan, and the detection logic:
In the Module name field, specify a name for the module. The name must be between 1 and 128 characters, start with a lowercase letter, and contain alphanumeric characters or underscores only. This name becomes the finding category of the findings that this detector produces. You can't change the name after the module is created.
Under Add resource type, specify one to five resource types to scan. You cannot specify a resource type more than once.
For a list of supported resource types, see Supported resource types.
In the Expression editor, write CEL expressions to run boolean checks on one or more properties of the resource that you specified in the last step. To trigger a finding, the expression must resolve to
TRUE. For example, the following expression triggers a finding if aCryptoKeyresource has a rotation period defined and the rotation period is longer than 2,592,000 seconds (30 days):has(resource.rotationPeriod) && (resource.rotationPeriod > duration('2592000s'))For more information, see the following:
Click Next. The Define finding details panel opens.
On the Define finding details panel, describe the issue that the custom module detects, including its severity, what the issue is, how to fix the issue, and any data that you want to include in the findings as custom source properties:
In the Severity field, specify the severity of the issue. You can specify
Low,Medium,High, orCritical.Mediumis the default.For information about severity levels, see Severity classifications for findings.
In the Finding description field, explain the issue that the custom module detects. This explanation appears in each finding instance to help security teams understand and address the detected issue.
In the Finding next steps field, explain the steps that your security team can take to fix or otherwise address the detected issue.
The steps display with each finding instance. Include specific steps that the security team can take to address the issue as quickly as possible.
Optional: In the Custom finding properties field, specify up to 10 name-value pairs to define custom source properties to return with each finding instance. The information is returned as source properties in the finding JSON and is displayed on the Source properties tab in the finding details in the Google Cloud console. Specify the text or property values as key-value pairs:
- In the Property name field, specify a name for the custom
source property. The name must conform to the following rules:
- The name must begin with a lowercase letter.
- The name must contain only alphanumeric characters or underscores.
- The name must be between 1 and 128 characters in length.
- Each name must be unique among the other source properties.
- In the Property value field, specify one of the following
values in 1024 characters or less:
- A text string enclosed in quotation marks. The quotation marks
are included in the 1024 character limit. For example,
"This string provides additional useful information." - Any property of the resource that is being scanned.
For example, if you are checking the
CryptoKeyresource, you might specifyresource.rotationPeriod. The value of therotationPeriodproperty is returned.
- A text string enclosed in quotation marks. The quotation marks
are included in the 1024 character limit. For example,
- In the Property name field, specify a name for the custom
source property. The name must conform to the following rules:
Click Next. The Enable module panel opens.
Optional: Use the drop-down menu of the Enable module panel to specify whether the custom module is enabled or disabled upon creation. By default, custom modules are enabled upon creation. If you specify Disable, you can enable the module later on the Modules tab in the Security Health Analytics settings page.
Click Next. The Test module panel opens.
Optional: Before you create your custom module, we recommend that you test it.
To test a custom module, follow these steps:
Create a YAML file that contains test resource definitions for the resources that your custom module checks.
For information about how to create a test data file, see Create test resources in a YAML file.
Under Upload the YAML file, click Browse to upload the YAML file that contains the test resource definitions. The test starts automatically when the file is uploaded.
Under Test results preview, check the results.
- If there are syntax or other errors in your YAML file, a floating error message displays near the bottom of the browser page.
If the test is a success, the test returns the following information:
- The display name of the custom module.
- The arbitrary name that you specified on the
resourceproperty in the test data file. - The organization, folder, or project in which the custom module was, or will be, created.
Test results are not stored or written to Security Command Center.
For more information, see Testing custom modules.
Click Create. You are returned to the Modules page and should see the module that you created with a status of Enabled.
New custom modules are not immediately available for use by Security Health Analytics in scans. For more information, see Detection latency.
gcloud CLI
To create a custom module by using gcloud commands, you first need to
code the definition of the custom module in a YAML file that includes
CEL expressions for the detection logic and output properties.
After the definition is complete, you upload the definition to Security Command Center by using gcloud CLI commands.
- Code a custom module definition in a YAML file according to the instructions in Code a custom module for Security Health Analytics.
- Save the YAML file to a location that is accessible to your instance of gcloud CLI.
Upload the custom definition to Security Command Center:
gcloud scc custom-modules sha create \ PARENT_FLAG=PARENT_ID \ --display-name="MODULE_DISPLAY_NAME" \ --enablement-state="ENABLEMENT_STATE" \ --custom-config-from-file=MODULE_FILE_NAME.yaml
Replace the following:
PARENT_FLAG: the level at which you are creating the custom module, either--organization,--folder, or--project.PARENT_ID: the ID of the organization, folder, or project in which you are creating the custom module.ENABLEMENT_STATE: eitherenabledordisabled.MODULE_DISPLAY_NAME: the finding category name that you want to display when the custom module returns a finding. The name must be between 1 and 128 characters, start with a lowercase letter, and contain alphanumeric characters or underscores only.MODULE_FILE_NAME: the path and filename of the YAML file that contains the definition of the custom module.
Terraform
Create a custom module for an organization:
Create a custom module for a folder:
Create a custom module for a project:
Detection latency
After you create or update the definition of a custom module, there can be a delay of up to several hours before the new or updated custom module is available for use in scans.
Creating or modifying a custom module doesn't trigger a scan. After a custom module is available for use, Security Health Analytics doesn't start using the custom modules until either the first batch scan or a change to the configuration of the target resource triggers a real-time scan.
For more information about Security Health Analytics scan types, see Security Health Analytics scan types.
Update a custom module
You can update most properties of Security Health Analytics custom modules.
The following properties of a custom module cannot be changed:
- The display name.
- The custom module ID.
- The full resource name of the custom module.
When you update a custom module, any findings that the custom module generated previously are not updated at the same time. If the changes to the module result in changes to the generated findings, the findings will reflect the changes only after the next Security Health Analytics batch or real-time scan.
To modify a custom module, you can use either the Google Cloud console or the gcloud CLI. Click one of the following tabs for instructions.
Google Cloud console
To update an existing custom module in the Google Cloud console, follow these steps:
Go to the Security Command Center Settings page in the Google Cloud console.