- What Grafana version and what operating system are you using?
Grafana v8.5.22 setup on Linux -
What are you trying to achieve?
Trying to enable JWT Authentication for accessing existing dashboards but configuration is not working - How are you trying to achieve it?
- Generated Public and Private keys at /etc/grafana directory with below commands
openssl genpkey -algorithm RSA -out private.key
openssl rsa -pubout -in private.key -out public.key
- Given required access to these 2 files with below commands following same ownership (root:grafana) as like other files in same directory /etc/grafana
chown root:grafana *.key
chmod 777 *.key
(Note: 777 only for temporary, I will change it later to 755)
- configured below details in /etc/grafana/grafana.ini
[auth.jwt]
enabled = true
header_name = X-JWT-Assertion
email_claim = sub
username_claim = sub
key_file = /etc/grafana/private.key
auto_sign_up = true
url_login = true
skip_org_role_sync = true
-
restarted grafana with below command
sudo service grafana-server restart -
generated JWT token with below python3 script
a) Install pyjwt module
pip install pyjwt
b) Python script to generate token as below âscript.pyâ
import jwt
private_key = open(âprivate.keyâ).read()
token = jwt.encode({âexpâ: 1681880400, âsubâ: âexistinguser@email.comâ}, private_key, algorithm=âRS256â)
print(token)
- Then used the jwt token with below URL for accessing existing dashboard (validated using incognito window)
http://grafana.staged-by-discourse.com/d/TPQDREZ/simple-streaming-example?orgId=1&kiosk&jwt=<JWT_Token>
- But it is redirecting me to login page with error status code 302 in logs at /var/log/grafana/grafana.log
(Note: I have already enabled debug level and then collected logs)
logger=context traceID=000000000000000000000000000 userId=0 orgId=0 uname= t=2023-04-22T18:14:00.66-0500 lvl=info msg=âRequest Completedâ method=GET path=/d/TPQDREZ/simple-streaming-example status=302 remote_addr=127.0.0.1 time_ms=0 duration=164.93”s size=29 referer= traceID=000000000000000000000000000
-
What happened?
Getting error status code 302 in debug logs at /var/log/grafana and URL getting redirected to login page. -
What did you expect to happen?
Iâm expecting that grafana shows me a kiosk view page of dashboard when trying to use jwt token in URL -
Can you copy/paste the configuration(s) that you are having problems with?
-
Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
-
Did you follow any online instructions? If so, what is the URL?
I followed grafana documentation for setup which is not working for JWT Authentication.