Grafana 7 with auth proxy through Nginx

Hi all,

I’m trying to deploy Grafana v7 behind a Nginx proxy for authentication. My configuration tests seem like:

[Grafana - defaults.ini]

[auth.proxy]
enabled = true
#false
header_name = X-WEBAUTH-USER
header_property = username
auto_sign_up = true
ldap_sync_ttl = 60
sync_ttl = 60
whitelist =
headers =
enable_login_token = true

[Nginx - nginx.conf]

worker_processes auto;
pid /run/nginx.pid;

events {
   worker_connections 768;
}

http {
  server {
        listen 80;
        server_name grafana.XYZ.com;

        location /
        {
                set $USUARI "";
        }
                if ($arg_user)
                {
                   set $USUARI $arg_user;
                }
                auth_basic_user_file "/etc/nginx/.htpasswd";
                proxy_set_header X-WEBAUTH-USER $USUARI;
                proxy_set_header Authorization "";

                proxy_pass http://linuxdemo:9999;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header X-Forwarded-For $remote_addr;
        }
   }
}

When I try to access grafana using the “user” parameter (like grafana.XYZ.com/?user=admin) I get an error “failed to fetch dashboard” briefly displayed on the browser, and these logs in the nginx output:

[Nginx - logs]

10.0.4.22 - - [22/Jun/2020:16:33:00 +0000] "GET /?user=admin HTTP/1.1" 200 

10.0.4.22 - - [22/Jun/2020:16:33:01 +0000] "GET /avatar/46d229b033af06a191ff2267bca9ae56 HTTP/1.1" 200 "/?user=admin"

10.0.4.22 - - [22/Jun/2020:16:33:01 +0000] "GET /api/dashboards/home HTTP/1.1" 401 "/?user=admin"

10.0.4.22 - - [22/Jun/2020:16:33:01 +0000] "GET /api/login/ping HTTP/1.1" 401 "/?user=admin"

10.0.4.22 - - [22/Jun/2020:16:33:01 +0000] "GET /logout HTTP/1.1" 302 "/?user=admin"

It was feasible back in version 5.4.3 to automatically log in through this proxy using the “user” parameter in the uri, but I’m unable to replicate this functionality for latest grafana version.

The only way I can automatically log in is when I manually set the authentication header in the nginx proxy like:

proxy_set_header Authorization "Basic d6llC9ByO7ZpnXdlcg==";

Any ideas? Any help will be blessed, thanks a lot.