如要使用 Monitoring,您必須具備適當的身分與存取權管理 (IAM) 權限。一般而言,API 中的每個 REST 方法都有關聯的權限。如要使用該方法,或使用依賴該方法的控制台功能,您必須具備使用對應方法的權限。權限不會直接授予使用者,而是透過角色間接授予權限,如此可將多個權限分組,使權限管理起來更加容易:
- 如要瞭解存取權控管,請參閱「存取權管理相關概念」。
- 如要瞭解如何將角色授予主體,請參閱「授予 Cloud Monitoring 存取權」。
系統已為您預先定義常見權限組合的角色。不過,您也可以建立 IAM 自訂角色,自行組合權限。
最佳做法
建議您建立 Google 群組,以便管理專案的存取權:Google Cloud
- 詳情請參閱「在 Google Cloud 控制台中管理群組」。
- 如要瞭解如何設定角色限制,請參閱設定角色授予限制。
- 如需完整的 IAM 角色和權限清單,請參閱「IAM 基本與預先定義角色參考資料」。
VPC Service Controls
如要進一步控管監控資料的存取權,請搭配使用 IAM 和 VPC Service Controls。
VPC Service Controls 可加強 Cloud Monitoring 的安全性,減少資料遭竊風險。您可以透過 VPC Service Controls 將指標範圍加入 Service Perimeter,如此一來,源自 perimeter 外部的要求就無法保護 Cloud Monitoring 資源及服務。
如要進一步瞭解服務範圍,請參閱 VPC Service Controls 服務範圍設定說明文件。
如要瞭解 Monitoring 對 VPC Service Controls 的支援情形 (包括已知限制),請參閱 Monitoring VPC Service Controls 說明文件。
授予 Cloud Monitoring 存取權
如要管理主體的 IAM 角色,可以使用 Google Cloud 控制台中的「身分與存取權管理」頁面,或使用 Google Cloud CLI。不過,Cloud Monitoring 提供簡化的介面,可讓您管理 Monitoring 專屬角色、專案層級角色,以及 Cloud Logging 和 Cloud Trace 的通用角色。
如要授予主體 Monitoring、Cloud Logging 或 Cloud Trace 的存取權,或是授予專案層級的角色,請按照下列步驟操作:
控制台
-
前往 Google Cloud 控制台的 「Permissions」(權限) 頁面:
如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果。
「具備存取權的主體」頁面不會顯示所有主體。這項指令只會列出具備專案層級角色,或 Monitoring、Logging 或 Trace 專屬角色的主體。
您可以在這個頁面查看所有具備 Monitoring 權限的角色主體。
按一下 「授予存取權」。
按一下「新增主體」,然後輸入主體的使用者名稱。您可以新增多個主體。
展開「選取角色」arrow_drop_down,從「依產品或服務」選單中選取值,然後從「角色」選單中選取角色:
選取「依產品或服務劃分」 選取角色 說明 監控 監控檢視者 查看監控資料和設定資訊。 舉例來說,具備這個角色的主體可以查看自訂資訊主頁和快訊政策。 監控 監控編輯者 查看監控資料,以及建立和編輯設定。舉例來說,具有這項角色的主體可以建立自訂資訊主頁和快訊政策。 監控 監控管理員 在 Google Cloud 控制台和 Cloud Monitoring API 中,擁有 Monitoring 的完整存取權。您可以查看監控資料、建立及編輯設定,以及修改指標範圍。 Cloud Trace Cloud Trace 使用者 Trace 主控台的完整存取權、追蹤記錄的讀取權限, 以及接收器的讀取/寫入權限。 詳情請參閱「追蹤角色」。 Cloud Trace Cloud Trace 管理員 Trace 主控台的完整存取權、追蹤記錄的讀取/寫入權限, 以及接收器的讀取/寫入權限。詳情請參閱「追蹤角色」。 記錄 記錄檢視器 查看記錄檔存取權。詳情請參閱「記錄角色」。 記錄 記錄管理員 具備 Cloud Logging 所有功能的完整存取權。詳情請參閱「記錄角色」。 專案 檢視者 具備大多數 Google Cloud 資源的檢視權限。 專案 編輯 查看、建立、更新及刪除大部分 Google Cloud 資源。 專案 版主 具備大多數 Google Cloud 資源的完整存取權。 選用:如要授予相同主體其他角色,請按一下「新增其他角色」,然後重複上一個步驟。
按一下 [儲存]。
前述步驟說明如何使用 Google Cloud 控制台的「監控」頁面,授予主體特定角色。對於這些角色,這個頁面也支援編輯和刪除選項:
如要移除主體的角色,請選取主體旁的方塊,然後按一下 「移除存取權」。
如要編輯主體的角色,請按一下 edit「編輯」。更新設定後,按一下「儲存」。
gcloud
使用 gcloud projects add-iam-policy-binding 指令授予 monitoring.viewer 或 monitoring.editor 角色。
例如:
export PROJECT_ID="my-test-project"
export EMAIL_ADDRESS="myuser@gmail.com"
gcloud projects add-iam-policy-binding \
$PROJECT_ID \
--member="user:$EMAIL_ADDRESS" \
--role="roles/monitoring.editor"
您可以使用 gcloud projects get-iam-policy 指令確認授予的角色:
export PROJECT_ID="my-test-project"
gcloud projects get-iam-policy $PROJECT_ID
預先定義的角色
本節列出 Cloud Monitoring 預先定義的部分 IAM 角色。
Monitoring 角色
以下角色為 Monitoring 授予一般權限:
| 名稱 標題 |
具備的權限 |
|---|---|
roles/monitoring.viewerMonitoring 檢視者 |
授予在 Google Cloud 控制台和 Cloud Monitoring API 中,對 Monitoring 進行唯讀存取的權限。 |
roles/monitoring.editorMonitoring 編輯者 |
授予 Google Cloud 控制台和 Cloud Monitoring API 的 Monitoring 讀取/寫入權限。 |
roles/monitoring.admin監控管理員 |
授予 Google Cloud 控制台和 Cloud Monitoring API 的完整 Monitoring 存取權。 |
以下角色由服務帳戶用於唯寫存取:
| 名稱 標題 |
說明 |
|---|---|
roles/monitoring.metricWriterMonitoring 指標寫入者 |
這個角色適用於服務帳戶和代理程式。 |
快訊政策角色
以下角色會授予快訊政策的權限:
| 名稱 標題 |
說明 |
|---|---|
roles/monitoring.alertPolicyViewerMonitoring AlertPolicy 檢視者 |
具備快訊政策的唯讀存取權。 |
roles/monitoring.alertPolicyEditorMonitoring AlertPolicy 編輯者 |
具備快訊政策的讀寫權限。 |
資訊主頁角色
以下角色僅為資訊主頁授予權限:
| 名稱 標題 |
說明 |
|---|---|
roles/monitoring.dashboardViewerMonitoring 資訊主頁設定檢視者 |
授予資訊主頁設定的唯讀存取權。 |
roles/monitoring.dashboardEditorMonitoring 資訊主頁設定編輯者 |
具備資訊主頁設定的讀寫權限。 |
事件角色
以下角色僅為事件授予權限:
| 名稱 標題 |
說明 |
|---|---|
roles/monitoring.cloudConsoleIncidentViewerMonitoring Cloud 控制台事件檢視者 |
可授予透過 Google Cloud 控制台查看事件的權限。 |
roles/monitoring.cloudConsoleIncidentEditorMonitoring Cloud 控制台事件編輯者 |
使用 Google Cloud 控制台授予權限,可查看、確認及結案事件。 |
如要瞭解如何解決查看事件時發生的 IAM 權限錯誤,請參閱「無法查看事件詳細資料,因為發生權限錯誤」。
通知管道角色
以下角色僅為通知管道授予權限:
| 名稱 標題 |
說明 |
|---|---|
roles/monitoring.notificationChannelViewerMonitoring NotificationChannel 檢視者 |
授予通知管道的唯讀存取權。 |
roles/monitoring.notificationChannelEditorMonitoring NotificationChannel 編輯者 |
具備通知管道的讀寫權限。 |
延後通知角色
以下角色可授予暫緩通知的權限:
| 名稱 標題 |
說明 |
|---|---|
roles/monitoring.snoozeViewerMonitoring 暫緩檢視者 |
授予暫緩通知的唯讀存取權。 |
roles/monitoring.snoozeEditorMonitoring 暫緩通知編輯者 |
具備暫緩通知的讀寫權限。 |
服務監控角色
下列角色可授予管理服務的權限:
| 名稱 標題 |
說明 |
|---|---|
roles/monitoring.servicesViewer監控服務檢視者 |
授予服務的唯讀存取權。 |
roles/monitoring.servicesEditor監控服務編輯者 |
具備服務的讀寫權限。 |
如要進一步瞭解服務監控,請參閱「SLO 監控」。
運作時間檢查設定角色
以下角色僅為運作時間檢查設定授予權限:
| 名稱 標題 |
說明 |
|---|---|
roles/monitoring.uptimeCheckConfigViewerMonitoring 運作時間檢查設定檢視者 |
授予運作時間檢查設定的唯讀存取權。 |
roles/monitoring.uptimeCheckConfigEditorMonitoring 運作時間檢查設定編輯者 |
具備運作時間檢查設定的讀寫權限。 |
指標範圍設定角色
以下角色授予指標範圍的一般權限:
| 名稱 標題 |
說明 |
|---|---|
roles/monitoring.metricsScopesViewerMonitoring 指標範圍檢視者 |
具備指標範圍的唯讀存取權。 |
roles/monitoring.metricsScopesAdminMonitoring 指標範圍管理員 |
具備指標範圍的讀寫權限。 |
預先定義角色的權限
本節列出指派給與 Monitoring 相關聯預先定義角色的權限。
如要進一步瞭解預先定義的角色,請參閱「IAM:角色和權限」。如需選擇最合適預先定義角色的說明,請參閱「選擇預先定義的角色」。
監控角色權限
| Role | Permissions |
|---|---|
Monitoring Admin( Provides full access to Cloud Monitoring. Lowest-level resources where you can grant this role:
|
|
Monitoring AlertPolicy Editor( Read/write access to alerting policies. |
|
Monitoring AlertPolicy Viewer( Read-only access to alerting policies. |
|
Monitoring Alert Viewer Beta( Read access to alerts. |
|
Monitoring Cloud Console Incident Editor Beta( Read/write access to incidents from Cloud Console. |
|
Monitoring Cloud Console Incident Viewer Beta( Read access to incidents from Cloud Console. |
|
Monitoring Dashboard Configuration Editor( Read/write access to dashboard configurations. |
|
Monitoring Dashboard Configuration Viewer( Read-only access to dashboard configurations. |
|
Monitoring Editor( Provides full access to information about all monitoring data and configurations. Lowest-level resources where you can grant this role:
|
|
Monitoring Metric Writer( Provides write-only access to metrics. This provides exactly the permissions needed by the Cloud Monitoring agent and other systems that send metrics. Lowest-level resources where you can grant this role:
|
|
Monitoring Metrics Scopes Admin Beta( Access to add and remove monitored projects from metrics scopes. |
|
Monitoring Metrics Scopes Viewer Beta( Read-only access to metrics scopes and their monitored projects. |
|
Monitoring NotificationChannel Editor Beta( Read/write access to notification channels. |
|
Monitoring NotificationChannel Viewer Beta( Read-only access to notification channels. |
|
Monitoring Service Agent( Grants permissions to deliver notifications directly to resources within the target project, such as delivering to Pub/Sub topics within the project. |
|
Monitoring Services Editor( Read/write access to services. |
|
Monitoring Services Viewer( Read-only access to services. |
|
Monitoring Snooze Editor(
|
|
Monitoring Snooze Viewer(
|
|
Monitoring Uptime Check Configuration Editor Beta( Read/write access to uptime check configurations. |
|
Monitoring Uptime Check Configuration Viewer Beta( Read-only access to uptime check configurations. |
|
Monitoring Viewer( Provides read-only access to get and list information about all monitoring data and configurations. Lowest-level resources where you can grant this role:
|
|
Ops Config Monitoring Resource Metadata Viewer Beta( Read-only access to resource metadata. |
|
Ops Config Monitoring Resource Metadata Writer Beta( Write-only access to resource metadata. This provides exactly the permissions needed by the Ops Config Monitoring metadata agent and other systems that send metadata. |
|
Stackdriver Accounts Editor( Read/write access to manage Stackdriver account structure. |
|
Stackdriver Accounts Viewer( Read-only access to get and list information about Stackdriver account structure. |
|
Stackdriver Resource Metadata Writer Beta( Write-only access to resource metadata. This provides exactly the permissions needed by the Stackdriver metadata agent and other systems that send metadata. |
|
Google Cloud 基本角色
Google Cloud 基本角色包含下列權限:
| 名稱 標題 |
具備的權限 |
|---|---|
roles/viewer檢視者 |
監控權限與 roles/monitoring.viewer 中的權限相同。
|
roles/editor編輯者 |
「監控」權限與 這個角色不會授予修改指標範圍的權限。
如要透過 API 修改指標範圍,您的角色必須具備 |
roles/owner擁有者 |
監控權限與
roles/monitoring.admin中的權限相同。
|
自訂角色
如要授予主體的權限比預先定義角色授予的權限更有限,您可能需要建立自訂角色。舉例來說,如果您因為有資料駐留或影響等級 4 (IL4) 的需求,而設定了保證工作負載,就不應使用正常運作時間檢查,因為無法保證正常運作時間檢查資料會保留在特定地理位置。如要禁止使用運作時間檢查,請建立不含任何前置字元為 monitoring.uptimeCheckConfigs 的權限。
如要建立具有 Monitoring 權限的自訂角色,請執行下列步驟:
對於只為 Monitoring API 授予權限的角色,請在「權限和預先定義的角色」一節選擇權限。
對於在Google Cloud 主控台中授予 Monitoring 權限的角色,請在「Monitoring roles」(Monitoring 角色) 區段選擇權限群組。
如要授予監控資料寫入權限,請在「權限和預先定義的角色」部分中,包含來自角色
roles/monitoring.metricWriter的權限。
如要進一步瞭解自訂角色,請參閱瞭解身分與存取權管理自訂角色一文。
Compute Engine 存取範圍
存取範圍是為 Compute Engine VM 執行個體指定權限的傳統方法。以下存取範圍適用於 Monitoring:
| 存取範圍 | 授予的權限 |
|---|---|
| https://www.googleapis.com/auth/monitoring.read | 權限與 roles/monitoring.viewer 相同。 |
| https://www.googleapis.com/auth/monitoring.write | 權限與 roles/monitoring.metricWriter 相同。 |
| https://www.googleapis.com/auth/monitoring | 具備 Monitoring 的完整權限。 |
| https://www.googleapis.com/auth/cloud-platform | 具備所有已啟用之 Cloud API 的完整權限。 |
詳情請參閱「存取範圍」。
最佳做法。建議您為 VM 執行個體提供最強大的存取範圍 (cloud-platform),然後使用 IAM 角色限制對特定 API 和作業的存取權。詳情請參閱服務帳戶權限一文。