分析のために検出結果を BigQuery にストリーミングする

このページでは、BigQuery の Security Command Center エクスポート機能を使用して、新しい検出結果と更新された検出結果を BigQuery データセットにストリーミングする方法について説明します。既存の検出結果は、更新しない限り BigQuery に送信されません。

BigQuery は、Google Cloud のペタバイト規模の費用対効果に優れたフルマネージド型の分析データ ウェアハウスです。膨大な量のデータに対してほぼリアルタイムで分析を行うことができます。BigQuery を使用すると、新規および更新された検索結果にクエリを実行して、データをフィルタして必要なものを探し、カスタム レポートを生成できます。BigQuery の詳細については、BigQuery のドキュメントをご覧ください。

概要

この機能を有効にすると、Security Command Center に書き込まれた新しい検出結果が、ほぼリアルタイムで BigQuery テーブルにエクスポートされます。このデータを既存のワークフローに統合し、カスタム分析を作成できます。この機能を組織、フォルダ、プロジェクトのレベルで有効にして、要件に基づいて検出結果をエクスポートできます。

この機能は、Security Command Center の検出結果を BigQuery にエクスポートする際におすすめの方法です。これはフルマネージド ソリューションであり、手動操作やカスタムコードの作成が不要です。

データセットの構造

この機能により、source_idfinding_idevent_time でクラスタ化された findings テーブルに、新しい検出結果とその後の更新が新しい行として追加されます。

検出結果が更新されると、複数の検出レコードが作成されます。source_idfinding_id の値は同じですが、event_time の値は異なります。このデータセット構造を使用して、検出状態の変化を時系列で把握できます。

データセット内でエントリが重複している可能性があります。これらのエントリを解析するには、最初のクエリ例に示すように、DISTINCT 句を使用します。

各データセットには findings テーブルが含まれています。テーブルには次のフィールドがあります。

フィールド 説明
source_id Security Command Center が検出結果のソースに割り当てる一意の識別子。たとえば、Cloud Anomaly Detection を情報源とする検出結果はすべて同じ source_id 値になります。

例: 1234567890
finding_id 検出結果を表す一意の識別子。これは、組織のソース内で一意です。英数字で、32 文字以下です。
event_time イベントが発生した時間、または検出結果の更新が発生した時間。たとえば、検出結果がオープン状態のファイアウォールを表している場合、event_time は、検出機能がオープン状態のファイアウォールを検出した時間になります。検出結果が後で解決された場合、この解決時間が反映されます。

例: 2019-09-26 12:48:00.985000 UTC
finding セキュリティ、リスク、健全性、プライバシーなどの評価データの記録。Security Command Center に取り込まれ、表示、通知、分析、ポリシーテスト、適用で使用されます。たとえば、App Engine アプリケーションで見つかったクロスサイト スクリプティング(XSS)の脆弱性が記録されます。

ネストされたフィールドの詳細については、API リファレンスの Finding オブジェクトをご覧ください。
resource この検出結果に関連付けられている Google Cloud リソースに関する情報。

ネストされたフィールドの詳細については、API リファレンスの Resource オブジェクトをご覧ください。

費用

この機能に関連して BigQuery の料金が請求されます。詳細については、BigQuery の料金をご覧ください。

始める前に

この機能を有効にする前に、次の手順を完了する必要があります。

権限を設定する

このガイドの内容を行うには、次の Identity and Access Management(IAM)ロールが必要です。

BigQuery データセットを作成する

BigQuery データセットを作成します。詳細については、データセットの作成をご覧ください。

データ所在地を計画する

Security Command Center でデータ所在地が有効になっている場合、BigQuery(BigQueryExport リソース)へのストリーミング エクスポートを定義する構成はデータ所在地の制御の対象であり、選択したSecurity Command Center のロケーションに保存されます。

Security Command Center のロケーションの検出結果を BigQuery にエクスポートするには、検出結果と同じ Security Command Center のロケーションに BigQuery エクスポートを構成する必要があります。

BigQuery エクスポートで使用されるフィルタには、所在地管理の対象となるデータが含まれる可能性があるため、作成する前に正しいロケーションを指定していることを確認してください。Security Command Center では、エクスポートを作成するロケーションは制限されません。

BigQuery エクスポートは作成場所にのみ保存され、他のロケーションで表示や編集はできません。

BigQuery エクスポートを作成した後に、そのロケーションを変更することはできません。ロケーションを変更するには、BigQuery エクスポートを削除して、新しいロケーションに再作成する必要があります。

API 呼び出しを使用して BigQuery エクスポートを取得するには、bigQueryExport の完全なリソース名でロケーションを指定する必要があります。次に例を示します。

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

同様に、gcloud CLI を使用して BigQuery エクスポートを取得するには、構成の完全なリソース名または --locations フラグを使用してロケーションを指定する必要があります。次に例を示します。

gcloud scc scc bqexports get myBigQueryExport organizations/123 \
    --location=locations/us

検出結果を Security Command Center から BigQuery にエクスポートする

検出結果をエクスポートするには、まず Security Command Center API を有効にします。

Security Command Center API の有効化

Security Command Center API を有効にするには、次のようにします。

  1. Google Cloud コンソールで [API ライブラリ] ページに移動します。

    [API ライブラリ] に移動

  2. Security Command Center API を有効にするプロジェクトを選択します。

  3. [検索] ボックスに「Security Command Center」と入力し、検索結果で [Security Command Center] をクリックします。

  4. 表示された API ページで [有効にする] をクリックします。

プロジェクトで Security Command Center API が有効になります。次に、gcloud CLI を使用して、BigQuery に新しいエクスポート構成を作成します。

VPC Service Controls で境界へのアクセス権を付与する

VPC Service Controls を使用していて、BigQuery データセットがサービス境界内のプロジェクトの一部である場合、検出結果をエクスポートするために、プロジェクトへのアクセス権を付与する必要があります。

プロジェクトへのアクセス権を付与するには、検出結果をエクスポートするプリンシパルとプロジェクトの上り(内向き)ルールと下り(外向き)ルールを作成します。このルールは、保護されたリソースへのアクセスを許可し、ユーザーが BigQuery データセットに対する setIamPolicy 権限を持っていることを BigQuery が確認できるようにします。

BigQuery への新しいエクスポートを設定する前に

  1. Google Cloud コンソールの [VPC Service Controls] ページに移動します。

    [VPC Service Controls] に移動

  2. 必要に応じて組織を選択します。

  3. 変更するサービス境界の名前をクリックします。

    変更する必要があるサービス境界を確認するには、ログで RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER 違反を示すエントリを確認します。これらのエントリで、servicePerimeterName フィールド accessPolicies/ACCESS_POLICY_ID/servicePerimeters/SERVICE_PERIMETER_NAME を確認します。

  4. [境界を編集] をクリックします。

  5. ナビゲーション メニューで、[上り(内向き)ポリシー] をクリックします。

  6. ユーザーやサービス アカウントの上り(内向き)ルールを構成するには、次のパラメータを使用します。

    • API クライアントの FROM 属性:
      • [ID] プルダウン メニューで [選択した ID] を選択します。
      • [ソース] プルダウン メニューで、[すべてのソース] を選択します。
      • [選択] をクリックして、Security Command Center API の呼び出しに使用するプリンシパルを入力します。
    • Google Cloud サービス / リソースの TO 属性:
      • [プロジェクト] プルダウン メニューで、[選択したプロジェクト] を選択します。
      • [選択] をクリックしてから、BigQuery データセットを含むプロジェクトを入力します。
      • [サービス] プルダウン メニューで [選択したサービス]、[BigQuery API] の順に選択します。
      • [メソッド] プルダウン メニューで、[すべてのアクション] を選択します。
  7. [保存] をクリックします。

  8. ナビゲーション メニューで、[下り(外向き)ポリシー] をクリックします。

  9. [Add Rule] をクリックします。

  10. ユーザー アカウントやサービス アカウントの下り(外向き)ルールを構成するには、次のパラメータを入力します。

    • API クライアントの FROM 属性:
      • [ID] プルダウン メニューで [選択した ID] を選択します。
      • [選択] をクリックして、Security Command Center API の呼び出しに使用するプリンシパルを入力します。
    • Google Cloud サービス / リソースの TO 属性:
      • [プロジェクト] プルダウン メニューで、[すべてのプロジェクト] を選択します。
      • [サービス] プルダウン メニューで [選択したサービス]、[BigQuery API] の順に選択します。
      • [メソッド] プルダウン メニューで、[すべてのアクション] を選択します。
  11. [保存] をクリックします。

BigQuery への新しいエクスポートを設定する

このステップでは、検出結果を BigQuery インスタンスにエクスポートするためのエクスポート構成を作成します。エクスポート構成は、プロジェクト、フォルダ、組織のレベルで作成できます。たとえば、プロジェクトから検出結果を BigQuery データセットにエクスポートする場合、プロジェクト レベルでエクスポート構成を作成し、そのプロジェクトに関連する検出結果のみをエクスポートします。必要に応じてフィルタを指定し、特定の検索結果のみをエクスポートすることもできます。

エクスポート構成設は適切なレベルで作成してください。たとえば、プロジェクト B でエクスポート構成を作成して、プロジェクト A から検出結果をエクスポートし、resource.project_display_name: project-a-id などのフィルタを定義する場合、この構成では検出結果はエクスポートされません。

組織で作成できる BigQuery へのエクスポート構成は最大 500 個です。同じデータセットを複数のエクスポート構成に使用できます。同じデータセットを使用する場合、すべての更新は同じ検出結果テーブルに対して行われます。

最初のエクスポート構成を作成すると、サービス アカウントが自動的に作成されます。このサービス アカウントは、データセット内に検出結果テーブルを作成または更新し、テーブルに結果をエクスポートするために必要です。形式は service-org-ORGANIZATION_ID@gcp-sa-scc-notification.iam.gservicaccount.com で、BigQuery データセット レベルで BigQuery データ編集者(roles/bigquery.dataEditor)のロールが付与されます。

gcloud

  1. Google Cloud コンソールに移動します。

    Google Cloud コンソールに移動

  2. Security Command Center API を有効にしたプロジェクトを選択します。

  3. [Cloud Shell をアクティブにする] をクリックします。

  4. 次のコマンドを実行して、新しいエクスポート構成を作成します。

    gcloud scc bqexports create BIG_QUERY_EXPORT \
      --dataset=DATASET_NAME \
      --folder=FOLDER_ID | --organization=ORGANIZATION_ID | --project=PROJECT_ID \
      --location=LOCATION \
      [--description=DESCRIPTION] \
      [--filter=FILTER]
    

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

    • BIG_QUERY_EXPORT は、このエクスポート構成の名前に置き換えます。

    • DATASET_NAME は、BigQuery データセットの名前に置き換えます(projects/<PROJECT_ID>/datasets/<DATASET_ID> など)。

    • FOLDER_IDORGANIZATION_ID または PROJECT_ID は、フォルダ、組織、またはプロジェクトの名前に置き換えます。次のいずれかのオプションを設定する必要があります。フォルダと組織の場合、名前はフォルダ ID または組織 ID です。プロジェクト名は、プロジェクト番号またはプロジェクト ID になります。

    • LOCATION: データ所在地が有効になっている場合は、BigQuery エクスポートを作成する Security Command Center のロケーションを指定します。BigQuery エクスポート構成は、この場所に保存されます。この場所からの検出結果のみがエクスポートに含まれます。

      データ所在地が有効になっていない場合、--location フラグを指定すると、Security Command Center API v2 を使用して BigQuery エクスポートが作成されます。フラグの有効な値は global のみです。

    • DESCRIPTION は、人が読める形式のエクスポート構成の説明に置き換えます。この変数の指定は任意です。

    • FILTER は、エクスポートに含める検出結果を定義する式で置き換えます。たとえば、XSS_SCRIPTING カテゴリでフィルタリングする場合は「"category=\"XSS_SCRIPTING\"」と入力します。この変数の指定は任意です。

Java

Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

次のサンプルでは、v1 API を使用します。v2 のサンプルを変更するには、v1v2 に置き換え、/locations/LOCATION をリソース名に追加します。

ほとんどのリソースでは、/PARENT/PARENT_ID の後に /locations/LOCATION をリソース名に追加します。ここで、PARENTorganizationsfolders、または projects です。

検出結果の場合は、/sources/SOURCE_ID の後に /locations/LOCATION をリソース名に追加します。ここで、SOURCE_ID は、検出結果を発行した Security Command Center サービスの ID です。


import com.google.cloud.securitycenter.v1.BigQueryExport;
import com.google.cloud.securitycenter.v1.CreateBigQueryExportRequest;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import java.io.IOException;
import java.util.UUID;

public class CreateBigQueryExport {

  public static void main(String[] args) throws IOException {
    // TODO(Developer): Modify the following variable values.

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

    // filter: Expression that defines the filter to apply across create/update events of findings.
    String filter =
        "severity=\"LOW\" OR severity=\"MEDIUM\" AND "
            + "category=\"Persistence: IAM Anomalous Grant\" AND "
            + "-resource.type:\"compute\"";

    // bigQueryDatasetId: The BigQuery dataset to write findings' updates to.
    String bigQueryDatasetId = "your-bigquery-dataset-id";

    // bigQueryExportId: Unique identifier provided by the client.
    // For more info, see:
    // https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query#export_findings_from_to
    String bigQueryExportId = "default-" + UUID.randomUUID().toString().split("-")[0];

    createBigQueryExport(parent, filter, bigQueryDatasetId, bigQueryExportId);
  }

  // Create export configuration to export findings from a project to a BigQuery dataset.
  // Optionally specify filter to export certain findings only.
  public static void createBigQueryExport(
      String parent, String filter, String bigQueryDatasetId, String bigQueryExportId)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      // Create the BigQuery export configuration.
      BigQueryExport bigQueryExport =
          BigQueryExport.newBuilder()
              .setDescription(
                  "Export low and medium findings if the compute resource "
                      + "has an IAM anomalous grant")
              .setFilter(filter)
              .setDataset(String.format("%s/datasets/%s", parent, bigQueryDatasetId))
              .build();

      CreateBigQueryExportRequest bigQueryExportRequest =
          CreateBigQueryExportRequest.newBuilder()
              .setParent(parent)
              .setBigQueryExport(bigQueryExport)
              .setBigQueryExportId(bigQueryExportId)
              .build();

      // Create the export request.
      BigQueryExport response = client.createBigQueryExport(bigQueryExportRequest);

      System.out.printf("BigQuery export request created successfully: %s\n", response.getName());
    }
  }
}

Python

Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

次のサンプルでは、v1 API を使用します。v2 のサンプルを変更するには、v1v2 に置き換え、/locations/LOCATION をリソース名に追加します。

ほとんどのリソースでは、/PARENT/PARENT_ID の後に /locations/LOCATION をリソース名に追加します。ここで、PARENTorganizationsfolders、または projects です。

検出結果の場合は、/sources/SOURCE_ID の後に /locations/LOCATION をリソース名に追加します。ここで、SOURCE_ID は、検出結果を発行した Security Command Center サービスの ID です。



def create_bigquery_export(
    parent: str, export_filter: str, bigquery_dataset_id: str, bigquery_export_id: str
):
    from google.cloud import securitycenter

    """
    Create export configuration to export findings from a project to a BigQuery dataset.
    Optionally specify filter to export certain findings only.

    Args:
        parent: Use any one of the following resource paths:
             - organizations/{organization_id}
             - folders/{folder_id}
             - projects/{project_id}
        export_filter: Expression that defines the filter to apply across create/update events of findings.
        bigquery_dataset_id: The BigQuery dataset to write findings' updates to.
        bigquery_export_id: Unique identifier provided by the client.
             - example id: f"default-{str(uuid.uuid4()).split('-')[0]}"
        For more info, see:
        https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query#export_findings_from_to
    """
    client = securitycenter.SecurityCenterClient()

    # Create the BigQuery export configuration.
    bigquery_export = securitycenter.BigQueryExport()
    bigquery_export.description = "Export low and medium findings if the compute resource has an IAM anomalous grant"
    bigquery_export.filter = export_filter
    bigquery_export.dataset = f"{parent}/datasets/{bigquery_dataset_id}"

    request = securitycenter.CreateBigQueryExportRequest()
    request.parent = parent
    request.big_query_export = bigquery_export
    request.big_query_export_id = bigquery_export_id

    # Create the export request.
    response = client.create_big_query_export(request)

    print(f"BigQuery export request created successfully: {response.name}\n")

エクスポート構成を作成してから約 15 分以内に、BigQuery データセットに検出結果が表示されます。BigQuery テーブルが作成されると、フィルタとスコープに一致する新しい結果と更新された結果が、ほぼリアルタイムでテーブルに表示されます。

検出結果を確認するには、検出結果の確認をご覧ください。

BigQuery への新しいエクスポートの上り(内向き)ルールを作成する

VPC Service Controls を使用していて、BigQuery データセットがサービス境界内のプロジェクトの一部である場合は、BigQuery への新しいエクスポートの上り(内向き)ルールを作成する必要があります。

  1. BigQuery への新しいエクスポートを設定するからサービス境界を再度開きます。

    [VPC Service Controls] に移動

  2. [上り(内向き)ポリシー] をクリックします。

  3. [Add Rule] をクリックします。

  4. エクスポート構成の上り(内向き)ルールを構成するには、次のパラメータを入力します。

    • API クライアントの FROM 属性:
      • [ソース] プルダウン メニューで、[すべてのソース] を選択します。
      • [ID] プルダウン メニューで [選択した ID] を選択します。
      • [選択] をクリックして、BigQuery エクスポート構成サービス アカウントの名前「service-org-ORGANIZATION_ID@gcp-sa-scc-notification.iam.gserviceaccount.com」を入力します。
    • GCP サービス / リソースの TO 属性:
      • [プロジェクト] プルダウン メニューで、[選択したプロジェクト] を選択します。
      • [選択] をクリックしてから、BigQuery データセットを含むプロジェクトを選択します。
      • [サービス] プルダウン メニューで [選択したサービス]、[BigQuery API] の順に選択します。
      • [メソッド] プルダウン メニューで、[すべてのアクション] を選択します。
  5. ナビゲーション メニューで、[保存] をクリックします。

選択したプロジェクト、ユーザー、サービス アカウントが保護されたリソースにアクセスし、検出結果をエクスポートできるようになりました。

このガイドの手順をすべて完了していて、エクスポートが正しく機能している場合、次のルールは削除できます。

  • プリンシパルの上り(内向き)ルール
  • プリンシパルの下り(外向き)ルール

これらのルールは、エクスポート構成の構成にのみ必要でした。ただし、エクスポート構成を引き続き使用するには、上記で作成した上り(内向き)ルールを保持する必要があります。これにより、Security Command Center がサービス境界の背後にある BigQuery データセットに検出結果をエクスポートできるようになります。

エクスポート構成の詳細を表示する

gcloud

  1. Google Cloud コンソールに移動します。

    Google Cloud コンソールに移動

  2. Security Command Center API を有効にしたプロジェクトを選択します。

  3. Cloud Shell をアクティブにする」をクリックします。

  4. エクスポート構成の詳細を確認するには、次のコマンドを実行します。

    gcloud scc bqexports get BIG_QUERY_EXPORT \
      --folder=FOLDER_ID | --organization=ORGANIZATION_ID | --project=PROJECT_ID \
      --location=LOCATION
    

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

    • BIG_QUERY_EXPORT は、このエクスポート構成の名前に置き換えます。

    • FOLDER_IDORGANIZATION_ID または PROJECT_ID は、フォルダ、組織、またはプロジェクトの名前に置き換えます。次のいずれかのオプションを設定する必要があります。フォルダと組織の場合、名前はフォルダ ID または組織 ID です。プロジェクト名は、プロジェクト番号またはプロジェクト ID になります。

    • LOCATION: データ所在地が有効になっているか、v2 API を使用して BigQueryExport リソースが作成された場合は必須。

      データ所在地が有効になっている場合は、エクスポートが保存される Security Command Center のロケーションを指定します。

      データ所在地が有効になっていない場合、Security Command Center API v2 を使用して、BigQueryExport リソースが作成された場合 /locations/LOCATION のみを含めます。この場合、唯一の有効な場所が global です。

    たとえば、組織 ID が 123 の組織から my-bq-export という名前のエクスポート構成を取得するには、次のコマンドを実行します。

    gcloud scc bqexports get my-bq-export --organization=123
    

Java

Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

次のサンプルでは、v1 API を使用します。v2 のサンプルを変更するには、v1v2 に置き換え、/locations/LOCATION をリソース名に追加します。

ほとんどのリソースでは、/PARENT/PARENT_ID の後に /locations/LOCATION をリソース名に追加します。ここで、PARENTorganizationsfolders、または projects です。

検出結果の場合は、/sources/SOURCE_ID の後に /locations/LOCATION をリソース名に追加します。ここで、SOURCE_ID は、検出結果を発行した Security Command Center サービスの ID です。


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

public class GetBigQueryExport {

  public static void main(String[] args) throws IOException {
    // TODO(Developer): Modify the following variable values.

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

    // bigQueryExportId: Unique identifier that is used to identify the export.
    String bigQueryExportId = "export-id";

    getBigQueryExport(parent, bigQueryExportId);
  }

  // Retrieve an existing BigQuery export.
  public static void getBigQueryExport(String parent, String bigQueryExportId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      GetBigQueryExportRequest bigQueryExportRequest =
          GetBigQueryExportRequest.newBuilder()
              .setName(String.format("%s/bigQueryExports/%s", parent, bigQueryExportId))
              .build();

      BigQueryExport response = client.getBigQueryExport(bigQueryExportRequest);
      System.out.printf("Retrieved the BigQuery export: %s", response.getName());
    }
  }
}

Python

Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

次のサンプルでは、v1 API を使用します。v2 のサンプルを変更するには、v1v2 に置き換え、/locations/LOCATION をリソース名に追加します。

ほとんどのリソースでは、/PARENT/PARENT_ID の後に /locations/LOCATION をリソース名に追加します。ここで、PARENTorganizationsfolders、または projects です。

検出結果の場合は、/sources/SOURCE_ID の後に /locations/LOCATION をリソース名に追加します。ここで、SOURCE_ID は、検出結果を発行した Security Command Center サービスの ID です。

def get_bigquery_export(parent: str, bigquery_export_id: str):
    from google.cloud import securitycenter

    """
    Retrieve an existing BigQuery export.
    Args:
        parent: Use any one of the following resource paths:
                 - organizations/{organization_id}
                 - folders/{folder_id}
                 - projects/{project_id}
        bigquery_export_id: Unique identifier that is used to identify the export.
    """

    client = securitycenter.SecurityCenterClient()

    request = securitycenter.GetBigQueryExportRequest()
    request.name = f"{parent}/bigQueryExports/{bigquery_export_id}"

    response = client.get_big_query_export(request)
    print(f"Retrieved the BigQuery export: {response.name}")

エクスポート構成を更新する

必要に応じて、既存のエクスポート構成のフィルタ、データセット、説明を変更できます。エクスポート構成の名前は変更できません。

gcloud

  1. Google Cloud コンソールに移動します。

    Google Cloud コンソールに移動

  2. Security Command Center API を有効にしたプロジェクトを選択します。

  3. [Cloud Shell をアクティブにする] をクリックします。

  4. エクスポート構成を更新するには、次のコマンドを実行します。

    gcloud scc bqexports update BIG_QUERY_EXPORT \
      --dataset=DATASET_NAME \
      --folder=FOLDER_ID | --organization=ORGANIZATION_ID | --project=PROJECT_ID \
      --location=LOCATION \
      [--description=DESCRIPTION] \
      [--filter=FILTER]
    

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

    • BIG_QUERY_EXPORT は、更新するエクスポート構成の名前に置き換えます。

    • DATASET_NAME は、BigQuery データセットの名前に置き換えます(projects/<PROJECT_ID>/datasets/<DATASET_ID> など)。

    • FOLDER_IDORGANIZATION_ID または PROJECT_ID は、フォルダ、組織、またはプロジェクトの名前に置き換えます。次のいずれかのオプションを設定する必要があります。フォルダと組織の場合、名前はフォルダ ID または組織 ID です。プロジェクト名は、プロジェクト番号またはプロジェクト ID になります。

    • LOCATION: データ所在地が有効になっているか、v2 API を使用して BigQueryExport リソースが作成された場合は必須。

      データ所在地が有効になっている場合は、エクスポートが保存される Security Command Center のロケーションを指定します。

      データ所在地が有効になっていない場合は、フルネームに /locations/LOCATION を含めるか、BigQueryExport リソースが Security Command Center API を使用して作成された場合にのみ --location フラグを指定します。v2 の場合、有効な場所は global のみです。

    • DESCRIPTION は、人が読める形式のエクスポート構成の説明に置き換えます。この変数の指定は任意です。

    • FILTER は、エクスポートに含める検出結果を定義する式で置き換えます。たとえば、XSS_SCRIPTING カテゴリでフィルタリングする場合は「"category=\"XSS_SCRIPTING\"」と入力します。この変数の指定は任意です。

Java

Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

次のサンプルでは、v1 API を使用します。v2 のサンプルを変更するには、v1v2 に置き換え、/locations/LOCATION をリソース名に追加します。

ほとんどのリソースでは、/PARENT/PARENT_ID の後に /locations/LOCATION をリソース名に追加します。ここで、PARENTorganizationsfolders、または projects です。

検出結果の場合は、/sources/SOURCE_ID の後に /locations/LOCATION をリソース名に追加します。ここで、SOURCE_ID は、検出結果を発行した Security Command Center サービスの ID です。


import com.google.cloud.securitycenter.v1.BigQueryExport;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import com.google.cloud.securitycenter.v1.UpdateBigQueryExportRequest;
import com.google.protobuf.FieldMask;
import java.io.IOException;

public class UpdateBigQueryExport {

  public static void main(String[] args) throws IOException {
    // TODO(Developer): Modify the following variable values.

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

    // filter: Expression that defines the filter to apply across create/update events of findings.
    String filter =
        "severity=\"LOW\" OR severity=\"MEDIUM\" AND "
            + "category=\"Persistence: IAM Anomalous Grant\" AND "
            + "-resource.type:\"compute\"";

    // bigQueryExportId: Unique identifier provided by the client.
    // For more info, see:
    // https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query#export_findings_from_to
    String bigQueryExportId = "big-query-export-id";

    updateBigQueryExport(parent, filter, bigQueryExportId);
  }

  // Updates an existing BigQuery export.
  public static void updateBigQueryExport(String parent, String filter, String bigQueryExportId)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      //  Set the new values for export configuration.
      BigQueryExport bigQueryExport =
          BigQueryExport.newBuilder()
              .setName(String.format("%s/bigQueryExports/%s", parent, bigQueryExportId))
              .setFilter(filter)
              .build();

      UpdateBigQueryExportRequest request =
          UpdateBigQueryExportRequest.newBuilder()
              .setBigQueryExport(bigQueryExport)
              // Set the update mask to specify which properties should be updated.
              // If empty, all mutable fields will be updated.
              // For more info on constructing field mask path, see the proto or:
              // https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.FieldMask
              .setUpdateMask(FieldMask.newBuilder().addPaths("filter").build())
              .build();

      BigQueryExport response = client.updateBigQueryExport(request);
      if (!response.getFilter().equalsIgnoreCase(filter)) {
        System.out.println("Failed to update BigQueryExport!");
        return;
      }
      System.out.println("BigQueryExport updated successfully!");
    }
  }
}

Python

Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

次のサンプルでは、v1 API を使用します。v2 のサンプルを変更するには、v1v2 に置き換え、/locations/LOCATION をリソース名に追加します。

ほとんどのリソースでは、/PARENT/PARENT_ID の後に /locations/LOCATION をリソース名に追加します。ここで、PARENTorganizationsfolders、または projects です。

検出結果の場合は、/sources/SOURCE_ID の後に /locations/LOCATION をリソース名に追加します。ここで、SOURCE_ID は、検出結果を発行した Security Command Center サービスの ID です。

def update_bigquery_export(parent: str, export_filter: str, bigquery_export_id: str):
    """
    Updates an existing BigQuery export.
    Args:
        parent: Use any one of the following resource paths:
                 - organizations/{organization_id}
                 - folders/{folder_id}
                 - projects/{project_id}
        export_filter: Expression that defines the filter to apply across create/update events of findings.
        bigquery_export_id: Unique identifier provided by the client.
        For more info, see:
        https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query#export_findings_from_to
    """
    from google.cloud import securitycenter
    from google.protobuf import field_mask_pb2

    client = securitycenter.SecurityCenterClient()

    # Set the new values for export configuration.
    bigquery_export = securitycenter.BigQueryExport()
    bigquery_export.name = f"{parent}/bigQueryExports/{bigquery_export_id}"
    bigquery_export.filter = export_filter

    # Field mask to only update the export filter.
    # Set the update mask to specify which properties should be updated.
    # If empty, all mutable fields will be updated.
    # For more info on constructing field mask path, see the proto or:
    # https://googleapis.dev/python/protobuf/latest/google/protobuf/field_mask_pb2.html
    field_mask = field_mask_pb2.FieldMask(paths=["filter"])

    request = securitycenter.UpdateBigQueryExportRequest()
    request.big_query_export = bigquery_export
    request.update_mask = field_mask

    response = client.update_big_query_export(request)

    if response.filter != export_filter:
        print("Failed to update BigQueryExport!")
        return
    print("BigQueryExport updated successfully!")

すべてのエクスポート構成を表示する

組織、フォルダ、プロジェクトのすべてのエクスポート構成を表示できます。

gcloud

  1. Google Cloud コンソールに移動します。

    Google Cloud コンソールに移動

  2. Security Command Center API を有効にしたプロジェクトを選択します。

  3. [Cloud Shell をアクティブにする] をクリックします。

  4. エクスポート構成を一覧表示するには、次のコマンドを実行します。

    gcloud scc bqexports list \
      --folder=FOLDER_ID | --organization=ORGANIZATION_ID | --project=PROJECT_ID \
      --location=LOCATION \
      [--limit=LIMIT] \
      [--page-size=PAGE_SIZE]
    

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

    • FOLDER_IDORGANIZATION_ID または PROJECT_ID は、フォルダ、組織、またはプロジェクトの名前に置き換えます。次のいずれかのオプションを設定する必要があります。フォルダと組織の場合、名前はフォルダ ID または組織 ID です。プロジェクト名は、プロジェクト番号またはプロジェクト ID になります。

      組織 ID を指定すると、リストには、その組織で定義されているすべてのエクスポート構成が含まれます(フォルダレベルとプロジェクト レベルの組織も含む)。フォルダ ID を指定すると、リストには、フォルダレベルとフォルダ内のプロジェクトで定義されたすべてのエクスポート構成が含まれます。プロジェクト番号またはプロジェクト ID を指定すると、リストには、そのプロジェクトのすべてのエクスポート構成が含まれます。

    • LOCATION: データ所在地が有効になっているか、v2 API を使用して BigQueryExport リソースが作成された場合は必須。

      データ所在地が有効になっている場合は、エクスポートが保存される Security Command Center のロケーションを指定します。

      データ所在地が有効になっていない場合、--location フラグを含めると、Security Command Center API v2 を使用して作成された BigQueryExport リソースのみが一覧表示されます。有効な場所は global のみです。

    • LIMIT は、表示するエクスポート構成の数に置き換えます。 この変数の指定は任意です。

    • PAGE_SIZE は、ページサイズの値で置き換えます。この変数の指定は任意です。

Java

Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

次のサンプルでは、v1 API を使用します。v2 のサンプルを変更するには、v1v2 に置き換え、/locations/LOCATION をリソース名に追加します。

ほとんどのリソースでは、/PARENT/PARENT_ID の後に /locations/LOCATION をリソース名に追加します。ここで、PARENTorganizationsfolders、または projects です。

検出結果の場合は、/sources/SOURCE_ID の後に /locations/LOCATION をリソース名に追加します。ここで、SOURCE_ID は、検出結果を発行した Security Command Center サービスの ID です。


import com.google.cloud.securitycenter.v1.BigQueryExport;
import com.google.cloud.securitycenter.v1.ListBigQueryExportsRequest;
import com.google.cloud.securitycenter.v1.SecurityCenterClient;
import com.google.cloud.securitycenter.v1.SecurityCenterClient.ListBigQueryExportsPagedResponse;
import java.io.IOException;

public class ListBigQueryExports {

  public static void main(String[] args) throws IOException {
    // TODO(Developer): Modify the following variable values.

    // parent: The parent, which owns the collection of BigQuery exports.
    //         Use any one of the following resource paths:
    //              - organizations/{organization_id}
    //              - folders/{folder_id}
    //              - projects/{project_id}
    String parent = String.format("projects/%s", "your-google-cloud-project-id");

    listBigQueryExports(parent);
  }

  // List BigQuery exports in the given parent.
  public static void listBigQueryExports(String parent) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      ListBigQueryExportsRequest request =
          ListBigQueryExportsRequest.newBuilder().setParent(parent).build();

      ListBigQueryExportsPagedResponse response = client.listBigQueryExports(request);

      System.out.println("Listing BigQuery exports:");
      for (BigQueryExport bigQueryExport : response.iterateAll()) {
        System.out.println(bigQueryExport.getName());
      }
    }
  }
}

Python

Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

次のサンプルでは、v1 API を使用します。v2 のサンプルを変更するには、v1v2 に置き換え、/locations/LOCATION をリソース名に追加します。

ほとんどのリソースでは、/PARENT/PARENT_ID の後に /locations/LOCATION をリソース名に追加します。ここで、PARENTorganizationsfolders、または projects です。

検出結果の場合は、/sources/SOURCE_ID の後に /locations/LOCATION をリソース名に追加します。ここで、SOURCE_ID は、検出結果を発行した Security Command Center サービスの ID です。

def list_bigquery_exports(parent: str):
    from google.cloud import securitycenter

    """
    List BigQuery exports in the given parent.
    Args:
         parent: The parent which owns the collection of BigQuery exports.
             Use any one of the following resource paths:
                 - organizations/{organization_id}
                 - folders/{folder_id}
                 - projects/{project_id}
    """

    client = securitycenter.SecurityCenterClient()

    request = securitycenter.ListBigQueryExportsRequest()
    request.parent = parent

    response = client.list_big_query_exports(request)

    print("Listing BigQuery exports:")
    for bigquery_export in response:
        print(bigquery_export.name)

エクスポート構成を削除する

不要になったエクスポート構成は削除できます。

gcloud

  1. Google Cloud コンソールに移動します。

    Google Cloud コンソールに移動

  2. Security Command Center API を有効にしたプロジェクトを選択します。

  3. [Cloud Shell をアクティブにする] をクリックします。

  4. エクスポート構成を削除するには、次のコマンドを実行します。

    gcloud scc bqexports delete BIG_QUERY_EXPORT \
      --folder=FOLDER_ID | --organization=ORGANIZATION_ID | --project=PROJECT_ID \
      --location=LOCATION
    

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

    • BIG_QUERY_EXPORT は、削除するエクスポート構成の名前に置き換えます。

    • FOLDER_IDORGANIZATION_ID または PROJECT_ID は、フォルダ、組織、またはプロジェクトの名前に置き換えます。次のいずれかのオプションを設定する必要があります。フォルダと組織の場合、名前はフォルダ ID または組織 ID です。プロジェクト名は、プロジェクト番号またはプロジェクト ID になります。

    • LOCATION: データ所在地が有効になっているか、v2 API を使用して BigQueryExport リソースが作成された場合は必須。

      データ所在地が有効になっている場合は、エクスポートが保存される Security Command Center のロケーションを指定します。

      データ所在地が有効になっていない場合、Security Command Center API v2 を使用して、BigQueryExport リソースが作成された場合 /locations/LOCATION のみを含めます。この場合、唯一の有効な場所が global です。

    たとえば、組織 ID が 123 の組織から my-bq-export という名前のエクスポート構成を削除するには、次のコマンドを実行します。

    gcloud scc bqexports delete my-bq-export --organization=123
    

Java

Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

次のサンプルでは、v1 API を使用します。v2 のサンプルを変更するには、v1v2 に置き換え、/locations/LOCATION をリソース名に追加します。

ほとんどのリソースでは、/PARENT/PARENT_ID の後に /locations/LOCATION をリソース名に追加します。ここで、PARENTorganizationsfolders、または projects です。

検出結果の場合は、/sources/SOURCE_ID の後に /locations/LOCATION をリソース名に追加します。ここで、SOURCE_ID は、検出結果を発行した Security Command Center サービスの ID です。


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

public class DeleteBigQueryExport {

  public static void main(String[] args) throws IOException {
    // TODO(Developer): Modify the following variable values.

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

    // bigQueryExportId: Unique identifier that is used to identify the export.
    String bigQueryExportId = "export-id";

    deleteBigQueryExport(parent, bigQueryExportId);
  }

  // Delete an existing BigQuery export.
  public static void deleteBigQueryExport(String parent, String bigQueryExportId)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      DeleteBigQueryExportRequest bigQueryExportRequest =
          DeleteBigQueryExportRequest.newBuilder()
              .setName(String.format("%s/bigQueryExports/%s", parent, bigQueryExportId))
              .build();

      client.deleteBigQueryExport(bigQueryExportRequest);
      System.out.printf("BigQuery export request deleted successfully: %s", bigQueryExportId);
    }
  }
}

Python

Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

次のサンプルでは、v1 API を使用します。v2 のサンプルを変更するには、v1v2 に置き換え、/locations/LOCATION をリソース名に追加します。

ほとんどのリソースでは、/PARENT/PARENT_ID の後に /locations/LOCATION をリソース名に追加します。ここで、PARENTorganizationsfolders、または projects です。

検出結果の場合は、/sources/SOURCE_ID の後に /locations/LOCATION をリソース名に追加します。ここで、SOURCE_ID は、検出結果を発行した Security Command Center サービスの ID です。

def delete_bigquery_export(parent: str, bigquery_export_id: str):
    """
    Delete an existing BigQuery export.
    Args:
        parent: Use any one of the following resource paths:
                 - organizations/{organization_id}
                 - folders/{folder_id}
                 - projects/{project_id}
        bigquery_export_id: Unique identifier that is used to identify the export.
    """
    from google.cloud import securitycenter

    client = securitycenter.SecurityCenterClient()

    request = securitycenter.DeleteBigQueryExportRequest()
    request.name = f"{parent}/bigQueryExports/{bigquery_export_id}"

    client.delete_big_query_export(request)
    print(f"BigQuery export request deleted successfully: {bigquery_export_id}")

エクスポート構成を削除した後、Looker Studio からデータを削除できます。詳細については、データソースの削除、削除、復元をご覧ください。

BigQuery で検出結果を確認する

エクスポート構成を作成すると、指定したプロジェクトの BigQuery データセットに新しい検出結果がエクスポートされます。

BigQuery で検出結果を確認するには、次の操作を行います。

  1. BigQuery でプロジェクトに移動します。

    BigQuery に移動

  2. 目的のプロジェクトが表示されない場合は、次の手順を行います。

    1. ツールバーで プロジェクト セレクタをクリックします。
    2. [選択元] の横で組織を選択します。
    3. プロジェクトのリストで、プロジェクトを選択します。
  3. [エクスプローラ] ペインで、プロジェクトのノードを開きます。

  4. データセットを開きます。

  5. findings テーブルをクリックします。

  6. 表示されたタブで [プレビュー] をクリックします。データのサンプルセットが表示されます。

有益なクエリ

このセクションでは、検出結果データを分析するためのクエリの例を紹介します。次の例では、DATASET をデータセットに割り当てられた名前に置き換え、PROJECT_ID をデータセットのプロジェクト名に置き換えます。

発生したエラーのトラブルシューティングについては、エラー メッセージをご覧ください。

1 日に作成および更新された新しい検出結果の数

SELECT
    FORMAT_DATETIME("%Y-%m-%d", event_time) AS date,
    count(DISTINCT finding_id)
FROM `PROJECT_ID.DATASET.findings`
GROUP BY date
ORDER BY date DESC

各検出結果の最新の検出レコード

SELECT
    * EXCEPT(row)
FROM (
    SELECT *, ROW_NUMBER() OVER(
        PARTITION BY finding_id
        ORDER BY event_time DESC, finding.mute_update_time DESC
    ) AS row
    FROM `PROJECT_ID.DATASET.findings`
)
WHERE row = 1

現在のアクティブな検出結果(時間順)

WITH latestFindings AS (
    SELECT * EXCEPT(row)
    FROM (
        SELECT *, ROW_NUMBER() OVER(
            PARTITION BY finding_id
            ORDER BY event_time DESC, finding.mute_update_time DESC
        ) AS row
        FROM `PROJECT_ID.DATASET.findings`
    ) WHERE row = 1
)
SELECT finding_id, event_time, finding
FROM latestFindings
WHERE finding.state = "ACTIVE"
ORDER BY event_time DESC

プロジェクト内の現在の検出結果

WITH latestFindings AS (
    SELECT * EXCEPT(row)
    FROM (
        SELECT *, ROW_NUMBER() OVER(
            PARTITION BY finding_id
            ORDER BY event_time DESC, finding.mute_update_time DESC
        ) AS row
        FROM `PROJECT_ID.DATASET.findings`
    ) WHERE row = 1
)
SELECT finding_id, event_time, finding, resource
FROM latestFindings
WHERE resource.project_display_name = 'PROJECT'

PROJECT は、プロジェクト名に置き換えます。

フォルダ内の現在の検出結果

WITH latestFindings AS(
    SELECT * EXCEPT(row)
    FROM (
        SELECT *, ROW_NUMBER() OVER(
            PARTITION BY finding_id
            ORDER BY event_time DESC, finding.mute_update_time DESC
        ) AS row
        FROM `PROJECT_ID.DATASET.findings`
    ) WHERE row = 1
)
SELECT finding_id, event_time, finding, resource
FROM latestFindings
CROSS JOIN UNNEST(resource.folders) AS folder
WHERE folder.resource_folder_display_name = 'FOLDER'

FOLDER は、フォルダ名に置き換えます。

スキャナ Logging Scanner から得られる現在の検出結果

WITH latestFindings AS (
    SELECT * EXCEPT(row)
    FROM (
        SELECT *, ROW_NUMBER() OVER(
            PARTITION BY finding_id
            ORDER BY event_time DESC, finding.mute_update_time DESC
        ) AS row
        FROM `PROJECT_ID.DATASET.findings`
    ) WHERE row = 1
)
SELECT finding_id, event_time, finding
FROM latestFindings
CROSS JOIN UNNEST(finding.source_properties) AS source_property
WHERE source_property.key = "ScannerName"
  AND source_property.value = "LOGGING_SCANNER"

Persistence: IAM Anomalous Grant タイプの現在のアクティブな検出結果

WITH latestFindings AS(
    SELECT * EXCEPT(row)
    FROM (
        SELECT *, ROW_NUMBER() OVER(
            PARTITION BY finding_id
            ORDER BY event_time DESC, finding.mute_update_time DESC
        ) AS row
        FROM `PROJECT_ID.DATASET.findings`
    ) WHERE row = 1
)
SELECT finding_id, event_time, finding
FROM latestFindings
WHERE finding.state = "ACTIVE"
  AND finding.category = "Persistence: IAM Anomalous Grant"

特定のタイプのアクティブな検出結果を Cloud Audit Logs に関連付ける

このサンプルクエリは、Cloud Audit Logs を使用して、Event Threat Detection から得られる異常な IAM 付与の検出結果を調査するのに役立ちます。異常な IAM 付与アクションの前後の期間に、権限付与者によって行われた一連の管理アクティビティ アクションを確認します。次のクエリは、検出結果のタイムスタンプの 1 時間前から 1 時間後までの管理アクティビティ ログを関連付けます。

WITH latestFindings AS(
    SELECT * EXCEPT(row)
    FROM (
        SELECT *, ROW_NUMBER() OVER(
            PARTITION BY finding_id
            ORDER BY event_time DESC, finding.mute_update_time DESC
        ) AS row
        FROM `PROJECT_ID.DATASET.findings`
    ) WHERE row = 1
)
SELECT
  finding_id,
  ANY_VALUE(event_time) as event_time,
  ANY_VALUE(finding.access.principal_email) as grantor,
  JSON_VALUE_ARRAY(ANY_VALUE(finding.source_properties_json), '$.properties.sensitiveRoleGrant.members') as grantees,
  ARRAY_AGG(
    STRUCT(
      timestamp,
      IF(timestamp < event_time, 'before', 'after') as timeline,
      protopayload_auditlog.methodName,
      protopayload_auditlog.resourceName,
      protopayload_auditlog.serviceName
    )
    ORDER BY timestamp ASC
  ) AS recent_activity
FROM (
  SELECT
    f.*,
    a.*,
  FROM latestFindings AS f
  LEFT JOIN `PROJECT_ID.DATASET.cloudaudit_googleapis_com_activity` AS a
  ON a.protopayload_auditlog.authenticationInfo.principalEmail = f.finding.access.principal_email
  WHERE f.finding.state = "ACTIVE"
    AND f.finding.category = "Persistence: IAM Anomalous Grant"
    AND a.timestamp >= TIMESTAMP_SUB(f.event_time, INTERVAL 1 HOUR)
    AND a.timestamp <= TIMESTAMP_ADD(f.event_time, INTERVAL 1 HOUR)
  )
GROUP BY
  finding_id
ORDER BY
  event_time DESC

出力は次のようになります。

クエリ結果のスクリーンショット。監査ログが関連付けられた検出結果が表示されています。

Looker Studio でグラフを作成する

Looker Studio では、インタラクティブなレポートとダッシュボードを作成できます。

通常、Looker Studio 経由で BigQuery にアクセスすると、BigQuery の使用料金が発生します。詳細については、Looker Studio を使用して BigQuery データを可視化するをご覧ください。

重要度とカテゴリで検出結果を可視化するグラフを作成するには、次の操作を行います。

  1. Looker Studio を開いてログインします。
  2. メッセージが表示されたら、追加情報を提供して他の設定を行います。利用規約を確認し、問題がなければ続行します。
  3. [Blank Report] をクリックします。
  4. [Connect to data] タブで、[BigQuery] カードをクリックします。
  5. プロンプトが表示されたら、Looker Studio が BigQuery プロジェクトにアクセスすることを承認します。
  6. 検出結果データに接続します。
    1. [Project] で、データセットのプロジェクトを選択します。または、[My projects] タブでプロジェクト ID を入力して検索します。
    2. [Dataset] で、データセットの名前をクリックします。
    3. [Table] で、[findings] をクリックします。
    4. [Add] をクリックします。
    5. ダイアログで [Add to report] をクリックします。
  7. レポートを追加したら、[Add a chart] をクリックします。
  8. [Stacked column chart] をクリックし、グラフを配置する領域をクリックします。

    グラフ選択のスクリーンショット

  9. [Chart] > [Bar] ペインの [Data] タブで、次のフィールドを設定します。

    1. [Dimension] フィールドで [finding.severity] を選択します。
    2. [Breakdown Dimension] フィールドで [finding.category] を選択します。
    重要度別に分類して、さらにカテゴリ別に分類した検出結果のグラフ

レポートが更新され、複数の列に検出結果と重要度とカテゴリ別に表示されます。

次のステップ

BigQuery でクエリを実行する方法を学習する。