Request for a filter box with user-level filtering capabilities.
Imagine you've connected a data source to Superset, containing data on all your clients and their corresponding account managers. To help the account managers perform their jobs better, you decide to build a beautiful dashboard containing all the right charts and visuals. However, these account managers shouldn't be able to see each other's client data (sensitive, security, etc.)
If you only have a handful of account managers (AMs), it's easy to write a script to split the master data set into account manager-specific subsets before importing it to Superset, and then create tables from there. Problem solved.
What if you have hundreds of AMs? One way to go about this is create a single dashboard with slices associated to the master data set, add a filter box, select the AM you want to narrow the data down to, and then export the report as a static image. This has several drawbacks:
- The dashboard the AM receives is a static image.
- Someone has to do apply the filter and perform the export manually each time.
- AMs have to wait for someone to send them the report each time they want it.
Now, if it were possible to adapt the existing filter box to auto-detect the Superset user and auto-apply a preset filter, then disable the dropdown menu from being changed, you could do away with those 3 drawbacks.
Of course there are millions of other ways to go about this, but thought I'd throw this out there.
If you have hundreds of AMs maybe you have an IT that can support providing separated views for the same data and find a way to build slices / dashboard programmatically?
Right; that could work, but maintaining a single dashboard has 2 key benefits I can think of:
-
Less clutter. 100 AMs = 100 views = at least 100 slices = at least 100 dashboards (in this scenario where data separation is important).
-
Any updates or enhancements made to a master view or master dashboard would propagate to all AMs.
I'm wondering how hard could it be to add "virtual" slice / dashboard that you can connect to different datasources.
Sounds like row level security to me (other issues talk about this). Though the mechanisms for row-level-security would be around enforcing a WHERE clause for people on certain tables, as opposed to enforcing a filter on a dashboard.
hi, Can you please, explain more about row level security? Someone have already implement this?
Has there been any progress on this request? I have tried to find the "recommended" approach for data level security but not sure if anything has been published. For instance, we use Druid+Superset and there are some requests for multi-tenant id but unsure if this works as expected. I would think having a user level permission on a specific data source is a requirement for most organizations. Also, on FilterBoxes, allowing a user to select specific dimension values based on Role/Group would be preferable.
In the meantime, how have others worked around this? Is using a Slice or Datasource per user really feasible? How does the networking work? Proxy? Kubernetes INGRES?
Any thoughts on this are appreciated. While we use Superset internally, we cannot expand to a broader user base without this functionality. If a User A is authorized to see a subset of a Druid Data source, how is this controlled exactly?
Thanks
@ahsanshah I hear you. I am facing a similar issue.
AIUI the current permission systems are about access to dashboards, charts and data-sources. That's a level above what we want (i.e we want to have granular permissions based access to the data within those charts).
Here is an initial thought on how maybe superset could be patched to make this work:
- When creating users, have a set of arbitrary key/values that you can populate for that user. It could be things like 'user_id', 'department' etc. The point here is to add key/values that we would want to later filter on.
- When creating Charts, where the 'Add Filter' is, have an 'Add User Filter' option. This might look the same as the regular Filter option, except the value would be a key that we had previously entered as the user. It might look something like storing a bindparam for later interpolation.
Table.get_sqla_query()would then build our query just like it does now, although in addition to afilterkey, it could also look foruser_filter(or whatever), and would do agetattr(flask.g.user, user_filter.val)or similar to get the user specific value that we are filtering against.
You'd obviously have to consider what to do if the User doesn't have the attribute, as well as other possible complexities I haven't thought of.
If those who know Superset better than I think this is a reasonable approach I'd be happy to get on and write a patch, because as much as I'd like to use Superset, without this kind of feature it's of limited use to me :(
@mistercrunch As to the security around the WHERE clause, is it possible for the user to pass in arbitrary filters to a GET call? If it isn't possible, and if they cannot modify the Chart then the WHERE clause should be secure...right ?
Also, here is a way you can implement your own Dashboard level filtering without touching the Superset codebase. Roughly speaking you need to do the following:
- Create a custom view and override the
/superset/explore_jsonendpoint - Modify the Viz
query_obj()method to include any additional filtering you want. - Import the custom view via the FLASK_APP_MUTATOR.
It looks something like this.
from flask import g
from flask_appbuilder import expose
from superset import appbuilder
from superset.views.core import Superset, log_this, has_access_api
class MyCustomView(Superset):
@log_this
@has_access_api
@expose('/explore_json/<datasource_type>/<datasource_id>/', methods=['GET', 'POST'])
@expose('/explore_json/', methods=['GET', 'POST'])
def explore_json(self, *args, **kwargs):
""" This is a copy of the method definition from Superset """
return super(MyCustomView, self).explore_json(*args, **kwargs)
def get_viz(self, *args, **kwargs):
""" Return the Vizualisation object
get_viz() overrides the Superset.get_viz() method
so it can wrap it and alter the filter pattern
that it produces. This is so we can filter
viz objects by whatever we want.
"""
viz_obj = super(DAView, self).get_viz(*args, **kwargs)
# The viz_obj has a query_obj() method which will be called
# and filters added before being fetched from the DB.
# We want to wrap this function, so when called we add our own
# filtering
def wrapped(f):
def inner(*args, **kwargs):
query_obj = f(*args, **kwargs)
# If we want here we can check the dashboard first
dashboard = urllib.urlparse(request.headers['referer']).path
if dashboard == '/superset/dashboard/dashboardX'/:
# Then filter by username
query_obj['filter'].append({'val': f'{g.user.username}', 'op': '==', 'col': 'username'})
return query_obj
return inner
viz_obj.query_obj = wrapped(viz_obj.query_obj)
return viz_obj
# Here we are making sure that any calls to explore_json()
# will call our custom view, thus giving us control of the response
for rule in appbuilder.app.url_map.iter_rules():
if rule.rule == '/superset/explore_json/':
rule.endpoint = 'MyCustomView.explore_json'
appbuilder.app.url_map.update()
appbuilder.add_view_no_menu(DAView)
Then in your superset config.py file add the following:
def import_stuff(app):
from my_app import views
FLASK_APP_MUTATOR = import_stuff
Here the views module has our previosuly defined MyCustomView class etc.
I tried this on 0.26 and it seemed to work fine. This will get called for every chart AFAICT, so you might have to be clever about what filters you are applying for what charts etc. The above is just a basic example.
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.
This request is definitely a must in my opinion. Like @anthonymhho said, the solution the way it is right now is in not scalable to different level of data access which is general the case in many organisation.
Any status on this?