-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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: safer insert RLS #20323
feat: safer insert RLS #20323
Conversation
Codecov Report
@@ Coverage Diff @@
## master #20323 +/- ##
==========================================
+ Coverage 66.87% 66.88% +0.01%
==========================================
Files 1847 1847
Lines 70561 70584 +23
Branches 7739 7739
==========================================
+ Hits 47186 47209 +23
Misses 21374 21374
Partials 2001 2001
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
4e0b670
to
19a4c6f
Compare
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.
I think this is a great improvement, as practically all modern databases nowadays should be able to push down predicates into subqueries without any performance issues. I remember old versions of MSSQL or Oracle being horrible at these, but I believe even recent versions of these have improved this functionality.
I didn't try this out yet, but I really just have one concern regarding potential problems with aliases. If aliases are handled ok then I think this is good to go (I'm happy to do a proper test pass after we add a few test cases for queries with aliases).
19a4c6f
to
75e7c9e
Compare
5e6a4d8
to
7f5c8a2
Compare
12af22c
to
d792a77
Compare
d792a77
to
776ae4a
Compare
SUMMARY
We currently have a feature flag
RLS_IN_SQLLAB
that, when enabled, applies any relevant RLS rules to the SQL executed in SQL Lab. The current approach parses the SQL and extracts all tables being queried. If any of those tables have RLS rules associated with them the parse tree is modified inplace, appending the RLS predicate to the associatedWHERE
clause or creating a new one if needed.@mistercrunch suggested an approach that is more bulletproof: replacing the table reference (eg,
my_table
) with a subquery that contains the RLS (SELECT * FROM my_table WHERE rls
). This can be done conditionally on databases that support subqueries. I implemented that solution in this PR.Note that this method is probably still not bulletproof. We're still using
sqlparse
to find table references, and this has been error-prone in the past. For example, we had problems where the identifier "RAW" was not detected properly becausesqlparse
considers it a reserved keyword, since it doesn't have separate lists of keywords for each dialect.This PR and the original implementation are both conservative in cases like these, trying to figure out if a keyword is actually and identifier, and the unit tests cover such cases. But we should consider this feature experimental, and warn users that there are risks associated with using it.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TESTING INSTRUCTIONS
Added unit tests.
ADDITIONAL INFORMATION