1) Install Grafana using Helm chart.
ở bài này mình xin hướng dẫn cài bạn cài grafana trên k8s bằng helm chart:
helm repo add grafana https://grafana.github.io/helm-charts helm repo update helm install my-release grafana/grafana
Chúng ta cần chú ý value 1 chút:
Mình cần tạo ingress cho grafana luôn nên mình sẽ cần update values of helm install 1 chút
ingress:
enabled: true
ingressClassName: nginx
annotations:
cert-manager.io/issuer: selfsigned-issuer-grafana
cert-manager.io/issuer-kind: Issuer
hosts:
- grafana.nimtechnology.com
tls:
- hosts:
- grafana.nimtechnology.com
secretName: tls-grafana-ingress
với helm values trên thì nó tự động tạo 1 grafana secret và store pass admin ở đây. Bạn sẽ dụng pass ở đây để login vào hệ thống.

Tiếp bạn thực hiện login vào grafana:

2) Configure authentication in Grafana.
2.1) Login Grafana by Azure or Microsoft account.
Log in to Azure Portal, then click Microsoft Entra ID in the side menu.
Nếu bạn chưa biêt tạo Application Registrations trên Azure thì tham khao mược này ở bên dưới này:
Sau đó chúng ta đá có 1 application registration

Vì ở đây mình có sãn
Tiếp đến chúng ta cần cung cấp Redirect URL để dựa trên domain của web của chúng ta


Tiếp đến bạn cần tạo 1 client credential và lấy ra client secret:



Bạn cần copy value ở trên vì nó sẽ là client_secret
Tiếp đến client_id sẽ là Application (client) ID
tenant_id sẽ là: Directory (tenant) ID
Bạn sẽ cần thay thế các value dựa theo chỉ dẫn bên trên:
grafana.ini:
auth.azuread:
enabled: true
client_id: <client_id>
client_secret = <client_secret>
scopes: openid email profile User.Read
auth_url: https://login.microsoftonline.com/<tenant_id >/oauth2/v2.0/authorize
token_url: https://login.microsoftonline.com/<tenant_id >/oauth2/v2.0/token
api_url: https://graph.microsoft.com/oidc/userinfo
redirect_uri: https://grafana.nimtechnology.com/login/azuread
skip_org_role_sync: false
role_attribute_strict: false
allow_assign_grafana_admin: false
skip_org_role_sync: true
use_pkce: true
Nhưng mà nếu bạn để secret trong helm value thì rất là kém bảo mật
Chúng ta sẽ đưa client_secret vào trong envionment:
secret:

Và value file như sau:
envValueFrom:
GF_AUTH_AZURE_OAUTH_CLIENT_SECRET:
secretKeyRef:
name: grafana-azure
key: GF_AUTH_AZURE_OAUTH_CLIENT_SECRET
grafana.ini:
security:
allow_embedding: true
cookie_samesite: none
cookie_secure: true
server:
domain: https://grafana.nimtechnology.com
root_url: https://grafana.nimtechnology.com
auth.azuread:
enabled: true
client_id: ${GF_AUTH_AZURE_OAUTH_CLIENT_SECRET}
client_secret = <client_secret>
scopes: openid email profile User.Read
auth_url: https://login.microsoftonline.com/<tenant_id >/oauth2/v2.0/authorize
token_url: https://login.microsoftonline.com/<tenant_id >/oauth2/v2.0/token
api_url: https://graph.microsoft.com/oidc/userinfo
redirect_uri: https://grafana.nimtechnology.com/login/azuread
skip_org_role_sync: false
role_attribute_strict: false
allow_assign_grafana_admin: false
skip_org_role_sync: true
use_pkce: true

Nếu bạn thấy việc nhấn vào Sign in with Microsoft rất là mất thời gian thì bạn có thể thêm 1 option auto_login: true trong phần: auth.azuread:
Grafana tự động đưa người dụng đến phần login Microsoft
Issue
https://community.grafana.com/t/azure-ad-oauth2-authentication-redirect-uri-error/117349/5