本頁面說明如何管理政策洞察資料,也就是機器學習技術所得出的權限使用情形相關發現。政策洞察資料可協助您找出哪些主體擁有不需要的權限。
本頁內容著重於專案、資料夾和機構的政策洞察資料。建議工具也提供下列資源類型的政策深入分析資料:
政策深入分析有時會連結至 角色建議。角色建議會建議您採取哪些行動,以便解決政策洞察所指出的問題。
事前準備
-
Enable the Recommender API.
- 熟悉 IAM 角色建議。
- 請確認您已 在機構或專案層級啟用 Security Command Center 的進階或企業級方案。詳情請參閱「 帳單問題」。
- 選用:瞭解Recommender 深入分析。
必要的角色
如要取得管理政策深入分析所需的權限,請要求管理員為您授予下列身分與存取權管理角色,以便您管理所需的專案、資料夾或機構:
-
如要查看政策深入分析資料:
IAM 推薦功能檢視器 (
roles/recommender.iamViewer
) -
如要修改政策深入分析資料:
IAM 推薦功能管理員 (
roles/recommender.iamAdmin
)
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這些預先定義的角色包含管理政策深入分析所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
您必須具備下列權限,才能管理政策深入分析資料:
-
如要查看政策深入分析資訊,請按照下列步驟操作:
-
recommender.iamPolicyInsights.get
-
recommender.iamPolicyInsights.list
-
-
如要修改政策深入分析資料,請按照下列步驟操作:
recommender.iamPolicyInsights.update
列出政策深入分析
如要列出專案、資料夾或機構的所有政策深入分析資料,請使用下列任一方法:控制台
-
前往 Google Cloud 控制台的「IAM」頁面。
- 選取專案、資料夾或機構。
「安全性洞察」欄會顯示專案的所有安全性相關洞察資料,包括政策洞察資料。政策深入分析資料的格式為 EXCESS/TOTAL excess
permissions
,其中 EXCESS
是角色中主體不需要的權限數量,而 TOTAL
是角色中權限的總數。
gcloud
使用 gcloud recommender
insights list
指令,查看專案、資料夾或機構的所有政策深入分析。
執行指令前,請先替換下列值:
-
RESOURCE_TYPE
:您要列出洞察資料的資源類型。請使用project
、folder
或organization
的值。 -
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
:您要列出洞察資料的資源類型。請使用projects
、folders
或organizations
的值。 -
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" } ] }
如要進一步瞭解洞察資料的組成元素,請參閱本頁的「查看政策洞察資料」一節。
取得單一政策洞察資訊
如要進一步瞭解單一洞察資訊,包括洞察資訊的說明、狀態,以及與之相關的任何建議,請使用下列任一方法:
控制台
-
前往 Google Cloud 控制台的「IAM」頁面。
- 選取專案、資料夾或機構。
-
在「安全性洞察資料」欄中,按一下政策洞察資料。 政策深入分析資料的格式為
EXCESS/TOTAL excess permissions
,其中EXCESS
是角色中主體不需要的權限數量,而TOTAL
是角色中權限的總數。
Google Cloud 控制台會開啟一個窗格,顯示洞察資料的詳細資料。
gcloud
使用 gcloud recommender
insights describe
指令搭配洞察 ID,即可查看單一洞察資訊的相關資訊。
-
INSIGHT_ID
:您要查看的洞察資料 ID。如要找出 ID,請列出專案、資料夾或機構的洞察資料。 -
RESOURCE_TYPE
:您要管理洞察資料的資源類型。請使用project
、folder
或organization
值。 -
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
:您要管理洞察資料的資源類型。請使用projects
、folders
或organizations
的值。 -
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 透過機器學習判斷角色中哪些權限是主體根據其已授予的權限,可能需要的權限。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
:已根據洞察資料採取某些行動。當相關建議標示為CLAIMED
、SUCCEEDED
或FAILED
,或是直接接受洞察時,系統就會接受洞察。洞察處於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 透過機器學習判斷角色中哪些權限是主體根據其已授予的權限,可能需要的權限。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
:已根據洞察資料採取某些行動。當相關建議標示為CLAIMED
、SUCCEEDED
或FAILED
,或是直接接受洞察時,系統就會接受洞察。洞察處於ACCEPTED
狀態時,就無法變更洞察內容。已接受的洞察資料會在接受後保留 90 天。
-
-
targetResources
:洞察資料所屬專案、資料夾或機構的完整資源名稱 。例如//cloudresourcemanager.googleapis.com/projects/123456789012
。
將政策洞察標示為 ACCEPTED
如果您根據有效洞察資料採取行動,可以將該洞察資料標示為 ACCEPTED
。ACCEPTED
狀態會向 Recommender API 指出您已根據這項洞察資料採取行動,有助於改善建議內容。
系統會在標示為 ACCEPTED
後,將已接受的洞察資料保留 90 天。
控制台
如果洞察與建議相關聯,套用建議會將洞察狀態變更為 ACCEPTED
。
如要將洞察標示為 ACCEPTED
而不套用最佳化建議,請使用 gcloud CLI 或 REST API。
gcloud
使用
gcloud recommender insights mark-accepted
指令搭配洞察 ID,將洞察標示為 ACCEPTED
。
-
INSIGHT_ID
:您要查看的洞察資料 ID。如要找出 ID,請列出專案、資料夾或機構的洞察資料。 -
RESOURCE_TYPE
:您要管理洞察資料的資源類型。請使用project
、folder
或organization
值。 -
RESOURCE_ID
:您要管理洞察資料的專案、資料夾或機構 ID。 -
ETAG
:洞察資料版本的 ID。如要取得etag
,請執行下列操作:-
使用
gcloud recommender insights describe
指令取得洞察資料。 -
在輸出內容中找出並複製
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
:您要管理洞察資料的資源類型。請使用projects
、folders
或organizations
的值。 -
RESOURCE_ID
:您要管理洞察資料的專案、資料夾或機構 ID。 -
INSIGHT_ID
:您要查看的洞察資料 ID。如果不知道洞察 ID,您可以前往專案、資料夾或機構列出洞察資料,洞察 ID 是洞察name
欄位中insights/
後面的所有內容。 -
ETAG
:洞察資料版本的 ID。如要取得etag
,請執行下列操作:- 使用
insights.get
方法取得洞察資料。 - 在回應中找出並複製
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" }
如要進一步瞭解洞察資料的狀態資訊,請參閱本頁的「查看政策洞察資料」一節。
後續步驟
- 瞭解如何查看及套用政策最佳化建議。
- 您可以使用建議中心查看及管理專案的所有建議,包括 IAM 建議。