在 Security Command Center 中忽略发现结果

本页面介绍了如何通过忽略发现结果来减少您在 Security Command Center 中收到的发现结果数量。

如果忽略某个发现结果,Google Cloud 控制台中的发现结果默认视图中就不会显示该发现结果。您可以手动或以编程方式忽略发现结果并创建过滤条件,以根据您指定的条件自动忽略现有和未来的发现结果。

Security Command Center 检测服务可为您的 Google Cloud 部署提供广泛的安全评估,但您可能会发现某些发现结果不适用于您的组织或项目。大量的发现结果还可能导致安全分析师难以有效识别和消除最关键的风险。忽略发现结果可以为您节省查看或响应隔离或属于可接受的业务参数的资产的安全性发现结果的时间。

停用检测器相比,忽略发现结果有以下几个优势:

  • 您可以创建自定义过滤条件,以微调要忽略的发现结果。
  • 忽略发现结果不会停止扫描底层资源。发现结果仍会生成,但在您决定查看它们之前会保持隐藏状态。

权限

如需忽略发现结果,您需要组织文件夹项目级别的以下某个 Identity and Access Management (IAM) 角色:

  • 查看忽略规则:
    • Security Center Admin Viewer (roles/securitycenter.adminViewer)
    • Security Center Settings Viewer (roles/securitycenter.settingsViewer)
    • Security Center Mute Configurations Viewer (roles/securitycenter.muteConfigsViewer)
  • 查看、创建、更新和删除忽略规则:
    • Security Center Admin (roles/securitycenter.admin)
    • Security Center Admin Editor (roles/securitycenter.adminEditor)
    • Security Center Settings Editor (roles/securitycenter.settingsEditor)
    • Security Center Mute Configurations Editor (roles/securitycenter.muteConfigsEditor)
  • 手动忽略发现结果:
    • Security Center Findings Editor (roles/securitycenter.findingsEditor)

您还可以创建并授予具有以下部分或全部权限的自定义角色

  • 忽略规则读取权限
    • securitycenter.muteconfigs.get
    • securitycenter.muteconfigs.list
  • 忽略规则写入权限
    • securitycenter.muteconfigs.create
    • securitycenter.muteconfigs.update
    • securitycenter.muteconfigs.delete
  • 发现结果写入权限
    • securitycenter.findings.setMute
    • securitycenter.findings.bulkMuteUpdate

您忽略发现结果的能力遵循在组织、文件夹或项目级层授予的角色。您可以忽略特定文件夹或项目中的发现结果,并限制其他人员根据他们获得的访问权限忽略发现结果的能力。例如,如果您有权访问单个项目,则只能忽略该项目中的发现结果。如果您有权访问某一文件夹,则可以忽略该文件夹内任何子文件夹或项目中的发现结果。

如需详细了解 Security Command Center 角色,请参阅访问权限控制

创建和管理忽略规则

忽略规则是 Security Command Center 配置,它们使用您创建的过滤条件,根据您指定的条件自动忽略未来的发现结果。匹配忽略过滤条件的新发现结果将持续自动忽略。如果您还希望忽略类似的现有发现结果,请使用相同的过滤条件批量忽略发现结果

忽略规则的范围

在创建过滤器时,请考虑忽略规则的范围。

例如,如果编写一个过滤条件以忽略 Project A 中的发现结果,但该过滤条件本身是在 Project B 下创建的,则该过滤条件可能不匹配任何发现结果。

同样,如果启用了数据驻留,则忽略规则的范围将限制为创建忽略规则的 Security Command Center 位置。例如,如果您在美国 (us) 位置创建忽略规则,则忽略规则不会忽略存储在欧盟 (eu) 或全球 (global) 位置的发现结果。如需详细了解数据驻留和忽略规则,请参阅忽略规则、持续导出和数据驻留

如需详细了解如何创建过滤条件,请参阅过滤通知

忽略规则限制

忽略规则并不支持所有发现结果属性。如需查看忽略规则不支持的属性列表,请参阅忽略规则不支持的发现结果属性

您可以根据 IAM 角色的范围创建、查看、更新和删除忽略规则。使用组织级层角色,您可以查看组织中所有文件夹和项目的忽略规则。如果您拥有文件夹级层角色,则可以访问和管理特定文件夹以及这些文件夹中所有子文件夹和项目的忽略规则。项目级层角色可让您管理特定项目中的忽略规则。

Security Command Center Premium 支持在组织、文件夹和项目级层授予角色。Security Command Center Standard 仅支持在组织级层授予角色。如需了解详情,请参阅访问权限控制

数据驻留和忽略规则

如果启用了数据驻留,则定义忽略规则的配置(muteConfig 资源)会受到数据驻留控制,并且会存储在您选择的 Security Command Center 位置中。

如需将忽略规则应用于 Security Command Center 位置中的发现结果,您必须在应用发现结果所在的位置创建忽略规则。

由于忽略规则中使用的过滤条件可能包含受驻留控制措施约束的数据,因此请确保在创建它们之前指定正确的位置。Security Command Center 不会限制您在哪个位置创建忽略规则或流式导出。

忽略规则只会存储在创建它们的位置,无法在其他位置查看或修改。

创建忽略规则后,便无法更改其位置。 如需更改位置,您需要删除忽略规则,然后在新位置重新创建该规则。

如需在 Google Cloud 控制台中查看忽略规则,您首先需要将 Google Cloud 控制台视图设置为创建这些规则的位置。

同样的规则也适用于忽略规则的 API 表示法 MuteConfig

如需使用 API 调用来检索 MuteConfig,您需要在 MuteConfig 的完整资源名称中指定位置。例如:

GET https://securitycenter.googleapis.com/v2/{name=organizations/123/locations/eu/muteConfigs/my-mute-rule-01}

同样,如需使用 gcloud CLI 检索 muteConfig,您可以使用 --locations 标志指定位置。例如:

gcloud scc muteconfigs list --organizations=123
--location=us

创建忽略规则

您的组织最多可以创建 1,000 条忽略规则。

您可以使用 Google Cloud 控制台、gcloud CLI 或 Security Command Center API 创建忽略规则。

如需查看创建忽略规则的示例代码,请参阅创建忽略规则

如需创建忽略规则,请点击您要使用的过程所在的标签页:

控制台

  1. 在 Google Cloud 控制台中,转到 Security Command Center 发现结果页面。

    转至“发现结果”

  2. 如有必要,请选择您的 Google Cloud 项目或组织。

    项目选择器

  3. 如果 Security Command Center 启用了数据驻留,请使用项目选择器正下方的位置选择器来选择要在哪个 Security Command Center 位置创建忽略规则。例如:

    位置选择器的屏幕截图

  4. 点击忽略选项,然后选择创建忽略规则

  5. 输入忽略规则 ID。必须提供此值。

  6. 输入忽略规则说明,其提供为何忽略发现结果的上下文。该值是可选的,但我们建议您使用。

    父级资源表示将创建和应用忽略规则的范围。

  7. 发现结果查询字段中,通过点击添加过滤条件来构建查询语句。或者,您也可以手动输入查询语句。

    选择过滤条件对话框中,您可以选择支持的发现结果属性和值。 查询过滤条件对话框

    1. 选择发现结果特性或在搜索发现结果特性框中输入其名称。 系统会显示可用子特性的列表。
    2. 选择子特性。评估选项的选择字段显示在位于发现结果的查询结果面板中的发现结果的子特性值列表上方。
    3. 为所选子特性的值选择评估选项。如需详细了解评估选项及其使用的运算符和函数,请参阅“添加过滤条件”菜单中的查询运算符
    4. 选择应用

      对话框将会关闭,并且您的查询即会更新。

    5. 重复这些步骤,直到发现结果查询包含所需的所有特性。

  8. 查看过滤条件,以确保准确性。如需进行更改,请根据需要删除或添加属性和过滤条件值。

  9. 点击预览匹配的发现结果

    表会显示与您的查询匹配的发现结果。

  10. 点击保存

gcloud

  1. 在 Google Cloud 控制台中,激活 Cloud Shell。

    激活 Cloud Shell

    Cloud Shell 会话随即会在 Google Cloud 控制台的底部启动,并显示命令行提示符。Cloud Shell 是一个已安装 Google Cloud CLI 且已为当前项目设置值的 Shell 环境。该会话可能需要几秒钟时间来完成初始化。

  2. 如需创建忽略规则,请运行 gcloud scc muteconfigs create 命令:

    gcloud scc muteconfigs create CONFIG_ID \
    --PARENT=PARENT_ID \
    --location=LOCATION
    --description="RULE_DESCRIPTION" \
    --filter="FILTER"
    

    请替换以下内容:

    • CONFIG_ID:忽略规则的名称。此 ID 必须使用字母数字字符和连字符,并且长度介于 1 到 63 个字符之间。
    • PARENT:应用忽略规则的资源层次结构中的范围,即 organizationfolderproject
    • PARENT_ID:父级组织、文件夹或项目的 ID,采用 organizations/123folders/456projects/789 格式指定。
    • LOCATION:如果启用了数据驻留,请指定要在其中创建忽略规则的 Security Command Center 位置。系统会存储忽略规则配置,该配置仅适用于此位置中的发现结果。

      如果未启用数据驻留,则指定 --location 标志会使用 Security Command Center API v2 创建忽略规则,并且该标志的唯一有效值为 global

    • RULE_DESCRIPTION:忽略规则的说明(不超过 1024 个字符)。

    • FILTER:您定义的用于过滤结果的表达式。例如,如需忽略 OPEN_FIREWALL 发现结果,您可以使用 FILTER="category=\"OPEN_FIREWALL\"" 过滤条件。

    响应包含忽略规则 ID,可用于查看、更新和删除忽略规则,如管理忽略规则中所述。

Go

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv1"
	"cloud.google.com/go/securitycenter/apiv1/securitycenterpb"
)

// createMuteRule: Creates a mute configuration under a given scope that will mute
// all new findings that match a given filter.
// Existing findings will not be muted.
func createMuteRule(w io.Writer, parent string, muteConfigId string) error {
	// parent: Use any one of the following options:
	//             - organizations/{organization_id}
	//             - folders/{folder_id}
	//             - projects/{project_id}
	// parent := fmt.Sprintf("projects/%s", "your-google-cloud-project-id")
	// muteConfigId: Set a random id; max of 63 chars.
	// muteConfigId := "random-mute-id-" + uuid.New().String()
	ctx := context.Background()
	client, err := securitycenter.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("securitycenter.NewClient: %w", err)
	}
	defer client.Close()

	muteConfig := &securitycenterpb.MuteConfig{
		Description: "Mute low-medium IAM grants excluding 'compute' ",
		// Set mute rule(s).
		// To construct mute rules and for supported properties, see:
		// https://cloud.google.com/security-command-center/docs/how-to-mute-findings#create_mute_rules
		Filter: "severity=\"LOW\" OR severity=\"MEDIUM\" AND " +
			"category=\"Persistence: IAM Anomalous Grant\" AND " +
			"-resource.type:\"compute\"",
	}

	req := &securitycenterpb.CreateMuteConfigRequest{
		Parent:       parent,
		MuteConfigId: muteConfigId,
		MuteConfig:   muteConfig,
	}

	response, err := client.CreateMuteConfig(ctx, req)
	if err != nil {
		return fmt.Errorf("failed to create mute rule: %w", err)
	}
	fmt.Fprintf(w, "Mute rule created successfully: %s", response.Name)
	return nil
}

Java

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import com.google.cloud.securitycenter.v1.CreateMuteConfigRequest;
import com.google.cloud.securitycenter.v1.MuteConfig;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import java.io.IOException;
import java.util.UUID;

public class CreateMuteRule {

  public static void main(String[] args) {
    // TODO: Replace the variables within {}

    // parentPath: Use any one of the following options:
    //             - organizations/{organization_id}
    //             - folders/{folder_id}
    //             - projects/{project_id}
    String parentPath = String.format("projects/%s", "your-google-cloud-project-id");

    // muteConfigId: Set a random id; max of 63 chars.
    String muteConfigId = "random-mute-id-" + UUID.randomUUID();
    createMuteRule(parentPath, muteConfigId);
  }

  // Creates a mute configuration under a given scope that will mute
  // all new findings that match a given filter.
  // Existing findings will not be muted.
  public static void createMuteRule(String parentPath, String muteConfigId) {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      MuteConfig muteConfig =
          MuteConfig.newBuilder()
              .setDescription("Mute low-medium IAM grants excluding 'compute' ")
              // Set mute rule(s).
              // To construct mute rules and for supported properties, see:
              // https://cloud.google.com/security-command-center/docs/how-to-mute-findings#create_mute_rules
              .setFilter(
                  "severity=\"LOW\" OR severity=\"MEDIUM\" AND "
                      + "category=\"Persistence: IAM Anomalous Grant\" AND "
                      + "-resource.type:\"compute\"")
              .build();

      CreateMuteConfigRequest request =
          CreateMuteConfigRequest.newBuilder()
              .setParent(parentPath)
              .setMuteConfigId(muteConfigId)
              .setMuteConfig(muteConfig)
              .build();

      // ExecutionException is thrown if the below call fails.
      MuteConfig response = client.createMuteConfig(request);
      System.out.println("Mute rule created successfully: " + response.getName());
    } catch (IOException e) {
      System.out.println("Mute rule creation failed! \n Exception: " + e);
    }
  }
}

Python

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。



def create_mute_rule(parent_path: str, mute_config_id: str) -> None:
    """
    Creates a mute configuration under a given scope that will mute
    all new findings that match a given filter.
    Existing findings will NOT BE muted.
    Args:
        parent_path: use any one of the following options:
                     - organizations/{organization_id}
                     - folders/{folder_id}
                     - projects/{project_id}
        mute_config_id: Set a unique id; max of 63 chars.
    """

    from google.cloud import securitycenter

    client = securitycenter.SecurityCenterClient()

    mute_config = securitycenter.MuteConfig()
    mute_config.description = "Mute low-medium IAM grants excluding 'compute' "
    # Set mute rule(s).
    # To construct mute rules and for supported properties, see:
    # https://cloud.google.com/security-command-center/docs/how-to-mute-findings#create_mute_rules
    mute_config.filter = (
        'severity="LOW" OR severity="MEDIUM" AND '
        'category="Persistence: IAM Anomalous Grant" AND '
        '-resource.type:"compute"'
    )

    request = securitycenter.CreateMuteConfigRequest()
    request.parent = parent_path
    request.mute_config_id = mute_config_id
    request.mute_config = mute_config

    mute_config = client.create_mute_config(request=request)
    print(f"Mute rule created successfully: {mute_config.name}")

REST API

在 Security Command Center API 中,使用 muteConfigs create 方法创建忽略规则。请求正文是 MuteConfig 的实例。

除非启用数据驻留,否则您可以使用 Security Command Center API v1 或 v2。API v2 提供预览版。启用数据驻留后,API v2 是唯一可用的 API。

如果您使用的是 Security Command Center API v1,请使用版本 1 端点来调用 muteConfigs create。在请求正文中,使用版本 1 MuteConfig 定义:

POST https://securitycenter.googleapis.com/v1/PARENT/PARENT_ID/muteConfigs?muteConfigId=MUTE_CONFIG_ID -d

  {
    "description": "RULE_DESCRIPTION",
    "filter": FILTER
  }

如果您使用的是 Security Command Center API v2,请使用版本 2 端点来调用 muteConfigs create。在请求正文中,使用版本 2 MuteConfig 定义:

POST https://securitycenter.googleapis.com/v2/PARENT/PARENT_ID/locations/LOCATION/muteConfigs?muteConfigId=MUTE_CONFIG_ID -d

  {
    "description": "RULE_DESCRIPTION",
    "filter": FILTER
    "type": "STATIC"
  }

请替换以下内容:

  • PARENT:忽略规则的父级资源(organizationsfoldersprojects
  • PARENT_ID:父级组织、文件夹或项目的 ID
  • LOCATION:(仅适用于 v2)指定应用忽略规则的 Security Command Center 位置。如果省略位置信息字段,则默认值为 global
  • MUTE_CONFIG_ID:忽略规则的名称(介于 1 到 63 个字符之间)
  • RULE_DESCRIPTION:忽略规则的说明(最多 1024 个字符)
  • FILTER:您定义的用于过滤结果的表达式

    例如,如需忽略 OPEN_FIREWALL 发现结果,您的过滤条件可以是 "category=\"OPEN_FIREWALL\""

响应包括忽略配置 ID,您可以使用该 ID 查看、更新和删除忽略规则,如管理忽略规则中所述。

与过滤条件完全匹配的新发现结果会被隐藏,发现结果的 mute 特性设置为 MUTED

忽略规则不支持的发现结果属性

忽略规则未必支持过滤条件中的所有发现结果属性。忽略规则过滤条件不支持以下属性。

  • createTime
  • eventTime
  • mute
  • mute_initiator
  • mute_update_time
  • name
  • parent
  • security_marks
  • source_properties
  • state

列出忽略规则

您可以使用 Google Cloud 控制台、gcloud CLI 或 Security Command Center API 列出组织、文件夹或项目中的忽略规则。

您能否列出给定范围的忽略规则取决于授予 IAM 角色的权限。

如果为 Security Command Center 启用了数据驻留,则 list 命令的范围也仅限于所选的 Security Command Center 位置

如需查看列出忽略规则的示例代码,请参阅列表忽略规则

如需列出组织、文件夹或项目的忽略规则,请点击您要使用的过程对应的标签页:

控制台

  1. 在 Google Cloud 控制台中,转到 Security Command Center 设置页面中的忽略规则标签页。

    转到“忽略规则”

  2. 如有必要,请选择您的 Google Cloud 项目或组织。

    项目选择器

  3. 如果 Security Command Center 启用了数据驻留,请使用项目选择器正下方的位置选择器,选择存储忽略规则的 Security Command Center 位置。例如:

    位置选择器的屏幕截图

  4. 忽略规则部分中,您可以查看有效忽略规则的详细信息,其中包括:

    • 名称:忽略规则 ID
    • 父级资源:忽略规则所在的资源
    • 说明:忽略规则的说明(如有)
    • 上次更新者为:上次更新规则的主账号
    • 上次更新时间:上次更新规则的日期和时间

gcloud

  1. 在 Google Cloud 控制台中,激活 Cloud Shell。

    激活 Cloud Shell

    Cloud Shell 会话随即会在 Google Cloud 控制台的底部启动,并显示命令行提示符。Cloud Shell 是一个已安装 Google Cloud CLI 且已为当前项目设置值的 Shell 环境。该会话可能需要几秒钟时间来完成初始化。

  2. 如需列出忽略规则,请运行 gcloud scc muteconfigs list 命令:

    gcloud scc muteconfigs list --PARENT=PARENT_ID --location=LOCATION
    

    请替换以下内容:

    • PARENT:要列出其忽略规则的父 organizationfolderproject
    • PARENT_ID:父级组织、文件夹或项目的 ID
    • LOCATION:如果启用了数据驻留,请指定要列出忽略规则的 Security Command Center 位置

      如果未启用数据驻留,则指定 --location 标志会使用 Security Command Center API v2 列出忽略规则,该标志的唯一有效值为 global

Go

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。

import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv1"
	"cloud.google.com/go/securitycenter/apiv1/securitycenterpb"
	"google.golang.org/api/iterator"
)

// listMuteRules lists mute configs at the organization level will return all the configs
// at the org, folder, and project levels.
// Similarly, listing configs at folder level will list all the configs
// at the folder and project levels.
func listMuteRules(w io.Writer, parent string) error {
	// Use any one of the following resource paths to list mute configurations:
	//         - organizations/{organization_id}
	//         - folders/{folder_id}
	//         - projects/{project_id}
	// parent := fmt.Sprintf("projects/%s", "your-google-cloud-project-id")
	ctx := context.Background()
	client, err := securitycenter.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("securitycenter.NewClient: %w", err)
	}
	defer client.Close()

	req := &securitycenterpb.ListMuteConfigsRequest{Parent: parent}

	// List all mute configs present in the resource.
	it := client.ListMuteConfigs(ctx, req)
	for {
		muteconfig, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("it.Next: %w", err)
		}
		fmt.Fprintf(w, "Muteconfig Name: %s, ", muteconfig.Name)
	}
	return nil
}

Java

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import com.google.cloud.securitycenter.v1.ListMuteConfigsRequest;
import com.google.cloud.securitycenter.v1.MuteConfig;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import java.io.IOException;

public class ListMuteRules {

  public static void main(String[] args) {
    // TODO: Replace variables enclosed within {}

    // parent: Use any one of the following resource paths to list mute configurations:
    //         - organizations/{organization_id}
    //         - folders/{folder_id}
    //         - projects/{project_id}
    String parentPath = String.format("projects/%s", "your-google-cloud-project-id");
    listMuteRules(parentPath);
  }

  // Listing mute configs at the organization level will return all the configs
  // at the org, folder, and project levels.
  // Similarly, listing configs at folder level will list all the configs
  // at the folder and project levels.
  public static void listMuteRules(String parent) {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      ListMuteConfigsRequest listMuteConfigsRequest =
          ListMuteConfigsRequest.newBuilder().setParent(parent).build();

      // List all mute configs present in the resource.
      for (MuteConfig muteConfig : client.listMuteConfigs(listMuteConfigsRequest).iterateAll()) {
        System.out.println(muteConfig.getName());
      }
    } catch (IOException e) {
      System.out.println("Listing Mute rule failed! \n Exception: " + e);
    }
  }
}

Python

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。

def list_mute_rules(parent: str) -> None:
    """
    Listing mute configs at organization level will return all the configs
    at the org, folder and project levels.
    Similarly, listing configs at folder level will list all the configs
    at the folder and project levels.
    Args:
        parent: Use any one of the following resource paths to list mute configurations:
                - organizations/{organization_id}
                - folders/{folder_id}
                - projects/{project_id}
    """
    from google.cloud import securitycenter

    client = securitycenter.SecurityCenterClient()

    request = securitycenter.ListMuteConfigsRequest()
    request.parent = parent

    # List all Mute Configs present in the resource.
    for mute_config in client.list_mute_configs(request):
        print(mute_config.name)

REST API

在 Security Command Center API 中,使用 muteConfigs list 方法列出忽略规则。请求正文为空。

除非启用数据驻留,否则您可以使用 Security Command Center API v1 或 v2。API v2 提供预览版。启用数据驻留后,API v2 是唯一可用的 API。

如果您使用的是 Security Command Center API v1,请使用 v1 端点来调用 muteConfigs list

GET https://securitycenter.googleapis.com/v1/PARENT/PARENT_ID/muteConfigs

如果您使用的是 Security Command Center API v2,请使用 v2 端点来调用 muteConfigs list

GET https://securitycenter.googleapis.com/v2/PARENT/PARENT_ID/locations/LOCATION/muteConfigs

请替换以下内容:

  • PARENT:忽略规则的父级资源(organizationsfoldersprojects
  • PARENT_ID:父级组织、文件夹或项目的 ID
  • LOCATION:仅适用于 v2 - 指定要为其列出忽略规则的 Security Command Center 位置。如果省略位置信息字段,则默认值为 global

响应包括忽略规则的名称、说明和忽略配置 ID。

查看忽略规则配置

您可以使用 Google Cloud 控制台、gcloud CLI 或 Security Command Center API 查看忽略规则配置。

如需查看用于检索忽略规则配置的示例代码,请参阅查看忽略规则

如需查看忽略规则配置,请点击您要使用的过程所在的标签页:

控制台

  1. 在 Google Cloud 控制台中,转到 Security Command Center 设置页面中的忽略规则标签页。

    转到“忽略规则”

  2. 如有必要,请选择您的 Google Cloud 项目或组织。

    项目选择器

  3. 如果 Security Command Center 启用了数据驻留,请使用项目选择器正下方的位置选择器来选择忽略规则的 Security Command Center 位置。例如:

    位置选择器的屏幕截图

  4. 忽略规则部分中,您会看到忽略规则列表。

  5. 点击要查看的规则的名称。

    此时将打开一个页面,其中包含忽略规则的配置。

gcloud

  1. 在 Google Cloud 控制台中,激活 Cloud Shell。

    激活 Cloud Shell

    Cloud Shell 会话随即会在 Google Cloud 控制台的底部启动,并显示命令行提示符。Cloud Shell 是一个已安装 Google Cloud CLI 且已为当前项目设置值的 Shell 环境。该会话可能需要几秒钟时间来完成初始化。

  2. 如需查看忽略规则的配置,请运行 gcloud scc muteconfigs get 命令:

    gcloud scc muteconfigs get MUTE_CONFIG_ID \
     --PARENT=PARENT_ID --location=LOCATION
    

    请替换以下内容:

    • MUTE_CONFIG_ID:忽略规则的 ID
    • PARENT:忽略规则的父级资源(organizationfolderproject
    • PARENT_ID:组织、文件夹或项目的 ID
    • LOCATION:如果启用了数据驻留,请指定存储忽略规则的 Security Command Center 位置。默认值为 global

      如果未启用数据驻留,则指定 --location 标志会使用 Security Command Center API v2 获取忽略规则,并且该标志的唯一有效值为 global

Go

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。

import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv1"
	"cloud.google.com/go/securitycenter/apiv1/securitycenterpb"
)

// getMuteRule retrieves a mute configuration given its resource name.
func getMuteRule(w io.Writer, parent string, muteConfigId string) error {
	// Use any one of the following resource paths to get mute configuration:
	//         - organizations/{organization_id}
	//         - folders/{folder_id}
	//         - projects/{project_id}
	// parent := fmt.Sprintf("projects/%s", "your-google-cloud-project-id")
	//
	// Name of the mute config to retrieve.
	// muteConfigId := "mute-config-id"
	ctx := context.Background()
	client, err := securitycenter.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("securitycenter.NewClient: %w", err)
	}
	defer client.Close()

	req := &securitycenterpb.GetMuteConfigRequest{
		Name: fmt.Sprintf("%s/muteConfigs/%s", parent, muteConfigId),
	}

	muteconfig, err := client.GetMuteConfig(ctx, req)
	if err != nil {
		return fmt.Errorf("Failed to retrieve Muteconfig: %w", err)
	}
	fmt.Fprintf(w, "Muteconfig Name: %s ", muteconfig.Name)
	return nil
}

Java

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import com.google.cloud.securitycenter.v1.MuteConfig;
import com.google.cloud.securitycenter.v1.MuteConfigName;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import java.io.IOException;

public class GetMuteRule {

  public static void main(String[] args) {
    // TODO(Developer): Replace the following variables

    // parentPath: Use any one of the following options:
    //             - organizations/{organization_id}
    //             - folders/{folder_id}
    //             - projects/{project_id}
    String parentPath = String.format("projects/%s", "your-google-cloud-project-id");

    // muteConfigId: Name of the mute config to retrieve.
    String muteConfigId = "mute-config-id";

    getMuteRule(parentPath, muteConfigId);
  }

  // Retrieves a mute configuration given its resource name.
  public static void getMuteRule(String projectId, String muteConfigId) {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
      // Use appropriate MuteConfigName methods depending on the type of parent.
      // (org -> MuteConfigName.ofOrganizationMuteConfigName()
      // folder -> MuteConfigName.ofFolderMuteConfigName()
      // project -> MuteConfigName.ofProjectMuteConfigName)
      MuteConfig muteConfig =
          client.getMuteConfig(MuteConfigName.ofProjectMuteConfigName(projectId, muteConfigId));

      System.out.println("Retrieved the mute config: " + muteConfig);
    } catch (IOException e) {
      System.out.println("Mute rule retrieval failed! \n Exception: " + e);
    }
  }
}

Python

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。

def get_mute_rule(mute_config_name: str) -> None:
    """
    Retrieves a mute configuration given its resource name.
    Args:
        mute_config_name: Name of the mute config to retrieve.
                          Use any one of the following formats:
                          - organizations/{organization}/muteConfigs/{config_id}
                          - folders/{folder}/muteConfigs/{config_id}
                          - projects/{project}/muteConfigs/{config_id}
    """
    from google.cloud import securitycenter

    client = securitycenter.SecurityCenterClient()

    request = securitycenter.GetMuteConfigRequest()
    request.name = mute_config_name

    mute_config = client.get_mute_config(request)
    print(f"Retrieved the mute rule: {mute_config.name}")

REST API

在 Security Command Center API 中,使用 muteConfigs get 方法返回忽略规则的配置。请求正文为空。

如需获取忽略规则的 CONFIG_ID,请先对列表忽略规则执行 API 调用。响应包含返回的忽略规则的配置 ID。

除非启用数据驻留,否则您可以使用 Security Command Center API v1 或 v2。API v2 提供预览版。启用数据驻留后,API v2 是唯一可用的 API。

如果您使用的是 Security Command Center API v1,请使用 v1 端点来调用 muteConfigs get

GET https://securitycenter.googleapis.com/v1/PARENT/PARENT_ID/muteConfigs/CONFIG_ID

如果您使用的是 Security Command Center API v2,请使用 v2 端点来调用 muteConfigs get

GET https://securitycenter.googleapis.com/v2/PARENT/PARENT_ID/locations/LOCATION/muteConfigs/CONFIG_ID

请替换以下内容:

  • PARENT:忽略规则的父级资源(organizationsfoldersprojects
  • PARENT_ID:组织、文件夹或项目的 ID
  • LOCATION:仅适用于 v2 指定存储忽略规则的 Security Command Center 位置。如果省略位置信息字段,则默认值为 global
  • CONFIG_ID:忽略规则的数字 ID

更新忽略规则

您可以使用 Google Cloud 控制台、gcloud CLI 或 Security Command Center API 更新忽略规则的说明或发现结果过滤条件。

您无法更改 ID、父级组织、文件夹或项目,也不能更改忽略规则的位置。如需更改上述任何值,您必须创建新的忽略规则。

如果您之前已取消忽略某些发现结果,但它们与 Google Cloud 控制台中更新的忽略规则匹配,则系统会再次忽略这些发现结果。如需了解详情,请参阅取消忽略的发现结果替换忽略规则

如需查看更新忽略规则的示例代码,请参阅更新忽略规则

如需更新忽略规则,请点击您要使用的过程对应的标签页:

控制台

  1. 在 Google Cloud 控制台中,转到 Security Command Center 设置页面中的忽略规则标签页。

    转到“忽略规则”

  2. 选择要修改的忽略规则的父资源的 Google Cloud 项目或组织。项目选择器

  3. 如果 Security Command Center 启用了数据驻留,请使用项目选择器正下方的位置选择器,选择忽略规则的 Security Command Center 位置。例如:

    位置选择器的屏幕截图

  4. 点击要修改的忽略规则的名称。

    如果您没有选择适当的项目或组织,可能会看到一条通知,指出您无权修改忽略规则。

  5. 输入新说明,然后点击保存

  6. 更新或更改过滤条件。

    如需了解相关说明,请参阅创建忽略规则

  7. 如需查看与更新后的过滤条件匹配的发现结果,请点击预览匹配的发现结果

    系统会加载表,其中包含与新查询匹配的发现结果。

  8. 点击保存

gcloud

  1. 在 Google Cloud 控制台中,激活 Cloud Shell。

    激活 Cloud Shell

    Cloud Shell 会话随即会在 Google Cloud 控制台的底部启动,并显示命令行提示符。Cloud Shell 是一个已安装 Google Cloud CLI 且已为当前项目设置值的 Shell 环境。该会话可能需要几秒钟时间来完成初始化。

  2. 如需更新忽略规则,请运行 gcloud scc muteconfigs update 命令:

      gcloud scc muteconfigs update MUTE_CONFIG_ID \
        --PARENT=PARENT_ID \
        --location=LOCATION
        --description=RULE_DESCRIPTION \
        --filter=FILTER
    

    请替换以下内容:

    • MUTE_CONFIG_ID:忽略规则的 ID。
    • PARENT:忽略规则的父级资源(organizationfolderproject)。
    • PARENT_ID:组织、文件夹或项目的 ID。
    • LOCATION:如果启用了数据驻留,请指定存储忽略规则的 Security Command Center 位置。默认值为 global

      如果未启用数据驻留,则指定 --location 标志会使用 Security Command Center API v2 更新忽略规则配置,并且该标志的唯一有效值为 global

    • RULE_DESCRIPTION:忽略规则的说明(最多 1024 个字符)。

    • FILTER:您定义的用于过滤结果的表达式。

      例如,如需忽略 OPEN_FIREWALL 发现结果,您的过滤条件可能是 FILTER="category=\"OPEN_FIREWALL\""

Go

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv1"
	"cloud.google.com/go/securitycenter/apiv1/securitycenterpb"
	"google.golang.org/protobuf/types/known/fieldmaskpb"
)

// updateMuteRule Updates an existing mute configuration.
// The following can be updated in a mute config: description and filter.
func updateMuteRule(w io.Writer, muteConfigName string) error {
	// Specify the name of the mute config to delete.
	// muteConfigName: Use any one of the following formats:
	//                 - organizations/{organization}/muteConfigs/{config_id}
	//                 - folders/{folder}/muteConfigs/{config_id}
	//                 - projects/{project}/muteConfigs/{config_id}
	// muteConfigName := fmt.Sprintf("projects/%s/muteConfigs/%s", "project-id", "mute-config")
	ctx := context.Background()
	client, err := securitycenter.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("securitycenter.NewClient: %w", err)
	}
	defer client.Close()

	updateMuteConfig := &securitycenterpb.MuteConfig{
		Name:        muteConfigName,
		Description: "Updated mute config description",
	}

	req := &securitycenterpb.UpdateMuteConfigRequest{
		MuteConfig: updateMuteConfig,
		// Set the update mask to specify which properties of the mute config should be
		// updated.
		// If empty, all mutable fields will be updated.
		// Make sure that the mask fields match the properties changed in 'updateMuteConfig'.
		// For more info on constructing update mask path, see the proto or:
		// https://cloud.google.com/security-command-center/docs/reference/rest/v1/folders.muteConfigs/patch?hl=en#query-parameters
		UpdateMask: &fieldmaskpb.FieldMask{
			Paths: []string{
				"description",
			},
		},
	}

	response, err := client.UpdateMuteConfig(ctx, req)
	if err != nil {
		return fmt.Errorf("mute rule update failed! %v", err)
	}
	fmt.Fprintf(w, "Mute rule updated %s", response.Name)
	return nil
}

Java

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import com.google.cloud.securitycenter.v1.MuteConfig;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import com.google.cloud.securitycenter.v1.UpdateMuteConfigRequest;
import com.google.protobuf.FieldMask;
import java.io.IOException;

public class UpdateMuteRule {

  public static void main(String[] args) {
    // TODO: Replace the variables within {}

    // Specify the name of the mute config to delete.
    // muteConfigName: Use any one of the following formats:
    //                 - organizations/{organization}/muteConfigs/{config_id}
    //                 - folders/{folder}/muteConfigs/{config_id}
    //                 - projects/{project}/muteConfigs/{config_id}
    String muteConfigName = "{any-one-of-the-above-formats}";
    updateMuteRule(muteConfigName);
  }

  // Updates an existing mute configuration.
  // The following can be updated in a mute config: description and filter.
  public static void updateMuteRule(String muteConfigName) {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient securityCenterClient = SecurityCenterClient.create()) {

      MuteConfig updateMuteConfig =
          MuteConfig.newBuilder()
              .setName(muteConfigName)
              .setDescription("Updated mute config description")
              .build();

      UpdateMuteConfigRequest updateMuteConfigRequest =
          UpdateMuteConfigRequest.newBuilder()
              .setMuteConfig(updateMuteConfig)
              // Set the update mask to specify which properties of the mute config should be
              // updated.
              // If empty, all mutable fields will be updated.
              // Make sure that the mask fields match the properties changed in 'updateMuteConfig'.
              // For more info on constructing update mask path, see the proto or:
              // https://cloud.google.com/security-command-center/docs/reference/rest/v1/folders.muteConfigs/patch?hl=en#query-parameters
              .setUpdateMask(FieldMask.newBuilder().addPaths("description").build())
              .build();

      MuteConfig response = securityCenterClient.updateMuteConfig(updateMuteConfigRequest);
      System.out.println(response);
    } catch (IOException e) {
      System.out.println("Mute rule update failed! \n Exception: " + e);
    }
  }
}

Python

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。

def update_mute_rule(mute_config_name: str) -> None:
    """
    Updates an existing mute configuration.
    The following can be updated in a mute config: description, and filter/ mute rule.
    Args:
        mute_config_name: Specify the name of the mute config to delete.
                          Use any one of the following formats:
                          - organizations/{organization}/muteConfigs/{config_id}
                          - folders/{folder}/muteConfigs/{config_id}
                          - projects/{project}/muteConfigs/{config_id}
    """
    from google.cloud import securitycenter
    from google.protobuf import field_mask_pb2

    client = securitycenter.SecurityCenterClient()

    update_mute_config = securitycenter.MuteConfig()
    update_mute_config.name = mute_config_name
    update_mute_config.description = "Updated mute config description"

    field_mask = field_mask_pb2.FieldMask(paths=["description"])

    request = securitycenter.UpdateMuteConfigRequest()
    request.mute_config = update_mute_config
    # Set the update mask to specify which properties of the Mute Config should be updated.
    # If empty, all mutable fields will be updated.
    # Make sure that the mask fields match the properties changed in 'update_mute_config'.
    # For more info on constructing update mask path, see the proto or:
    # https://cloud.google.com/security-command-center/docs/reference/rest/v1/folders.muteConfigs/patch?hl=en#query-parameters
    request.update_mask = field_mask

    mute_config = client.update_mute_config(request)
    print(f"Updated mute rule : {mute_config}")

REST API

在 Security Command Center API 中,使用 muteConfigs patch 方法更新忽略规则。请求正文是 MuteConfig 的实例。

如需获取忽略规则的 CONFIG_ID,请执行 API 调用以列出忽略规则。响应包含返回的忽略规则的配置 ID。

除非启用数据驻留,否则您可以使用 Security Command Center API v1 或 v2。API v2 提供预览版。启用数据驻留后,API v2 是唯一可用的 API。

如果您使用的是 Security Command Center API v1,请使用 v1 端点来调用 muteConfigs patch

PATCH https://securitycenter.googleapis.com/v1/PARENT/PARENT_ID/muteConfigs/CONFIG_ID

  {
    "description": "RULE_DESCRIPTION",
    "filter": "FILTER",
  }

如果您使用的是 Security Command Center API v2,请使用 v2 端点来调用 muteConfigs patch

PATCH https://securitycenter.googleapis.com/v2/PARENT/PARENT_ID/locations/LOCATION/muteConfigs/CONFIG_ID

  {
    "description": "RULE_DESCRIPTION",
    "filter": "FILTER",
    "type": "STATIC"
  }

请替换以下内容:

  • PARENT:忽略规则的父级资源(organizationsfoldersprojects
  • PARENT_ID:组织、文件夹或项目的 ID
  • LOCATION:仅适用于 v2 指定存储忽略规则的 Security Command Center 位置。如果省略位置信息字段,则默认值为 global
  • CONFIG_ID:忽略规则的数字 ID
  • RULE_DESCRIPTION:忽略规则的说明(最多 1024 个字符)
  • FILTER:您定义来过滤发现结果的表达式

    例如,如需忽略 OPEN_FIREWALL 发现结果,您的过滤条件可以是 "category=\"OPEN_FIREWALL\""

与过滤条件完全匹配的新发现结果会被隐藏,发现结果的 mute 特性设置为 MUTED

更新忽略规则不会自动取消忽略之前规则忽略的任何发现结果。您必须手动取消忽略发现结果

删除忽略规则

您可以使用 Google Cloud 控制台、gcloud CLI 或 Security Command Center API 删除忽略规则。

在删除忽略规则之前,请先了解以下内容:

  • 您无法恢复已删除的忽略规则。
  • 删除忽略规则不会自动取消忽略任何已忽略的发现结果。您必须手动或以编程方式取消忽略发现结果
  • 系统不会忽略将来与已删除忽略规则中的过滤条件匹配的发现结果。

如需查看用于删除忽略规则的示例代码,请参阅删除忽略规则

如需删除忽略规则,请点击您要使用的过程对应的标签页:

控制台

  1. 在 Google Cloud 控制台中,转到 Security Command Center 设置页面中的忽略规则标签页。

    转到“忽略规则”

  2. 如有必要,请选择您的 Google Cloud 项目或组织。

    项目选择器

  3. 如果 Security Command Center 启用了数据驻留,请使用项目选择器正下方的位置选择器,选择存储忽略规则的 Security Command Center 位置。例如:

    位置选择器的屏幕截图

  4. 点击要删除的忽略规则的名称。

  5. 点击 删除

  6. 阅读对话框,如果满意,请点击删除

gcloud

  1. 在 Google Cloud 控制台中,激活 Cloud Shell。

    激活 Cloud Shell

    Cloud Shell 会话随即会在 Google Cloud 控制台的底部启动,并显示命令行提示符。Cloud Shell 是一个已安装 Google Cloud CLI 且已为当前项目设置值的 Shell 环境。该会话可能需要几秒钟时间来完成初始化。

  2. 如需删除忽略规则,请运行 gcloud scc muteconfigs delete 命令:

    gcloud scc muteconfigs delete MUTE_CONFIG_ID \
     --PARENT=PARENT_ID --location=LOCATION
    

    请替换以下内容:

    • MUTE_CONFIG_ID:忽略配置的 ID
    • PARENT:忽略规则的父级资源(organizationfolderproject
    • PARENT_ID:组织、文件夹或项目的 ID
    • LOCATION:如果启用了数据驻留,请指定存储忽略规则配置的 Security Command Center 位置。默认值为 global

      如果未启用数据驻留,则指定 --location 标志会使用 Security Command Center API v2 删除忽略规则,并且该标志的唯一有效值为 global

  3. 确认您删除忽略规则的请求。

Go

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv1"
	"cloud.google.com/go/securitycenter/apiv1/securitycenterpb"
)

// deleteMuteRule deletes a mute configuration given its resource name.
// Note: Previously muted findings are not affected when a mute config is deleted.
func deleteMuteRule(w io.Writer, parent string, muteConfigId string) error {
	// parent: Use any one of the following options:
	//             - organizations/{organization_id}
	//             - folders/{folder_id}
	//             - projects/{project_id}
	// parent := fmt.Sprintf("projects/%s", "your-google-cloud-project-id")
	//
	// muteConfigId: Specify the name of the mute config to delete.
	// muteConfigId := "mute-config-id"
	ctx := context.Background()
	client, err := securitycenter.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("securitycenter.NewClient: %w", err)
	}
	defer client.Close()

	req := &securitycenterpb.DeleteMuteConfigRequest{
		Name: fmt.Sprintf("%s/muteConfigs/%s", parent, muteConfigId),
	}

	if err := client.DeleteMuteConfig(ctx, req); err != nil {
		return fmt.Errorf("failed to delete Muteconfig: %w", err)
	}
	fmt.Fprintf(w, "Mute rule deleted successfully: %s", muteConfigId)
	return nil
}

Java

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import com.google.cloud.securitycenter.v1.MuteConfigName;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import java.io.IOException;

public class DeleteMuteRule {

  public static void main(String[] args) {
    // TODO(Developer): Replace the following variables
    // parentPath: Use any one of the following options:
    //             - organizations/{organization_id}
    //             - folders/{folder_id}
    //             - projects/{project_id}
    String parentPath = String.format("projects/%s", "your-google-cloud-project-id");

    // muteConfigId: Specify the name of the mute config to delete.
    String muteConfigId = "mute-config-id";

    deleteMuteRule(parentPath, muteConfigId);
  }

  // Deletes a mute configuration given its resource name.
  // Note: Previously muted findings are not affected when a mute config is deleted.
  public static void deleteMuteRule(String projectId, String muteConfigId) {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
      // Use appropriate MuteConfigName methods depending on the type of parent.
      // org -> MuteConfigName.ofOrganizationMuteConfigName()
      // folder -> MuteConfigName.ofFolderMuteConfigName()
      // project -> MuteConfigName.ofProjectMuteConfigName)
      client.deleteMuteConfig(MuteConfigName.ofProjectMuteConfigName(projectId, muteConfigId));

      System.out.println("Mute rule deleted successfully: " + muteConfigId);
    } catch (IOException e) {
      System.out.println("Mute rule deletion failed! \n Exception: " + e);
    }
  }
}

Python

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。

def delete_mute_rule(mute_config_name: str) -> None:
    """
    Deletes a mute configuration given its resource name.
    Note: Previously muted findings are not affected when a mute config is deleted.
    Args:
        mute_config_name: Specify the name of the mute config to delete.
                          Use any one of the following formats:
                          - organizations/{organization}/muteConfigs/{config_id}
                          - folders/{folder}/muteConfigs/{config_id} or
                          - projects/{project}/muteConfigs/{config_id}
    """
    from google.cloud import securitycenter

    client = securitycenter.SecurityCenterClient()

    request = securitycenter.DeleteMuteConfigRequest()
    request.name = mute_config_name

    client.delete_mute_config(request)
    print(f"Mute rule deleted successfully: {mute_config_name}")

REST API

在 Security Command Center API 中,使用 muteConfigs delete 方法删除忽略规则。请求正文为空。

如需获取忽略规则的 CONFIG_ID,请执行对列表忽略规则的 API 调用。响应包含返回的忽略规则的配置 ID。

除非启用数据驻留,否则您可以使用 Security Command Center API v1 或 v2。API v2 提供预览版。启用数据驻留后,API v2 是唯一可用的 API。

如果您使用的是 Security Command Center API v1,请使用 v1 端点来调用 muteConfigs delete

DELETE https://securitycenter.googleapis.com/v1/PARENT/PARENT_ID/muteConfigs/CONFIG_ID

如果您使用的是 Security Command Center API v2,请使用 v2 端点来调用 muteConfigs delete

DELETE https://securitycenter.googleapis.com/v2/PARENT/PARENT_ID/locations/LOCATION/muteConfigs/CONFIG_ID

请替换以下内容:

  • PARENT:忽略规则的父级资源(organizationsfoldersprojects
  • PARENT_ID:组织、文件夹或项目的 ID
  • LOCATION:仅适用于 v2 指定存储忽略规则的 Security Command Center 位置。如果省略位置信息字段,则默认值为 global
  • CONFIG_ID:忽略规则的数字 ID

忽略个别发现结果

您可以使用 Google Cloud 控制台、gcloud CLI 或 Security Command Center API 忽略单个发现结果。

如需查看用于忽略发现结果的示例代码,请参阅忽略发现结果

如需忽略单个发现结果,请点击您要使用的过程对应的标签页:

控制台

  1. 在 Google Cloud 控制台中,转到 Security Command Center 发现结果页面。

    转至“发现结果”

  2. 如有必要,请选择您的 Google Cloud 项目或组织。 项目选择器

  3. 如果 Security Command Center 启用了数据驻留,请使用项目选择器正下方的位置选择器,选择发现结果的 Security Command Center 位置。例如:

    位置选择器的屏幕截图

  4. 如果您在发现结果的查询结果面板中没有看到需要忽略的发现结果,请在快速过滤条件面板的类别部分选择该发现结果的类别。

  5. 勾选需要忽略的发现结果旁边的复选框。您可以选择一个或多个发现结果。

  6. 发现结果的查询结果操作栏上,点击忽略选项,然后选择忽略

    所选发现结果的 mute 属性将被设置为 MUTED,并且该发现结果会从发现结果的查询结果面板中被移除。

或者,您也可以在发现结果的详细信息面板中忽略相应的发现结果:

  1. 发现结果页面的发现结果的查询结果面板中,选择类别列,然后点击需要忽略的发现结果的名称。系统会打开该发现结果的详细信息面板。
  2. 点击执行操作
  3. 执行操作菜单中,选择忽略

    如果您选择忽略这类发现结果,则系统会打开创建忽略规则页面,您可以在其中为具有相同类型或包含相同 Indicator 属性的发现结果创建忽略规则。

gcloud

  1. 在 Google Cloud 控制台中,激活 Cloud Shell。

    激活 Cloud Shell

    Cloud Shell 会话随即会在 Google Cloud 控制台的底部启动,并显示命令行提示符。Cloud Shell 是一个已安装 Google Cloud CLI 且已为当前项目设置值的 Shell 环境。该会话可能需要几秒钟时间来完成初始化。

  2. 如需将发现结果的忽略状态设置为 MUTED,请使用 gcloud CLI 中的 set-mute 命令:

    gcloud scc findings set-mute FINDING_ID \
     --PARENT=PARENT_ID \
     --location=LOCATION --source=SOURCE_ID \
     --mute=MUTED
    

    请替换以下内容:

    • FINDING_ID:要忽略的发现结果的 ID

      如需检索发现结果 ID,请使用 Security Command Center API 列出发现结果。发现结果 ID 是 canonicalName 特性的最后一部分,例如 projects/123456789012/sources/1234567890123456789/findings/5ee30aa342e799e4e1700826de053aa9

    • PARENT:父资源(projectfolderorganization),区分大小写

    • PARENT_ID:父级组织、文件夹或项目的 ID

    • LOCATION:如果启用了数据驻留,请指定存储发现结果的 Security Command Center 位置

      如果未启用数据驻留,则指定 --location 标志会使用 Security Command Center API v2 忽略发现结果,并且该标志的唯一有效值为 global

    • SOURCE_ID:来源 ID

      如需了解如何检索来源 ID,请参阅获取来源 ID

Go

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。

import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv1"
	"cloud.google.com/go/securitycenter/apiv1/securitycenterpb"
)

// setMute mutes an individual finding.
// If a finding is already muted, muting it again has no effect.
// Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
func setMute(w io.Writer, findingPath string) error {
	// findingPath: The relative resource name of the finding. See:
	// https://cloud.google.com/apis/design/resource_names#relative_resource_name
	// Use any one of the following formats:
	//  - organizations/{organization_id}/sources/{source_id}/finding/{finding_id}
	//  - folders/{folder_id}/sources/{source_id}/finding/{finding_id}
	//  - projects/{project_id}/sources/{source_id}/finding/{finding_id}
	// findingPath := fmt.Sprintf("projects/%s/sources/%s/finding/%s", "your-google-cloud-project-id", "source", "finding-id")
	ctx := context.Background()
	client, err := securitycenter.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("securitycenter.NewClient: %w", err)
	}
	defer client.Close()

	req := &securitycenterpb.SetMuteRequest{
		Name: findingPath,
		Mute: securitycenterpb.Finding_MUTED}

	finding, err := client.SetMute(ctx, req)
	if err != nil {
		return fmt.Errorf("failed to set the specified mute value: %w", err)
	}
	fmt.Fprintf(w, "Mute value for the finding: %s is %s", finding.Name, finding.Mute)
	return nil
}

Java

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import com.google.cloud.securitycenter.v1.Finding;
import com.google.cloud.securitycenter.v1.Finding.Mute;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import com.google.cloud.securitycenter.v1.SetMuteRequest;
import java.io.IOException;

public class SetMuteFinding {

  public static void main(String[] args) throws IOException {
    // TODO: Replace the variables within {}

    // findingPath: The relative resource name of the finding. See:
    // https://cloud.google.com/apis/design/resource_names#relative_resource_name
    // Use any one of the following formats:
    //  - organizations/{organization_id}/sources/{source_id}/finding/{finding_id}
    //  - folders/{folder_id}/sources/{source_id}/finding/{finding_id}
    //  - projects/{project_id}/sources/{source_id}/finding/{finding_id}
    String findingPath = "{path-to-the-finding}";
    setMute(findingPath);
  }

  // Mute an individual finding.
  // If a finding is already muted, muting it again has no effect.
  // Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
  public static Finding setMute(String findingPath) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      SetMuteRequest setMuteRequest =
          SetMuteRequest.newBuilder().setName(findingPath).setMute(Mute.MUTED).build();

      Finding finding = client.setMute(setMuteRequest);
      System.out.println(
          "Mute value for the finding " + finding.getName() + " is: " + finding.getMute());
      return finding;
    }
  }
}

Python

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。

def set_mute_finding(finding_path: str) -> None:
    """
      Mute an individual finding.
      If a finding is already muted, muting it again has no effect.
      Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
    Args:
        finding_path: The relative resource name of the finding. See:
        https://cloud.google.com/apis/design/resource_names#relative_resource_name
        Use any one of the following formats:
        - organizations/{organization_id}/sources/{source_id}/finding/{finding_id},
        - folders/{folder_id}/sources/{source_id}/finding/{finding_id},
        - projects/{project_id}/sources/{source_id}/finding/{finding_id}.
    """
    from google.cloud import securitycenter

    client = securitycenter.SecurityCenterClient()

    request = securitycenter.SetMuteRequest()
    request.name = finding_path
    request.mute = securitycenter.Finding.Mute.MUTED

    finding = client.set_mute(request)
    print(f"Mute value for the finding: {finding.mute.name}")

REST API

在 Security Command Center API 中,使用 setMute 方法忽略发现结果。请求正文是一个枚举,用于指明生成的静音状态。

除非启用数据驻留,否则您可以使用 Security Command Center API v1 或 v2。API v2 提供预览版。启用数据驻留后,API v2 是唯一可用的 API。

如果您使用的是 Security Command Center API v1,请使用 v1 端点调用 setMute


POST https://securitycenter.googleapis.com/v1/PARENT/PARENT_ID/sources/SOURCE_ID/findings/FINDING_ID:setMute

{
  "mute": "MUTED"
}

如果您使用的是 Security Command Center API v2,请使用 v2 端点调用 setMute

POST https://securitycenter.googleapis.com/v2/PARENT/PARENT_ID/sources/SOURCE_ID/locations/LOCATION/findings/FINDING_ID:setMute

{
  "mute": "MUTED"
}

请替换以下内容:

  • PARENT:父资源(organizationsfoldersprojects)。
  • PARENT_ID:父级组织、文件夹或项目的 ID。
  • LOCATION:仅适用于 v2,用于指定存储发现结果的 Security Command Center 位置。如果省略位置信息字段,则默认值为 global
  • SOURCE_ID:来源的数字 ID。

    如需了解如何检索来源 ID,请参阅获取来源 ID

  • FINDING_ID:您要忽略的发现结果的 ID。

    如需检索发现结果 ID,请使用 Security Command Center API 列出发现结果。发现结果 ID 是 canonicalName 特性的最后一部分,例如 projects/123456789012/sources/1234567890123456789/findings/5ee30aa342e799e4e1700826de053aa9

忽略发现结果后,其 mute 属性会被设为 MUTED

忽略发现结果不会影响其有效状态。如果某个有效的发现结果被忽略,其 state 属性会保持不变,即仍为 state="ACTIVE"。虽然该发现结果被隐藏起来,但在其相关的底层漏洞、配置错误或威胁得以消除之前,它会一直保持有效状态。

如需详细了解忽略规则,请参阅创建忽略规则

取消忽略各个发现结果

您可以使用 Google Cloud 控制台、gcloud CLI 或 Security Command Center API 取消忽略个别发现结果。

如需查看用于取消忽略发现结果的示例代码,请参阅取消忽略发现结果

如需取消忽略单个发现结果,请点击您要使用的流程对应的标签页:

控制台

  1. 在 Google Cloud 控制台中,转到 Security Command Center 发现结果页面。

    转至“发现结果”

  2. 如有必要,请选择您的 Google Cloud 项目或组织。 项目选择器

    系统随即会打开发现结果页面,并在查询预览部分中显示默认查询。由于默认查询会过滤掉已忽略的发现结果,因此您需要先修改该查询,之后系统才会在发现结果的查询结果面板中显示已忽略的发现结果。

  3. 如果 Security Command Center 启用了数据驻留,请使用项目选择器正下方的位置选择器,选择发现结果的 Security Command Center 位置。例如:

    位置选择器的屏幕截图

  4. 查询预览部分右侧,点击修改查询以打开查询编辑器

  5. 查询编辑器字段中,将现有忽略语句替换为以下内容:

    mute="MUTED"
  6. 点击应用发现结果的查询结果面板中的发现结果会相应更新,以仅包含已忽略的发现结果。

  7. 如有必要,您可以过滤掉其他已忽略的发现结果。例如,您可以在快速过滤条件面板下方的类别部分,选择需要取消忽略的发现结果的名称,以过滤掉所有其他类别的发现结果。

  8. 勾选要取消忽略的发现结果旁边的复选框。您可以选择一个或多个发现结果。

  9. 发现结果的查询结果操作栏上,点击忽略选项,然后选择取消忽略

    所选发现结果的 mute 属性将被设置为 UNMUTED,并且该发现结果会从发现结果的查询结果面板中被移除。

或者,您也可以在发现结果的详细信息面板中取消忽略相应的发现结果:

  1. 发现结果页面的发现结果的查询结果面板中,选择类别列,然后点击需要取消忽略的发现结果的名称。系统会打开该发现结果的详细信息面板。
  2. 点击执行操作
  3. 执行操作菜单中,选择取消忽略

gcloud

  1. 在 Google Cloud 控制台中,激活 Cloud Shell。

    激活 Cloud Shell

    Cloud Shell 会话随即会在 Google Cloud 控制台的底部启动,并显示命令行提示符。Cloud Shell 是一个已安装 Google Cloud CLI 且已为当前项目设置值的 Shell 环境。该会话可能需要几秒钟时间来完成初始化。

  2. 如需将发现结果的忽略状态设置为 UNMUTED,请使用 gcloud CLI 中的 set-mute 命令:

    gcloud scc findings set-mute FINDING_ID \
     --PARENT=PARENT_ID \
     --location=LOCATION --source=SOURCE_ID \
     --mute=UNMUTED
    

    请替换以下内容:

    • FINDING_ID:要忽略的发现结果的 ID

      如需检索发现结果 ID,请使用 Security Command Center API 列出发现结果。发现结果 ID 是 canonicalName 特性的最后一部分,例如 projects/123456789012/sources/1234567890123456789/findings/5ee30aa342e799e4e1700826de053aa9

    • PARENT:父资源(projectfolderorganization),区分大小写

    • PARENT_ID:父级组织、文件夹或项目的 ID

    • LOCATION:如果启用了数据驻留,请指定存储发现结果的 Security Command Center 位置

      如果未启用数据驻留,则指定 --location 标志会使用 Security Command Center API v2 取消发现结果,并且该标志的唯一有效值为 global

    • SOURCE_ID:来源 ID

      如需了解如何检索来源 ID,请参阅获取来源 ID

Go

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv1"
	"cloud.google.com/go/securitycenter/apiv1/securitycenterpb"
)

// setUnmute unmutes an individual finding.
// Unmuting a finding that isn't muted has no effect.
// Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
func setUnmute(w io.Writer, findingPath string) error {
	// findingPath: The relative resource name of the finding. See:
	// https://cloud.google.com/apis/design/resource_names#relative_resource_name
	// Use any one of the following formats:
	//  - organizations/{organization_id}/sources/{source_id}/finding/{finding_id}
	//  - folders/{folder_id}/sources/{source_id}/finding/{finding_id}
	//  - projects/{project_id}/sources/{source_id}/finding/{finding_id}
	// findingPath := fmt.Sprintf("projects/%s/sources/%s/finding/%s", "your-google-cloud-project-id", "source", "finding-id")
	ctx := context.Background()
	client, err := securitycenter.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("securitycenter.NewClient: %w", err)
	}
	defer client.Close()

	req := &securitycenterpb.SetMuteRequest{
		Name: findingPath,
		Mute: securitycenterpb.Finding_UNMUTED}

	finding, err := client.SetMute(ctx, req)
	if err != nil {
		return fmt.Errorf("failed to set the specified mute value: %w", err)
	}
	fmt.Fprintf(w, "Mute value for the finding: %s is %s", finding.Name, finding.Mute)
	return nil
}

Java

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import com.google.cloud.securitycenter.v1.Finding;
import com.google.cloud.securitycenter.v1.Finding.Mute;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import com.google.cloud.securitycenter.v1.SetMuteRequest;
import java.io.IOException;

public class SetUnmuteFinding {

  public static void main(String[] args) throws IOException {
    // TODO: Replace the variables within {}

    // findingPath: The relative resource name of the finding. See:
    // https://cloud.google.com/apis/design/resource_names#relative_resource_name
    // Use any one of the following formats:
    //  - organizations/{organization_id}/sources/{source_id}/finding/{finding_id}
    //  - folders/{folder_id}/sources/{source_id}/finding/{finding_id}
    //  - projects/{project_id}/sources/{source_id}/finding/{finding_id}
    String findingPath = "{path-to-the-finding}";
    setUnmute(findingPath);
  }

  // Unmute an individual finding.
  // Unmuting a finding that isn't muted has no effect.
  // Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
  public static Finding setUnmute(String findingPath) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      SetMuteRequest setMuteRequest =
          SetMuteRequest.newBuilder().setName(findingPath).setMute(Mute.UNMUTED).build();

      Finding finding = client.setMute(setMuteRequest);
      System.out.println(
          "Mute value for the finding " + finding.getName() + " is: " + finding.getMute());
      return finding;
    }
  }
}

Python

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。

def set_unmute_finding(finding_path: str) -> None:
    """
      Unmute an individual finding.
      Unmuting a finding that isn't muted has no effect.
      Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
    Args:
        finding_path: The relative resource name of the finding. See:
        https://cloud.google.com/apis/design/resource_names#relative_resource_name
        Use any one of the following formats:
        - organizations/{organization_id}/sources/{source_id}/finding/{finding_id},
        - folders/{folder_id}/sources/{source_id}/finding/{finding_id},
        - projects/{project_id}/sources/{source_id}/finding/{finding_id}.
    """
    from google.cloud import securitycenter

    client = securitycenter.SecurityCenterClient()

    request = securitycenter.SetMuteRequest()
    request.name = finding_path
    request.mute = securitycenter.Finding.Mute.UNMUTED

    finding = client.set_mute(request)
    print(f"Mute value for the finding: {finding.mute.name}")

REST API

在 Security Command Center API 中,使用 setMute 方法将发现结果取消静音。请求正文是一个枚举,用于指明生成的静音状态。

除非启用数据驻留,否则您可以使用 Security Command Center API v1 或 v2。API v2 提供预览版。启用数据驻留后,API v2 是唯一可用的 API。

如果您使用的是 Security Command Center API v1,请使用 v1 端点调用 setMute

POST https://securitycenter.googleapis.com/v1/PARENT/PARENT_ID/sources/SOURCE_ID/findings/FINDING_ID:setMute

{
  "mute": "UNMUTED"
}

如果您使用的是 Security Command Center API v2,请使用 v2 端点调用 setMute

POST https://securitycenter.googleapis.com/v2/PARENT/PARENT_ID/sources/SOURCE_ID/locations/LOCATION/findings/FINDING_ID:setMute

{
  "mute": "UNMUTED"
}

请替换以下内容:

  • PARENT:父级资源(organizationsfoldersprojects
  • PARENT_ID:父级组织、文件夹或项目的 ID
  • LOCATION:仅适用于 v2,用于指定存储发现结果的 Security Command Center 位置。如果省略位置信息字段,则默认值为 global
  • SOURCE_ID:来源的数字 ID

    如需了解如何检索来源 ID,请参阅获取来源 ID

  • FINDING_ID:您要忽略的发现结果的 ID。

    如需检索发现结果 ID,请使用 Security Command Center API 列出发现结果。发现结果 ID 是 canonicalName 特性的最后一部分,例如 projects/123456789012/sources/1234567890123456789/findings/5ee30aa342e799e4e1700826de053aa9

所选的发现结果不再隐藏,并且发现结果的 mute 特性设置为 UNMUTED

取消忽略的发现结果会覆盖忽略规则

如果用户取消忽略发现结果,则即使现有的忽略规则仍与发现结果匹配,它们仍会保持取消忽略状态。实际上,用户取消忽略操作会覆盖忽略规则。

仅当用户手动忽略发现结果或在 Google Cloud 控制台中创建新的匹配忽略规则时,未忽略的发现结果才会再次忽略。使用 gcloud CLI 或 Security Command Center API 创建的忽略规则不会影响用户取消忽略的发现结果。

忽略多个现有发现结果

您可以使用 gcloud scc findings bulk-mute gcloud CLI 命令或 Security Command Center API 的 bulkMute 方法批量忽略多个现有发现结果。如果您需要忽略类似的未来发现结果,请创建忽略规则

通过定义发现结果过滤条件,指定需要忽略的一组发现结果。批量忽略过滤条件并不支持所有发现结果属性。如需查看不受支持的属性列表,请参阅忽略规则不支持的发现结果属性

如果为 Security Command Center 启用了数据驻留,则批量忽略操作的范围仅限于执行批量控制的 Security Command Center 位置。

如需查看批量忽略发现结果的示例代码,请参阅批量忽略发现结果

如需批量忽略发现结果,请点击您要使用的过程对应的标签页:

控制台

在 Google Cloud 控制台中,您只能通过创建忽略规则来批量忽略发现结果。在 Google Cloud 控制台中,创建忽略规则会隐藏现有和未来的发现结果。

gcloud

  1. 在 Google Cloud 控制台中,激活 Cloud Shell。

    激活 Cloud Shell

    Cloud Shell 会话随即会在 Google Cloud 控制台的底部启动,并显示命令行提示符。Cloud Shell 是一个已安装 Google Cloud CLI 且已为当前项目设置值的 Shell 环境。该会话可能需要几秒钟时间来完成初始化。

  2. 如需批量忽略多个发现结果,请运行 gcloud scc findings bulk-mute 命令:

    gcloud scc findings bulk-mute --PARENT=PARENT_ID \
    --location=LOCATION --filter="FILTER" \
    

    请替换以下内容:

    • PARENT:应用忽略规则的资源层次结构中的范围,即 organizationfolderproject
    • PARENT_ID:父级组织、文件夹或项目的 ID,采用 organizations/123folders/456projects/789 格式指定。
    • LOCATION:如果启用了数据驻留,请指定用于批量忽略发现结果的 Security Command Center 位置。只有此位置中的发现结果会被忽略。

      如果未启用数据驻留,则指定 --location 标志会使用 Security Command Center API v2 忽略发现结果,并且该标志的唯一有效值为 global

    • FILTER:您定义的用于过滤结果的表达式

    例如,如需忽略 internal-test 项目中所有现有的低严重级别 OPEN_FIREWALLPUBLIC_IP_ADDRESS 发现结果,您的过滤条件可以是 "category=\"OPEN_FIREWALL\" OR category=\"PUBLIC_IP_ADDRESS\" AND severity=\"LOW\" AND resource.project_display_name=\"internal-test\""

Go

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv1"
	"cloud.google.com/go/securitycenter/apiv1/securitycenterpb"
)

// bulkMute kicks off a long-running operation (LRO) to bulk mute findings for a parent based on a filter.
// The parent can be either an organization, folder, or project. The findings
// matched by the filter will be muted after the LRO is done.
func bulkMute(w io.Writer, parent string, muteRule string) error {
	// parent: Use any one of the following options:
	//             - organizations/{organization_id}
	//             - folders/{folder_id}
	//             - projects/{project_id}
	// parent := fmt.Sprintf("projects/%s", "your-google-cloud-project-id")
	// muteRule: Expression that identifies findings that should be muted.
	// To create mute rules, see:
	// https://cloud.google.com/security-command-center/docs/how-to-mute-findings#create_mute_rules
	// muteRule := "filter-condition"
	ctx := context.Background()
	client, err := securitycenter.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("securitycenter.NewClient: %w", err)
	}
	defer client.Close()

	req := &securitycenterpb.BulkMuteFindingsRequest{
		Parent: parent,
		Filter: muteRule,
	}

	op, err := client.BulkMuteFindings(ctx, req)
	if err != nil {
		return fmt.Errorf("failed to bulk mute findings: %w", err)
	}
	response, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("failed to bulk mute findings: %w", err)
	}
	fmt.Fprintf(w, "Bulk mute findings completed successfully! %s", response)
	return nil
}

Java

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。


import com.google.cloud.securitycenter.v1.BulkMuteFindingsRequest;
import com.google.cloud.securitycenter.v1.BulkMuteFindingsResponse;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class BulkMuteFindings {

  public static void main(String[] args) {
    // TODO: Replace the variables within {}

    // parentPath: Use any one of the following options:
    //             - organizations/{organization_id}
    //             - folders/{folder_id}
    //             - projects/{project_id}
    String parentPath = String.format("projects/%s", "your-google-cloud-project-id");

    // muteRule: Expression that identifies findings that should be muted.
    // eg: "resource.project_display_name=\"PROJECT_ID\""
    String muteRule = "{filter-condition}";

    bulkMute(parentPath, muteRule);
  }

  // Kicks off a long-running operation (LRO) to bulk mute findings for a parent based on a filter.
  // The parent can be either an organization, folder, or project. The findings
  // matched by the filter will be muted after the LRO is done.
  public static void bulkMute(String parentPath, String muteRule) {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      BulkMuteFindingsRequest bulkMuteFindingsRequest =
          BulkMuteFindingsRequest.newBuilder()
              .setParent(parentPath)
              // To create mute rules, see:
              // https://cloud.google.com/security-command-center/docs/how-to-mute-findings#create_mute_rules
              .setFilter(muteRule)
              .build();

      // ExecutionException is thrown if the below call fails.
      BulkMuteFindingsResponse response =
          client.bulkMuteFindingsAsync(bulkMuteFindingsRequest).get();
      System.out.println("Bulk mute findings completed successfully! " + response);
    } catch (IOException | InterruptedException | ExecutionException e) {
      System.out.println("Bulk mute findings failed! \n Exception: " + e);
    }
  }
}

Python

以下示例使用 v1 API。如需修改 v2 的示例,请将 v1 替换为 v2,并将 /locations/LOCATION 添加到资源名称中。

对于大多数资源,请在资源名称的 /PARENT/PARENT_ID 后添加 /locations/LOCATION,其中 PARENTorganizationsfoldersprojects

对于发现结果,请在资源名称的 /sources/SOURCE_ID 后添加 /locations/LOCATION,其中 SOURCE_ID 是发出发现结果的 Security Command Center 服务的 ID。

def bulk_mute_findings(parent_path: str, mute_rule: str) -> None:
    """
      Kicks off a long-running operation (LRO) to bulk mute findings for a parent based on a filter.
      The parent can be either an organization, folder, or project. The findings
      matched by the filter will be muted after the LRO is done.
    Args:
        parent_path: use any one of the following options:
                     - organizations/{organization}
                     - folders/{folder}
                     - projects/{project}
        mute_rule: Expression that identifies findings that should be updated.
    """
    from google.cloud import securitycenter

    client = securitycenter.SecurityCenterClient()

    request = securitycenter.BulkMuteFindingsRequest()
    request.parent = parent_path
    # To create mute rules, see:
    # https://cloud.google.com/security-command-center/docs/how-to-mute-findings#create_mute_rules
    request.filter = mute_rule

    response = client.bulk_mute_findings(request)
    print(f"Bulk mute findings completed successfully! : {response}")

REST API

在 Security Command Center API 中,使用 bulkMute 方法忽略多个现有发现结果。请求正文包含用于过滤结果的表达式。

除非启用数据驻留,否则您可以使用 Security Command Center API v1 或 v2。API v2 提供预览版。启用数据驻留后,API v2 是唯一可用的 API。

如果您使用的是 Security Command Center API v1,请使用 v1 端点调用 bulkMute

POST https://securitycenter.googleapis.com/v1/PARENT/PARENT_ID/findings:bulkMute -d

{
  "filter": "FILTER"
}

如果您使用的是 Security Command Center API v2,请使用 v2 端点调用 bulkMute

POST https://securitycenter.googleapis.com/v2/PARENT/PARENT_ID/locations/LOCATION/findings:bulkMute -d

{
  "filter": "FILTER"
}

请替换以下内容:

  • PARENT:父资源(organizationsfoldersprojects)。
  • PARENT_ID:父级组织、文件夹或项目的 ID。
  • LOCATION:仅适用于 v2,用于指定存储发现结果的 Security Command Center 位置。如果省略位置信息字段,则默认值为 global
  • FILTER:您定义的用于过滤结果的表达式。

    例如,如需忽略 internal-test 项目中所有现有的低严重级别 OPEN_FIREWALLPUBLIC_IP_ADDRESS 发现结果,您的过滤条件可以是 "category=\"OPEN_FIREWALL\" OR category=\"PUBLIC_IP_ADDRESS\" AND severity=\"LOW\" AND resource.project_display_name=\"internal-test\""

系统会隐藏您选择的资源中与过滤条件完全匹配的所有现有发现结果。发现结果的 mute 特性设置为 MUTED

如果忽略发现结果,则系统不会更改其状态。如果有效的发现结果被忽略,这些发现结果会隐藏起来,但在底层漏洞、配置错误或威胁得以消除之前会保持有效状态。

在 Google Cloud 控制台中查看已忽略的发现结果

您可以在 Google Cloud 控制台中查看已忽略的发现结果,方法是修改发现结果查询,选择包含属性值 mute="MUTED" 的发现结果。

例如,以下发现结果查询仅显示已忽略的有效发现结果:

state="ACTIVE"
AND mute="MUTED"

如需显示所有活跃的发现结果(包括已忽略的发现结果和取消忽略的发现结果),请完全省略查询中的 mute 属性:

state="ACTIVE"

默认情况下,Google Cloud 控制台中的发现结果查询仅显示未忽略的发现结果。

如需详细了解如何修改发现结果查询,请参阅在信息中心内创建或修改发现结果查询

查找与忽略相关的属性

本部分列出了与发现结果的忽略状态相关的发现结果属性,并说明了忽略操作对这些属性的影响:

  • mute:在创建发现结果时设置为 UNDEFINED 并在以下情况下进行更改:
    • MUTED:发现结果被手动忽略或通过忽略规则忽略。
    • UNMUTED:用户取消忽略发现结果。
  • mute_update_time:发现结果被忽略或取消忽略的时间
  • mute_initiator:忽略发现结果的主账号或忽略规则的标识符

停止通知和导出已忽略的发现结果

如果您启用发现结果通知,与您的通知过滤条件匹配的新发现结果或已更新的已忽略发现结果仍会导出到 Pub/Sub。

如需停止导出已忽略的发现结果并发送通知,请使用 mute 属性在 NotificationConfig 过滤条件中排除已忽略的发现结果。例如,以下过滤条件仅发送有关未忽略或未设置忽略特性的有效发现结果的通知:

FILTER="state=\"ACTIVE\" AND -mute=\"MUTED\""

后续步骤

详细了解如何过滤发现结果通知

浏览您可以使用的更多过滤条件示例