本頁面說明如何管理機構政策洞察,也就是資源設定和使用情況的發現。機構政策洞察資料可協助您找出未受機構政策保護的資源。
有時,機構政策深入分析資訊會連結至 機構政策建議。組織政策建議會根據組織政策洞察資料,建議您採取哪些行動來解決問題。
事前準備
必要的角色
如要取得查看及修改機構政策洞察資訊所需的權限,請要求管理員在您要管理洞察資訊的資源 (專案、資料夾或機構) 上,授予您機構政策建議管理員 (roles/recommender.orgPolicyAdmin
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這個預先定義的角色具備查看及修改組織政策洞察資料所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要查看及修改組織政策洞察,必須具備下列權限:
-
recommender.orgPolicyInsights.get
-
recommender.orgPolicyInsights.list
-
recommender.orgPolicyInsights.update
列出機構政策深入分析
如要列出專案、資料夾或機構的所有機構政策洞察,請使用下列其中一種方法:gcloud
使用 gcloud recommender
insights list
指令,查看專案、資料夾或機構的所有機構政策深入分析。
執行指令前,請先取代下列值:
-
RESOURCE_TYPE
:要列出洞察資料的資源類型。請使用下列值:project
、folder
或organization
。 -
RESOURCE_ID
:要列出洞察資料的專案、資料夾或機構的 ID。
gcloud recommender insights list --insight-type=google.orgpolicy.policy.Insight \ --RESOURCE_TYPE=RESOURCE_ID \ --location=global
輸出內容會列出專案、資料夾或機構的所有機構政策深入分析。例如:
INSIGHT_ID CATEGORY INSIGHT_STATE LAST_REFRESH_TIME SEVERITY INSIGHT_SUBTYPE DESCRIPTION 66d543f3-845d-49d6-a26b-80d84804d8a8 SECURITY ACTIVE 2024-12-10T08:00:00Z HIGH RESOURCE_VIOLATION_DISABLE_SERVICE_ACCOUNT_KEY_CREATION Scanned 3 resources and found 0 violations for constraints/iam.managed.disableServiceAccountKeyCreation.
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.orgpolicy.policy.Insight/insights
如要傳送要求,請展開以下其中一個選項:
回應會列出專案、資料夾或機構的所有機構政策深入分析。例如:
[ { "associatedRecommendations": [ { "recommendation": "projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f" } ], "category": "SECURITY", "content": { "consolidatedPolicy": { "inheritFromParent": false, "name": "projects/123456789012/policies/iam.managed.disableServiceAccountKeyCreation", "policyRules": { "rules": [ { "enforce": false } ] }, "reset": false }, "constraint": { "id": "constraints/iam.managed.disableServiceAccountKeyCreation", "name": "Disable service account key creation" }, "evaluatedResources": [ { "numOfResources": "2", "resourceType": "iam.googleapis.com/ServiceAccountKey" }, { "numOfResources": "1", "resourceType": "cloudresourcemanager.googleapis.com/Project" } ], "violations": [ { "numOfResources": "0", "resourceType": "iam.googleapis.com/ServiceAccountKey" }, { "numOfResources": "0", "resourceType": "cloudresourcemanager.googleapis.com/Project" } ] }, "description": "Scanned 3 resources and found 0 violations for constraints/iam.managed.disableServiceAccountKeyCreation.", "etag": "\"9a1ad019022f9f56\"", "insightSubtype": "RESOURCE_VIOLATION_DISABLE_SERVICE_ACCOUNT_KEY_CREATION", "lastRefreshTime": "2024-12-07T08:00:00Z", "name": "projects/123456789012/locations/global/insightTypes/google.orgpolicy.policy.Insight/insights/66d543f3-845d-49d6-a26b-80d84804d8a8", "observationPeriod": "86400s", "severity": "HIGH", "stateInfo": { "state": "ACTIVE", "stateMetadata": { "reviewedBy": "alice", "priority": "high" } }, "targetResources": [ "//cloudresourcemanager.googleapis.com/projects/123456789012" ] } ]
如要進一步瞭解洞察資料的組成元素,請參閱本頁的「查看機構政策洞察資料」。
取得單一組織政策洞察資訊
如要進一步瞭解單一洞察資料,包括洞察資料的說明、狀態和任何相關聯的建議,請使用下列其中一種方法:
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.orgpolicy.policy.Insight \ --RESOURCE_TYPE=RESOURCE_ID \ --location=global
輸出內容會詳細顯示洞察資料。舉例來說,系統分析了兩項資源的外部服務帳戶金鑰,但未偵測到任何違規事項:
associatedRecommendations: - recommendation: projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f category: SECURITY content: consolidatedPolicy: inheritFromParent: false name: 'projects/123456789012/policies/iam.managed.disableServiceAccountKeyCreation' policyRules: rules: [ "enforce": false ] reset: false constraint: { id: constraints/iam.managed.disableServiceAccountKeyCreation name: Disable service account key creation } evaluatedResources: - numOfResources: '1' resourceType: cloudresourcemanager.googleapis.com/Project - numOfResources: '2' resourceType: iam.googleapis.com/ServiceAccountKey violations: - numOfResources: '0' resourceType: iam.googleapis.com/ServiceAccountKey - numOfResources: '0' resourceType: cloudresourcemanager.googleapis.com/Project description: Scanned 3 resources and found 0 violations for constraints/iam.managed.disableServiceAccountKeyCreation. etag: '"34ddfdcefd214fd7"' insightSubtype: RESOURCE_VIOLATION_DISABLE_SERVICE_ACCOUNT_KEY_CREATION lastRefreshTime: '2024-12-10T08:00:00Z' name: projects/123456789012/locations/global/insightTypes/google.orgpolicy.policy.Insight/insights/66d543f3-845d-49d6-a26b-80d84804d8a8 observationPeriod: 86400s 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.orgpolicy.policy.Insight/insights/INSIGHT_ID
如要傳送要求,請展開以下其中一個選項:
回覆會包含洞察資料。舉例來說,系統分析了兩項資源的外部服務帳戶金鑰,但未偵測到任何違規事項:
[ { "associatedRecommendations": [ { "recommendation": "projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f" } ], "category": "SECURITY", "content": { "consolidatedPolicy": { "inheritFromParent": false, "name": "projects/123456789012/policies/iam.managed.disableServiceAccountKeyCreation", "policyRules": { "rules": [ { "enforce": false } ] }, "reset": false }, "constraint": { "id": "constraints/iam.managed.disableServiceAccountKeyCreation", "name": "Disable service account key creation" }, "evaluatedResources": [ { "numOfResources": "1", "resourceType": "cloudresourcemanager.googleapis.com/Project" }, { "numOfResources": "2", "resourceType": "iam.googleapis.com/ServiceAccountKey" } ], "violations": [ { "numOfResources": "0", "resourceType": "iam.googleapis.com/ServiceAccountKey" }, { "numOfResources": "0", "resourceType": "cloudresourcemanager.googleapis.com/Project" } ] }, "description": "Scanned 2 resources and found 0 violations for constraints/iam.managed.disableServiceAccountKeyCreation.", "etag": "\"9a1ad019022f9f56\"", "insightSubtype": "RESOURCE_VIOLATION_DISABLE_SERVICE_ACCOUNT_KEY_CREATION", "lastRefreshTime": "2024-12-03T08:00:00Z", "name": "projects/123456789012/locations/global/insightTypes/google.orgpolicy.policy.Insight/insights/66d543f3-845d-49d6-a26b-80d84804d8a8", "observationPeriod": "86400s", "severity": "HIGH", "stateInfo": { "state": "ACTIVE", "stateMetadata": { "reviewedBy": "alice", "priority": "high" } }, "targetResources": [ "//cloudresourcemanager.googleapis.com/projects/123456789012" ] } ]
如要進一步瞭解洞察資料的組成元素,請參閱本頁的「查看機構政策洞察資料」。
查看機構政策深入分析
取得單一洞察後,您可以查看其內容,瞭解資源的機構政策設定,包括任何違規事項。
機構政策洞察 (google.orgpolicy.policy.Insight
) 洞察包含下列元件,順序不一定如下:
-
associatedRecommendations
:與洞察資料相關聯的任何建議 ID。如果沒有與洞察資料相關的建議,這個欄位會留空。 -
category
:機構政策洞察的類別一律為SECURITY
。 -
content
:提供所分析資源和機構政策的詳細資料。這個欄位包含下列元件:-
constraint
:分析的限制。 -
consolidatedPolicy
:所分析資源的機構政策。 -
evaluatedResources
:用於評估以產生洞察的資源。 -
violations
:違反機構政策的資源數量和類型。
-
-
description
:使用者可自然閱讀的洞察摘要。 -
etag
:洞察資料目前狀態的專屬 ID。 每次洞察資料變更時,系統都會指派新的etag
值。如要變更洞察的狀態,必須提供現有洞察的
etag
。使用etag
可確保只有在洞察資料自上次擷取後未變更時,才會執行任何作業。 -
insightSubtype
:洞察子類型。 -
lastRefreshTime
:洞察資料上次更新的日期,表示用於產生洞察資料的資料更新間隔。 -
name
:洞察名稱,格式如下:RESOURCE_TYPE/RESOURCE_ID/locations/global/insightTypes/google.orgpolicy.policy.Insight/insights/INSIGHT_ID
預留位置的值如下:
-
RESOURCE_TYPE
:洞察資訊的產生對象資源類型。 -
RESOURCE_ID
:產生洞察資料的專案、資料夾或機構 ID。 INSIGHT_ID
:洞察的專屬 ID。
-
-
observationPeriod
:產生洞察資料的時間範圍。用於生成洞察的來源資料結束於lastRefreshTime
,開始於lastRefreshTime
減去observationPeriod
。 -
severity
:洞察資料的嚴重程度。機構政策洞察資訊的嚴重程度為HIGH
。 -
stateInfo
:提案後,洞察資料會經歷多種狀態轉換:-
ACTIVE
:洞察資料已產生,但未採取任何動作,或採取動作後未更新洞察資料的狀態。基礎資料變更時,系統會更新有效的洞察資料。 -
ACCEPTED
:已根據洞察資料採取行動。當相關聯的建議標示為CLAIMED
、SUCCEEDED
或FAILED
,或直接接受洞察資料時,洞察資料就會獲得採用。洞察資料處於ACCEPTED
狀態時,洞察資料的內容無法變更。接受的洞察資料會在接受後保留 90 天。
-
-
targetResources
:洞察資訊所屬專案、資料夾或機構的完整資源名稱 。例如://cloudresourcemanager.googleapis.com/projects/1234567890
。
將機構政策洞察資料標示為 ACCEPTED
如果根據有效洞察資料採取行動,您可以將該洞察資料標示為 ACCEPTED
。ACCEPTED
狀態會告知 Recommender API 您已根據這項洞察資料採取行動,有助於改善建議。
接受的洞察資料在標示為 ACCEPTED
後,會保留 90 天。
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.orgpolicy.policy.Insight \ --RESOURCE_TYPE=RESOURCE_ID \ --location=global \ --etag=ETAG
輸出內容會顯示洞察資料,現在狀態為 ACCEPTED
:
associatedRecommendations: - recommendation: folders/234567890123/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f category: SECURITY content: consolidatedPolicy: inheritFromParent: false name: 'projects/123456789012/policies/iam.managed.disableServiceAccountKeyCreation' policyRules: rules: [ "enforce": false ] reset: false constraint: { id: constraints/iam.managed.disableServiceAccountKeyCreation name: Disable service account key creation } evaluatedResources: - numOfResources: '0' resourceType: iam.googleapis.com/ServiceAccountKey - numOfResources: '1' resourceType: cloudresourcemanager.googleapis.com/Folder - numOfResources: '1' resourceType: cloudresourcemanager.googleapis.com/Project violations: - numOfResources: '0' resourceType: iam.googleapis.com/ServiceAccountKey - numOfResources: '0' resourceType: cloudresourcemanager.googleapis.com/Folder - numOfResources: '0' resourceType: cloudresourcemanager.googleapis.com/Project description: Scanned 2 resources and found 0 violations for constraints/iam.managed.disableServiceAccountKeyUpload. etag: '"2cbb89b22fe2dab7"' insightSubtype: RESOURCE_VIOLATION_DISABLE_SERVICE_ACCOUNT_KEY_UPLOAD lastRefreshTime: '2024-12-10T08:00:00Z' name: folders/234567890123/locations/global/insightTypes/google.orgpolicy.policy.Insight/insights/66d543f3-845d-49d6-a26b-80d84804d8a8 observationPeriod: 86400s severity: HIGH stateInfo: state: ACCEPTED targetResources: - //cloudresourcemanager.googleapis.com/folders/234567890123
如要進一步瞭解洞察資訊的狀態,請參閱本頁的「查看機構政策洞察資訊」。
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.orgpolicy.policy.Insight/insights/INSIGHT_ID:markAccepted
JSON 要求主體:
{ "etag": "ETAG" }
如要傳送要求,請展開以下其中一個選項:
回應包含洞察資料,現在會顯示 ACCEPTED
的狀態:
[ { "associatedRecommendations": [ { "recommendation": "projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f" } ], "category": "SECURITY", "content": { "consolidatedPolicy": { "inheritFromParent": false, "name": "projects/123456789012/policies/iam.managed.disableServiceAccountKeyCreation", "policyRules": { "rules": [ { "enforce": false } ] }, "reset": false }, "constraint": { "id": "constraints/iam.managed.disableServiceAccountKeyCreation", "name": "Disable service account key creation" }, "evaluatedResources": [ { "numOfResources": "1", "resourceType": "cloudresourcemanager.googleapis.com/Project" }, { "numOfResources": "2", "resourceType": "iam.googleapis.com/ServiceAccountKey" } ], "violations": [ { "numOfResources": "0", "resourceType": "iam.googleapis.com/ServiceAccountKey" }, { "numOfResources": "0", "resourceType": "cloudresourcemanager.googleapis.com/Project" } ] }, "description": "Scanned 2 resources and found 0 violations for constraints/iam.managed.disableServiceAccountKeyCreation.", "etag": "\"9a1ad019022f9f56\"", "insightSubtype": "RESOURCE_VIOLATION_DISABLE_SERVICE_ACCOUNT_KEY_CREATION", "lastRefreshTime": "2024-12-03T08:00:00Z", "name": "projects/123456789012/locations/global/insightTypes/google.orgpolicy.policy.Insight/insights/66d543f3-845d-49d6-a26b-80d84804d8a8", "observationPeriod": "86400s", "severity": "HIGH", "stateInfo": { "state": "ACCEPTED", "stateMetadata": { "reviewedBy": "alice", "priority": "high" } }, "targetResources": [ "//cloudresourcemanager.googleapis.com/projects/123456789012" ] } ]
如要進一步瞭解洞察資訊的狀態,請參閱本頁的「查看機構政策洞察資訊」。
後續步驟
- 瞭解如何 查看及套用機構政策建議。
- 使用建議中心查看及管理專案的所有建議,包括 IAM 建議。