Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to auth via browser URL without enabling anonymous? #2729

Closed
discoduck2x opened this issue Sep 11, 2015 · 42 comments
Closed

How to auth via browser URL without enabling anonymous? #2729

discoduck2x opened this issue Sep 11, 2015 · 42 comments

Comments

@discoduck2x
Copy link

First sorry for posting this prob really stupid Q...

Im spawning a browser from an inhouse application which should authenticate automatically via the browser URL to a dashboard but i cant get it to work with http://username:pass@grafanaserver/dash.......tried to pass an api key in the url aswell but cant figure it out (if it even should work?)

(the URL will reach a templated dashboard with repeat panels and will have the host as a variable from the inhouse app)

again,,sorry :)

@torkelo
Copy link
Member

torkelo commented Sep 11, 2015

there is no url based auth :(

@torkelo torkelo closed this as completed Sep 11, 2015
@ernoaapa
Copy link

@torkelo ok if there is no plan for url based authentication, do you have idea how to share rendered image with some password/token so that it doesn't require login?

The use case where I would need the url based auth is that I would like to embed a graph to our monitoring email alert.

@torkelo
Copy link
Member

torkelo commented Sep 12, 2015

the snapshot sharing is exactly for this case :)

You can snapshot a single graph or whole dashboard, it will store the data in the panel and use can then use the snapshot to get a rendered png that is public
http://docs.grafana.org/reference/sharing/

@ernoaapa
Copy link

No that doesn't work. I need a url what I can add to the email template what get updated when the email get sent. With snapshot sharing it store the current data :/

@Ivan076
Copy link

Ivan076 commented Dec 28, 2015

Same thing has happened to me had to scrap 3 months of work because i never managed to figure out how to extract the graphs into a pdf. Management want reports not browsing......Tried to install hubot but that was a total flop, my ubuntu crashed after i installed it, I am really over board with this.....

@mattttt
Copy link
Contributor

mattttt commented Apr 28, 2016

+1 from Grafana.net user

The second use case is for our NOC screens. Having a /dashboard/db/demo?key=AAAA where the key is (or like) an API key to allow very simple views would be great.

@erowan
Copy link

erowan commented Aug 11, 2016

+1

2 similar comments
@peterfroehlich
Copy link

+1

@gabrielmocan
Copy link

+1

@hco
Copy link

hco commented May 8, 2017

I have the NOC screen usecase, too.

@jbein
Copy link

jbein commented May 15, 2017

+1

2 similar comments
@igortroitsky
Copy link

+1

@PatrikNorrgard
Copy link

+1

@hwinkel
Copy link

hwinkel commented Oct 12, 2017

Woo, Expectation of a closed ticket was this is working, but seems is simply closed to report that is not working without any statement this feature will be added or not.
We having 12 NOC screens as well and there is no way to get them authenticated somehow.

Anybody knows another solution?

@meeeller
Copy link

meeeller commented Jan 8, 2018

+1

3 similar comments
@Shadosky
Copy link

+1

@ssozonoff
Copy link

+1

@Hadlock
Copy link

Hadlock commented Apr 10, 2018

+1

@koendc
Copy link

koendc commented Jun 27, 2018

This can be achieved with Grafana API keys + a browser extension that allows for Header insertion.
I use the Modify Header Value HTTP extension as this extension allows you to limit the header insertion to a certain domain.

  1. In Grafana, go to Configuration > API Keys
  2. Create a new key and note down the key
  3. In the Modify Header Value HTTP configuration, add a line:
    • URL: Grafana URL
    • Header Name: Authorization
    • Header Value: Bearer GRAFANA_API_KEY

@kedare
Copy link

kedare commented Jul 19, 2018

I confirm this is more than needing, we are migrating from Datadog to Grafana/Prometheus and I was quite surprised of this limitation.
Typically on Datadog you can generate an unique, shareable URL for dashboard without authentication (For those NOC screens)

@marceloscharan
Copy link

+1

5 similar comments
@sporkbyspork
Copy link

+1

@kaned
Copy link

kaned commented Aug 4, 2018

+1

@akulakhan
Copy link

+1

@slucase
Copy link

slucase commented Aug 23, 2018

+1

@leobudima
Copy link

+1

@josefkorbel
Copy link

+2

@AntonyKing7D
Copy link

+1 for a NOC screen not using auth. It's tedious having to log in manually to each one when they are reset or changed for any reason.

@deggle
Copy link

deggle commented Feb 19, 2019

+1

8 similar comments
@ipasic
Copy link

ipasic commented Feb 28, 2019

+1

@emoods
Copy link

emoods commented Mar 21, 2019

+1

@FSMa5ter
Copy link

+1

@unk1nd
Copy link

unk1nd commented Mar 28, 2019

+1

@errietta
Copy link

errietta commented May 9, 2019

👍

@avandermeer
Copy link

+1

@LEMNX
Copy link

LEMNX commented Jun 25, 2019

+1

@mskorge
Copy link

mskorge commented Oct 22, 2019

+1

@MimbaMonkeyHouse
Copy link

+1
Anyone got a solution?

@ruanhang1993
Copy link

ruanhang1993 commented Mar 11, 2020

Here is my solution for iframe access by using auth proxy(https://grafana.com/docs/grafana/latest/auth/auth-proxy/#auth-proxy-authentication). Hope it will help someone.

The structure is Grafana Server(port:3000) + Nginx Auth Proxy(port:8088) + web auth service.
Here is the setting in grafana.ini.

#################################### Auth Proxy ##########################
[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
header_property = username
auto_sign_up = true

Here is the setting in nginx.conf.

location / {
            set $cors "1";

            # OPTIONS indicates a CORS pre-flight request
            if ($request_method = 'OPTIONS') {
                set $cors "${cors}o";
            }

            # OPTIONS (pre-flight) request from allowed
            # CORS domain. return response directly
            if ($cors = "1o") {
                add_header 'Access-Control-Allow-Origin' '$http_origin' always;
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
                add_header 'Access-Control-Allow-Credentials' 'true' always;
                add_header 'Access-Control-Allow-Headers' 'Origin,Content-Type,Accept,Authorization,X-WEBAUTH-USER' always;
                add_header Content-Length 0;
                add_header Content-Type text/plain;
                return 204;
            }

            add_header Access-Control-Allow-Origin '*' always;
            add_header Access-Control-Allow-Credentials  true always;
            add_header Access-Control-Allow-Headers 'Origin,Content-Type,Accept,Authorization' always;


            #auth_basic "grafana";
            #auth_basic_user_file "/etc/nginx/htpasswd";

            auth_request     /auth;

            proxy_set_header X-WEBAUTH-USER "admin";
            proxy_set_header Authorization "";

            proxy_pass http://localhost:3000/;
        }

        location = /auth {
            internal;
            proxy_pass              http://test.org/auth; #The Auth request will send here. Return 2xx status code for success, and return 4xx for failure.
            proxy_pass_request_body off;
            proxy_set_header        Content-Length "";
            proxy_set_header        X-Original-URI $request_uri;
        }

Here is the web auth service

@GetMapping(value = "/auth", produces = "application/json;charset=UTF-8")
    @ResponseBody
    /* Auth should return 2xx ok. 4xx error. */
    public JSONObject auth(@RequestParam Map<String, String> paramMap, HttpServletRequest request) {
        if(checkHeaderAuth(request.getHeader("X-Original-URI"))){
            return new JSONObject();
        }
        throw new IllegalArgumentException("Error token");
    }

    private boolean checkHeaderAuth(String uri) {
        if(uri == null) {
            return false;
        }

        // filter the resource requests
        if(!uri.startsWith("/d-solo/")){
            LOG.info("auth header(skip):" + uri);
            return true;
        }
        LOG.info("auth header:" + uri);

        // get token and org
        String token = null;
        Long orgId = null;
        String paramString = uri.split("\\?")[1];
        String[] params = paramString.split("&");
        for(String param : params) {
            if(token == null && param.contains("token=")){
                token = param.split("token=")[1];
            }
            if(orgId == null && param.contains("orgId=")){
                orgId = Long.parseLong(param.split("orgId=")[1]);
            }
        }
        LOG.info("auth:" + token + " orgId:" + orgId);

        // use token and orgId to judge 
        ......
    }

When using the iframe way for embedding, we can add the token to the url, like http://test.org:8088/d-solo/123456/test?orgId=1&token=XXXXX.

But there are some shortcomings.

  1. All user are logged in with the system admin. I don't find a way to pass the username to the grafana server.
  2. Skip the authentication for all resource requests.

@steverweber
Copy link

should this be reopened?
I would find using an api_key handy to allow kiosk/tv viewing dashboards.

@steverweber
Copy link

disregard #3752 would likely solve this.

@choeflake
Copy link

I used the original source of @infobeamer-fw to create a version which has support for custom headers. This allows you to add an Authorization header with Basc auth or a Bearer token for example.
See: choeflake/infobeamer-fullscreen-browser-package (github.com)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests