查看專案、資料夾和機構的政策深入分析

本頁面說明如何管理政策洞察,這是根據機器學習技術得出的權限使用情況調查結果。政策洞察資料可協助您找出具備不必要權限的主體。

本頁面著重於專案、資料夾和機構的政策洞察資料。 建議工具也提供下列資源類型的政策洞察:

政策洞察資訊有時會連結至 角色建議。角色建議會提供建議動作,協助您解決政策洞察功能發現的問題。

事前準備

必要的角色

如要取得管理政策洞察資訊所需的權限,請要求管理員在您要管理洞察資訊的專案、資料夾或機構中,授予下列 IAM 角色:

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

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

所需權限

如要管理政策洞察,必須具備下列權限:

  • 如要查看政策洞察資料,請按照下列步驟操作:
    • recommender.iamPolicyInsights.get
    • recommender.iamPolicyInsights.list
  • 如要修改政策洞察資料: recommender.iamPolicyInsights.update

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

列出政策深入分析

如要列出專案、資料夾或機構的所有政策洞察,請使用下列其中一種方法:

控制台

  1. 前往 Google Cloud 控制台的「IAM」IAM頁面。

    前往 IAM

  2. 選取專案、資料夾或機構。

「安全性洞察」欄會顯示專案的所有安全性相關洞察資料,包括政策洞察資料。政策洞察資料的格式為 EXCESS/TOTAL excess permissions,其中 EXCESS 是主體不需要的角色權限數量,TOTAL 則是角色權限總數。

gcloud

使用 gcloud recommender insights list 指令,查看專案、資料夾或機構的所有政策深入分析。

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

  • RESOURCE_TYPE:您要列出洞察資料的資源類型。請使用下列值: projectfolderorganization
  • RESOURCE_ID:要列出洞察資料的專案、資料夾或機構的 ID。
gcloud recommender insights list --insight-type=google.iam.policy.Insight \
    --RESOURCE_TYPE=RESOURCE_ID \
    --location=global

輸出內容會列出專案、資料夾或機構的所有政策深入分析。例如:

INSIGHT_ID                            CATEGORY  INSIGHT_STATE  LAST_REFRESH_TIME     SEVERITY  INSIGHT_SUBTYPE    DESCRIPTION
00133c0b-5431-4b30-9172-7c903aa4af24  SECURITY  ACTIVE         2022-05-24T07:00:00Z  LOW       PERMISSIONS_USAGE  9 of the permissions in this role binding were used in the past 90 days.
0161f2eb-acb7-4a5e-ad52-50284beaa312  SECURITY  ACTIVE         2022-05-24T07:00:00Z  LOW       PERMISSIONS_USAGE  0 of the permissions in this role binding were used in the past 90 days.
01ea0d0d-e9a1-4073-9367-5a934a857fb4  SECURITY  ACTIVE         2022-05-24T07:00:00Z  LOW       PERMISSIONS_USAGE  1 of the permissions in this role binding were used in the past 90 days.
039407bc-a25b-4aeb-b573-5c851f2e9833  SECURITY  ACTIVE         2022-05-24T07:00:00Z  HIGH      PERMISSIONS_USAGE  52 of the permissions in this role binding were used in the past 90 days.
0541df88-8bc3-44b3-ad5d-9cb372630aeb  SECURITY  ACTIVE         2022-05-24T07:00:00Z  HIGH      PERMISSIONS_USAGE  31 of the permissions in this role binding were used in the past 90 days.
07841f74-02ce-4de8-bbe6-fc4eabb68568  SECURITY  ACTIVE         2022-05-24T07:00:00Z  HIGH      PERMISSIONS_USAGE  0 of the permissions in this role binding were used in the past 90 days.
07713094-fdee-4475-9c43-cd53d52c9de1  SECURITY  ACTIVE         2022-05-24T07:00:00Z  LOW       PERMISSIONS_USAGE  2 of the permissions in this role binding were used in the past 90 days.
0a438d19-9d63-4749-aadd-578aa4e77908  SECURITY  ACTIVE         2022-05-24T07:00:00Z  LOW       PERMISSIONS_USAGE  0 of the permissions in this role binding were used in the past 90 days.
f4292f55-105b-4744-9dc3-fcacf59685bb  SECURITY  ACTIVE         2022-05-24T07:00:00Z  HIGH      PERMISSIONS_USAGE  4 of the permissions in this role binding were used in the past 90 days.

REST

Recommender API 的 insights.list 方法會列出專案、資料夾或機構的所有政策深入分析。

使用任何要求資料之前,請先替換以下項目:

  • RESOURCE_TYPE:您要列出洞察資料的資源類型。 請使用下列值: projectsfoldersorganizations
  • RESOURCE_ID:要列出洞察資料的專案、資料夾或機構的 ID。
  • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 為英數字串,例如 my-project

HTTP 方法和網址:

GET https://recommender.googleapis.com/v1/RESOURCE_TYPE/RESOURCE_ID/locations/global/insightTypes/google.iam.policy.Insight/insights

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

回應會列出專案、資料夾或機構的所有政策深入分析。例如:

{
  "insights": [
    {
      "name": "projects/123456789012/locations/global/insightTypes/google.iam.policy.Insight/insights/07841f74-02ce-4de8-bbe6-fc4eabb68568",
      "description": "0 of the permissions in this role binding were used in the past 90 days.",
      "content": {
        "role": "roles/viewer",
        "member": "serviceAccount:my-service-account@my-project.iam.gserviceaccount.com",
        "condition": {
          "expression": "",
          "title": "",
          "description": "",
          "location": ""
        },
        "exercisedPermissions": [],
        "inferredPermissions": []
      },
      "lastRefreshTime": "2022-05-24T07:00:00Z",
      "observationPeriod": "7776000s",
      "stateInfo": {
        "state": "ACTIVE"
      },
      "category": "SECURITY",
      "associatedRecommendations": [
        {
          "recommendation": "projects/123456789012/locations/global/recommenders/google.iam.policy.Recommender/recommendations/b1932220-867d-43d1-bd74-fb95876ab656"
        }
      ],
      "targetResources": [
        "//cloudresourcemanager.googleapis.com/projects/123456789012"
      ],
      "insightSubtype": "PERMISSIONS_USAGE",
      "etag": "\"b153ab487e4ae100\"",
      "severity": "HIGH"
    },
    {
      "name": "projects/123456789012/locations/global/insightTypes/google.iam.policy.Insight/insights/f4292f55-105b-4744-9dc3-fcacf59685bb",
      "description": "4 of the permissions in this role binding were used in the past 90 days.",
      "content": {
        "role": "roles/owner",
        "member": "serviceAccount:my-service-account2@my-project.iam.gserviceaccount.com",
        "condition": {
          "expression": "",
          "title": "",
          "description": "",
          "location": ""
        },
        "exercisedPermissions": [
          {
            "permission": "iam.roles.create"
          },
          {
            "permission": "iam.roles.delete"
          },
          {
            "permission": "iam.roles.list"
          },
          {
            "permission": "iam.roles.update"
          }
        ],
        "inferredPermissions": []
      },
      "lastRefreshTime": "2022-05-24T07:00:00Z",
      "observationPeriod": "7776000s",
      "stateInfo": {
        "state": "ACTIVE"
      },
      "category": "SECURITY",
      "associatedRecommendations": [
        {
          "recommendation": "projects/123456789012/locations/global/recommenders/google.iam.policy.Recommender/recommendations/6ab16c1d-edce-45e5-8d82-570fdd49892a"
        }
      ],
      "targetResources": [
        "//cloudresourcemanager.googleapis.com/projects/123456789012"
      ],
      "insightSubtype": "PERMISSIONS_USAGE",
      "etag": "\"49bb705553338fc3\"",
      "severity": "HIGH"
    }
  ]
}

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

取得單一政策深入分析

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

控制台

  1. 前往 Google Cloud 控制台的「IAM」IAM頁面。

    前往 IAM

  2. 選取專案、資料夾或機構。
  3. 在「安全性洞察資料」欄中,按一下政策洞察資料。 政策洞察資訊的格式為 EXCESS/TOTAL excess permissions,其中 EXCESS 是主體不需要的角色權限數量,TOTAL 則是角色中的權限總數。

Google Cloud 控制台會開啟窗格,顯示洞察資料的詳細資料。

gcloud

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

  • INSIGHT_ID:要查看的洞察 ID。如要找出 ID,請列出專案、資料夾或機構的洞察資料
  • RESOURCE_TYPE:要管理洞察資料的資源類型。請使用下列值: projectfolderorganization
  • RESOURCE_ID:要管理洞察資料的專案、資料夾或機構 ID。
gcloud recommender insights describe INSIGHT_ID \
    --insight-type=google.iam.policy.Insight \
    --RESOURCE_TYPE=RESOURCE_ID \
    --location=global

輸出內容會詳細顯示洞察資料。舉例來說,以下洞察資訊指出,my-service-account@my-project.iam.gserviceaccount.com 在過去 90 天內,完全未使用檢視者角色 (roles/viewer) 的權限:

associatedRecommendations:
- recommendation: projects/123456789012/locations/global/recommenders/google.iam.policy.Recommender/recommendations/0573b702-96a5-4622-a916-c762e7b0731f
category: SECURITY
content:
  condition:
    description: ''
    expression: ''
    location: ''
    title: ''
  exercisedPermissions: []
  inferredPermissions: []
  member: serviceAccount:my-service-account@my-project.iam.gserviceaccount.com
  role: roles/viewer
description: 0 of the permissions in this role binding were used in the past 90 days.
etag: '"d3cdec23cc712bd0"'
insightSubtype: PERMISSIONS_USAGE
lastRefreshTime: '2020-07-11T07:00:00Z'
name: projects/123456789012/locations/global/insightTypes/google.iam.policy.Insight/insights/0d3ce433-f067-4e78-b6ae-03d7d1f6f040
observationPeriod: 7776000s
severity: HIGH
stateInfo:
  state: ACTIVE
targetResources:
- //cloudresourcemanager.googleapis.com/projects/123456789012

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

REST

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

使用任何要求資料之前,請先替換以下項目:

  • RESOURCE_TYPE:要管理洞察資料的資源類型。請使用以下值: projectsfoldersorganizations
  • RESOURCE_ID:您要管理洞察資料的專案、資料夾或機構的 ID。
  • INSIGHT_ID:要查看的洞察 ID。如果您不知道洞察 ID,可以列出專案、資料夾或機構中的洞察,洞察 ID 是洞察的 name 欄位中 insights/ 後方的所有內容。
  • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 為英數字串,例如 my-project

HTTP 方法和網址:

GET https://recommender.googleapis.com/v1/RESOURCE_TYPE/RESOURCE_ID/locations/global/insightTypes/google.iam.policy.Insight/insights/INSIGHT_ID

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

回覆會包含洞察資料。舉例來說,以下洞察資訊指出,my-service-account@my-project.iam.gserviceaccount.com 在過去 90 天內,完全未使用檢視者角色 (roles/viewer) 的權限:

{
  "name": "projects/123456789012/locations/global/insightTypes/google.iam.policy.Insight/insights/07841f74-02ce-4de8-bbe6-fc4eabb68568",
  "description": "0 of the permissions in this role binding were used in the past 90 days.",
  "content": {
    "role": "roles/viewer",
    "member": "serviceAccount:my-service-account@my-project.iam.gserviceaccount.com",
    "condition": {
      "expression": "",
      "title": "",
      "description": "",
      "location": ""
    },
    "exercisedPermissions": [],
    "inferredPermissions": []
  },
  "lastRefreshTime": "2022-05-24T07:00:00Z",
  "observationPeriod": "7776000s",
  "stateInfo": {
    "state": "ACTIVE"
  },
  "category": "SECURITY",
  "associatedRecommendations": [
    {
      "recommendation": "projects/123456789012/locations/global/recommenders/google.iam.policy.Recommender/recommendations/b1932220-867d-43d1-bd74-fb95876ab656"
    }
  ],
  "targetResources": [
    "//cloudresourcemanager.googleapis.com/projects/123456789012"
  ],
  "insightSubtype": "PERMISSIONS_USAGE",
  "etag": "\"d3cdec23cc712bd0\"",
  "severity": "HIGH"
}

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

查看政策深入分析

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

控制台

在 Google Cloud 控制台中點選政策洞察資料時, Google Cloud 控制台會開啟一個窗格,顯示洞察資料的詳細資料。這些詳細資料的顯示方式,取決於洞察資訊是否與建議相關聯。

如果洞察資訊與建議相關聯,窗格會顯示建議詳細資料

如果洞察資訊未與建議相關聯,窗格會顯示角色中的所有權限清單。主體使用的權限會顯示在清單頂端,接著是超額權限。

gcloud

洞察內容取決於子類型。 政策洞察 (google.iam.policy.Insight) 洞察具有 PERMISSIONS_USAGE 子類型。

PERMISSIONS_USAGE 洞察包含下列元件,但不一定會依此順序顯示:

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

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

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

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

    RESOURCE_TYPE/RESOURCE_ID/locations/global/insightTypes/google.iam.policy.Insight/insights/INSIGHT_ID

    預留位置的值如下:

    • RESOURCE_TYPE:洞察資訊的產生對象資源類型。
    • RESOURCE_ID:洞察資訊所屬的專案、資料夾或機構 ID。
    • INSIGHT_ID:洞察的專屬 ID。
  • observationPeriod:洞察資料的參考時間範圍。用來生成洞察的來源資料結束於 lastRefreshTime,開始於 lastRefreshTime 減去 observationPeriod
  • stateInfo:洞察資料在提出後會經歷多種狀態轉換:

    • ACTIVE:洞察資料已產生,但未採取任何動作,或採取動作後未更新洞察資料的狀態。基礎資料變更時,系統會更新有效的洞察資料。
    • ACCEPTED:已根據洞察資料採取行動。當相關聯的建議標示為 CLAIMEDSUCCEEDEDFAILED,或直接接受洞察資料時,洞察資料就會獲得採用。洞察資料處於 ACCEPTED 狀態時,洞察資料內容無法變更。接受的洞察資料會在接受後保留 90 天。
  • targetResources:洞察資訊所屬專案、資料夾或機構的完整資源名稱 。例如: //cloudresourcemanager.googleapis.com/projects/123456789012

REST

洞察內容取決於子類型。 政策洞察 (google.iam.policy.Insight) 洞察具有 PERMISSIONS_USAGE 子類型。

PERMISSIONS_USAGE 洞察包含下列元件,但不一定會依此順序顯示:

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

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

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

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

    RESOURCE_TYPE/RESOURCE_ID/locations/global/insightTypes/google.iam.policy.Insight/insights/INSIGHT_ID

    預留位置的值如下:

    • RESOURCE_TYPE:洞察資訊的產生對象資源類型。
    • RESOURCE_ID:洞察資訊所屬的專案、資料夾或機構 ID。
    • INSIGHT_ID:洞察的專屬 ID。
  • observationPeriod:洞察資料的參考時間範圍。用來生成洞察的來源資料結束於 lastRefreshTime,開始於 lastRefreshTime 減去 observationPeriod
  • stateInfo:洞察資料在提出後會經歷多種狀態轉換:

    • ACTIVE:洞察資料已產生,但未採取任何動作,或採取動作後未更新洞察資料的狀態。基礎資料變更時,系統會更新有效的洞察資料。
    • ACCEPTED:已根據洞察資料採取行動。當相關聯的建議標示為 CLAIMEDSUCCEEDEDFAILED,或直接接受洞察資料時,洞察資料就會獲得採用。洞察資料處於 ACCEPTED 狀態時,洞察資料內容無法變更。接受的洞察資料會在接受後保留 90 天。
  • targetResources:洞察資訊所屬專案、資料夾或機構的完整資源名稱 。例如: //cloudresourcemanager.googleapis.com/projects/123456789012

將政策洞察標示為 ACCEPTED

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

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

控制台

如果深入分析資料與建議相關聯,套用建議後,深入分析資料的狀態會變更為 ACCEPTED

如要將洞察標示為 ACCEPTED,但不套用建議,請使用 gcloud CLI 或 REST API。

gcloud

使用 gcloud recommender insights mark-accepted 指令並提供洞察 ID,將洞察標示為 ACCEPTED

  • INSIGHT_ID:要查看的洞察 ID。如要找出 ID,請列出專案、資料夾或機構的洞察資料
  • RESOURCE_TYPE:要管理洞察資料的資源類型。請使用下列值: projectfolderorganization
  • RESOURCE_ID:要管理洞察資料的專案、資料夾或機構 ID。
  • ETAG:洞察版本的 ID。如要取得 etag,請按照下列步驟操作:

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

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

associatedRecommendations:
- recommendation: projects/123456789012/locations/global/recommenders/google.iam.policy.Recommender/recommendations/0573b702-96a5-4622-a916-c762e7b0731f
category: SECURITY
content:
  condition:
    description: ''
    expression: ''
    location: ''
    title: ''
  exercisedPermissions: []
  inferredPermissions: []
  member: serviceAccount:my-service-account@my-project.iam.gserviceaccount.com
  role: roles/viewer
description: 0 of the permissions in this role binding were used in the past 90 days.
etag: '"b153ab487e4ae100"'
insightSubtype: PERMISSIONS_USAGE
lastRefreshTime: '2020-07-11T07:00:00Z'
name: projects/123456789012/locations/global/insightTypes/google.iam.policy.Insight/insights/0d3ce433-f067-4e78-b6ae-03d7d1f6f040
observationPeriod: 7776000s
severity: HIGH
stateInfo:
  state: ACCEPTED
targetResources:
- //cloudresourcemanager.googleapis.com/projects/123456789012

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

REST

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

使用任何要求資料之前,請先替換以下項目:

  • RESOURCE_TYPE:要管理洞察資料的資源類型。請使用以下值: projectsfoldersorganizations
  • RESOURCE_ID:您要管理洞察資料的專案、資料夾或機構的 ID。
  • INSIGHT_ID:要查看的洞察 ID。如果您不知道洞察 ID,可以列出專案、資料夾或機構中的洞察,洞察 ID 是洞察的 name 欄位中 insights/ 後方的所有內容。
  • ETAG:洞察版本的 ID。如要取得 etag,請按照下列步驟操作:
    1. 使用 insights.get 方法取得洞察資料
    2. 從回應中找出並複製 etag 值。
  • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 為英數字串,例如 my-project

HTTP 方法和網址:

POST https://recommender.googleapis.com/v1/RESOURCE_TYPE/RESOURCE_ID/locations/global/insightTypes/google.iam.policy.Insight/insights/INSIGHT_ID:markAccepted

JSON 要求主體:

{
  "etag": "ETAG"
}

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

回應包含洞察資料,現在會顯示 ACCEPTED 的狀態:

{
  "name": "projects/1234567890/locations/global/insightTypes/google.iam.policy.Insight/insights/07841f74-02ce-4de8-bbe6-fc4eabb68568",
  "description": "0 of the permissions in this role binding were used in the past 90 days.",
  "content": {
    "role": "roles/viewer",
    "member": "serviceAccount:my-service-account@my-project.iam.gserviceaccount.com",
    "condition": {
      "expression": "",
      "title": "",
      "description": "",
      "location": ""
    },
    "exercisedPermissions": [],
    "inferredPermissions": []
  },
  "lastRefreshTime": "2022-05-24T07:00:00Z",
  "observationPeriod": "7776000s",
  "stateInfo": {
    "state": "ACCEPTED"
    },
  "category": "SECURITY",
  "associatedRecommendations": [
    {
      "recommendation": "projects/1234567890/locations/global/recommenders/google.iam.policy.Recommender/recommendations/b1932220-867d-43d1-bd74-fb95876ab656"
    }
  ],
  "targetResources": [
    "//cloudresourcemanager.googleapis.com/projects/123456789012"
  ],
  "insightSubtype": "PERMISSIONS_USAGE",
  "etag": "\"b153ab487e4ae100\"",
  "severity": "HIGH"
}

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

後續步驟