如果使用 Grafana 平常登入要在使用一組帳密實在是有點麻煩,這時候就可以串接 GitHub OAuth2 Authentication。
串接方法
新增 GitHub OAuth Apps
它串接的方法很簡單,只需要到 GitHub 的後台找到 Developer settings 的 OAuth Apps,新增一個 New OAuth App 然後輸入一下資訊就可以了。
設定 Grafana 的設定檔
修改 Grafana 的設定檔(/etc/grafana/grafana.ini),找到 [auth.github] 部分,將相關設定填入如下:
#################################### GitHub Auth ########################## [auth.github] enabled = true allow_sign_up = true auto_login = false client_id = 0000007a199e9c6f0000 client_secret = 0000b231e614ec837eb24855772954e100000000 scopes = user:email,read:org auth_url = https://github.com/login/oauth/authorize token_url = https://github.com/login/oauth/access_token api_url = https://api.github.com/user ;allowed_domains = ;team_ids = allowed_organizations = clarencetw ;role_attribute_path = ;role_attribute_strict = false ;allow_assign_grafana_admin = false
問題排解
如果出現以下問題
t=2023-01-01T00:00:00+0000 lvl=eror msg="failed to login " logger=oauth error=redirect_uri_mismatch errorDesc="The redirect_uri MUST match the registered callback URL for this application."
解決方法是修改 root_url 參數,將其改成目前伺服器的位置。如以上範例修改 Grafana 的設定檔(/etc/grafana/grafana.ini)
[server] root_url = https://grafana.example.com/
《AWS CDK 完全學習手冊:打造雲端基礎架構程式碼 IaC》
第 12 屆 iT 邦幫忙鐵人賽 DevOps 組冠的《用 CDK 定 義 AWS 架構》
第 11 屆 iT 邦幫忙鐵人賽《LINE bot 好好玩 30 天玩轉 LINE API》
一個熱愛分享的雲端工程師!