I am running a react app with a django backend. Users can log in to my app via django and are redirected to my react app. Now I want to show a grafana panel. I already set up a self-hosted grafana instance with a reverse proxy (for https). I can embedd the panel without a problem (iframe) when I use grafanas anonymous_authentication
. But this is not an option for me. Also not an option for me is a login page on in app/iframe. I am reading alot that there is the option to manage the authentication via the reverse proxy. But since I am a nginx noob, I don’t really know how I can implement this.
Can someone guide me here? I think I have to somehow log in via the proxy to grafana
My nginx setup thus far:
server {
server_name myserver.co;
location / {
proxy_set_header Host $http_host;
proxy_pass http://localhost:3000/;
}
##here is also some cert stuff
}
server {
if ($host = myserver.co) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
server_name myserver.co;
return 404;
}
2
Answers
Have you tried using
auth_request
from Nginx? It will allows you to make the validation before allowing/denying access to the Grafana.Install the
htpasswd
command-line tool to manage users and passwords for basic authentication:Create a password file for authorized users:
This will create a new password file at
/etc/nginx/.htpasswd
with a user named "myuser" and a hashed password.Modify the Nginx configuration to add basic authentication for Grafana:
This configuration restricts access to the
/grafana/
path using basic authentication. Theauth_basic
directive sets the message that will be displayed to users when they are prompted for credentials, and theauth_basic_user_file
directive specifies the path to the password file.Restart Nginx to apply the changes:
With these steps, Nginx will prompt users for credentials when they try to access Grafana, and only users with valid credentials will be able to access the dashboard.