變更風險建議
變更風險建議會智慧地標示重要資源的常見風險變更,並提供建議來預防及減輕問題,協助您降低雲端基礎架構設定錯誤的風險。
簡介
設定錯誤是造成雲端事件的常見原因。這類事件可能是人為錯誤或工作負載意外變更所致,並可能導致各種問題,包括效能問題、可靠性問題,甚至是服務中斷。許多設定錯誤一開始可能不會引起注意,因此難以追蹤及解決。
變更風險建議是 Recommender 服務中,Active Assist 建議和洞察資料的新系列。變更風險建議會根據用量和其他信號,自動將標示為「重要」的雲端資源變更標示為有風險,協助您預防、偵測及減輕因重要雲端資源設定錯誤而導致的問題 (例如服務中斷)。舉例來說,如果您嘗試刪除使用率很高的專案,或是修改可能成為重要依附元件的 IAM 政策 (根據近期使用活動),變更風險建議會主動提醒您特定變更相關的風險,協助避免發生非預期的問題。
變更風險建議範圍
目前只有下表列出的資源和動作支援變更風險建議。
資源 | 動作 | 介面 | 決定資源重要性的標準 |
---|---|---|---|
專案 | 刪除 |
|
|
服務帳戶 | 刪除 |
|
|
IAM 政策 | 變更 |
|
|
事前準備
開始使用這項功能前,請先設定服務:
- 在單一帳單專案中啟用 Recommender API。然後,您可以使用 gcloud/API 的帳單專案功能,透過這個帳單專案,為其他專案、整個機構或帳單帳戶擷取建議和洞察資料。
- 授予您將用於存取這項功能的使用者或服務帳戶權限。
權限
如要查看變更風險建議,您必須具備特定資源的特定權限。
專案
recommender.resourcemanagerProjectChangeRiskRecommendations.get
recommender.resourcemanagerProjectChangeRiskRecommendations.list
recommender.resourcemanagerProjectChangeRiskInsights.get
recommender.resourcemanagerProjectChangeRiskInsights.list
服務帳戶
recommender.iamServiceAccountChangeRiskRecommendations.get
recommender.iamServiceAccountChangeRiskRecommendations.list
recommender.iamServiceAccountChangeRiskInsights.get
recommender.iamServiceAccountChangeRiskInsights.list
身分與存取權管理政策
recommender.iamPolicyChangeRiskRecommendations.get
recommender.iamPolicyChangeRiskRecommendations.list
recommender.iamPolicyChangeRiskInsights.get
recommender.iamPolicyChangeRiskInsights.list
您也可以授予 roles/recommender.viewer 角色,涵蓋這些權限。
瞭解變更風險建議/深入分析的相關回應
下表說明建議和洞察物件中顯示的欄位:
建議
欄位名稱 | 類型 | 說明 |
---|---|---|
associatedInsights
|
string
|
與這項建議相關的洞察。
projects/[project_number]/locations/global/
insightTypes/google.resourcemanager.project.
ChangeRiskInsight/insights/[fingerprint]
|
asset
|
object
|
包含相關資源的資產名稱和資產類型。 |
etag
|
string
|
RecommenderConfig 的指紋。 更新時提供樂觀鎖定。 |
updateTime
|
string
|
上次更新建議的時間戳記。採用 RFC 3339 UTC Zulu 格式的時間戳記,精確度達奈秒單位。
例如:2022-01-10T22:47:38.421626Z 。
|
深入分析
欄位名稱 | 類型 | 說明 |
---|---|---|
associatedRecommendations
|
string
|
與這項建議相關聯的建議。
projects/[project_number]/locations/global/
recommenders/google.resourcemanager.project.
ChangeRiskRecommender/recommendations/
[recommendation_id]
|
constraint
|
object
|
包含建議使用者不要執行的變更風險建議限制。
This project should not be deleted.
|
importance
|
object
|
包含我們判定這項資源重要的原因清單。例如使用量偏高。 |
risk
|
object
|
內含風險評估詳細資料。舉例來說,系統會根據資源用量活動值判斷重要性。 |
updateTime
|
string
|
上次更新建議的時間戳記。
RFC 3339 UTC Zulu 格式的時間戳記,精確度達奈秒單位。例如:2022-01-10T22:47:38.421626Z 。
|
查看變更風險建議
除了上述使用模型,您也可以使用 Recommender 服務的標準方法,查看專案、服務帳戶或 IAM 政策的變更風險建議和洞察:
- Google Cloud 控制台
- API
- gcloud
Google Cloud 控制台
您可以在產品頁面查看變更風險建議和深入分析結果。只要您具備上述權限,系統就會自動啟用最佳化建議。
Active Assist 會在您刪除重要資源時發出警告,並在下列情況中指出該如何處理警告:
gcloud 和 API
以下各節將說明如何透過 gcloud
和 API,為專案、服務帳戶或 IAM 政策要求變更風險建議和深入分析。
專案
所有客戶都可以透過 Google Cloud 控制台、gcloud
或 Recommender API 存取深入分析和建議。
gcloud
如要使用 gcloud
查看建議和洞察資料,請按照下列步驟操作。
詳情請參閱「使用 API - 洞察資料」和「使用 API - 建議」。
建議:
如要列出已啟用 Recommender API 的專案建議,請執行下列指令:
gcloud recommender recommendations list
--recommender=google.resourcemanager.project.ChangeRiskRecommender
--project=PROJECT_ID --location=global --format=yaml
更改下列內容:
PROJECT_ID
:專案 ID。
洞察資訊:
您可以使用類似的指令集列出洞察資料:
gcloud recommender insights list
--insight-type=google.resourcemanager.project.ChangeRiskInsight
--project=PROJECT_ID --location=global --format=yaml
更改下列內容:
PROJECT_ID
:專案 ID。
API
如要查看建議和洞察資料,可以使用 curl
將要求傳送至 Recommender API。
建議
如要列出已啟用 Recommender API 的專案建議,請執行下列指令:
curl -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "x-goog-user-project: BILLING_PROJECT_ID " "https://recommender.googleapis.com/v1/projects/PROJECT_ID /locations/global/
recommenders/google.resourcemanager.project.ChangeRiskRecommender/recommendations"
更改下列內容:
BILLING_PROJECT_ID
:計費專案 ID。
洞察資訊:
您可以使用類似的指令集列出洞察資料:
curl -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "x-goog-user-project: BILLING_PROJECT_ID " "https://recommender.googleapis.com/v1/projects/PROJECT_ID /locations/global/insightTypes/google.resourcemanager.project.ChangeRiskInsight/insights"
請替換下列項目:
* BILLING_PROJECT_ID
:帳單專案 ID。
服務帳戶
所有客戶都可以透過 Google Cloud 控制台、gcloud
或 Recommender API,取得服務帳戶的深入分析和建議。
gcloud
如要使用 gcloud
查看建議和洞察資料,請按照下列步驟操作。
詳情請參閱「使用 API - 洞察資料」和「使用 API - 建議」。
建議:
如要列出已啟用 Recommender API 的服務帳戶建議,請執行下列指令:
gcloud recommender recommendations list
--recommender=google.iam.serviceAccount.ChangeRiskRecommender
--project=PROJECT_ID --location=global --format=yaml
更改下列內容:
PROJECT_ID
:專案 ID。
洞察資訊:
您可以使用類似的指令集列出洞察資料:
gcloud recommender insights list
--insight-type=google.iam.serviceAccount.ChangeRiskInsight
--project=PROJECT_ID --location=global --format=yaml
請替換下列項目:
* PROJECT_ID
:專案 ID。
API
如要查看建議和洞察資料,可以使用 curl
將要求傳送至 Recommender API。
建議:
如要列出已啟用 Recommender API 的服務帳戶建議,請執行下列指令:
curl -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "x-goog-user-project: BILLING_PROJECT_ID " "https://recommender.googleapis.com/v1/projects/PROJECT_ID /locations/global/
recommenders/google.iam.serviceAccount.ChangeRiskRecommender/recommendations"
更改下列內容:
PROJECT_ID
:專案 ID。BILLING_PROJECT_ID
:計費專案 ID。
洞察資訊:
您可以使用類似的指令集列出洞察資料:
curl -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "x-goog-user-project: BILLING_PROJECT_ID " "https://recommender.googleapis.com/v1/projects/PROJECT_ID /locations/global/insightTypes/google.iam.serviceAccount.ChangeRiskInsight/insights"
請替換下列項目:
* PROJECT_ID
:專案 ID。
* BILLING_PROJECT_ID
:帳單專案 ID。
身分與存取權管理政策
所有客戶都可以透過 Google Cloud 控制台、gcloud
或 Recommender API,取得有關 IAM 政策的深入分析和建議。
gcloud
如要使用 gcloud
查看建議和洞察資料,請按照下列步驟操作。
詳情請參閱「使用 API - 洞察資料」和「使用 API - 建議」。
建議:
如要列出已啟用 Recommender API 的 IAM 政策建議,請執行下列指令:
gcloud recommender recommendations list --recommender=google.iam.policy.ChangeRiskRecommender --project=PROJECT_ID --location=global --format=yaml
更改下列內容:
PROJECT_ID
:專案 ID。
洞察資訊:
您可以使用類似的指令集列出洞察資料:
gcloud recommender insights list --insight-type=google.iam.policy.ChangeRiskInsight --project=PROJECT_ID --location=global --format=yaml
請替換下列項目:
* PROJECT_ID
:專案 ID。
API
如要查看建議和洞察資料,可以使用 curl
將要求傳送至 Recommender API。
建議:
如要列出已啟用 Recommender API 的 IAM 政策建議,請執行下列指令:
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://recommender.googleapis.com/v1/projects/PROJECT_ID /locations/global/\recommenders/google.iam.policy.ChangeRiskRecommender/recommendations"
更改下列內容:
PROJECT_ID
:專案 ID。
洞察資訊:
您可以使用類似的指令集列出洞察資料:
curl -H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "x-goog-user-project: BILLING_PROJECT_ID " "https://recommender.googleapis.com/v1/projects/PROJECT_ID /locations/global/insightTypes/google.iam.policy.ChangeRiskInsight/insights"
請替換下列項目:
* PROJECT_ID
:專案 ID。
* BILLING_PROJECT_ID
:帳單專案 ID。
使用 gcloud CLI 刪除項目時的風險
透過 gcloud CLI 刪除資源時,您可以使用 ALPHA 軌中的選用隱藏旗標 --recommend=yes
,中斷有風險的變更。以下列出支援的風險變更和建議。如果沒有顯示風險評估,表示變更不具風險。
刪除專案
下列指令會刪除專案:
gcloud alpha projects delete PROJECT_ID --recommend=yes
系統會顯示下列支援的風險異動和最佳化建議:
Shutting down this project will immediately:
- Stop all traffic and billing.
- Start deleting resources.
- Schedule the final deletion of the project after 30 days.
- Block your access to the project.
- Notify the owner of the project.
Learn more about the shutdown process at
https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects
WARNING: If you shut down this project you risk losing data or interrupting your services. In the last 30 days we observed this project had:
- It had significant usage, including 9942 API calls.
- It contains at least 1 highly utilized service account.
- It included at least 211 resources.
We recommend verifying this is the correct project to shut down.
View the full risk assessment at: https://console.cloud.google.com/home/recommendations/view-link/projects/123456/locations/global/recommenders/google.resourcemanager.project.ChangeRiskRecommender/recommendations/reco-id-0000-0000-000000000
Do you want to continue (Y/n)? n
刪除服務帳戶
下列指令會刪除服務帳戶:
gcloud alpha iam service-accounts delete example@PROJECT_ID .iam.gserviceaccount.com --recommend=yes
系統會顯示下列支援的風險異動和最佳化建議:
You are about to delete service account [example@PROJECT_ID .iam.gserviceaccount.com]
Deleting this service account (SA) will delete all associated key IDs, and will prevent the account from authenticating to any Google Cloud service API.
You cannot restore or roll back this change easily. We highly recommend disabling the account first, testing for any unexpected impact, and only then deleting.
WARNING: If you delete this SA you risk interrupting your service, as we observed it was substantially used in the last 90 days.
We recommend verifying this is the correct account to delete.
View the full risk assessment at: https://console.cloud.google.com/home/recommendations/view-link/projects/123456/locations/global/recommenders/google.iam.serviceAccount.ChangeRiskRecommender/recommendations/reco-id-0000-0000-000000000
Do you want to continue (Y/n)? n
如果看到下列錯誤訊息:
ERROR: (gcloud.alpha.iam.service-accounts.delete) NOT_FOUND: Method not found.
- '@type': type.googleapis.com/google.rpc.DebugInfo
detail: 'Method ListInsights not found for service recommender.googleapis.com. Method not visible to labels: {PUBLIC}'
請使用下列指令,確認專案設定已設為允許使用 Alpha Recommender API 的專案:
gcloud config set project PROJECT_ID
刪除專案 IAM 政策繫結
下列指令會刪除專案 IAM 政策繫結:
gcloud alpha projects remove-iam-policy-binding PROJECT_ID --member=YOUR_EMAIL@DOMAIN.COM --role=roles/owner --recommend=yes
系統會顯示下列支援的風險異動和最佳化建議:
You are about to delete the role [roles/owner].
WARNING: If you remove the role [roles/owner], there is a high risk that you might cause interruptions because it was used in the last 90 days.
We recommend you verify the details and replace them with less privileged roles, if necessary.
View the full risk assessment at: https://console.cloud.google.com/home/recommendations/view-link/projects/123456/locations/global/recommenders/google.iam.policy.ChangeRiskRecommender/recommendations/reco-id-0000-0000-000000000
Do you want to continue (Y/n)? n
意見回饋和支援服務
如有技術問題、疑問或意見,請傳送電子郵件至 active-assist-feedback@google.com。