除了提供建议之外,Recommender 还会使用机器学习 (ML) 来提供详细的数据分析。数据分析是突出显示资源使用情况中重要格式的发现结果。例如,您可以收集有关项目中权限使用情况的其他信息,或者识别未使用的服务帐号。一些数据分析还与建议相关联,因为数据分析能够为建议提供证据。
Identity and Access Management (IAM) 提供以下数据分析类型:
- 政策数据分析:基于机器学习的有关项目中权限使用情况的发现结果。
- 服务帐号数据分析:有关项目中服务帐号的发现结果,例如过去 90 天内未使用的服务帐号。
准备工作
- 如果您想使用政策数据分析,请熟悉 IAM Recommender。
- 可选:了解 Recommender 数据分析。
所需权限
使用数据分析所需的权限因您希望执行的操作而异。
查看数据分析的权限
如需查看数据分析,您需要包含以下权限的角色,其中 insight-type 为 iamPolicyInsights
或 iamServiceAccountInsights
:
recommender.insight-type.get
recommender.insight-type.list
如需获得这些权限,同时遵循最小权限原则,请让管理员向您授予以下角色之一:
- IAM Recommender Viewer (
roles/recommender.iamViewer
) - IAM Security Reviewer (
roles/iam.securityReviewer
)
或者,管理员也可以向您授予具有所需权限的其他角色,例如自定义角色或更宽松的预定义角色。
修改数据分析的权限
如需修改数据分析,您需要包含以下权限的角色,其中 insight-type 为 iamPolicyInsights
或 iamServiceAccountInsights
:
recommender.insight-type.get
recommender.insight-type.list
recommender.insight-type.update
如需获得这些权限,同时遵循最小权限原则,请让管理员向您授予 IAM Recommender Admin 角色 (roles/recommender.iamAdmin
)。
或者,管理员也可以向您授予具有所需权限的其他角色,例如自定义角色或更宽松的预定义角色。
列出数据分析
如需列出项目的特定类型的所有数据分析,请使用以下方法之一:
gcloud
使用 gcloud recommender insights list
命令查看项目的特定类型的所有数据分析。
将 insight-type-id
替换为您要列出的数据分析类型。使用 google.iam.policy.Insight
进行政策数据分析,并使用 google.iam.serviceAccount.Insight
获取服务帐号数据分析。
gcloud recommender insights list --insight-type=insight-type-id \ --location=global
输出会列出项目的特定类型的所有数据分析。例如,列出项目的所有政策数据分析会输出如下结果:
INSIGHT_ID LOCATION INSIGHT_TYPE CATEGORY INSIGHT_STATE LAST_REFRESH_TIME 07841f74-02ce-4de8-bbe6-fc4eabb68568 global google.iam.policy.Insight SECURITY ACCEPTED 2020-07-12T07:00:00Z 0d3ce433-f067-4e78-b6ae-03d7d1f6f040 global google.iam.policy.Insight SECURITY ACTIVE 2020-07-13T07:00:00Z 0e2cc488-38fb-4b9b-942c-cfe06a0ab88f global google.iam.policy.Insight SECURITY ACTIVE 2020-07-13T07:00:00Z 12b557be-d48f-49cf-a0b0-b3b73a178edf global google.iam.policy.Insight SECURITY ACTIVE 2020-07-13T07:00:00Z 279ef748-408f-44db-9a4a-1ff8865b9839 global google.iam.policy.Insight SECURITY ACTIVE 2020-07-13T07:00:00Z 29a4553d-9ffb-4508-9f13-77f40fc4e8b6 global google.iam.policy.Insight SECURITY ACTIVE 2020-07-13T07:00:00Z 2a00a91a-3e37-4dca-81f7-fb607d18053f global google.iam.policy.Insight SECURITY ACTIVE 2020-07-13T07:00:00Z 2baea818-df89-4ab3-8a48-0e752459d816 global google.iam.policy.Insight SECURITY ACTIVE 2020-07-13T07:00:00Z 4a59da9d-cde8-46cc-9c68-6980487175fb global google.iam.policy.Insight SECURITY ACTIVE 2020-07-13T07:00:00Z 78fee8d9-c25c-4070-9f1b-ae5e4a4a164b global google.iam.policy.Insight SECURITY ACTIVE 2020-07-13T07:00:00Z
REST
Recommender API 的 insights.list
方法可列出项目中特定类型的所有数据分析。
在使用下面的请求数据之前,请先进行以下替换:
project-id
:您的 Google Cloud 项目 ID。insight-type-id
:您要列出的数据分析类型。对于政策数据分析,请使用google.iam.policy.Insight
。对于服务帐号数据分析,请使用google.iam.serviceAccount.Insight
。
HTTP 方法和网址:
GET https://recommender.googleapis.com/v1/projects/project-id/locations/global/insightTypes/insight-type-id/insights
如需发送您的请求,请展开以下选项之一:
响应会列出项目中特定类型的所有数据分析。例如,它可列出项目中的所有政策数据分析:
{ "insights": [ { "name": "projects/123456789012/locations/global/insightTypes/google.iam.policy.Insight/insights/07841f74-02ce-4de8-bbe6-fc4eabb68568", "description": "0 permission checks were authorized by this policy binding tuple.", "content": { "role": "roles/viewer", "member": "serviceAccount:my-service-account@my-project.iam.gserviceaccount.com", "condition": { "expression": "", "title": "", "description": "", "location": "" }, "exercisedPermissions": [], "inferredPermissions": [] }, "lastRefreshTime": "2020-07-12T07: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/1234567890" ], "insightSubtype": "PERMISSIONS_USAGE", "etag": "\"b153ab487e4ae100\"" }, { "name": "projects/123456789012/locations/global/insightTypes/google.iam.policy.Insight/insights/f4292f55-105b-4744-9dc3-fcacf59685bb", "description": "4 permission checks were authorized by this policy binding tuple.", "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": "2020-07-12T07: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/1234567890" ], "insightSubtype": "PERMISSIONS_USAGE", "etag": "\"49bb705553338fc3\"" } ] }
如需详细了解数据分析组件,请参阅本页面中的查看数据分析。
获取单一数据分析
如需获取有关单一数据分析的更多信息(包括数据分析的说明、状态及其关联的任何建议),请使用以下方法之一:
gcloud
将 gcloud recommender insights describe
命令与您的数据分析 ID 结合使用,以查看单一 IAM 数据分析的相关信息。
在使用此示例之前,请先进行以下替换:
insight-id
:您要查看的数据分析的 ID。如需查找此 ID,请列出项目中的数据分析。insight-type-id
:您要查看的数据分析类型。使用google.iam.policy.Insight
进行政策数据分析,并使用google.iam.serviceAccount.Insight
获取服务帐号数据分析。
gcloud recommender insights describe insight-id \ --insight-type=insight-type-id --location=global
输出会显示详细数据分析。例如,以下数据分析表明,过去 90 天内 my-service-account@my-project.iam.gserviceaccount.com
未使用 Viewer 角色 (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 permission checks were authorized by this policy binding tuple. 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 stateInfo: state: ACTIVE targetResources: - //cloudresourcemanager.googleapis.com/projects/1234567890
如需详细了解数据分析组件,请参阅本页面中的查看数据分析。
REST
Recommender API 的 insights.get
方法可获取单一数据分析。
在使用下面的请求数据之前,请先进行以下替换:
project-id
:您的 Google Cloud 项目 ID。insight-type-id
:您要查看的数据分析的类型。对于政策数据分析,请使用google.iam.policy.Insight
。对于服务帐号数据分析,请使用google.iam.serviceAccount.Insight
。insight-id
:您要查看的数据分析的 ID。如果您不知道数据分析 ID,可在项目中列出数据分析进行查找。数据分析的 ID 是数据分析的name
字段中insights/
之后的所有内容。
HTTP 方法和网址:
GET https://recommender.googleapis.com/v1/projects/project-id/locations/global/insightTypes/insight-type-id/insights/insight-id
如需发送您的请求,请展开以下选项之一:
响应包含数据分析。例如:
{ "name": "projects/123456789012/locations/global/insightTypes/google.iam.policy.Insight/insights/07841f74-02ce-4de8-bbe6-fc4eabb68568", "description": "0 permission checks were authorized by this policy binding tuple.", "content": { "role": "roles/viewer", "member": "serviceAccount:my-service-account@my-project.iam.gserviceaccount.com", "condition": { "expression": "", "title": "", "description": "", "location": "" }, "exercisedPermissions": [], "inferredPermissions": [] }, "lastRefreshTime": "2020-07-12T07: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\"" }
如需详细了解数据分析组件,请参阅本页面中的查看数据分析。
查看数据分析
数据分析分为数据分析类型和数据分析子类型。数据分析类型反映了数据分析适用于哪种资源类型。数据分析子类型可让您了解数据分析包含哪类信息。
IAM 提供以下数据分析类型和子类型:
数据分析类型 | 数据分析子类型 |
---|---|
政策数据分析 | PERMISSION_USAGE :基于机器学习的有关项目中权限使用情况的发现结果。 |
服务帐号数据分析 | SERVICE_ACCOUNT_USAGE :有关项目中服务帐号的发现结果,例如过去 90 天内未使用的服务帐号。 |
数据分析的内容由其子类型确定。上表中列出的数据分析子类型具有以下组件:
associatedRecommendations
:与数据分析相关联的任何建议的标识符。如果没有与数据分析相关联的建议,则此字段为空。category
:PERMISSION_USAGE
和SERVICE_ACCOUNT_USAGE
数据分析的类别始终为SECURITY
。content
:content
字段中的信息由数据分析子类型确定:数据分析子类型 内容 PERMISSION_USAGE
报告成员使用特定角色的权限的情况。此字段包含以下组成部分:
member
:已分析其权限使用情况的成员。role
:已分析其权限使用情况的角色。condition
:关联到向成员授予该角色的绑定的任何条件。如果没有条件,则此字段将包含空条件。exercisedPermissions
:成员在观察期间使用的角色权限。inferredPermissions
:IAM Recommender 通过机器学习根据成员实际使用的权限来确定成员可能需要的角色权限。
SERVICE_ACCOUNT_USAGE
报告上次对服务帐号进行身份验证的时间。此字段包含以下组成部分:
serviceAccountId
:服务帐号的唯一数字 ID。email
:服务帐号的电子邮件地址。lastAuthenticatedTime
:服务帐号最近进行身份验证的时间。如果服务帐号没有任何记录的身份验证,则不包含此字段。
description
:直观易懂的数据分析摘要。etag
:标识数据分析当前状态的唯一指纹。每次数据分析发生更改时,系统都会分配新的 ETag 值。要更改数据分析的状态,您必须提供现有数据分析的 ETag。使用 etag 有助于确保仅在上次检索数据分析后没有任何更改的情况下执行所有操作。
insightSubtype
:数据分析子类型:PERMISSION_USAGE
或SERVICE_ACCOUNT_USAGE
。lastRefreshTime
:上次刷新数据分析的日期,它表示用于生成数据分析的数据的新鲜度。name
:数据分析的名称,格式如下:projects/project-id/locations/global/insightTypes/insight-type-id/insights/insight-id
占位符具有以下值:
project-id
:生成数据分析的项目的 ID。insight-type-id
:数据分析的类型。政策数据分析的类型为google.iam.policy.Insight
。服务帐号数据分析具有google.iam.serviceAccount.Insight
类型。insight-id
:数据分析的唯一 ID。
observationPeriod
:生成数据分析的时间段。用于生成数据分析的源数据结束于lastRefreshTime
,在lastRefreshTime
减observationPeriod
开始。stateInfo
:数据分析被提出后,会经历多次状态转换:ACTIVE
:数据分析已生成,但尚未执行任何操作,或执行的操作并未更新数据分析状态。当底层数据发生更改时,系统会更新活跃数据分析。ACCEPTED
:已根据数据分析执行某种操作。如果关联的建议标记为CLAIMED
、SUCCEEDED
或FAILED
,或数据分析被直接接受,则表示数据分析已被接收。如果数据分析处于ACCEPTED
状态,则数据分析内容无法更改。标记为已接受的数据分析会保留 90 天。
targetResources
:数据分析所适用的 Google Cloud 项目的完整资源名称。例如://cloudresourcemanager.googleapis.com/projects/1234567890
将数据分析标记为 ACCEPTED
如果您根据有效数据分析执行操作,则可以将该数据分析标记为 ACCEPTED
。ACCEPTED
状态会通知 Recommender API 您已根据此数据分析执行操作,这有助于优化您的建议。
标记为 ACCEPTED
后,已接受的数据分析将保留 90 天。
gcloud
将 gcloud recommender insights mark-accepted
命令与数据分析 ID 搭配使用可将数据分析标记为 ACCEPTED
。
在使用示例命令之前,请替换以下值:
insight-id
:您要标记为ACCEPTED
的数据分析的 ID。如需查找此 ID,请列出项目中的数据分析。insight-type-id
:您要标记为ACCEPTED
的数据分析的类型。对于政策数据分析,请使用google.iam.policy.Insight
。对于服务帐号数据分析,请使用google.iam.serviceAccount.Insight
。etag
:数据分析版本的标识符。如需获取etag
,请执行以下操作:- 使用
gcloud recommender insights describe
命令获取数据分析。 - 在输出中查找并复制
etag
值,包括引号。例如"d3cdec23cc712bd0"
。
- 使用
gcloud recommender insights mark-accepted insight-id \ --insight-type=insight-type-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 permission checks were authorized by this policy binding tuple. 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 stateInfo: state: ACCEPTED targetResources: - //cloudresourcemanager.googleapis.com/projects/1234567890
如需详细了解数据分析的状态信息,请参阅本页面上的查看数据分析。
REST
Recommender API 的 insights.markAccepted
方法可将数据分析标记为 ACCEPTED
。
在使用下面的请求数据之前,请先进行以下替换:
project-id
:您的 Google Cloud 项目 ID。insight-type-id
:您要标记为ACCEPTED
的数据分析类型。对于政策数据分析,请使用google.iam.policy.Insight
。对于服务帐号数据分析,请使用google.iam.serviceAccount.Insight
。insight-id
:您要标记为ACCEPTED
的数据分析的 ID。如果您不知道数据分析 ID,可在项目中列出数据分析进行查找。数据分析的 ID 是数据分析的name
字段中insights/
之后的所有内容。etag
:数据分析版本的标识符。如需获取etag
,请执行以下操作:- 使用
insights.get
方法获取数据分析。 - 查找并复制响应中的
etag
值。
- 使用
HTTP 方法和网址:
POST https://recommender.googleapis.com/v1/projects/project-id/locations/global/insightTypes/insight-type-id/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 permission checks were authorized by this policy binding tuple.", "content": { "role": "roles/viewer", "member": "serviceAccount:my-service-account@my-project.iam.gserviceaccount.com", "condition": { "expression": "", "title": "", "description": "", "location": "" }, "exercisedPermissions": [], "inferredPermissions": [] }, "lastRefreshTime": "2020-07-12T07: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/1234567890" ], "insightSubtype": "PERMISSIONS_USAGE", "etag": "\"b153ab487e4ae100\"" }
如需详细了解数据分析的状态信息,请参阅本页面上的查看数据分析。
后续步骤
- 了解如何查看和应用建议。
- 使用建议中心查看和管理项目的所有建议,包括 IAM 建议。
- 使用服务帐号使用情况指标监控上次使用服务帐号的时间。