superset icon indicating copy to clipboard operation
superset copied to clipboard

Question: How to auto login (bypass) login page?

Open govardhank opened this issue 9 years ago • 18 comments

Hi ,

I am new to superset. Actually what i want is when i click a link in my application, it should redirect to superset and open dashboard page bypassing the login page in a separate window? can you please briefly explain or give me step wise instructions on how to do this. My mail Id: [email protected]

Thanks & Regards, Govardhan

govardhank avatar Apr 10 '17 14:04 govardhank

Do you want 1) to grant public access to there dashboards, or 2) you want to setup some sort of auto login?

  1. there should be a Public role, you can setup the install param PUBLIC_ROLE_LIKE_GAMMA to give a set of basic permissions to public, and then manually add datasources you want public to the Public role.

  2. for auto login at Airbnb we use REMOTE_USER, a mechanism that Flask App Builder (FAB) support that involves a reverse proxy that does LDAP authentication and adds headers with username and groups as it passes requests to the app itself. The app has to be configured to expect that. FAB documents how to do this.

mistercrunch avatar Apr 10 '17 15:04 mistercrunch

Hi, Thanks for your reply.

I want to setup some sort of auto login? I am developing a web application using nodejs. After loging into my app then clicking on some link redirect to superset auto login. can you please get me some more detailed information on this as I couldn't find it in FAB.

Thanks, Govardhan

govardhank avatar Apr 11 '17 05:04 govardhank

Not sure where/if you looked but authentication is very well documented: http://flask-appbuilder.readthedocs.io/en/latest/security.html#authentication-methods

mistercrunch avatar Apr 11 '17 15:04 mistercrunch

@govardhank are you finished?

qq273681448 avatar Jul 07 '17 07:07 qq273681448

@govardhank thanks,I have solved this problem

qq273681448 avatar Jul 07 '17 07:07 qq273681448

@qq273681448 Hi, how do you solve this? Can you help me out? Thx 👍

jfsdcgy avatar May 09 '18 15:05 jfsdcgy

You need 3 things in your superset_config.py:

  1. A custom REMOTE_USER authenticator
  2. Update the security manager to point to a new one that have you custom authenticator
  3. Set the auth type to AUTH_REMOTE_USER

In a nutshel:

# Import some libraries that are required
from flask_appbuilder.security.views import expose
from flask_appbuilder.security.sqla.manager import SecurityManager
from flask_appbuilder.security.manager import BaseSecurityManager
from flask_appbuilder.security.manager import AUTH_REMOTE_USER

# Create a custom view to authenticate the user
AuthRemoteUserView=BaseSecurityManager.authremoteuserview
class AirbnbAuthRemoteUserView(AuthRemoteUserView):
    @expose('/login/')
    def login(self):
      print("This is LOGIN")
      return ("This is the response from your custom authenticator")


# Create a custom Security manager that override the authremoteuserview with the one I've created
class CustomSecurityManager(SecurityManager):
    authremoteuserview = AirbnbAuthRemoteUserView

# Use my custom authenticator
CUSTOM_SECURITY_MANAGER = CustomSecurityManager

# User remote authentication
AUTH_TYPE = AUTH_REMOTE_USER

I use docker to do all my test and found that running superset with gunicorn is much easier because I can reload the server as soon as I update the configuration file:

# Start the docker container
# I'm using 0.23.3 because I had issue with more recent versions

docker run -it -v $(pwd)/config:/etc/superset -v $(pwd)/SQLlite:/var/lib/superset -p 8088:6000 --entrypoint sh --user root amancevice/superset:0.23.3

# First you'll need to update gunicorn to get the version >= 19.8+ in order to use reload-extra-file
pip3 install gunicorn --upgrade

# Then inside the container start gunicorn
gunicorn -w 1 -k gevent --timeout 120 \
  --reload \
  --reload-extra-file /etc/superset/superset_config.py \
  -b  0.0.0.0:6000 --limit-request-line 0 --limit-request-field_size 0 superset:app

I hope this will help anyone looking for auto-login. I could not find any clear documentation anywhere, but once I found out that it was using Flask App then it was a bit more easy. All the doc is here and here is the source code of the security views

Maxwell2022 avatar May 15 '18 06:05 Maxwell2022

@Maxwell2022 I tried to apply your changes to config file from Superset docker image and am now getting 502 error for all requests from browser. I tried to CURL to endpoints while passing REMOTE_USER header additionally - same result.

This REMOTE_USER auth scheme is really poorly documented, could you give a complete working example? I think it will worth it as Superset looks like a product that gets integrated as part of other products.

snowindy avatar May 20 '18 18:05 snowindy

@Maxwell2022 In fact I found how to use REMOTE_USER , instruction is pretty obvious in main doc.

snowindy avatar May 20 '18 20:05 snowindy

Try this in superset_config.py:

from flask_appbuilder.security.views import expose
from superset.security import SupersetSecurityManager
from flask_appbuilder.security.manager import BaseSecurityManager
from flask_appbuilder.security.manager import AUTH_REMOTE_USER
from flask import  redirect
from flask_login import login_user

# Create a custom view to authenticate the user
AuthRemoteUserView=BaseSecurityManager.authremoteuserview
class AirbnbAuthRemoteUserView(AuthRemoteUserView):
    @expose('/login/')
    def login(self):
      user = self.appbuilder.sm.auth_user_db("admin", "admin")
      login_user(user, remember=False)
      return redirect(self.appbuilder.get_url_for_index)


# Create a custom Security manager that override the authremoteuserview with the one I've created
class CustomSecurityManager(SupersetSecurityManager):
    authremoteuserview = AirbnbAuthRemoteUserView

# Use my custom authenticator
CUSTOM_SECURITY_MANAGER = CustomSecurityManager

# User remote authentication
AUTH_TYPE = AUTH_REMOTE_USER

hsnotebook avatar Aug 17 '21 09:08 hsnotebook

source code of the security views

Can you please explain how you solved ?

riki-nitdgp avatar Dec 10 '21 11:12 riki-nitdgp

HI!我是邵磊,您的邮件我已经收到啦,我会在第一时间给您回复哦。

qq273681448 avatar Dec 10 '21 11:12 qq273681448

The solution mentioned https://github.com/apache/superset/issues/2580#issuecomment-293291888 works for me, i.e. adding:

class RemoteUserMiddleware(object):
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        user = environ.pop('HTTP_X_PROXY_REMOTE_USER', None)
        environ['REMOTE_USER'] = user
        return self.app(environ, start_response)

ADDITIONAL_MIDDLEWARE = [RemoteUserMiddleware, ]
AUTH_TYPE = AUTH_REMOTE_USER
AUTH_USER_REGISTRATION = True

Ensure the header used is X-PROXY-REMOTE-USER (without the HTTP).

raags avatar Jan 08 '22 16:01 raags

HI!我是邵磊,您的邮件我已经收到啦,我会在第一时间给您回复哦。

qq273681448 avatar Jan 08 '22 16:01 qq273681448

session = requests.session() login_url = "http://<superset_server>:8088/api/v1/security/login" login_data = {'username': 'xxx_user', 'password': 'xxx_pass', 'provider': 'db', 'refresh': True} response = session.post(url=login_url, json=login_data) Then you can obtain csrf_token from response, and use it as a key for the following requests

marshell0 avatar Mar 17 '22 06:03 marshell0

HI!我是邵磊,您的邮件我已经收到啦,我会在第一时间给您回复哦。

qq273681448 avatar Oct 11 '22 08:10 qq273681448

can anyone please tell how to fetch value of guest token in superset_config.py file ...as in url am passing token and that token need to verify in config file so it bypass the login screen of superset for user. http:/localhost.com:8080/login?token=1234&next=/superset/dashboard/11?standalone=true

Thanks in advance!!!!!!

falgunifb avatar Feb 03 '23 10:02 falgunifb

HI!我是邵磊,您的邮件我已经收到啦,我会在第一时间给您回复哦。

qq273681448 avatar Feb 03 '23 10:02 qq273681448