ミュートルールを管理

このドキュメントでは、Security Command Center で検出結果を自動的にミュートするミュートルールを作成して管理する方法について説明します。

必要なロール

ミュートルールを管理するために必要な権限を取得するには、組織、フォルダ、またはプロジェクトに対する次の IAM ロールを付与するよう管理者に依頼します。

ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

必要な権限は、カスタムロールや他の事前定義ロールから取得することもできます。

ミュートルールの作成

1 つの組織で作成できるミュートルールは 1,000 個までです。

動的ミュートルールは静的ミュートルールよりも柔軟性が高いため、ミュートルール構成では動的ミュートルールのみを使用することをおすすめします。ミュートルールのタイプの比較については、ミュートルールのタイプをご覧ください。

ミュートルールを作成するには、使用する方法のタブをクリックします。

コンソール

ミュートルールを定義する

  1. Google Cloud コンソールで、[検出結果] ページに移動します。

    [検出結果] に移動

  2. 組織またはプロジェクトを選択します。

  3. [ミュート オプション] をクリックし、[ミュートルールを管理] を選択します。

  4. [ミュートルールを作成する] をクリックします。

  5. ミュートルール ID を入力します。

  6. 推奨: 検出結果がミュートされる理由を説明する説明を入力します。

  7. ミュートルールの範囲を確認するには、[親リソース] の値を確認します。

省略可: 有効期限を追加する

動的ミュートルールに有効期限を追加できます。

  1. [一致する検出結果を一時的にミュートする] を選択します。
  2. 動的ミュートルールの有効期限を構成するには、カレンダーを選択し、24 時間以上先の日時を選択します。

    有効期限が切れると、ミュートルールは無効になります。

省略可: クエリでミュート ルールを制限する

クエリを追加すると、ミュートルールはクエリに一致する検出結果にのみ適用されます。

クエリでミュートルールを制限するには、[検出クエリ] セクションで [フィルタを追加] をクリックします。

[フィルタを追加] メニューでは、サポートされている検出結果属性と値を選択できます。

  1. [フィルタを選択] メニューで、検出属性を選択するか、[検出属性の検索] ボックスに名前を入力します。使用可能なサブ属性のリストが表示されます。
  2. サブ属性を選択します。選択フィールドには、選択したサブ属性、クエリ演算子、サブ属性の 1 つ以上の値を使用してクエリ ステートメントを作成できる場所が表示されます。
  3. パネルで演算子とサブ属性の値を 1 つ以上選択します。クエリ演算子とそれらが使用する関数の詳細については、[フィルタを追加] メニューのクエリ演算子をご覧ください。

    最初からやり直す場合は、[リセット] をクリックします。

  4. [適用] をクリックします。

    メニューが閉じて、クエリが更新されます。

  5. 検出クエリに必要な属性がすべて表示されるまで、この操作を繰り返します。
クエリ結果を確認するには、[一致する検出をプレビュー] をクリックします。クエリに一致する検出結果がテーブルに表示されます。

クエリが正しい結果と一致しない場合は、必要に応じてクエリを修正し、結果を再度プレビューします。結果に満足するまで、この手順を繰り返します。

ミュートルールを保存する

[保存] をクリックします。 Google Cloud コンソールにミュートルールのリストが表示されます。

gcloud

  1. Google Cloud コンソールで Cloud Shell をアクティブにします。

    Cloud Shell をアクティブにする

    Google Cloud コンソールの下部にある Cloud Shell セッションが開始し、コマンドライン プロンプトが表示されます。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: ミュートルールが適用されるリソース階層内の範囲(organizationfolder、または project)。
    • 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: 動的ミュートルールを作成する場合にのみ適用されます。動的ミュートルールの有効期限を示す日時文字列。この値は、今後 1 日以上先の日付に設定する必要があります。設定しないと、リクエストは拒否されます。時間形式については、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: ミュートルールの親リソース(organizationsfolders、または projects
  • 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: 動的ミュートルールを作成する場合にのみ適用されます。動的ミュートルールの有効期限を示す日時文字列。この値は、今後 1 日以上先の日付に設定する必要があります。設定しないと、リクエストは拒否されます。時間形式については、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
  • 1gcpMetadata.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 をアクティブにする

    Google Cloud コンソールの下部にある Cloud Shell セッションが開始し、コマンドライン プロンプトが表示されます。Cloud Shell はシェル環境です。Google Cloud CLI がすでにインストールされており、現在のプロジェクトの値もすでに設定されています。セッションが初期化されるまで数秒かかることがあります。

  2. ミュートルールを一覧表示するには、gcloud scc muteconfigs list コマンドを実行します。

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

    次のように置き換えます。

    • PARENT: 親 organizationfolder、または project(ミュートルールを一覧表示する場合)
    • 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: ミュートルールの親リソース(organizationsfolders、または projects
  • 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 をアクティブにする

    Google Cloud コンソールの下部にある Cloud Shell セッションが開始し、コマンドライン プロンプトが表示されます。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: ミュートルールの親リソース(organizationfolder、または project
    • 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: ミュートルールの親リソース(organizationsfolders、または projects
  • 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 をアクティブにする

    Google Cloud コンソールの下部にある Cloud Shell セッションが開始し、コマンドライン プロンプトが表示されます。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: ミュートルールの親リソース(organizationfolder、または project
    • PARENT_ID: 組織、フォルダ、プロジェクトの ID
    • LOCATION: ミュートルールを管理する Security Command Center のロケーション。データ所在地が有効になっている場合は、eusaus を使用します。それ以外の場合は、global を使用します。
    • RULE_DESCRIPTION: ミュートルールの説明(最大: 1,024 文字)。
    • FILTER: 検出結果のフィルタを定義する式。

      たとえば、OPEN_FIREWALL の検出結果をミュートするには、フィルタを FILTER="category=\"OPEN_FIREWALL\"" にします。

    • MUTE_TYPE: 更新するミュートルールのタイプ。有効なミュートルールのタイプは DYNAMICSTATIC です。作成後にミュートルールのタイプを変更することはできません。

    • TIMESTAMP: 動的ミュートルールを更新する場合にのみ適用されます。動的ミュートルールの有効期限を示す日時文字列。この値は、今後 1 日以上先の日付に設定する必要があります。設定しないと、リクエストは拒否されます。時間形式については、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: ミュートルールの親リソース(organizationsfolders、または projects
  • PARENT_ID: 組織、フォルダ、プロジェクトの ID
  • LOCATION: ミュートルールを管理する Security Command Center のロケーション。データ所在地が有効になっている場合は、eusaus を使用します。それ以外の場合は、global を使用します。
  • CONFIG_ID: ミュートルールの数値 ID
  • RULE_DESCRIPTION: ミュートルールの説明(最大: 1,024 文字)
  • FILTER: 検出結果のフィルタを定義する式
  • MUTE_TYPE: 更新するミュートルールのタイプ。有効なミュートルールのタイプは DYNAMICSTATIC です。作成後にミュートルールのタイプを変更することはできません。
  • TIMESTAMP: 動的ミュートルールを更新する場合にのみ適用されます。動的ミュートルールの有効期限を示す日時文字列。この値は、今後 1 日以上先の日付に設定する必要があります。設定しないと、リクエストは拒否されます。時間形式については、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 をアクティブにする

    Google Cloud コンソールの下部にある Cloud Shell セッションが開始し、コマンドライン プロンプトが表示されます。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: ミュートルールの親リソース(organizationfolder、または project
    • 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: ミュートルールの親リソース(organizationsfolders、または projects
  • PARENT_ID: 組織、フォルダ、プロジェクトの ID
  • LOCATION: ミュートルールを管理する Security Command Center のロケーション。データ所在地が有効になっている場合は、eusaus を使用します。それ以外の場合は、global を使用します。
  • CONFIG_ID: ミュートルールの数値 ID