管理忽略規則

本文說明如何建立及管理靜音規則,自動將 Security Command Center 中的發現項目設為靜音。

必要的角色

如要取得管理靜音規則所需的權限,請要求管理員在組織、資料夾或專案中,授予您下列 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

建立忽略規則

貴機構最多可建立 1,000 條靜音規則。

建議您在忽略規則設定中只使用動態忽略規則,因為這類規則比靜態忽略規則更具彈性。如要比較忽略規則類型,請參閱「忽略規則類型」。

如要建立忽略規則,請按一下要使用程序的標籤:

控制台

定義忽略規則

  1. 前往 Google Cloud 控制台的「Findings」(發現事項) 頁面。

    前往「發現項目」

  2. 選取機構或專案。

  3. 按一下「忽略選項」,然後選取「管理忽略規則」

  4. 按一下「建立忽略規則」

  5. 輸入「忽略規則 ID」

  6. 建議:輸入說明,提供發現項目遭到靜音的背景資訊。

  7. 如要確認忽略規則的範圍,請檢查「父項資源」值。

選用:新增到期日

您可以為動態忽略規則新增到期日。

  1. 選取「暫時忽略相符的發現項目」
  2. 如要設定動態忽略規則的到期日,請選取日曆,然後選擇至少 24 小時以後的日期和時間。

    過期後,靜音規則將失效。

選用:使用查詢限制忽略規則

如果您新增查詢,忽略規則只會套用至符合查詢的發現項目。

如要使用查詢限制忽略規則,請在「Findings query」(發現項目查詢) 部分中,按一下 「Add filter」(新增篩選器)

「新增篩選器」選單可供選擇支援的搜尋屬性和值。

  1. 在「選取篩選條件」選單中,選取發現項目屬性,或在「搜尋發現項目屬性」方塊中輸入屬性名稱。系統會顯示可用的子屬性清單。
  2. 選取子屬性。系統會顯示選取欄位,您可以使用所選子屬性、查詢運算子,以及一或多個子屬性值,建構查詢陳述式。
  3. 從面板中選取子屬性的運算子和一或多個值。 如要進一步瞭解查詢運算子和使用的函式,請參閱「新增篩選條件」選單中的查詢運算子

    如要重新開始,請按一下「重設」

  4. 按一下「套用」

    選單會關閉,查詢也會更新。

  5. 重複上述步驟,直到結果查詢包含所有需要的屬性為止。
如要查看查詢結果,請按一下「預覽相符的發現項目」。表格會列出符合查詢條件的發現項目。

如果查詢結果與正確發現不符,請視需要修訂查詢,然後再次預覽結果。重複這個步驟,直到對結果感到滿意為止。

儲存忽略規則

按一下 [儲存]。 Google Cloud 控制台會顯示靜音規則清單。

gcloud

  1. 在 Google Cloud 控制台中啟用 Cloud Shell。

    啟用 Cloud Shell

    控制台底部會開啟 Cloud Shell 工作階段,並顯示指令列提示。 Google Cloud Cloud Shell 是已安裝 Google Cloud CLI 的殼層環境,並已針對您目前的專案設定好相關值。工作階段可能要幾秒鐘的時間才能初始化。

  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:靜音規則的說明,最多 1,024 個字元。
    • 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:靜音規則的說明 (最多 1,024 個半形字元)
  • FILTER:您定義的運算式,用於篩選調查結果

    舉例來說,如要將 OPEN_FIREWALL 發現項目設為靜音,篩選器可以是 "category=\"OPEN_FIREWALL\""

  • MUTE_TYPE:要建立的忽略規則類型。有效的忽略規則類型為 DYNAMICSTATIC。建立忽略規則後,就無法變更規則類型。

  • TIMESTAMP:僅適用於建立動態忽略規則。日期和時間字串,指出動態忽略規則的失效時間。值必須設為至少一天後的日期,否則系統會拒絕要求。如要瞭解時間格式,請參閱 gcloud topic datetimes。動態靜音規則過期後,系統會從所有相符的發現項目中移除該規則。如要讓動態忽略規則無限期忽略相符的發現項目,請省略這個欄位。

回覆內容會包含靜音設定 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 啟用資料落地功能,則 list 指令的範圍也會限制在所選的 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 的殼層環境,並已針對您目前的專案設定好相關值。工作階段可能要幾秒鐘的時間才能初始化。

  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 設定」頁面,然後點選「Mute rules」(靜音規則) 分頁標籤。

    前往忽略規則

  2. 視需要選取 Google Cloud 專案或機構。

  3. 「忽略規則」部分會顯示忽略規則清單。

  4. 按一下要查看的規則名稱。

    系統會開啟頁面,顯示靜音規則的設定。

gcloud

  1. 在 Google Cloud 控制台中啟用 Cloud Shell。

    啟用 Cloud Shell

    控制台底部會開啟 Cloud Shell 工作階段,並顯示指令列提示。 Google Cloud Cloud Shell 是已安裝 Google Cloud CLI 的殼層環境,並已針對您目前的專案設定好相關值。工作階段可能要幾秒鐘的時間才能初始化。

  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 的殼層環境,並已針對您目前的專案設定好相關值。工作階段可能要幾秒鐘的時間才能初始化。

  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 的殼層環境,並已針對您目前的專案設定好相關值。工作階段可能要幾秒鐘的時間才能初始化。

  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