0. 前言
無論是企業組織還是個人用戶,安全機制的設置都是不可忽視的課題。當涉及到系統的使用權限與資源訪問時,妥善的用戶與權限管理更顯得尤為重要。
那關於 Grafana 針對企業的管理架構又如何呢?讓我們一探究竟!
1. 重點
2. 內容
2.1. 分立帳戶
對於多數個人用戶對於帳戶分立肯定沒有感覺,畢竟就是自己操作肯定想要最高權限。但是這樣的優勢在於如果哪天 普通子用戶 被盜用,還能使用 管理員帳戶 登入並移除被侵略的帳戶。而對於組織而言該功能更加重要,畢竟多數員工不該掌握過大的權限。
那首先點開左側選單找到 Administration >> Users and Access 。

這邊可以看到總共分三個種類,User 就是通常登入到介面的帳戶,Team 則是將用戶分組方便管理,而 Service Account 則是用於 API 的憑證。

2.1.1. 登入用戶
2.1.1.1. 新增用戶
首先我們就從用戶的建立開始,進入頁面後找到表格右上的 New User 並開始建立用戶。

用來辨別的名稱 (Name) 與進行登入的密碼 (Password) 設置完成後,雖然沒有米字號但這邊 eMail 與 Username 需要至少填寫一個,那是登入時所必須的輸入資料。

壓下建立用戶我們馬上就要來調整權限,這邊關於 Grafana Admin 的部份我就不做啟用,這項功能是讓該用戶能夠超出組織並操作整個系統,對於平常使用來說權限太高。
另外要讓用戶能夠操作資源,我們需要指派組織資源並開通權限,這邊我們用上 Editor 權限就夠介面多數的操作。

2.1.1.2. 邀請用戶
如果使用組織的 Admin 權限用戶可以掌管組織內的所有人力資源,惡意人士也能偷偷塞入新的帳戶竊用資料,畢竟平常沒人會檢查用戶紀錄,再說人員一多也感覺不出來,所以一般不會隨意配與。

另外以上介面其實與 Grafana Admin 分頁中的 Organization Users 是相同的。

這時我們嘗試按壓 Invite,可以看到其密碼是交由受邀請者自行設定。這邊由於我們還沒設定 SMTP(下回),請先將 Send Invite eMail 取消後進行生成。

完成後在右上角切換到 Pending Invites 分頁,此時我們能夠拿到一組網址,透過這種方式受邀請的用戶就能調整自己的密碼與個人資訊(就後者這部分不太合格)。


2.1.2. 建立分群
重新登入到管理員帳號,我們接著往下進到分群的部分,壓下 New Team 按鈕。

我們輸入個團隊名稱就能進到下一步,並開始添加用戶進群。

而團隊的概念是在組織建立區隔,就公司角度來說同是開發部門可能有不同的專案,透過這種方式能避免相互影響,也能避免逐個發派資源給予指定用戶。而隊內同樣區分管理人員與普通成員,這邊我們按下 Add Member 並選擇元戶與權限,接著 Save 新增入群。

而設置的板塊主要則是控管偏好設定,除了樣式與首頁之外,主要考慮有些組織還有跨國的因素存在。

2.1.3. 建立憑證
最後來到自動化經常會用到的 API 呼叫,我們註冊一個 Service Account 進行憑證授權。

這邊我們就先做為測試,使用基礎的 Viewer 權限且後續就會砍掉。

在最底層我們先設定誰能取得金鑰,透過 Add Permission 還能看到這次我們分有 User 與 Team 都可選擇,而權限的部分則是 Edit 與 Admin 兩種權限,記得按下 Save 進行添加。

接著我們按下表格右上的 Add Service Account Token 進行添增,這邊還能設置是否到期失效。滿有趣的是其預設時長是工作日 5 天而非整整 1 周。這邊金鑰記得保存起來,外來沒法再做查看。


這邊展示另個帳號的狀態,上圖處在配與憑證之前,下圖則是配發之後,可以看到多出一個區塊。


最後來實際嘗試看看,這邊使用該金鑰來查找其所屬的組織訊息。
GET /api/org/ HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

各位稍微回想下流程是不是哪裡怪怪的?我們並沒有詳細設定金鑰有哪些權限,目前還沒法做到 fine-grained 去做最小權限原則。
額外題下,雖然風險很高但其 API 也能透過 Basic Auth (帳密) 進行單個用戶的授權。
2.2. 新增組織
前面的案例我們使用的為預設的組織,那如果今天我們有外部合作夥伴,要與內部系統做區隔,又要如何新增組織呢?看到左側選單的 Administration >> General >> Organization 就能設定所有組織。

馬上透過 New Org 快速建立一個組織,接著經過偏好設定就完成囉。

當用戶有組織權限後,要做介面的切換只需在左上選擇組織就可以到不同的頻道囉。

3. 後話
儘管設置用戶和權限顯得繁瑣,但這些額外的步驟能大幅提升組織管理的效率與安全性。當資源共享需求提升時,清晰的權限管理不僅能確保內容的分隔,也能減少無意中修改關鍵數據的風險。
隨著組織或個人逐漸擴大的規模,這些設置雖然麻煩卻能為長期的系統管理打下穩固的基礎,確保系統的高效運行與安全。
4. 參考
[1] Roles and Permissions — Official
https://grafana.com/docs/grafana/latest/administration/roles-and-permissions/
[2] HTTP API — Official
https://grafana.com/docs/grafana/latest/developers/http_api/