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

URL Prefix Superset Flask #3690

Closed
abhisharma7 opened this issue Oct 18, 2017 · 43 comments
Closed

URL Prefix Superset Flask #3690

abhisharma7 opened this issue Oct 18, 2017 · 43 comments
Labels
inactive Inactive for >= 30 days

Comments

@abhisharma7
Copy link

abhisharma7 commented Oct 18, 2017

Make sure these boxes are checked before submitting your issue - thank you!

  • [*] I have checked the superset logs for python stacktraces and included it here as text if any
  • [*] I have reproduced the issue with at least the latest released version of superset
  • [*] I have checked the issue tracker for the same issue and I haven't found one similar

Superset version

superset-0.20.4

Expected results

Want to run superset on http://127.0.0.1:8088/analytics/ , currently it runs on http://127.0.0.1:8088. Although, I understand this is not a bug but there should be a way in configuration file (config.py) to change url_prefix. When I am moving my superset installation to Production, I would prefer to keep it behind the proxypass of apache and not expose it directly on /.

Actual results

I couldn't find any option in config file to change the url_prefix in flask.

Steps to reproduce

Its a default setting. Need an option in config file or a procedure to add url_prefix.

Thanks

@geekSnails
Copy link

I meet the same problem

@raditsp
Copy link

raditsp commented Nov 21, 2017

👍

@movekj
Copy link

movekj commented Nov 28, 2017

@geekSnails +1

@michailsal
Copy link

+1

@lambdaq
Copy link

lambdaq commented Jan 26, 2018

basically, no

#1866

This PR was closed after 3 months... Sad.

@kirankumarpv
Copy link

Hi,

I am also having the same issue. I tried to fix it using Blurprints but superset doesn't seem to take into consideration blueprints with url_prefix.

The main reason the need for me is I am trying to deploy superset on AWS Lambda on a serverless environment and since AWS API Gateway adds a stage name like '/dev' all the links are broken. I am able to get to the login page but most of them doesn't work because it seems it's trying to access resources at "/" but API Gateway puts all of them at "/dev".

Any other way or do we need to modify all the static URL's?

Can you help me to see if someone can get Blueprints working on superset with url_prefix option?

Thanks

@sshcherbakov
Copy link

sshcherbakov commented Oct 4, 2018

Just a feedback here.
This is a shame that such basic functionality doesn't work because of the code quality (and subsequent difficulty to fix).
The workaround in the PR #1866 is ugly and doesn't really work. It relies on the reverse proxy config (which might not be appropriate in some cases) and still does not solve the issue of Superset running on the default root context path ('/').
:(

@pandamien
Copy link

pandamien commented Oct 9, 2018

Hi all, i have been working on the same issue for a while and i have some suggestions,
like @sshcherbakov mentioned the only way to workaround is to rely on reverse proxy configuration which is not very appropriate, you will end up with a configuration like this:

location ~ ^/(users|userstatschartview|roles|permissions|permissionviews|viewmenus|logout|login|logmodelview|dashboardasync|databaseasync|csstemplateasyncmodelview|druid|druidclustermodelview|druiddatasourcemodelview|csstemplatemodelview|csvtodatabaseview|sliceaddview|dashboard|chart|databaseview|tablemodelview|queryview|annotationlayermodelview|annotationmodelview|lang)/ {
    		auth_basic off;
		rewrite ^/(.*) /MY_PREFIX/$1 permanent;
    		proxy_pass http://MY_ADDRESS:MY_PORT;
    		proxy_set_header Host $host;
	}

as you can see you need to match all the hard codded path that are being redirected to the default root context ('/'). i will say this is ugly. There might be some further modifications in these paths which make the maintenance not very interesting.
1- The first solution i'm proposing is to make all the routes uniform by adding /superset, then you can rewrite the URL in nginx configuration like this:

location ^~ /MY_PREFIX/ {
    		auth_basic off;
    		proxy_pass http://MY_ADDRESS:MY_PORT;
    		proxy_set_header Host $host;
	}
		
	location ^~ /superset/ {
    		auth_basic off;
		rewrite ^/superset/(.*) /MY_PREFIX/superset/$1 permanent;
    		proxy_pass http://MY_ADDRESS:MY_PORT;
    		proxy_set_header Host $host;
	}

this is working well as long as all the paths start with /superset, but because there are many other paths that does you have to match all of them like mentioned above. Even if it will still be hard coded at least it will make the workaround much easy to maintain and reliable.

2- And the second which might be less easier but good for long term is to define a global parameter configuration in the config file like (URL_PREFIX), which should be added as base path to all the routes, then get rid of the hard coded URL.
But even if there is still hard codes like redirects make sure to add the base path to it.
This issue is been open for 2 years now and i really hope it can be fixed.
Also @joharohl has done a pretty job with this pull request https://github.com/apache/incubator-superset/pull/1866/files and i think it deserve to be reviewed, applied to all hardcoded, and merge to the master branch.

Thanks.

@dominijk
Copy link

dominijk commented Jan 29, 2019

@pandamien I've attempted your first option to configure as below;

location ~ ^/(users|userstatschartview|roles|permissions|permissionviews|viewmenus|logout|login|logmodelview|dashboardasync|databaseasync|csstemplateasyncmodelview|druid|druidclustermodelview|druiddatasourcemodelview|csstemplatemodelview|csvtodatabaseview|sliceaddview|dashboard|chart|databaseview|tablemodelview|queryview|annotationlayermodelview|annotationmodelview|lang)/ {
    		auth_basic off;
		rewrite ^/(.*) /dashboard/$1 permanent;
    		proxy_pass http://MY_ADDRESS:MY_PORT;
    		proxy_set_header Host $host;
	}

but i just end up with endless redirect as;

http://wesbsite/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/login/

Have I missed something obvious? This is with NGINX

@dominijk
Copy link

Theres an interesting looking option on Stackoverflow which I'm trying to set up

@kirankumarpv
Copy link

kirankumarpv commented Feb 25, 2019

Hi,

I wanted to run 'Superset' in complete serverless environment on AWS. Basically, want to run superset on AWS Lambda.

I have tried different methods recommended and all of them resulted in some or other place break of functionality. Eventually what i did was the below to make it work:

  1. In config.py i have added another configuration variable and used this variable in locations where redirect or appbuilder.add_link has been used.
  2. In templates folder there are places where directly '/superset/' has been used. So, even if i did first step right, the templates are not rendering in right way. So, i have to go and change the template as well (As of now I have hard-coded this. I need to make it configurable)
  3. In front-end i have added a file called config.ts and I have used this config in locations wherever redirect was done in front-end. This has fixed up all my front-end links.
  4. Only thing remaining for me was fixing "Upload CSV to Database" Link. When we click this link and enter the data, since Lambda doesn't allow any writes i tried to write to /tmp - but since we don't know whether the next request is going to be served by same lambda or not... so this is an issue as of now. The way I am planning to fix this is to write the files to s3 instead of local folder. I am still figuring out a way to do this.

After above all are done, I have used AWS Aurora Serverless as my metadata database. This way I don't even need to pay for the database since Aurora is MySQL version.

Hope this helps. Once i fix up the remaining this, I need to check how to make this available to all.

-- No more nginx or other links. We don't even need gunicorn in this setup.

Thanks
Kiran

@dominijk
Copy link

@kirankumarpv I'd be very interested in an update on this as I was about to attempt the same thing.

@kirankumarpv
Copy link

kirankumarpv commented Feb 26, 2019

@kirankumarpv I'd be very interested in an update on this as I was about to attempt the same thing.

All the fixes has been done and tested. Everything working fine on Local. On AWS Lambda "Upload CSV to Database" is not working because it cannot write to /static folder.

For my use case, I don't really need to use "upload CSV to Database" function. So, I am not going to put effort to fix it as of now. But, ideally if you are running locally on any server on any endpoint other than '/', my fix should perfectly work fine.

@kirankumarpv
Copy link

Hi,

Can anyone help me to make a pull request for this particular issue so that i can merge the code?

Thanks

@alikefia
Copy link

I am facing the same problem.
This is due to absolute redirection (not using url_for)
example: https://github.com/apache/incubator-superset/blob/master/superset/__init__.py#L191
Workaround: wsgi middleware to catch redirection response and dirty patch Location HEADER
Sorry, no time immediately to propose a PR

@kirankumarpv
Copy link

I am facing the same problem.
This is due to absolute redirection (not using url_for)
example: https://github.com/apache/incubator-superset/blob/master/superset/__init__.py#L191
Workaround: wsgi middleware to catch redirection response and dirty patch Location HEADER
Sorry, no time immediately to propose a PR

I have tried that. Using wsgi middleware to catch redirection reponse and dirty patch location HEADER but that results in sometimes application going to indefinite multiple redirects

@stale
Copy link

stale bot commented May 3, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

@stale stale bot added the inactive Inactive for >= 30 days label May 3, 2019
@stale stale bot closed this as completed May 10, 2019
@chethanMRP
Copy link

Hi Kirankumar,

I was seeing you comments on your success of implementing Superset on AWS Lambda. I was struggling to get any literature for doing the same. Can you please guide me to do this.

Regards,
Chethan G Puttaswamy

@psykidellic
Copy link

Can this be reopened as a feature request? we would like to use it but not able to run it on a subpath /superset makes it impossible to use it in our environment. I have been able to run it using the helm chart but not being able to run a subpath makes it a non starter for me.

@thammaneni
Copy link

Hi Team,

Do we have fix for this issue in latest 0.36 version?

Thanks.

@alikefia
Copy link

Hello @thammaneni,
I don't think so since there is still "hard" redirections (path vs url_for)
Example : https://github.com/apache/incubator-superset/blob/master/superset/views/core.py#L496
++ / Ali

@cdmikechen
Copy link
Contributor

cdmikechen commented Dec 30, 2020

I forked and opened a new branch to support URL Prefix by /superset, https://github.com/cdmikechen/incubator-superset/tree/0.38-syzh .
I have added some custom class extend flask-appbuilder and changed superset rest api blueprint. If anyone is interested, we can communicate with each other.

@Moofasax
Copy link

Any updates on this?

@mrgokul
Copy link

mrgokul commented Mar 25, 2021

+1, this is a very useful feature. @cdmikechen does this still work the latest release of superset?

@cdmikechen
Copy link
Contributor

@mrgokul You can look at this apache-superset/superset-roadmap#105
I've add it in version 1.0.1 and test for a month. The python codes change between 0.38 and 1.0.1 are not too big, so they can be directly used as reference. I think I'll open a pr some time later.

@syazshafei
Copy link

Is it possible to use Nginx to rewrite the URL using latest Superset?

@mrgokul
Copy link

mrgokul commented Mar 31, 2021

@mrgokul You can look at this apache-superset/superset-roadmap#105
I've add it in version 1.0.1 and test for a month. The python codes change between 0.38 and 1.0.1 are not too big, so they can be directly used as reference. I think I'll open a pr some time later.

Awaiting your PR!

@andrey-mikhailov
Copy link

andrey-mikhailov commented Dec 23, 2021

I had the same issue. I had to add url prefix to all routes in python and js files. The patched Superset version is here https://github.com/andrey-mikhailov/superset-custom-path
It's a "hacky" way and probably the solution won't work with other Superset versions, currently it supports only 1.3.2

@mrgokul
Copy link

mrgokul commented Dec 30, 2021

Hi @andrey-mikhailov , Any chance you can create a PR for (the fix after running your script) and ask an admin to approve?

@andrey-mikhailov
Copy link

Superset community will never accept this implementation, custom url path should be done in more robust way

@parked-toes
Copy link

I would be fine, at least, if all sub-pages have /superset prefix. Currently, it's very inconsistent.
E..g /dashboard/list
/superset/dashboard

@SimonKlausLudwig
Copy link

Its a shame that this is not possible. I set up superset, everything is great and now i need to stick to something else as i cant integrate it into our app.

@villebro
Copy link
Member

FWIW, I'm sure the community is open to review a PR that adds this functionality.

@cdmikechen
Copy link
Contributor

@villebro Hi~ where is the PR? I want to see it~

@alikefia
Copy link

The issue identified, years ago, is hard coded urls in the code (https://github.com/apache/superset/blob/master/superset/views/core.py#L297).
The idea is to track them and use url_for that will build the effective URL based on the global configurations.

@villebro
Copy link
Member

villebro commented Apr 1, 2022

@villebro Hi~ where is the PR? I want to see it~

@cdmikechen to rephrase, if this feature is important for the community, feel free to open a PR that adds the functionality. But keep in mind: for it to get merged it needs to be of high quality in general (abide to best practices generally recommended by the used libraries/frameworks) and include good tests.

@Step1N
Copy link

Step1N commented Jun 1, 2022

Theres an interesting looking option on Stackoverflow which I'm trying to set up

By setting up ADDITIONAL_MIDDLEWARE it working for some routes, for statics need to bypass it.

@emesday
Copy link

emesday commented Sep 28, 2022

I tried reverse proxy with sub_filter. I haven't checked that all the rules have been added, but most of them seem to work.

https://github.com/mskimm/prefixed-superset

@ralberich
Copy link

Thanks @MsKimm , it definitly works with docker, but tried to make it work using manual install with gunicorn / superset in an env, somehow it works, but referer and links in the page doesnt get rewritten. Any idea what could cause that?

@emesday
Copy link

emesday commented Oct 26, 2022

Is there nginx in front? If so, there doesn't seem to be difference between manual installation and docker.
@ralberich

@RoBYCoNTe
Copy link

I tried reverse proxy with sub_filter. I haven't checked that all the rules have been added, but most of them seem to work.

https://github.com/mskimm/prefixed-superset

You literally save my life, in next days I will try all routes and add what is missing, right now I can confirm that your solution is the only one working with the application subpath configuration.

@596192804
Copy link

I tried reverse proxy with sub_filter. I haven't checked that all the rules have been added, but most of them seem to work.

https://github.com/mskimm/prefixed-superset

Thanks a lot!!!

@ziritrion
Copy link

I tried reverse proxy with sub_filter. I haven't checked that all the rules have been added, but most of them seem to work.

https://github.com/mskimm/prefixed-superset

Is there a possibility that a similar approach could work for Apache? I'm having issues setting up httpd.conf in a way similar to what you propose here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inactive Inactive for >= 30 days
Projects
None yet
Development

No branches or pull requests