Row Level Security filter wildcard for all tables and multiple table filters
Case
As we work closely with Superset and the new Row Level Security feature we soon came to the situation in which we have pretty much the same filters for multiple tables. And the amount of the filters is growing constantly. So, it becomes difficult to manage all these filters in the current RowLevelSecurityView.
Also, there is a security case when the user have a filter constraint on a certain table and an additional sqllab_view table is being created. So the user will be able to see unauthorised data. And the 1st solution below will solve this one too.
Suggestion
As now we have only per table filters we propose to implement some kind of all table filters and multiple table filters.
Possible solutions
- We can make the table_id column of the row_level_security_filters table nullable. And null will stand for asterisk (apply the filter to all tables). The solution currently fits all our requirements.
- As a development of the 1st idea we can introduce a new table called, for example, rls_filter_tables. It will represent the relation between rls_filter_id and table_id pretty much the same as we have for role-filter relations in the rls_filter_roles.
id | table_id | rls_filter_id
1 | 5 | 1
2 | 6 | 1
Outcomes
This way we can re-use existing filters for other tables and preserve space and readability on the RowLevelSecurityView page.
@altef @villebro @justin-barton @mistercrunch Hey guys, please express your thoughts on the ideas if any :slightly_smiling_face:
Thanks for the proposal @axelet ! please let me digest this a bit and get back in a day or two.
Hey @villebro , did you have a chance to look at these ones? I can try to implement if they are all right
Hey @axelet thanks for the ping! Will put a post-it on my desk to remember to review asap!
@axelet Have you tested making these changes locally as a POC? While in principle this makes sense, it would be interesting to see if any problems arise with this change. Also, this does require all tables to conform to a specific column naming convention, so there would need to be logic in place to handle cases where a filter's columns are not present in the table. Also, this could potentially be circumvented by introducing aliases in a SQL query, and injecting filters into the subquery (expr_qry) might be problematic, so I'm not sure if these filters can be enforced in SQL Lab as easily as in regular tables.
@villebro As for now I posted a version (https://github.com/apache/incubator-superset/pull/9751) where we have the same filters for different tables grouped together in one filter with multiple tables (Solution 2 described above, except that it doesn't support any wildcard logic). I also added a test to ensure that it works. The original behaviour is not changed for now. However, this doesn't cover the security case I described before.
As for your question about column not present in the table we can handle it by checking and filtering all clauses came from _get_sqla_row_level_filters() (if I got you correctly). We need them to have the filters specific columns, so we can check them in SqlaTable.get_sqla_query() and apply only appropriate ones. We have the cols dict with col_names, let's check the clauses to have the col_names. Or can we leave it as a user responsibility?
For expr_qry and aliases I agree it can be circumvented as long as a potential admin grants the SQL Lab access to users. I'm not sure if it's possible without Sql Lab, could you provide any cases? So, I assume it could be done for users without SQL Lab rights (if only admins can create views). Please, correct me if I'm wrong. So, there is nothing we can do here if not introducing some wildcards for tables or schemas.
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.