查看 BigQuery 資料集的政策洞察資料

本頁面說明如何管理資料集層級政策洞察,也就是以機器學習技術為基礎,針對 BigQuery 資料集權限使用情形產生的發現項目。政策洞察可協助您找出哪些主體擁有不必要的權限。

本頁面著重於資料集的政策洞察。Recommender 也提供下列資源類型的政策洞察:

資料集層級政策洞察有時會連結至角色建議。角色建議會提供建議的動作,協助您修復資料集層級政策洞察發現的問題。

事前準備

  • 啟用 Recommender API (如果尚未啟用)。

    啟用 API 所需的角色

    如要啟用 API,您必須具備 serviceusage.services.enable 權限。如果您建立了專案,可能已透過擁有者角色 (roles/owner) 取得這項權限。否則,您可以透過 Service Usage 管理員角色 (roles/serviceusage.serviceUsageAdmin) 取得這項權限。瞭解如何授予角色。

    啟用 API

  • 熟悉 IAM 角色建議。
  • 確認您已在組織或專案層級啟用 Security Command Center 的 Premium 或 Enterprise 方案。詳情請參閱帳單問題。
  • 選用:參閱建議工具洞察。

必要的角色

如要取得管理資料集層級政策洞察所需的權限,請要求管理員在專案中授予您下列 IAM 角色:

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

這些預先定義的角色具備管理資料集層級政策洞察所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

所需權限

必須具備下列權限,才能管理資料集層級政策洞察:

  • 查看資料集層級政策洞察:
    • recommender.iamPolicyInsights.get
    • recommender.iamPolicyInsights.list
  • 修改資料集層級政策洞察:recommender.iamPolicyInsights.update
  • 使用 gcloud CLI 或 REST API 管理資料集層級政策洞察:serviceusage.services.use

您或許還可透過自訂角色或其他預先定義的角色取得這些權限。

列出資料集層級政策洞察

如要列出專案的所有資料集層級政策洞察,請使用下列其中一種方法:

gcloud

使用 gcloud recommender insights list 指令,查看專案的所有資料集層級政策洞察。

執行指令前,請先替換下列值:

  • PROJECT_ID:要列出洞察的專案 ID。
  • LOCATION:要列出洞察的資料集位置。
gcloud recommender insights list --insight-type=google.iam.policy.Insight \
    --project=PROJECT_ID \
    --location=LOCATION\
    --filter="insightSubtype:PERMISSIONS_USAGE_BIGQUERY_DATASET"

輸出內容會列出專案在指定位置的所有資料集層級政策洞察。例如:

INSIGHT_ID                            CATEGORY  INSIGHT_STATE  LAST_REFRESH_TIME     SEVERITY  INSIGHT_SUBTYPE                     DESCRIPTION
101d03ad-6148-4628-943e-fcf1a3af6b57  SECURITY  ACTIVE         2024-02-02T08:00:00Z  LOW       PERMISSIONS_USAGE_BIGQUERY_DATASET  0 of the permissions in this role binding were used in the past 90 days.
15133dd9-4cbc-41e9-8990-b189241676d8  SECURITY  ACTIVE         2024-02-02T08:00:00Z  LOW       PERMISSIONS_USAGE_BIGQUERY_DATASET  0 of the permissions in this role binding were used in the past 90 days.
1590aeae-d5bf-4e3d-b7d5-e230212f5faf  SECURITY  ACTIVE         2024-02-02T08:00:00Z  LOW       PERMISSIONS_USAGE_BIGQUERY_DATASET  4 of the permissions in this role binding were used in the past 90 days.
280e5a14-4d09-4ac6-8e14-be7407611ad7  SECURITY  ACTIVE         2024-02-02T08:00:00Z  LOW       PERMISSIONS_USAGE_BIGQUERY_DATASET  0 of the permissions in this role binding were used in the past 90 days.
34102078-085f-45d3-ae72-81da16c75781  SECURITY  ACTIVE         2024-02-02T08:00:00Z  LOW       PERMISSIONS_USAGE_BIGQUERY_DATASET  10 of the permissions in this role binding were used in the past 90 days.

REST

Recommender API 的 insights.list 方法會列出專案的所有資料集層級政策洞察。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:要列出洞察的專案 ID。
  • LOCATION:要列出洞察的資料集位置。

HTTP 方法和網址:

GET https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/insightTypes/google.iam.policy.Insight/insights?filter=insightSubtype%20%3D%20PERMISSIONS_USAGE_BIGQUERY_DATASET

請展開以下其中一個選項,以傳送要求:

回應會列出專案在指定位置的所有資料集層級政策洞察。例如:

{
  "insights": [
    {
      "name": "projects/1069248613794/locations/us/insightTypes/google.iam.policy.Insight/insights/101d03ad-6148-4628-943e-fcf1a3af6b57",
      "description": "0 of the permissions in this role binding were used in the past 90 days.",
      "content": {
        "role": "roles/bigquery.dataEditor",
        "member": "projectEditor:my-project",
        "condition": {
          "expression": "",
          "title": "",
          "description": "",
          "location": ""
        },
        "exercisedPermissions": [],
        "inferredPermissions": [],
        "currentTotalPermissionsCount": "37"
      },
      "lastRefreshTime": "2024-02-02T08:00:00Z",
      "observationPeriod": "7779600s",
      "stateInfo": {
        "state": "ACTIVE"
      },
      "category": "SECURITY",
      "associatedRecommendations": [
        {
          "recommendation": "projects/1069248613794/locations/us/recommenders/google.iam.policy.Recommender/recommendations/9327f952-1ceb-488e-9e49-f17eb21f6e5e"
        }
      ],
      "targetResources": [
        "//bigquery.googleapis.com/projects/my-project/datasets/dataset-1"
      ],
      "insightSubtype": "PERMISSIONS_USAGE_BIGQUERY_DATASET",
      "etag": "\"35d4af47524d3f0c\"",
      "severity": "LOW"
    },
    {
      "name": "projects/1069248613794/locations/us/insightTypes/google.iam.policy.Insight/insights/15133dd9-4cbc-41e9-8990-b189241676d8",
      "description": "0 of the permissions in this role binding were used in the past 90 days.",
      "content": {
        "role": "roles/bigquery.dataViewer",
        "member": "projectViewer:my-project",
        "condition": {
          "expression": "",
          "title": "",
          "description": "",
          "location": ""
        },
        "exercisedPermissions": [],
        "inferredPermissions": [],
        "currentTotalPermissionsCount": "17"
      },
      "lastRefreshTime": "2024-02-02T08:00:00Z",
      "observationPeriod": "7779600s",
      "stateInfo": {
        "state": "ACTIVE"
      },
      "category": "SECURITY",
      "associatedRecommendations": [
        {
          "recommendation": "projects/1069248613794/locations/us/recommenders/google.iam.policy.Recommender/recommendations/bc9b4c28-cc93-4a91-97ea-ff67e3cef1b4"
        }
      ],
      "targetResources": [
        "//bigquery.googleapis.com/projects/my-project/datasets/dataset-2"
      ],
      "insightSubtype": "PERMISSIONS_USAGE_BIGQUERY_DATASET",
      "etag": "\"eafa79df1b329063\"",
      "severity": "LOW"
    }
  ]
}

如要進一步瞭解洞察的組成部分,請參閱本頁的「查看資料集層級政策洞察」一節。

取得單一資料集層級政策洞察

如要進一步瞭解單一洞察,包括洞察的說明、狀態和任何相關聯的建議,請使用下列其中一種方法:

gcloud

使用 gcloud recommender insights describe 指令搭配洞察 ID,即可查看單一洞察的相關資訊。

  • INSIGHT_ID:要查看的洞察 ID。如要找出 ID,請列出專案的洞察。
  • PROJECT_ID:要管理洞察的專案 ID。
  • LOCATION:要取得洞察的資料集位置。
gcloud recommender insights describe INSIGHT_ID \
    --insight-type=google.iam.policy.Insight \
    --project=PROJECT_ID \
    --location=LOCATION

輸出內容會顯示洞察詳細資料。舉例來說,下列洞察指出,在專案 my-project (projectEditor:my-project) 中,所有具備「編輯者」角色的使用者,在資料集 dataset-1 中都具備「BigQuery 資料編輯者」角色 (roles/bigquery.dataEditor),但在過去 90 天內,沒有人使用過該角色的任何權限:

associatedRecommendations:
- recommendation: projects/1069248613794/locations/us/recommenders/google.iam.policy.Recommender/recommendations/9327f951-1ceb-488e-9e49-f17eb21f6e5e
category: SECURITY
content:
  condition:
    description: ''
    expression: ''
    location: ''
    title: ''
  currentTotalPermissionsCount: '37'
  exercisedPermissions: []
  inferredPermissions: []
  member: projectEditor:my-project
  role: roles/bigquery.dataEditor
description: 0 of the permissions in this role binding were used in the past 90 days.
etag: '"5f2f352a738f7a24"'
insightSubtype: PERMISSIONS_USAGE_BIGQUERY_DATASET
lastRefreshTime: '2024-02-04T08:00:00Z'
name: projects/1069248613794/locations/us/insightTypes/google.iam.policy.Insight/insights/101d03ad-6148-4628-943e-fcf1a3af6b57
observationPeriod: 7776000s
severity: LOW
stateInfo:
  state: ACTIVE
targetResources:
- //bigquery.googleapis.com/projects/my-project/datasets/dataset-1

如要進一步瞭解洞察的組成部分,請參閱本頁的「查看資料集層級政策洞察」。

REST

Recommender API 的 insights.get 方法會取得單一洞察。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:要管理洞察的專案 ID。
  • LOCATION:要取得洞察的資料集位置。
  • INSIGHT_ID:要查看的洞察 ID。如果不知道洞察 ID,可以列出專案中的洞察來找出 ID。洞察的 ID 是指洞察 name 欄位中 insights/ 之後的所有內容。

HTTP 方法和網址:

GET https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/insightTypes/google.iam.policy.Insight/insights/INSIGHT_ID

請展開以下其中一個選項,以傳送要求:

回應中包含洞察資料。舉例來說,下列洞察指出,在專案 my-project (projectEditor:my-project) 中,所有具備「編輯者」角色的使用者,在資料集 dataset-1 中都具備「BigQuery 資料編輯者」角色 (roles/bigquery.dataEditor),但在過去 90 天內,沒有人使用過該角色的任何權限:

{
  "name": "projects/1069248613794/locations/us/insightTypes/google.iam.policy.Insight/insights/101d03ad-6148-4628-943e-fcf1a3af6b57",
  "description": "0 of the permissions in this role binding were used in the past 90 days.",
  "content": {
    "role": "roles/bigquery.dataEditor",
    "member": "projectEditor:my-project",
    "condition": {
      "expression": "",
      "title": "",
      "description": "",
      "location": ""
    },
    "exercisedPermissions": [],
    "inferredPermissions": [],
    "currentTotalPermissionsCount": "37"
  },
  "lastRefreshTime": "2024-02-02T08:00:00Z",
  "observationPeriod": "7779600s",
  "stateInfo": {
    "state": "ACTIVE"
  },
  "category": "SECURITY",
  "associatedRecommendations": [
    {
      "recommendation": "projects/1069248613794/locations/us/recommenders/google.iam.policy.Recommender/recommendations/9327f952-1ceb-488e-9e49-f17eb21f6e5e"
    }
  ],
  "targetResources": [
    "//bigquery.googleapis.com/projects/my-project/datasets/dataset-1"
  ],
  "insightSubtype": "PERMISSIONS_USAGE_BIGQUERY_DATASET",
  "etag": "\"35d4af47524d3f0c\"",
  "severity": "LOW"
}

如要進一步瞭解洞察的組成部分,請參閱本頁的「查看資料集層級政策洞察」。

查看資料集層級政策洞察

取得單一洞察後,您可以查看內容,瞭解其中強調的資源使用模式。

洞察的內容取決於其子類型。 資料集層級政策洞察 (google.iam.policy.Insight) 洞察具有 PERMISSIONS_USAGE_BIGQUERY_DATASET 子類型。

PERMISSIONS_USAGE_BIGQUERY_DATASET洞察包含下列元件,不一定按照這個順序:

  • associatedRecommendations:與洞察相關聯的任何建議 ID。如果沒有與洞察相關聯的建議,這個欄位會留空。
  • category:IAM 洞察的類別一律為 SECURITY。
  • content:回報主體對特定角色的權限使用情形。這個欄位包含下列元件:

    • condition:附加至繫結的任何條件,用於將角色授予主體。如果沒有條件,這個欄位會包含空白條件。
    • exercisedPermissions:主體在觀測期間使用的角色權限。
    • inferredPermissions:Recommender 透過ML判斷,主體可能需要根據其行使的權限,取得該角色中的權限。
    • member:權限使用情形分析的主體。
    • role:已分析權限使用情形的角色。
  • description:人類可讀的洞察摘要。
  • etag:洞察目前狀態的專屬 ID。 每次洞察資料變更時,系統都會指派新的 etag 值。

    如要變更洞察狀態,您必須提供現有洞察的 etag。使用 etag 有助於確保只有在洞察資料自上次擷取後未變更時,才會執行任何作業。

  • insightSubtype:洞察子類型。
  • lastRefreshTime:洞察上次重新整理的日期,代表用於產生洞察的資料更新程度。
  • name:洞察的名稱,格式如下:

    projects/PROJECT_ID/locations/LOCATION/insightTypes/google.iam.policy.Insight/insights/INSIGHT_ID

    預留位置的值如下:

    • PROJECT_ID:產生洞察的專案 ID。
    • LOCATION:洞察所屬資料集的位置。
    • INSIGHT_ID:洞察的專屬 ID。
  • observationPeriod:洞察產生前的時間範圍。用來生成洞察的來源資料,時間範圍是從 lastRefreshTime 減去 observationPeriod,到 lastRefreshTime 為止。
  • stateInfo:洞察資料在提出後會經歷多個狀態轉換:

    • ACTIVE:洞察已產生,但尚未採取任何動作,或已採取動作但未更新洞察狀態。基礎資料變更時,系統會更新有效洞察。
    • ACCEPTED:已根據洞察資料採取行動。如果相關聯的建議標示為「CLAIMED」、「SUCCEEDED」或「FAILED」,或洞察直接獲得接受,洞察就會變成已接受狀態。當洞察處於 ACCEPTED 狀態時,洞察的內容無法變更。採用的洞察資料會保留 90 天。
  • targetResources:洞察所屬資料集的完整資源名稱。例如://bigquery.googleapis.com/projects/my-project/datasets/my-dataset。

將資料集層級政策洞察標示為ACCEPTED

如果您根據有效洞察資料採取行動,可以將該洞察資料標示為ACCEPTED。ACCEPTED 狀態會告知 Recommender API,您已根據這項洞察資料採取行動,這有助於改善建議。

接受的洞察資料標示為「ACCEPTED」後,會保留 90 天。

gcloud

使用 gcloud recommender insights mark-accepted 指令搭配洞察 ID,將洞察標示為 ACCEPTED。

  • INSIGHT_ID:要查看的洞察 ID。如要找出 ID,請列出專案的洞察。
  • PROJECT_ID:要管理洞察的專案 ID。
  • LOCATION:資料集的位置,您要將該資料集的洞察標示為 ACCEPTED。
  • ETAG:洞察版本的 ID。如要取得 etag,請按照下列步驟操作:

    1. 使用 gcloud recommender insights describe 指令取得洞察。
    2. 從輸出內容中找出並複製 etag 值,包括前後的引號。例如 "d3cdec23cc712bd0"。
gcloud recommender insights mark-accepted INSIGHT_ID \
    --insight-type=google.iam.policy.Insight \
    --project=PROJECT_ID \
    --location=LOCATION \
    --etag=ETAG

輸出內容會顯示洞察,現在狀態為 ACCEPTED:

associatedRecommendations:
- recommendation: projects/1069248613794/locations/us/recommenders/google.iam.policy.Recommender/recommendations/9327f951-1ceb-488e-9e49-f17eb21f6e5e
category: SECURITY
content:
  condition:
    description: ''
    expression: ''
    location: ''
    title: ''
  currentTotalPermissionsCount: '37'
  exercisedPermissions: []
  inferredPermissions: []
  member: projectEditor:my-project
  role: roles/bigquery.dataEditor
description: 0 of the permissions in this role binding were used in the past 90 days.
etag: '"5f2f352a738f7a24"'
insightSubtype: PERMISSIONS_USAGE_BIGQUERY_DATASET
lastRefreshTime: '2024-02-04T08:00:00Z'
name: projects/1069248613794/locations/us/insightTypes/google.iam.policy.Insight/insights/101d03ad-6148-4628-943e-fcf1a3af6b57
observationPeriod: 7776000s
severity: LOW
stateInfo:
  state: ACCEPTED
targetResources:
- //bigquery.googleapis.com/projects/my-project/datasets/dataset-1

如要進一步瞭解洞察的狀態資訊,請參閱本頁的「查看資料集層級政策洞察」。

REST

Recommender API 的 insights.markAccepted 方法會將洞察標示為 ACCEPTED。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:要管理洞察的專案 ID。
  • LOCATION:資料集的位置,您要將該資料集的洞察標示為 ACCEPTED。
  • INSIGHT_ID:要查看的洞察 ID。如果不知道洞察 ID,可以列出專案中的洞察來找出 ID。洞察的 ID 是指洞察 name 欄位中 insights/ 之後的所有內容。
  • ETAG:洞察版本的 ID。如要取得 etag,請按照下列步驟操作:
    1. 使用 insights.get 方法取得洞察。
    2. 從回應中找出並複製 etag 值。

HTTP 方法和網址:

POST https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/insightTypes/google.iam.policy.Insight/insights/INSIGHT_ID:markAccepted

JSON 要求主體:

{
  "etag": "ETAG"
}

請展開以下其中一個選項,以傳送要求:

回應包含洞察,現在狀態為 ACCEPTED:

{
  "name": "projects/1069248613794/locations/us/insightTypes/google.iam.policy.Insight/insights/101d03ad-6148-4628-943e-fcf1a3af6b57",
  "description": "0 of the permissions in this role binding were used in the past 90 days.",
  "content": {
    "role": "roles/bigquery.dataEditor",
    "member": "projectEditor:my-project",
    "condition": {
      "expression": "",
      "title": "",
      "description": "",
      "location": ""
    },
    "exercisedPermissions": [],
    "inferredPermissions": [],
    "currentTotalPermissionsCount": "37"
  },
  "lastRefreshTime": "2024-02-02T08:00:00Z",
  "observationPeriod": "7779600s",
  "stateInfo": {
    "state": "ACCEPTED"
  },
  "category": "SECURITY",
  "associatedRecommendations": [
    {
      "recommendation": "projects/1069248613794/locations/us/recommenders/google.iam.policy.Recommender/recommendations/9327f952-1ceb-488e-9e49-f17eb21f6e5e"
    }
  ],
  "targetResources": [
    "//bigquery.googleapis.com/projects/my-project/datasets/dataset-1"
  ],
  "insightSubtype": "PERMISSIONS_USAGE_BIGQUERY_DATASET",
  "etag": "\"35d4af47524d3f0c\"",
  "severity": "LOW"
}

如要進一步瞭解洞察的狀態資訊,請參閱本頁的「查看資料集層級政策洞察」。

後續步驟