-
Notifications
You must be signed in to change notification settings - Fork 0
feat: use per-user db role for query exec (ENG-2474) #48
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
feat: use per-user db role for query exec (ENG-2474) #48
Conversation
Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries.
9656e5f
to
bc1e229
Compare
a46c1d5
to
f5f217b
Compare
@listens_for(BaseQuery, "before_compile", retval=True) | ||
def prefilter_query_results(query): | ||
for desc in query.column_descriptions: | ||
if desc['type'] is QueryResult: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach was the best I could come up with. It does ensure that the user only sees the QueryResult
records that they "own" but doesn't actually use the role / RLS policy on that table because I couldn't figure out a way to actually wrap the query in a set
/ reset role
, since there is no corresponding "after" event for queries. I'm open to suggestions on how to make it actually use the role, but it's worth noting that the RLS policy on the redash.query_results
table is still important to prevent the user from issuing queries directly against that table to see results that they shouldn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment in the code to this affect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Only ask is for a comment.
@listens_for(BaseQuery, "before_compile", retval=True) | ||
def prefilter_query_results(query): | ||
for desc in query.column_descriptions: | ||
if desc['type'] is QueryResult: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment in the code to this affect?
* feat: use per-user db role for query exec (ENG-2474) Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries. * Reject login from unknown SSO users * Use pre-filtered query for QueryResults rather than session-level `set role` * Add docstring with non-obvious context
* feat: use per-user db role for query exec (ENG-2474) Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries. * Reject login from unknown SSO users * Use pre-filtered query for QueryResults rather than session-level `set role` * Add docstring with non-obvious context
* feat: use per-user db role for query exec (ENG-2474) Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries. * Reject login from unknown SSO users * Use pre-filtered query for QueryResults rather than session-level `set role` * Add docstring with non-obvious context
* feat: use per-user db role for query exec (ENG-2474) Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries. * Reject login from unknown SSO users * Use pre-filtered query for QueryResults rather than session-level `set role` * Add docstring with non-obvious context
…8) (#47) If the current user has a `db_role`, they should only see query results that they have generated, so that they don't see results which contain info about resources they don't have permission to view. feat: use per-user db role for query exec (ENG-2474) (#48) * feat: use per-user db role for query exec (ENG-2474) Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries. * Reject login from unknown SSO users * Use pre-filtered query for QueryResults rather than session-level `set role` * Add docstring with non-obvious context
…8) (#47) If the current user has a `db_role`, they should only see query results that they have generated, so that they don't see results which contain info about resources they don't have permission to view. feat: use per-user db role for query exec (ENG-2474) (#48) * feat: use per-user db role for query exec (ENG-2474) Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries. * Reject login from unknown SSO users * Use pre-filtered query for QueryResults rather than session-level `set role` * Add docstring with non-obvious context
…8) (#47) If the current user has a `db_role`, they should only see query results that they have generated, so that they don't see results which contain info about resources they don't have permission to view. feat: use per-user db role for query exec (ENG-2474) (#48) * feat: use per-user db role for query exec (ENG-2474) Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries. * Reject login from unknown SSO users * Use pre-filtered query for QueryResults rather than session-level `set role` * Add docstring with non-obvious context
…8) (#47) If the current user has a `db_role`, they should only see query results that they have generated, so that they don't see results which contain info about resources they don't have permission to view. feat: use per-user db role for query exec (ENG-2474) (#48) * feat: use per-user db role for query exec (ENG-2474) Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries. * Reject login from unknown SSO users * Use pre-filtered query for QueryResults rather than session-level `set role` * Add docstring with non-obvious context
…8) (#47) If the current user has a `db_role`, they should only see query results that they have generated, so that they don't see results which contain info about resources they don't have permission to view. feat: use per-user db role for query exec (ENG-2474) (#48) * feat: use per-user db role for query exec (ENG-2474) Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries. * Reject login from unknown SSO users * Use pre-filtered query for QueryResults rather than session-level `set role` * Add docstring with non-obvious context
Login with per-user PG database role, if available, to ensure that RLS policies are applied to user queries. Also changes how the
redash.query_results
table is filtered, since setting the role for the entire session broke saving queries (and probably some other things) due to the rest of the entire request session losing access to all of the other Redash tables.Depends on: https://github.com/stacklet/platform/pull/1732
Tested on my sandbox with my non-admin SSO user and manually injected account mappings. Confirmed that the user could only get query results from the
resources
table that they had an account mapping for, and that they could neither see query results generated by other users, nor directly query theredash.query_results
table and see anything other than their own records.