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

fix: shut off unneeded endpoints #8960

Merged
merged 14 commits into from
Jan 23, 2020
Merged

Conversation

mistercrunch
Copy link
Member

@mistercrunch mistercrunch commented Jan 13, 2020

Our list of exposed endpoints has gotten out of control, mostly due to the default FAB behavior to auto-generate and auto-expose lots of endpoints dynamically on all ModelViews, combined with the fact that we have lots of models, and sometimes multiple ModelViews per model.

This PR disables ~300 endpoints out of ~500+ we currently have.

This PR is a fairly thorough pass on all ModelViews disabling endpoints that are not used. The focus has been on ModelViews, and generally only enabling what is needed (either the CRUD and/or the REST endpoints). In many cases, I used either logic, my personal understanding of how models should be exposes, and simple grep commands to confirm assumptions.

Command to list the active endpoints

echo "print('\n'.join(sorted([str(o) for o in app.url_map.iter_rules()])))" | flask shell

Note that longer term, we want to disable all ModelView REST endpoints and favor of FAB's newer RestModelView. We also want to move away from the FAB's MVC / jinja CRUD, meaning we'll be deprecating all ModelViews.

@request-info
Copy link

request-info bot commented Jan 13, 2020

We would appreciate it if you could provide us with more info about this issue/pr! Please do not leave the title or description empty.

@request-info request-info bot added the need:more-info Requires more information from author label Jan 13, 2020
@@ -261,14 +255,11 @@ def init_views(self) -> None:
appbuilder.add_view_no_menu(Dashboard)
appbuilder.add_view_no_menu(DashboardAddView)
appbuilder.add_view_no_menu(DashboardModelViewAsync)
appbuilder.add_view_no_menu(DatabaseAsync)
appbuilder.add_view_no_menu(DatabaseTablesAsync)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 are unused now...

appbuilder.add_view_no_menu(Datasource)
appbuilder.add_view_no_menu(KV)
appbuilder.add_view_no_menu(R)
appbuilder.add_view_no_menu(SavedQueryView)
appbuilder.add_view_no_menu(SavedQueryViewApi)
appbuilder.add_view_no_menu(SliceAddView)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged with SliceAsync to simplify

@@ -24,3 +24,4 @@

class LogModelView(LogMixin, SupersetModelView): # pylint: disable=too-many-ancestors
datamodel = SQLAInterface(models.Log)
include_route_methods = {"list"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding "show" also, since the fields retrieved by list are not very useful, it's important to access the log detail

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless this is 100% required for application functionality, I would recommend against exposing this information.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what makes sense is either {"list", "show"} or nothing here. I was thinking about leaving it for backwards compatibility. I could put it behind a config flag too, let me do that.

@etr2460
Copy link
Member

etr2460 commented Jan 16, 2020

@graceguo-supercat do you know if we use any of these endpoints for programmatic chart/dashboard generation?

@mistercrunch mistercrunch force-pushed the endpoints branch 3 times, most recently from 9575b43 to 425bcfa Compare January 18, 2020 16:23
@mistercrunch mistercrunch added .important risk:hard-to-test The change will be hard to test labels Jan 18, 2020
@mistercrunch mistercrunch force-pushed the endpoints branch 3 times, most recently from 6a89dd9 to 944e077 Compare January 18, 2020 17:27
@@ -218,6 +211,16 @@ def init_views(self) -> None:
category_label=__("Sources"),
category_icon="fa-database",
)
appbuilder.add_link(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side mission: fix the menu ordering

superset/app.py Show resolved Hide resolved
superset/security/manager.py Outdated Show resolved Hide resolved
@@ -2984,16 +2983,3 @@ def apply_http_headers(response: Response):
if k not in response.headers:
response.headers[k] = v
return response


@app.route('/<regex("panoramix\/.*"):url>')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Killing redirects for things that would have been bookmarked 4+ years ago

@@ -117,18 +121,3 @@ class DashboardModelViewAsync(DashboardModelView): # pylint: disable=too-many-a
"creator": _("Creator"),
"modified": _("Modified"),
}


class DashboardAddView(DashboardModelView): # pylint: disable=too-many-ancestors
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore now that we have ModelRestApi

@mistercrunch mistercrunch marked this pull request as ready for review January 18, 2020 17:31
@mistercrunch mistercrunch force-pushed the endpoints branch 2 times, most recently from 6172183 to 06c58ce Compare January 18, 2020 17:53
@codecov-io
Copy link

codecov-io commented Jan 18, 2020

Codecov Report

Merging #8960 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #8960   +/-   ##
=======================================
  Coverage   59.16%   59.16%           
=======================================
  Files         367      367           
  Lines       11679    11679           
  Branches     2862     2862           
=======================================
  Hits         6910     6910           
  Misses       4590     4590           
  Partials      179      179
Impacted Files Coverage Δ
...rset/assets/src/dashboard/actions/sliceEntities.js 9.67% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e46ff23...c868620. Read the comment docs.

requirements.txt Outdated
@@ -22,7 +22,7 @@ croniter==0.3.30
cryptography==2.7
decorator==4.4.0 # via retry
defusedxml==0.6.0 # via python3-openid
flask-appbuilder==2.2.1
flask-appbuilder==2.2.2rc1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest rc is rc3. When no more features are needed to support this I'll release 2.2.2

@@ -345,7 +345,7 @@ def test_add_slice(self):
def test_get_user_slices(self):
self.login(username="admin")
userid = security_manager.find_user("admin").id
url = "/sliceaddview/api/read?_flt_0_created_by={}".format(userid)
url = "/sliceasync/api/read?_flt_0_created_by={}".format(userid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Take the chance to use f strings

# Limiting routes on FAB model views
UserModelView.include_route_methods = CRUD_ROUTE_METHODS | {"userinfo"}
RoleModelView.include_route_methods = CRUD_ROUTE_METHODS
PermissionViewModelView.include_route_methods = {"list"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dry these up? You added a constant above ^^

superset/app.py Show resolved Hide resolved
We recently added a new feature to FAB allowing to whitelist the needed
endpoints in ModelView and ModelRestApi.

First, we set our base wrapper class to an empty set, forcing each
class inheriting from it to explicitely turn on the endpoints that
Superset intends to use.

Second, we go ModelView by ModelView to whitelist the actual endpoints
used in the app.

Notes:
* as a result a large set of [unneeded] permissions should be cleaned up
* outside of the "private" use of endpoints in the app, people that have
  been using endpoints in their environment for other purposes may
  experience loss of functionality
@mistercrunch mistercrunch force-pushed the endpoints branch 2 times, most recently from 107e756 to 94b1642 Compare January 22, 2020 16:45
@mistercrunch
Copy link
Member Author

mistercrunch commented Jan 22, 2020

@etr2460 @graceguo-supercat , we'd like to move forward and merge this, let us know if you use other endpoints that we can open up for the time being.

If you share a list of endpoints you use we can take that into account as we do change management in this area.

Copy link

@graceguo-supercat graceguo-supercat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mistercrunch mistercrunch merged commit 315a11d into apache:master Jan 23, 2020
@mistercrunch mistercrunch deleted the endpoints branch January 23, 2020 16:25
@etr2460 etr2460 mentioned this pull request Jan 25, 2020
12 tasks
@john-bodley
Copy link
Member

john-bodley commented Jan 28, 2020

@mistercrunch we use the /sqlmetricinlineview/api/* and /tablecolumninlineview/api/* routes syncing metadata.

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.36.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels need:more-info Requires more information from author risk:hard-to-test The change will be hard to test size/L 🚢 0.36.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants