Single authentication Sign on Django and Grafana

Asked

Viewed 553 times

0

Hello people I am using the iframes of the graphana in my HTML page running in Django/python, however every time I open my page to view the embed Graficos I need to access the graphana and so perform the login to authenticate my user, my application Django already has a login page, I would like to use just one login on my page and send a proxy request to grafana, so I do not need to perform two logins every time I open my application.

I tried to use it this way:

View

class GraphanaProxyView(ProxyView):
    upstream = 'http://172.30.3.141:3000/'

    def get_proxy_request_headers(self, request):
        headers = super(GraphanaProxyView, self).get_proxy_request_headers(request)
        headers['X-WEBAUTH-USER'] = request.user.username
        return headers

Urls

url(r'^grafana/(?P<path>.*)$', views.GraphanaProxyView.as_view(), name='graphana-dashboards'),

Config Grafana

grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: always
    ports:
      - "3000:3000"
    volumes:
      - "./grafana/datastore:/var/lib/grafana"

    environment:
      - GF_SMTP_ENABLED=true  
      - GF_SMTP_HOST=smtp.gmail.com:587
      - [email protected]
      - GF_SMTP_PASSWORD=password
      - GF_SMTP_FROM_NAME=Grafana Snipped
      - GF_SMTP_SKIP_VERIFY=true


      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_NAME=View
      - GF_AUTH_ANONYMOUS_ORG_ROLE=View
      - GF_USERS_ALLOW_SIGN_UP=false

      - GF_AUTH_PROXY_ENABLED=true
      - GF_AUTH_PROXY_HEADER_NAME = X-WEBAUTH-USER
      - GF_AUTH_PROXY_HEADER_PROPERTY=username       
      - GF_AUTH_PROXY_AUTO_SIGN_UP=true 
      - GF_AUTH_PROXY_LDAP_SYNC_TTL=60
      - GF_AUTH_PROXY_WHITELIST = 172.30.3.207
      - GF_SERVER_DOMAIN = 172.30.3.141

I’m getting this error when accessing URL:

If you’re Seeing this Grafana has failed to load its application files

  1. This could be caused by your Reverse proxy Settings.

  2. If you host grafana under subpath make sure your grafana.ini root_path Setting includes subpath

  3. If you have a local dev build make sure you build frontend using: npm run dev, npm run watch, or npm run build

  4. Sometimes restarting graphana-server can help

1 answer

1


(Sorry I don’t know Portoguese, Google Translated helped me)

Oi Gabriel thank you for contacting me by email also.

Your report is almost complete, great!

Given the warning

`Esta configuração também é importante se você tiver um proxy reverso na frente do Grafana que o expõe através de um subcaminho. Nesse caso, adicione o subcaminho ao final dessa configuração de URL .

in http://docs.grafana.org/installation/configuration/#root-url

a fault may be the configuration of the container 'GF_SERVER_DOMAINque deve ser substituído peloGF_SERVER_ROT_URL = http: //172.30.3.141: 3000 /` which contains the port (and this would mean a bug in the Grafana documentation ...)

Otherwise, only two other questions come to mind to identify the problem:

 1. Does your request.user.username match the Grafana username?  2. What is the "src" attribute of your iframe? It should be https://172.30.3.207/grafana/(dashboard path)

Next to these basic questions I suggest you try to remove the envvar from GF_AUTH_PROXY_WHITELIST and try to authenticate viacurl as:

curl -H" X-WEBAUTH-USER: anthony "http: //172.30.3.141: 3000 / api / user

how can you find in http://docs.grafana.org/auth/auth-proxy/#interacting-with-grafana-s-authproxy-via-Curl


(Sorry I don’t know English, Google Translated helped me)

Hi Gabriel, Thank you for contacting me by email also.

Your report is Almost complete, Great!

Given the Warning

This setting is also important if you have a reverse proxy in front of Grafana that exposes it through a subpath. In that case add the subpath to the end of this URL setting.

at http://docs.grafana.org/installation/configuration/#root-url

a fault can be the Setting of the GF_SERVER_DOMAIN envvar that should be replaced by the GF_SERVER_ROOT_URL=http://172.30.3.141:3000/ that Holds the port (and this would Mean a bug of Grafana Documentation...)

If not this, only two other questions come to my Mind to identify the Issue:

  1. does your request.user.username match the Grafana username?
  2. what is the "src" attribute of your iframe? It must be https://172.30.3.207/grafana/(dashboard path)

beside this basic questions I Suggest you to Try to remove the GF_AUTH_PROXY_WHITELIST envvar and to Try to authenticate via curl like:

curl -H "X-WEBAUTH-USER: anthony" http://172.30.3.141:3000/api/user

as you can find at http://docs.grafana.org/auth/auth-proxy/#interacting-with-grafana-s-authproxy-via-Curl

  • Fero, translate your answer to English!

  • Luca, Answering your Question, the request.user.username I Believe is not the same Registered in grafana. I have one a Question, Every time I Register a new user in my application, the same user needs to be Registered in grafana or this is generated Automatically? my iframe src is "<iframe src =" http://172.30. 3.141:3000/d-solo/cFb9_r9mz/senseops-Dashboard? refresh=5s&orgId=1&panelId=71&Theme=light "width =" 100% "height = "200" frameborder = "0"> "

  • You are right. Try the Curl and Let me know

Browser other questions tagged

You are not signed in. Login or sign up in order to post.