Assign AnonymousUserMixin to a real user

Question:

I want to make a Superset app1 that is configured to use flask-login for auth work without any auth at all. Anonymous users are already assigned/executed as the AnonymousUserMixin but parts of the app require a username and presumably ID.

My idea is to create an Admin user in the database and somehow assign AnonymousUserMixin to always be equal to that user. How would I do that and where in the flask-login or superset code would I be looking to do this?

Note: authentication to get into this application will already be taken care of and so security implications are moot.

Asked By: Mark Silverberg

||

Answers:

Superset uses as Flask-AppBuilder as the underlying web framework. Its configuration includes:

AUTH_TYPE = 0 | 1 | 2 | 3 | 4
This is the authentication type

  • 0 = Open ID
  • 1 = Database style (user/password)
  • 2 = LDAP, use AUTH_LDAP_SERVER also
  • 3 = uses web server environ var REMOTE_USER
  • 4 = USE ONE OR MANY OAUTH PROVIDERS

Our interest is 3. Because Superset supports middleware setting predefined user is as easy as (in superset_config.py):

AUTH_TYPE = 3

class PredefinedUserMiddleware:

    def __init__(self, app):
        self.app = app

    def __call__(self, environ, start_response):
        environ['REMOTE_USER'] = 'admin'
        return self.app(environ, start_response)

ADDITIONAL_MIDDLEWARE = [PredefinedUserMiddleware]
Answered By: saaj