將發現項目串流至 BigQuery 進行分析

Security Command Center 的 BigQuery 匯出功能可讓您以近乎即時的方式,將新的和更新後的發現項目串流至 BigQuery 資料集。在 BigQuery 中,您可以查詢發現項目狀態隨時間的變化、分析資安態勢趨勢,以及建立自訂報表。匯出作業會在新發現項目出現時串流,並在現有發現項目更新時串流。

總覽

啟用這項功能後,寫入 Security Command Center 的新發現項目會近乎即時地匯出至 BigQuery 資料表。接著,您可以將資料整合至現有工作流程,並建立自訂分析。您可以在組織、資料夾和專案層級啟用這項功能,根據需求匯出發現項目。

這項功能完全由系統代管,不需手動操作或編寫自訂程式碼,因此是將 Security Command Center 發現項目匯出至 BigQuery 的建議方式。

資料集結構

這項功能會將每項新發現項目和後續更新,新增為 findings 資料表中的新資料列,並依 source_id、finding_id 和 event_time 進行分群。這會建立多筆發現項目記錄,其 source_id 和 finding_id 值相同,但 event_time 值不同。這種資料集結構可讓您查看各項發現項目的狀態變化。

請注意,資料集中可能會有重複的項目。如要剖析這些資料,可以使用 DISTINCT 子句,如第一個查詢範例所示。

每個資料集都包含 findings 資料表,其中含有下列欄位:

欄位 說明
source_id

Security Command Center 指派給發現項目來源的專屬 ID。舉例來說,Cloud 異常偵測 來源的所有發現項目都具有相同的 source_id 值。

範例:1234567890

finding_id 代表發現項目的專屬 ID。在組織的來源中是唯一的。由英數字元組成,長度不超過 32 個字元。
event_time

事件發生的時間,或發現項目更新的時間。舉例來說,如果發現項目代表開放式防火牆,event_time 會擷取偵測工具認為防火牆開啟的時間。如果發現項目之後已解決,這個值就會是解決時間。

範例:2019-09-26 12:48:00.985000 UTC

如要進一步瞭解會更新事件時間的變更,請參閱「發現項目生命週期總覽」。

bulk_export_id

如果是大量匯出,則為 UUID。

如果是持續匯出作業,這個欄位會留空。

finding

評估資料記錄 (例如安全性、風險、健康狀態或隱私權),會擷取至 Security Command Center,用於呈現、通知、分析、政策測試和強制執行。舉例來說,App Engine 應用程式中的跨網站指令碼攻擊 (XSS) 安全漏洞就是一項發現項目。

如要進一步瞭解巢狀欄位,請參閱 Finding 物件的 API 參考資料。

resource

與這項發現項目相關聯的 Google Cloud 資源相關資訊。

如要進一步瞭解巢狀欄位,請參閱 Resource 物件的 API 參考資料。

費用

您會產生與這項功能相關的 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 Export。

由於 BigQuery Export 中使用的篩選器可能包含受資料落地控管機制限制的資料,因此請務必先指定正確的位置,再建立篩選器。Security Command Center 不會限制您建立匯出項目的位置。

BigQuery Export 只會儲存在建立位置,無法在其他位置查看或編輯。

建立 BigQuery Export 後,就無法變更位置。如要變更位置,請刪除 BigQuery Export,然後在新位置重新建立。

如要瞭解如何在啟用資料落地功能時使用 Security Command Center,請參閱「Security Command Center 區域端點」。

Security Command Center 如何將發現項目匯出至 BigQuery

以下各節說明 Security Command Center 如何將新增、更新和刪除的發現項目匯出至 BigQuery。

匯出新發現項目和更新項目

發現項目屬性更新時,Security Command Center 會建立快照,並嘗試將快照傳送至 BigQuery。

這項嘗試會產生下列其中一種結果:

  • 如果快照中的發現項目屬性符合 BigQuery Export 中定義的匯出篩選器,快照就會傳送至 BigQuery,成為 BigQuery 中發現項目的目前記錄。

  • 如果發現項目的屬性不符合篩選條件,快照就不會傳送至 BigQuery。如果 BigQuery 中有發現項目的先前快照,該快照仍會是資料集中的最新可用記錄,即使未反映 Security Command Center 的最新更新也一樣。

舉例來說,如果 BigQuery Export 作業的篩選器包含「active」狀態,系統就會產生狀態為「active」的新發現項目,並成功將發現項目的快照匯出至 BigQuery。

之後,Security Command Center 中該發現項目的狀態會更新為「無效」。這項更新會觸發將發現項目的新快照匯出至 BigQuery,但由於狀態值不再符合篩選器,篩選器會封鎖發現項目快照的匯出。

因此,BigQuery 中的發現項目快照仍處於有效狀態,但 Security Command Center 中的相同發現項目則處於無效狀態。

這也會導致 Security Command Center 中的有效發現項目數量,與 BigQuery 中的有效發現項目數量不一致。BigQuery 中的有效發現項目數量,幾乎一律多於 Security Command Center。

舉例來說,如果匯出篩選器指定「active」狀態,且系統產生 100 個狀態為「active」的發現項目,則這 100 個項目都會匯出至 BigQuery。之後,在 Security Command Center 中,其中 50 個發現項目更新為無效,篩選器會封鎖更新觸發的匯出作業,因為狀態值不再符合篩選條件。因此,在 BigQuery 中,所有 100 個發現項目仍為有效,但在 Security Command Center 中,只有 50 個發現項目仍為有效。

匯出已刪除的發現項目

Security Command Center 會根據資料保留政策定期刪除發現項目。您可以設定 Security Command Center 是否要將已刪除發現項目的快照匯出至 BigQuery。

建立或更新匯出設定時,您可以啟用刪除通知。啟用刪除通知後,Security Command Center 會將發現項目快照傳送至 BigQuery,並將 deleted_finding 欄位設為 true,event_time 則設為發現項目的刪除時間。這樣一來,您就能執行查詢,追蹤已刪除的發現項目。修改匯出設定的刪除通知選項後,變更只會套用至日後刪除的發現項目。啟用這個選項前刪除的發現項目不會溯及匯出。

將 Security Command Center 的發現項目匯出至 BigQuery

如要匯出發現項目,請先啟用 Security Command Center API。

啟用 Security Command Center API

如要啟用 Security Command Center API,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「API Library」(API 程式庫) 頁面。

    前往 API 程式庫

  2. 選取要啟用 Security Command Center API 的專案。

  3. 在「Search」(搜尋) 方塊中輸入 Security Command Center,然後在搜尋結果中點選「Security Command Center」。

  4. 在顯示的 API 頁面中,按一下「啟用」。

專案已啟用 Security Command Center API。接著,您將使用 gcloud CLI 建立新的 BigQuery 匯出設定。

在 VPC Service Controls 中授予 perimeter 存取權

如果您使用 VPC Service Controls,且 BigQuery 資料集屬於 service perimeter 內的專案,則必須授予專案存取權,才能匯出發現項目。

如要授予專案存取權,請為要匯出發現項目的主體和專案建立輸入和輸出規則。這些規則允許存取受保護的資源,並讓 BigQuery 驗證使用者是否具備 BigQuery 資料集的 setIamPolicy 權限。

設定新的 BigQuery 匯出作業前

控制台

  1. 前往 Google Cloud 控制台的「VPC Service Controls」頁面。

    前往「VPC Service Controls」

  2. 選取您的機構。
  3. 在下拉式選單中,選取要授予存取權的 service perimeter 所在的存取權政策。

    與存取權政策相關聯的 service perimeter 會顯示在清單中。

  4. 按一下要更新的 service perimeter 名稱。

    如要找出需要修改的 service perimeter,請查看記錄中是否有顯示 RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER 違規事項的項目。在這些項目中,請檢查 servicePerimeterName 欄位:

    accessPolicies/ACCESS_POLICY_ID/servicePerimeters/SERVICE_PERIMETER_NAME
  5. 按一下「Edit」(編輯)。

新增 egress 規則

  1. 按一下「輸出政策」。
  2. 按一下「Add an egress rule」(新增輸出規則)。
  3. 在「From」(來源) 部分,設定下列詳細資料:

    1. 在「Identities」(身分) >「Identity」(身分) 部分,選取「Select identities & groups」(選取身分和群組)。
    2. 按一下「Add identities」(新增身分)。
    3. 輸入電子郵件地址,識別用於呼叫 Security Command Center API 的主體。
    4. 選取主體或按下 ENTER 鍵,然後按一下「Add identities」(新增身分)。
  4. 在「To」(收件者) 部分,設定下列詳細資料:

    1. 在「資源」>「專案」部分,選取「所有專案」。
    2. 在「Operations or IAM roles」(作業或 IAM 角色) 部分,選取「Select operations」(選取作業)。
    3. 按一下「Add operations」,然後新增下列作業:

      • 新增 bigquery.googleapis.com 服務。
        1. 按一下「所有方法」。
        2. 按一下「新增所有方法」。

新增 ingress 規則

  1. 按一下「輸入政策」。
  2. 按一下「Add an ingress rule」(新增輸入規則)。
  3. 在「From」(來源) 部分,設定下列詳細資料:

    1. 在「Identities」(身分) >「Identity」(身分) 部分,選取「Select identities & groups」(選取身分和群組)。
    2. 按一下「Add identities」(新增身分)。
    3. 輸入電子郵件地址,識別用於呼叫 Security Command Center API 的主體。
    4. 選取主體或按下 ENTER 鍵,然後按一下「Add identities」(新增身分)。
  4. 在「To」(收件者) 部分,設定下列詳細資料:

    1. 在「資源」>「專案」部分,選取「選取專案」。
    2. 按一下「Add projects」(新增專案),然後新增包含 BigQuery 資料集的專案。
    3. 在「Operations or IAM roles」(作業或 IAM 角色) 部分,選取「Select operations」(選取作業)。
    4. 按一下「Add operations」,然後新增下列作業:

      • 新增 bigquery.googleapis.com 服務。
        1. 按一下「所有方法」。
        2. 按一下「新增所有方法」。
  5. 按一下「儲存」。

gcloud

  1. 如果尚未設定配額專案,請先設定。選擇已啟用 Access Context Manager API 的專案。

    gcloud config set billing/quota_project QUOTA_PROJECT_ID

    將 QUOTA_PROJECT_ID 替換為要用於計費和配額的專案 ID。

  2. 建立名為 egress-rule.yaml 的檔案,並在當中加入下列內容:

    - egressFrom:
        identities:
        - PRINCIPAL_ID
      egressTo:
        operations:
        - serviceName: bigquery.googleapis.com
          methodSelectors:
          - method: '*'
        resources:
        - '*'

    將 PRINCIPAL_ID 替換成用於呼叫 Security Command Center API 的主體 ID。

  3. 建立名為 ingress-rule.yaml 的檔案,並在當中加入下列內容:

    - ingressFrom:
        identities:
        - PRINCIPAL_ID
        sources:
        - accessLevel: '*'
      ingressTo:
        operations:
        - serviceName: bigquery.googleapis.com
          methodSelectors:
          - method: '*'
        resources:
        - projects/PROJECT_ID

    將 PRINCIPAL_ID 替換成用於呼叫 Security Command Center API 的主體 ID。

    將 PROJECT_ID 替換為包含 BigQuery 資料集的專案 ID。

  4. 將輸出規則新增至 perimeter:

    gcloud access-context-manager perimeters update PERIMETER_NAME \
        --set-egress-policies=egress-rule.yaml

    更改下列內容:

    • PERIMETER_NAME:perimeter 的名稱。例如:accessPolicies/1234567890/servicePerimeters/example_perimeter。

      如要找出需要修改的 service perimeter,請查看記錄中是否有顯示 RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER 違規事項的項目。在這些項目中,檢查 servicePerimeterName 欄位:

      accessPolicies/ACCESS_POLICY_ID/servicePerimeters/SERVICE_PERIMETER_NAME
  5. 將輸入規則新增至 perimeter:

    gcloud access-context-manager perimeters update PERIMETER_NAME \
        --set-ingress-policies=ingress-rule.yaml

    更改下列內容:

    • PERIMETER_NAME:perimeter 的名稱。例如:accessPolicies/1234567890/servicePerimeters/example_perimeter。

      如要找出需要修改的 service perimeter,請查看記錄中是否有顯示 RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER 違規事項的項目。在這些項目中,檢查 servicePerimeterName 欄位:

      accessPolicies/ACCESS_POLICY_ID/servicePerimeters/SERVICE_PERIMETER_NAME

詳情請參閱「輸入和輸出規則」。

設定新的 BigQuery 匯出作業

在這個步驟中,您會建立匯出設定,將發現項目匯出至 BigQuery 執行個體。您可以在專案、資料夾或組織層級建立匯出設定。舉例來說,如要將專案的發現項目匯出至 BigQuery 資料集,請在專案層級建立匯出設定,只匯出與該專案相關的發現項目。您也可以指定篩選條件,只匯出特定發現項目。

請務必在適當層級建立匯出設定。舉例來說,如果您在專案 B 建立匯出設定,要匯出專案 A 的發現項目,並定義 resource.project_display_name: project-a-id 等篩選器,則該設定不會匯出任何發現項目。

您最多可以為組織建立 500 項 BigQuery 匯出設定。您可以將同一個資料集用於多項匯出設定。如果使用相同的資料集,所有更新都會套用至同一個發現項目資料表。

建立第一個匯出設定時,系統會自動為您建立服務帳戶。必須有這個服務帳戶,才能在資料集內建立或更新發現項目資料表,並將發現項目匯出至資料表。其格式為 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. 按一下「Activate Cloud Shell」(啟用 Cloud Shell)。

  4. 如要建立新的匯出設定,請執行下列指令:

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

    更改下列內容:

    • BIGQUERY_EXPORT:這項匯出設定的名稱。
    • DATASET_NAME 替換為 BigQuery 資料集的名稱,例如 projects/PROJECT_ID/datasets/DATASET_ID。
    • FOLDER_ID、ORGANIZATION_ID 或 PROJECT_ID:資料夾、組織或專案的名稱。您必須設定其中一個選項。如果是資料夾和組織,名稱就是資料夾 ID 或組織 ID。如果是專案,名稱就是專案編號或專案 ID。
    • LOCATION:要建立匯出設定的 Security Command Center 位置。如果已啟用資料落地功能,請使用 eu、sa 或 us,否則請使用 global 值。
    • DESCRIPTION:匯出設定的人類可讀說明。這個變數為選用。
    • FILTER,並使用運算式定義要匯出的發現項目。舉例來說,如要依 XSS_SCRIPTING 類別篩選,請輸入 "category=\"XSS_SCRIPTING\"。這個變數為選用。

    使用下列旗標,設定是否要接收已刪除發現項目的通知。如未指定任何旗標,預設行為是不匯出已刪除的發現項目。

    • --deletion-notifications-enabled:啟用通知,以便接收因資料保留政策而刪除的發現項目。啟用後,刪除的發現項目會匯出至 BigQuery,並標示為 deleted_finding = true。這個標記僅適用於日後的刪除事件。啟用這個旗標前刪除的發現項目不會追溯匯出。

    • --no-deletion-notifications-enabled:停用已刪除發現項目的通知。

Terraform

如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。詳情請參閱 Terraform 供應商參考文件。

為組織建立匯出設定:

resource "google_bigquery_dataset" "default" {
  dataset_id                  = "my-dataset"
  friendly_name               = "test"
  description                 = "This is a test description"
  location                    = "US"
  default_table_expiration_ms = 3600000
  default_partition_expiration_ms = null

  labels = {
    env = "default"
  }

  lifecycle {
    ignore_changes = [default_partition_expiration_ms]
  }
}

resource "google_scc_v2_organization_scc_big_query_export" "custom_big_query_export_config" {
  name         = "my-export"
  big_query_export_id    = "my-export"
  organization = "123456789"
  dataset      = google_bigquery_dataset.default.id
  location     = "global"
  description  = "Cloud Security Command Center Findings Big Query Export Config"
  filter       = "state=\"ACTIVE\" AND NOT mute=\"MUTED\""
}

為資料夾建立匯出設定:

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

  deletion_protection = false
}

resource "google_bigquery_dataset" "default" {
  dataset_id                  = "my_dataset_id"
  friendly_name               = "test"
  description                 = "This is a test description"
  location                    = "US"
  default_table_expiration_ms = 3600000
  default_partition_expiration_ms = null

  labels = {
    env = "default"
  }

  lifecycle {
    ignore_changes = [default_partition_expiration_ms]
  }
}

resource "google_scc_v2_folder_scc_big_query_export" "custom_big_query_export_config" {
  big_query_export_id    = "my-export"
  folder       = google_folder.folder.folder_id
  dataset      = google_bigquery_dataset.default.id
  location     = "global"
  description  = "Cloud Security Command Center Findings Big Query Export Config"
  filter       = "state=\"ACTIVE\" AND NOT mute=\"MUTED\""
}

為專案建立匯出設定:

resource "google_bigquery_dataset" "default" {
  dataset_id                  = "my_dataset_id"
  friendly_name               = "test"
  description                 = "This is a test description"
  location                    = "US"
  default_table_expiration_ms = 3600000
  default_partition_expiration_ms = null

  labels = {
    env = "default"
  }

  lifecycle {
    ignore_changes = [default_partition_expiration_ms]
  }
}

resource "google_scc_v2_project_scc_big_query_export" "custom_big_query_export_config" {
  name         = "my-export"
  big_query_export_id    = "my-export"
  project      = "my-project-name"
  dataset      = google_bigquery_dataset.default.id
  location     = "global"
  description  = "Cloud Security Command Center Findings Big Query Export Config"
  filter       = "state=\"ACTIVE\" AND NOT mute=\"MUTED\""
}

Java

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。


import com.google.cloud.securitycenter.v2.BigQueryExport;
import com.google.cloud.securitycenter.v2.CreateBigQueryExportRequest;
import com.google.cloud.securitycenter.v2.OrganizationLocationName;
import com.google.cloud.securitycenter.v2.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.
    // organizationId: Google Cloud Organization id.
    String organizationId = "{google-cloud-organization-id}";

    // projectId: Google Cloud Project id.
    String projectId = "{your-project}";

    // Specify the location.
    String location = "global";

    // filter: Expression that defines the filter to apply across create/update events of findings.
    String filter = "severity=\"LOW\" OR severity=\"MEDIUM\"";

    // bigQueryDatasetId: The BigQuery dataset to write findings' updates to.
    String bigQueryDatasetId = "{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(organizationId, location, projectId, 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 BigQueryExport createBigQueryExport(String organizationId, String location,
      String projectId, 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.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
      OrganizationLocationName organizationName = OrganizationLocationName.of(organizationId,
          location);
      // 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("projects/%s/datasets/%s", projectId, bigQueryDatasetId))
              .build();

      CreateBigQueryExportRequest bigQueryExportRequest =
          CreateBigQueryExportRequest.newBuilder()
              .setParent(organizationName.toString())
              .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());
      return response;
    }
  }
}

Python

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。



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

    """
    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}/locations/{location_id}
             - folders/{folder_id}/locations/{location_id}
             - projects/{project_id}/locations/{location_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.
             - projects/{PROJECT_ID}/datasets/{BIGQUERY_DATASET_ID}
        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_v2.SecurityCenterClient()

    # Create the BigQuery export configuration.
    bigquery_export = securitycenter_v2.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 = bigquery_dataset_id

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

建立匯出設定後,您應該會在約 15 分鐘內看到 BigQuery 資料集中的發現項目。建立 BigQuery 資料表後,只要有符合篩選條件和範圍的新發現項目和更新項目,就會近乎即時地顯示在資料表中。

如要查看發現項目,請參閱「查看發現項目」。

為新的 BigQuery 匯出作業建立輸入規則

如果您使用 VPC Service Controls,且 BigQuery 資料集屬於 service perimeter 內部的專案,則必須為新的 BigQuery 匯出作業建立輸入規則。

控制台

  1. 重新開啟上一節中的 service perimeter。

    前往「VPC Service Controls」

新增 ingress 規則

  1. 按一下「輸入政策」。
  2. 按一下「Add an ingress rule」(新增輸入規則)。
  3. 在「From」(來源) 部分,設定下列詳細資料:

    1. 在「Identities」(身分) >「Identity」(身分) 部分,選取「Select identities & groups」(選取身分和群組)。
    2. 按一下「Add identities」(新增身分)。
    3. 輸入用來識別 BigQuery 匯出設定服務代理程式的電子郵件地址。這個地址的格式如下:

      service-org-ORGANIZATION_ID@gcp-sa-scc-notification.iam.gserviceaccount.com

      請將 ORGANIZATION_ID 替換成組織 ID。

    4. 選取服務代理或按下 ENTER 鍵,然後按一下「Add identities」(新增身分)。
  4. 在「To」(收件者) 部分,設定下列詳細資料:

    1. 在「資源」>「專案」部分,選取「選取專案」。
    2. 按一下「Add projects」(新增專案),然後新增包含 BigQuery 資料集的專案。
    3. 在「Operations or IAM roles」(作業或 IAM 角色) 部分,選取「Select operations」(選取作業)。
    4. 按一下「Add operations」,然後新增下列作業:

      • 新增 bigquery.googleapis.com 服務。
        1. 按一下「所有方法」。
        2. 按一下「新增所有方法」。
  5. 按一下「儲存」。

gcloud

  1. 如果尚未設定配額專案,請先設定。選擇已啟用 Access Context Manager API 的專案。

    gcloud config set billing/quota_project QUOTA_PROJECT_ID

    將 QUOTA_PROJECT_ID 替換為要用於計費和配額的專案 ID。

  2. 建立名為 ingress-rule.yaml 的檔案,並在當中加入下列內容:

    - ingressFrom:
        identities:
        - serviceAccount:service-org-ORGANIZATION_ID@gcp-sa-scc-notification.iam.gserviceaccount.com
        sources:
        - accessLevel: '*'
      ingressTo:
        operations:
        - serviceName: bigquery.googleapis.com
          methodSelectors:
          - method: '*'
        resources:
        - projects/PROJECT_ID

    請將 ORGANIZATION_ID 替換成組織 ID。

    將 PROJECT_ID 替換為包含 BigQuery 資料集的專案 ID。

  3. 將輸入規則新增至 perimeter:

    gcloud access-context-manager perimeters update PERIMETER_NAME \
        --set-ingress-policies=ingress-rule.yaml

    更改下列內容:

    • PERIMETER_NAME:perimeter 的名稱。例如:accessPolicies/1234567890/servicePerimeters/example_perimeter。

      如要找出需要修改的 service perimeter,請查看記錄中是否有顯示 RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER 違規事項的項目。在這些項目中,檢查 servicePerimeterName 欄位:

      accessPolicies/ACCESS_POLICY_ID/servicePerimeters/SERVICE_PERIMETER_NAME

詳情請參閱「輸入和輸出規則」。

所選專案、使用者和服務帳戶現在可以存取受保護的資源,並匯出發現項目。

如果您已按照本指南中的所有步驟操作,且匯出作業正常運作,現在可以刪除下列項目:

  • 主體的輸入規則
  • 主體的輸出規則

這些規則僅用於設定匯出作業。不過,如要讓匯出設定繼續運作,您必須保留先前建立的輸入規則,讓 Security Command Center 將發現項目匯出至 service perimeter 後方的 BigQuery 資料集。

查看匯出設定的詳細資料

gcloud

  1. 前往 Google Cloud 控制台。

    前往 Google Cloud 控制台

  2. 選取已啟用 Security Command Center API 的專案。

  3. 按一下「Activate Cloud Shell」(啟用 Cloud Shell)。

  4. 如要驗證匯出設定的詳細資料,請執行下列指令:

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

    更改下列內容:

    • BIGQUERY_EXPORT:這項匯出設定的名稱。
    • FOLDER_ID、ORGANIZATION_ID 或 PROJECT_ID:資料夾、組織或專案的名稱。您必須設定其中一個選項。如果是資料夾和組織,名稱就是資料夾 ID 或組織 ID。如果是專案,名稱就是專案編號或專案 ID。
    • LOCATION:要建立匯出設定的 Security Command Center 位置。如果已啟用資料落地功能,請使用 eu、sa 或 us,否則請使用 global 值。

      舉例來說,如要從組織 ID 設為 123 的組織取得名為 my-bq-export 的匯出設定,請執行下列指令:

      gcloud scc bqexports get my-bq-export \
          --organization=123 \
          --location=global
      

Java

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。


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

public class GetBigQueryExport {

  public static void main(String[] args) throws IOException {
    // TODO(Developer): Modify the following variable values.
    // organizationId: Google Cloud Organization id.
    String organizationId = "{google-cloud-organization-id}";

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

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

    getBigQueryExport(organizationId, location, bigQueryExportId);
  }

  // Retrieve an existing BigQuery export.
  public static BigQueryExport getBigQueryExport(String organizationId, String location,
      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.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      BigQueryExportName bigQueryExportName = BigQueryExportName.of(organizationId, location,
          bigQueryExportId);

      GetBigQueryExportRequest bigQueryExportRequest =
          GetBigQueryExportRequest.newBuilder()
              .setName(bigQueryExportName.toString())
              .build();

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

Python

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。

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

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

    client = securitycenter_v2.SecurityCenterClient()

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

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

更新匯出設定

如有需要,您可以修改現有匯出設定的篩選器、資料集和說明。匯出設定的名稱無法變更。

gcloud

  1. 前往 Google Cloud 控制台。

    前往 Google Cloud 控制台

  2. 選取已啟用 Security Command Center API 的專案。

  3. 按一下「Activate Cloud Shell」(啟用 Cloud Shell)。

  4. 如要更新匯出設定,請執行下列指令:

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

    更改下列內容:

    • BIGQUERY_EXPORT:要更新的匯出設定名稱。
    • DATASET_NAME 替換為 BigQuery 資料集的名稱,例如 projects/PROJECT_ID/datasets/DATASET_ID。
    • FOLDER_ID、ORGANIZATION_ID 或 PROJECT_ID:資料夾、組織或專案的名稱。您必須設定其中一個選項。如果是資料夾和組織,名稱就是資料夾 ID 或組織 ID。如果是專案,名稱就是專案編號或專案 ID。
    • LOCATION:要更新匯出設定的 Security Command Center 位置。如果已啟用資料落地功能,請使用 eu、sa 或 us,否則請使用 global 值。
    • DESCRIPTION:匯出設定的人類可讀說明。這個變數為選用。
    • FILTER,並使用運算式定義要匯出的發現項目。舉例來說,如要依 XSS_SCRIPTING 類別篩選,請輸入 "category=\"XSS_SCRIPTING\"。這個變數為選用。

    使用下列旗標,設定是否要接收已刪除發現項目的通知。如未指定任一旗標,預設行為是不匯出已刪除的發現項目。

    • --deletion-notifications-enabled:啟用因資料保留政策而刪除的發現項目通知。啟用後,刪除的發現項目會匯出至 BigQuery,並標示為 deleted_finding = true。這個標記僅適用於日後的刪除事件。啟用這個旗標前刪除的發現項目,不會溯及既往匯出。

    • --no-deletion-notifications-enabled:停用已刪除發現項目的通知。

Java

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。


import com.google.cloud.securitycenter.v2.BigQueryExport;
import com.google.cloud.securitycenter.v2.BigQueryExportName;
import com.google.cloud.securitycenter.v2.SecurityCenterClient;
import com.google.cloud.securitycenter.v2.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.
    // organizationId: Google Cloud Organization id.
    String organizationId = "{google-cloud-organization-id}";

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

    // 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 = "{bigquery-export-id}";

    updateBigQueryExport(organizationId, location, filter, bigQueryExportId);
  }

  // Updates an existing BigQuery export.
  public static BigQueryExport updateBigQueryExport(String organizationId, String location,
      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.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
      // Optionally BigQueryExportName or String can be used
      // String bigQueryExportName = String.format("organizations/%s/locations/%s
      // /bigQueryExports/%s",organizationId,location, bigQueryExportId);
      BigQueryExportName bigQueryExportName = BigQueryExportName.of(organizationId, location,
          bigQueryExportId);

      //  Set the new values for export configuration.
      BigQueryExport bigQueryExport =
          BigQueryExport.newBuilder()
              .setName(bigQueryExportName.toString())
              .setDescription("Updated description.")
              .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")
                  .addPaths("description").build())
              .build();

      BigQueryExport response = client.updateBigQueryExport(request);
      System.out.println("BigQueryExport updated successfully!");
      return response;
    }
  }
}

Python

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。

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}/locations/{location_id}
                 - folders/{folder_id}/locations/{location_id}
                 - projects/{project_id}/locations/{location_id}
        export_filter: Expression that defines the filter to apply across create/update events of findings.export_filter = 'severity="MEDIUM"'
        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_v2
    from google.protobuf import field_mask_pb2

    client = securitycenter_v2.SecurityCenterClient()

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

    # 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", "description"])

    request = securitycenter_v2.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!")
    return response

查看所有匯出設定

您可以查看組織、資料夾或專案中的所有匯出設定。

gcloud

  1. 前往 Google Cloud 控制台。

    前往 Google Cloud 控制台

  2. 選取已啟用 Security Command Center API 的專案。

  3. 按一下「Activate Cloud Shell」(啟用 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_ID、ORGANIZATION_ID 或 PROJECT_ID:資料夾、組織或專案的名稱。您必須設定其中一個選項。如果是資料夾和組織,名稱就是資料夾 ID 或組織 ID。如果是專案,名稱就是專案編號或專案 ID。

      如果指定組織 ID,清單會包含該組織中定義的所有匯出設定,包括資料夾和專案層級的設定。如果指定資料夾 ID,清單會包含在資料夾層級和該資料夾內專案中定義的所有匯出設定。如果指定專案編號或專案 ID,清單只會包含該專案的所有匯出設定。

    • LOCATION:要列出匯出設定的 Security Command Center 位置。如果已啟用資料落地,請使用 eu、sa 或 us,否則請使用 global 值。

    • LIMIT 替換為要查看的匯出設定數量。這個變數為選用。

    • PAGE_SIZE,並提供頁面大小值。這個變數為選用。

Java

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。


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

public class ListBigQueryExports {

  public static void main(String[] args) throws IOException {
    // TODO(Developer): Modify the following variable values.
    // organizationId: Google Cloud Organization id.
    String organizationId = "{google-cloud-organization-id}";

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

    listBigQueryExports(organizationId, location);
  }

  // List BigQuery exports in the given parent.
  public static ListBigQueryExportsPagedResponse listBigQueryExports(String organizationId,
      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()) {
      OrganizationLocationName organizationName = OrganizationLocationName.of(organizationId,
          location);

      ListBigQueryExportsRequest request = ListBigQueryExportsRequest.newBuilder()
          .setParent(organizationName.toString())
          .build();

      ListBigQueryExportsPagedResponse response = client.listBigQueryExports(request);

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

Python

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。

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

    """
    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}/locations/{location_id}
                 - folders/{folder_id}/locations/{location_id}
                 - projects/{project_id}/locations/{location_id}
    """

    client = securitycenter_v2.SecurityCenterClient()

    request = securitycenter_v2.ListBigQueryExportsRequest()
    request.parent = parent

    response = client.list_big_query_exports(request)

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

刪除匯出設定

如果不再需要匯出設定,可以刪除。

gcloud

  1. 前往 Google Cloud 控制台。

    前往 Google Cloud 控制台

  2. 選取已啟用 Security Command Center API 的專案。

  3. 按一下「Activate Cloud Shell」(啟用 Cloud Shell)。

  4. 如要刪除匯出設定,請執行下列指令:

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

    更改下列內容:

    • 將 BIGQUERY_EXPORT 替換為要刪除的匯出設定名稱。
    • FOLDER_ID、ORGANIZATION_ID 或 PROJECT_ID:資料夾、組織或專案的名稱。您必須設定其中一個選項。如果是資料夾和組織,名稱就是資料夾 ID 或組織 ID。如果是專案,名稱就是專案編號或專案 ID。
    • LOCATION:要刪除匯出設定的 Security Command Center 位置。如果已啟用資料落地功能,請使用 eu、sa 或 us,否則請使用 global 值。

      舉例來說,如要從組織 ID 設為 123 的組織中刪除名為 my-bq-export 的匯出設定,請執行下列指令:

      gcloud scc bqexports delete my-bq-export \
          --organization=123 \
          --location=global
      

Java

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。


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

public class DeleteBigQueryExport {

  public static void main(String[] args) throws IOException {
    // TODO(Developer): Modify the following variable values.
    // organizationId: Google Cloud Organization id.
    String organizationId = "{google-cloud-organization-id}";

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

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

    deleteBigQueryExport(organizationId, location, bigQueryExportId);
  }

  // Delete an existing BigQuery export.
  public static void deleteBigQueryExport(String organizationId, String location,
      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.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
      // Optionally BigQueryExportName or String can be used
      // String bigQueryExportName = String.format("organizations/%s/locations/%s
      // /bigQueryExports/%s",organizationId,location, bigQueryExportId);
      BigQueryExportName bigQueryExportName = BigQueryExportName.of(organizationId, location,
          bigQueryExportId);

      DeleteBigQueryExportRequest bigQueryExportRequest =
          DeleteBigQueryExportRequest.newBuilder()
              .setName(bigQueryExportName.toString())
              .build();

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

Python

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定 ADC」。

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}/locations/{location_id}
                 - folders/{folder_id}/locations/{location_id}
                 - projects/{project_id}/locations/{location_id}
        bigquery_export_id: Unique identifier that is used to identify the export.
    """
    from google.cloud import securitycenter_v2

    client = securitycenter_v2.SecurityCenterClient()

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

刪除匯出設定後,即可從數據分析中移除資料。詳情請參閱「移除、刪除及還原資料來源」。

在 BigQuery 查看發現項目

建立匯出設定後,新的發現項目會匯出至指定專案中的 BigQuery 資料集。

如要在 BigQuery 中查看發現項目,請按照下列步驟操作:

  1. 前往 BigQuery 中的專案。

    前往「BigQuery」頁面

  2. 選取專案。

  3. 在「Explorer」窗格中展開專案的節點。

  4. 展開資料集。

  5. 點選「findings」資料表。

  6. 在開啟的分頁中,按一下「預覽」。系統會顯示一組範例資料。

實用查詢

本節提供範例查詢,用於分析發現項目資料。在下列範例中,請將 DATASET 替換為指派給資料集的名稱,並將 PROJECT_ID 替換為資料集的專案名稱。

如要排解遇到的錯誤,請參閱「錯誤訊息」一文。

每天建立及更新的新發現項目數量

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 稽核記錄建立關聯

這項範例查詢會顯示授予者在異常 IAM 授予動作前後的時間範圍內,執行的一連串管理員活動動作,協助您使用 Cloud 稽核記錄,調查 Event Threat Detection 的異常 IAM 授予發現項目。下列查詢會將管理員活動記錄與發現項目的時間戳記前後 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

輸出結果會與下列內容相似:

查詢結果螢幕截圖,顯示發現項目和相關聯的稽核記錄

在數據分析中建立圖表

數據分析可讓您建立互動式報表和資訊主頁。

一般來說,透過數據分析存取 BigQuery 時,會產生 BigQuery 使用費用。詳情請參閱「使用數據分析以圖表呈現 BigQuery 資料」。

如要建立圖表,依嚴重性和類別以視覺化方式呈現發現項目資料,請按照下列步驟操作:

  1. 開啟數據分析並登入。
  2. 如果系統提示,請提供其他資訊並設定其他偏好設定。詳閱服務條款,如果同意,請繼續操作。
  3. 按一下「空白報表」。
  4. 在「連結至資料」分頁中,點選「BigQuery」資訊卡。
  5. 如果系統提示,請授權數據分析存取 BigQuery 專案。
  6. 連結至發現項目資料:

    1. 在「Project」(專案) 部分,選取資料集所屬的專案。或者,您也可以在「My projects」(我的專案) 分頁中輸入專案 ID 來搜尋。
    2. 在「Dataset」(資料集) 部分,按一下資料集名稱。
    3. 在「Table」(資料表) 部分,按一下「findings」。
    4. 按一下「新增」。
    5. 在對話方塊中,點選「加入報表」。
  7. 新增報表後,按一下「新增圖表」。

  8. 按一下「堆疊柱狀圖」,然後點選要放置圖表的區域。

    圖表選取畫面的螢幕截圖
  9. 在「圖表」>「長條」窗格的「資料」分頁中,設定下列欄位:

    1. 在「維度」欄位中,選取「finding.severity」。
    2. 在「細目維度」欄位中,選取「finding.category」。
    螢幕截圖:發現項目圖表,依嚴重性分類,並依類別細分

報表會更新,顯示多個資料欄,並依嚴重性和類別區分發現項目。

後續步驟