管理忽略规则

本文档介绍了如何创建和管理静音规则,以自动将 Security Command Center 中的发现结果设为静音。

所需的角色

如需获得管理忽略规则所需的权限,请让管理员向您授予组织、文件夹或项目的以下 IAM 角色:

如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

您也可以通过自定义角色或其他预定义角色来获取所需的权限。

创建忽略规则

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

我们建议您仅在忽略规则配置中使用动态忽略规则,因为它们比静态忽略规则更灵活。如需比较忽略规则类型,请参阅忽略规则的类型

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

控制台

定义忽略规则

  1. 在 Google Cloud 控制台中,前往发现结果页面。

    前往“发现结果”

  2. 选择组织或项目。

  3. 点击忽略选项,然后选择管理忽略规则

  4. 点击创建忽略规则

  5. 输入忽略规则 ID

  6. 建议:输入说明,提供有关为何忽略发现结果的背景信息。

  7. 如需确认忽略规则的范围,请检查父资源值。

可选:添加失效日期

您可以为动态忽略规则添加失效日期。

  1. 选择暂时忽略匹配的发现结果
  2. 如需配置动态忽略规则的失效日期,请选择日历,然后选择至少 24 小时后的日期和时间。

    在到期日期之后,静音规则将不再生效。

可选:使用查询限制忽略规则

如果您添加查询,则忽略规则仅适用于与查询匹配的发现结果。

如需使用查询来限制忽略规则,请在发现结果查询部分中点击 添加过滤条件

您可以在添加过滤条件菜单中选择支持的发现结果属性和值。

  1. 选择过滤条件菜单中,选择发现结果特性或在搜索发现结果特性框中输入其名称。系统会显示可用子特性的列表。
  2. 选择子特性。系统会显示一个选择字段,您可以在其中使用所选子属性、查询运算符以及子属性的一个或多个值来构建查询语句。
  3. 从面板中为子属性选择运算符和一个或多个值。 如需详细了解查询运算符及其使用的函数,请参阅添加过滤条件菜单中的查询运算符

    如果您想重新开始,请点击重置

  4. 点击应用

    菜单将会关闭,并且您的查询即会更新。

  5. 重复这些步骤,直到发现结果查询包含所需的所有特性。
如需查看查询结果,请点击预览匹配的发现结果。表格会列出与您的查询匹配的发现结果。

如果查询与正确的结果不符,请根据需要修改查询,然后再次预览结果。重复此步骤,直到您对结果感到满意为止。

保存忽略规则

点击保存。 Google Cloud 控制台会显示您的忽略规则列表。

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" \
      --type=MUTE_TYPE \
      --expiry-time=TIMESTAMP

    替换以下内容:

    • CONFIG_ID:忽略规则的名称。ID 必须使用字母数字字符和连字符,且长度介于 1 到 63 个字符之间。
    • PARENT:忽略规则适用的资源层次结构中的范围,即 organizationfolderproject
    • PARENT_ID:父级组织、文件夹或项目的数字 ID,或父级项目的字母数字 ID。
    • LOCATION:在其中管理忽略规则的 Security Command Center 位置;如果启用了数据驻留,请使用 eusaus;否则,请使用值 global
    • RULE_DESCRIPTION:忽略规则的说明,不超过 1024 个字符。
    • FILTER:您定义来过滤发现结果的表达式。例如,如需忽略 OPEN_FIREWALL 发现结果,您的过滤条件可以是 FILTER="category=\"OPEN_FIREWALL\""
    • MUTE_TYPE:您要创建的忽略规则的类型。有效的忽略规则类型为 DYNAMICSTATIC。默认情况下,忽略规则类型设置为 STATIC。 您无法在创建后更改忽略规则的类型。
    • TIMESTAMP:仅在您创建动态忽略规则时适用。表示动态忽略规则何时到期的日期/时间字符串。该值必须设置为至少未来一天,否则请求将被拒绝。如需了解时间格式,请参阅 gcloud topic datetimes。动态忽略规则到期后,系统会将其从所有匹配的结果中移除。如果您希望动态忽略规则对匹配的发现结果无限期地起作用,请省略此字段。

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

Terraform

为组织创建忽略规则:

resource "google_scc_v2_organization_mute_config" "default" {
  mute_config_id    = "my-config"
  organization = "123456789"
  location     = "global"
  description  = "My custom Cloud Security Command Center Finding Organization mute Configuration"
  filter = "severity = \"HIGH\""
  type = "STATIC"
}

为文件夹创建忽略规则:

resource "google_folder" "folder" {
  parent       = "organizations/123456789"
  display_name = "folder-name"
}

resource "google_scc_v2_folder_mute_config" "default" {
  mute_config_id    = "my-config"
  folder = google_folder.folder.folder_id
  location     = "global"
  description  = "My custom Cloud Security Command Center Finding Folder mute Configuration"
  filter = "severity = \"HIGH\""
  type = "STATIC"
}

为项目创建忽略规则:

resource "google_scc_v2_project_mute_config" "default" {
  mute_config_id    = "my-config"
  project = "my-project-name"
  location     = "global"
  description  = "My custom Cloud Security Command Center Finding Project mute Configuration"
  filter = "severity = \"HIGH\""
  type = "STATIC"
}

Go


import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv2"
	"cloud.google.com/go/securitycenter/apiv2/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\"",
		Type: securitycenterpb.MuteConfig_STATIC,
	}

	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


import com.google.cloud.securitycenter.v2.LocationName;
import com.google.cloud.securitycenter.v2.MuteConfig;
import com.google.cloud.securitycenter.v2.MuteConfig.MuteConfigType;
import com.google.cloud.securitycenter.v2.SecurityCenterClient;
import java.io.IOException;
import java.util.UUID;

public class CreateMuteRule {

  public static void main(String[] args) throws IOException {
    // TODO: Replace the following variables.
    // projectId: Google Cloud Project id.
    String projectId = "google-cloud-project-id";

    // Specify the location of the mute config.
    String location = "global";

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

    createMuteRule(projectId, location, muteConfigId);
  }

  // Creates a mute configuration in a project under a given location.
  public static void createMuteRule(String projectId, String location, String muteConfigId)
      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.
    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\"")
              .setType(MuteConfigType.STATIC)
              .build();

      // You can also create mute rules in an organization/ folder.
      // Construct the parameters according to the parent resource.
      //  * Organization -> client.createMuteConfig(OrganizationLocationName.of(...
      //  * Folder -> client.createMuteConfig(FolderLocationName.of(...
      MuteConfig response = client.createMuteConfig(
          LocationName.of(projectId, location), muteConfig, muteConfigId);
      System.out.println("Mute rule created successfully: " + response.getName());
    }
  }
}

Python

def create_mute_rule(parent_path: str, location_id: str, mute_config_id: str) -> Dict:
    """
    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}
        location_id: Gcp location id; example: 'global'
        mute_config_id: Set a unique id; max of 63 chars.
    Returns:
        Dict: returns the mute rule details
    """

    from google.cloud import securitycenter_v2

    client = securitycenter_v2.SecurityCenterClient()

    mute_config = securitycenter_v2.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"'
    )
    mute_config.type = "STATIC"

    request = securitycenter_v2.CreateMuteConfigRequest()
    request.parent = parent_path + "/locations/" + location_id
    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}")
    return mute_config

REST

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

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

  {
    "description": "RULE_DESCRIPTION",
    "filter": "FILTER",
    "type": "MUTE_TYPE",
    "expiryTime": "TIMESTAMP"
  }

替换以下内容:

  • PARENT:忽略规则的父级资源(organizationsfoldersprojects
  • PARENT_ID:父级组织、文件夹或项目的 ID
  • LOCATION:在其中管理忽略规则的 Security Command Center 位置;如果启用了数据驻留,请使用 eusaus;否则,请使用值 global
  • MUTE_CONFIG_ID:忽略规则的名称(长度介于 1 到 63 个字符之间)
  • RULE_DESCRIPTION:忽略规则的说明(最多 1024 个字符)
  • FILTER:您定义来过滤发现结果的表达式

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

  • MUTE_TYPE:您要创建的忽略规则的类型。有效的忽略规则类型为 DYNAMICSTATIC。您无法在创建后更改忽略规则的类型。

  • TIMESTAMP:仅在您创建动态忽略规则时适用。表示动态忽略规则何时到期的日期/时间字符串。该值必须设置为至少未来一天,否则请求将被拒绝。如需了解时间格式,请参阅 gcloud topic datetimes。动态忽略规则到期后,系统会将其从所有匹配的结果中移除。如果您希望动态忽略规则对匹配的发现结果无限期地起作用,请省略此字段。

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

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

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

忽略规则未必支持过滤条件中的所有发现结果属性。展开以下部分查看忽略规则过滤条件不支持的属性列表。

不支持的发现结果属性

  • caiResource
  • canonicalName
  • createTime
  • description
  • eventTime
  • externalUri
  • gcpMetadata.folders1
  • libraryPaths
  • mute
  • muteAnnotation
  • muteInfo
  • muteInitiator
  • muteUpdateTime
  • name
  • nextSteps
  • originalProviderId
  • parent
  • processes.binaryPath
  • processes.libraryPaths
  • propertyDataTypes
  • resource.tags
  • resourceName
  • securityMarks
  • sourceProperties
  • state
  • workflowState
  • 1 gcpMetadata.folders 属性包含忽略过滤条件支持的子字段。

列出忽略规则

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

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

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

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

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

控制台

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

    转到“忽略规则”

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

  3. 忽略规则部分中,您会看到有效忽略规则的详细信息,包括以下内容:

    • 名称:忽略规则 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 位置;如果启用了数据驻留,请使用 eusaus;否则,请使用值 global

Go

import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv2"
	"cloud.google.com/go/securitycenter/apiv2/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


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

public class ListMuteRules {

  public static void main(String[] args) throws IOException {
    // TODO: Replace variables enclosed within {}
    // projectId: Google Cloud Project id.
    String projectId = "google-cloud-project-id";

    // Specify the location to list mute configs.
    String location = "global";

    listMuteRules(projectId, location);
  }

  // Lists all mute rules present under the resource type in the given location.
  public static void listMuteRules(String projectId, String location) 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.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      // Parent can also be one of:
      //  * "organizations/{org_id}/locations/{location}"
      //  * "folders/{folder_id}/locations/{location}"
      ListMuteConfigsRequest listMuteConfigsRequest = ListMuteConfigsRequest.newBuilder()
          .setParent(String.format("projects/%s/locations/%s", projectId, location))
          .build();

      // List all mute configs present in the resource.
      for (MuteConfig muteConfig : client.listMuteConfigs(listMuteConfigsRequest).iterateAll()) {
        System.out.println(muteConfig.getName());
      }
    }
  }
}

Python

def list_mute_rules(parent: str, location_id: str) -> Dict:
    """
    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}
        location_id: Gcp location id; example: 'global'
    Returns:
         Dict: returns the mute rule details
    """
    from google.cloud import securitycenter_v2

    client = securitycenter_v2.SecurityCenterClient()

    request = securitycenter_v2.ListMuteConfigsRequest()
    request.parent = parent + "/locations/" + location_id
    response = client.list_mute_configs(request)
    # List all Mute Configs present in the resource.
    for mute_config in response:
        print(mute_config.name)
    return response

REST

在 Security Command Center API 中,使用 muteConfigs.list 方法列出忽略规则:

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

替换以下内容:

  • PARENT:忽略规则的父级资源(organizationsfoldersprojects
  • PARENT_ID:父级组织、文件夹或项目的 ID
  • LOCATION:在其中管理忽略规则的 Security Command Center 位置;如果启用了数据驻留,请使用 eusaus;否则,请使用值 global

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

查看忽略规则配置

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

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

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

控制台

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

    转到“忽略规则”

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

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

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

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

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 位置;如果启用了数据驻留,请使用 eusaus;否则,请使用值 global

Go

import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv2"
	"cloud.google.com/go/securitycenter/apiv2/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


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

public class GetMuteRule {

  public static void main(String[] args) throws IOException {
    // TODO(Developer): Replace the following variables
    // projectId: Google Cloud Project id.
    String projectId = "google-cloud-project-id";

    // Specify the location of the mute config. If the mute config was
    // created with v1 API, it can be accessed with "global".
    String location = "global";

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

    getMuteRule(projectId, location, muteConfigId);
  }

  // Retrieves a mute configuration given its resource name.
  public static MuteConfig getMuteRule(String projectId, String location, String muteConfigId)
      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.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
      // Use appropriate `MuteConfigName` methods depending on the parent type.
      //  * organization -> MuteConfigName.ofOrganizationLocationMuteConfigName()
      //  * folder -> MuteConfigName.ofFolderLocationMuteConfigName()

      MuteConfigName muteConfigName = MuteConfigName.ofProjectLocationMuteConfigName(projectId,
          location, muteConfigId);
      return client.getMuteConfig(muteConfigName);
    }
  }
}

Python

def get_mute_rule(parent_path: str, location_id: str, mute_config_id: str) -> Dict:
    """
    Retrieves a mute configuration given its resource name.
    Args:
        parent_path: use any one of the following options:
                     - organizations/{organization_id}
                     - folders/{folder_id}
                     - projects/{project_id}
        location_id: Gcp location id; example: 'global'
        mute_config_id: Set a unique id; max of 63 chars.
    Returns:
         Dict: returns the mute rule details
    """
    from google.cloud import securitycenter_v2

    client = securitycenter_v2.SecurityCenterClient()

    request = securitycenter_v2.GetMuteConfigRequest()
    request.name = (
        parent_path + "/locations/" + location_id + "/muteConfigs/" + mute_config_id
    )

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

REST

在 Security Command Center API 中,使用 muteConfigs.get 方法返回忽略规则的配置:

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

替换以下内容:

  • PARENT:忽略规则的父级资源(organizationsfoldersprojects
  • PARENT_ID:组织、文件夹或项目的 ID
  • LOCATION:在其中管理忽略规则的 Security Command Center 位置;如果启用了数据驻留,请使用 eusaus;否则,请使用值 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. 点击要修改的忽略规则的名称。

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

  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 update 命令:

    gcloud scc muteconfigs update MUTE_CONFIG_ID \
        --PARENT=PARENT_ID \
        --location=LOCATION \
        --description=RULE_DESCRIPTION \
        --filter=FILTER \
        --type=MUTE_TYPE \
        --expiry-time=TIMESTAMP
    

    替换以下内容:

    • MUTE_CONFIG_ID:忽略规则的 ID。
    • PARENT:忽略规则的父级资源(organizationfolderproject
    • PARENT_ID:组织、文件夹或项目的 ID
    • LOCATION:在其中管理忽略规则的 Security Command Center 位置;如果启用了数据驻留,请使用 eusaus;否则,请使用值 global
    • RULE_DESCRIPTION:忽略规则的说明(最多 1,024 个字符)。
    • FILTER:您定义来过滤发现结果的表达式。

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

    • MUTE_TYPE:您要更新的忽略规则的类型。有效的忽略规则类型为 DYNAMICSTATIC。您无法在创建后更改忽略规则的类型。

    • TIMESTAMP:仅在您更新动态忽略规则时适用。表示动态忽略规则何时到期的日期/时间字符串。该值必须设置为至少未来一天,否则请求将被拒绝。如需了解时间格式,请参阅 gcloud topic datetimes。动态忽略规则到期后,系统会将其从所有匹配的结果中移除。如果您希望动态忽略规则对匹配的发现结果无限期地起作用,请省略此字段。

Go


import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv2"
	"cloud.google.com/go/securitycenter/apiv2/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! %w", err)
	}
	fmt.Fprintf(w, "Mute rule updated %s", response.Name)
	return nil
}

Java


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

public class UpdateMuteRule {

  public static void main(String[] args) throws IOException {
    // TODO: Replace the variables within {}
    // projectId: Google Cloud Project id.
    String projectId = "google-cloud-project-id";

    // Specify the location of the mute config to update. If the mute config was
    // created with v1 API, it can be accessed with "global".
    String location = "global";

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

    updateMuteRule(projectId, location, muteConfigId);
  }

  // Updates an existing mute configuration.
  // The following can be updated in a mute config: description and filter.
  public static void updateMuteRule(String projectId, String location, String muteConfigId)
      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.
    try (SecurityCenterClient securityCenterClient = SecurityCenterClient.create()) {

      MuteConfig updateMuteConfig =
          MuteConfig.newBuilder()
              // Construct the name according to the parent type of the mute rule.
              // Parent can also be one of:
              //  * "organizations/{org_id}/locations/{location}/muteConfigs/{muteConfig_id}"
              //  * "folders/{folder_id}/locations/{location}/muteConfigs/{muteConfig_id}"
              .setName(String.format("projects/%s/locations/%s/muteConfigs/%s", projectId, location,
                  muteConfigId))
              .setDescription("Updated mute config description")
              .build();

      UpdateMuteConfigRequest updateMuteConfigRequest =
          UpdateMuteConfigRequest.newBuilder()
              .setMuteConfig(updateMuteConfig)
              // Make sure that the mask fields match the properties changed in
              // 'updateMuteConfig' object.
              // For more info on constructing update mask path, see the proto or:
              // https://cloud.google.com/security-command-center/docs/reference/rest/v2/folders.muteConfigs/patch?hl=en#query-parameters
              .setUpdateMask(FieldMask.newBuilder().addPaths("description").build())
              .build();

      MuteConfig response = securityCenterClient.updateMuteConfig(updateMuteConfigRequest);
      System.out.println(response);
    }
  }
}

Python

def update_mute_rule(parent_path: str, location_id: str, mute_config_id: str) -> Dict:
    """
    Updates an existing mute configuration.
    The following can be updated in a mute config: description, and filter/ mute rule.
    Args:
        parent: Use any one of the following resource paths to list mute configurations:
                - organizations/{organization_id}
                - folders/{folder_id}
                - projects/{project_id}
        location_id: Gcp location id; example: 'global'
        mute_config_id: Set a unique id; max of 63 chars.
    Returns:
         Dict: returns the mute rule details
    """
    from google.cloud import securitycenter_v2
    from google.protobuf import field_mask_pb2

    client = securitycenter_v2.SecurityCenterClient()

    update_mute_config = securitycenter_v2.MuteConfig()
    update_mute_config.name = (
        parent_path + "/locations/" + location_id + "/muteConfigs/" + mute_config_id
    )
    update_mute_config.description = "Updated mute config description"

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

    request = securitycenter_v2.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}")
    return mute_config

REST

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

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

  {
    "description": "RULE_DESCRIPTION",
    "filter": "FILTER",
    "type": "MUTE_TYPE",
    "expiryTime": "TIMESTAMP"
  }

替换以下内容:

  • PARENT:忽略规则的父级资源(organizationsfoldersprojects
  • PARENT_ID:组织、文件夹或项目的 ID
  • LOCATION:在其中管理忽略规则的 Security Command Center 位置;如果启用了数据驻留,请使用 eusaus;否则,请使用值 global
  • CONFIG_ID:忽略规则的数字 ID
  • RULE_DESCRIPTION:忽略规则的说明(最多 1,024 个字符)
  • FILTER:您定义来过滤发现结果的表达式
  • MUTE_TYPE:您要更新的忽略规则的类型。有效的忽略规则类型为 DYNAMICSTATIC。您无法在创建后更改忽略规则的类型。
  • TIMESTAMP:仅在您更新动态忽略规则时适用。表示动态忽略规则何时到期的日期/时间字符串。该值必须设置为至少未来一天,否则请求将被拒绝。如需了解时间格式,请参阅 gcloud topic datetimes。动态忽略规则到期后,系统会将其从所有匹配的结果中移除。如果您希望动态忽略规则对匹配的发现结果无限期地起作用,请省略此字段。

删除忽略规则

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

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

  • 您无法恢复已删除的忽略规则。
  • 删除静态忽略规则并不会自动取消忽略任何已忽略的发现结果。您必须手动或以编程方式取消忽略发现结果
  • 删除动态忽略规则会自动从之前匹配的所有发现结果中移除该规则,并在这些发现结果与任何其他规则不匹配时取消忽略这些发现结果。
  • 系统不会忽略将来与已删除忽略规则中的过滤条件匹配的发现结果。

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

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

控制台

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

    转到“忽略规则”

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

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

  4. 点击 删除

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

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 位置;如果启用了数据驻留,请使用 eusaus;否则,请使用值 global
  3. 确认您删除忽略规则的请求。

Go


import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv2"
	"cloud.google.com/go/securitycenter/apiv2/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


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

public class DeleteMuteRule {

  public static void main(String[] args) throws IOException {
    // TODO(Developer): Replace the following variables
    // projectId: Google Cloud Project id.
    String projectId = "google-cloud-project-id";

    // Specify the location of the mute config. If the mute config was
    // created with v1 API, it can be accessed with "global".
    String location = "global";

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

    deleteMuteRule(projectId, location, 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 location, String muteConfigId)
      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.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
      // Use appropriate `MuteConfigName` methods depending on the parent type.
      // folder -> MuteConfigName.ofFolderLocationMuteConfigName()
      // organization -> MuteConfigName.ofOrganizationLocationMuteConfigName()
      client.deleteMuteConfig(
          MuteConfigName.ofProjectLocationMuteConfigName(projectId, location, muteConfigId));

      System.out.println("Mute rule deleted successfully: " + muteConfigId);
    }
  }
}

Python

def delete_mute_rule(parent_path: str, location_id: str, mute_config_id: str) -> None:
    """
    Deletes a mute configuration given its resource name.
    Note: Previously muted findings are not affected when a mute config is deleted.
    Args:
         parent_path: use any one of the following options:
                     - organizations/{organization_id}
                     - folders/{folder_id}
                     - projects/{project_id}
        location_id: Gcp location id; example: 'global'
        mute_config_id: Set a unique id; max of 63 chars.
    Returns:
         None: returns none mute rule is deleted
    """
    from google.cloud import securitycenter_v2

    client = securitycenter_v2.SecurityCenterClient()

    request = securitycenter_v2.DeleteMuteConfigRequest()
    request.name = (
        parent_path + "/locations/" + location_id + "/muteConfigs/" + mute_config_id
    )

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

REST

在 Security Command Center API 中,使用 muteConfigs.delete 方法删除忽略规则。

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

替换以下内容:

  • PARENT:忽略规则的父级资源(organizationsfoldersprojects
  • PARENT_ID:组织、文件夹或项目的 ID
  • LOCATION:在其中管理忽略规则的 Security Command Center 位置;如果启用了数据驻留,请使用 eusaus;否则,请使用值 global
  • CONFIG_ID:忽略规则的数字 ID