-
Notifications
You must be signed in to change notification settings - Fork 14k
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(sql lab): SQL Lab access restrictions not applied to default schema #20285
fix(sql lab): SQL Lab access restrictions not applied to default schema #20285
Conversation
@@ -1054,19 +1054,24 @@ def raise_for_access( | |||
denied = set() | |||
|
|||
for table_ in tables: | |||
schema_perm = self.get_schema_perm(database, schema=table_.schema) |
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.
table._schema
could be the one defined in the query itself, or the one selected on the left dropdown.
For that reason, we could be fetching the permission for a schema that does not contain the table, and validate the request (if the user has permission to that schema).
So, we invert the request order here, by querying all the datasources for the database/table combination, and then matching the schema. If there's a match, then we check the permission on that schema.
ac26cc5
to
da23b76
Compare
ec3638d
to
0c424f7
Compare
Codecov Report
@@ Coverage Diff @@
## master #20285 +/- ##
===========================================
- Coverage 66.83% 55.23% -11.61%
===========================================
Files 1750 1750
Lines 65894 65899 +5
Branches 7017 7017
===========================================
- Hits 44041 36399 -7642
- Misses 20067 27714 +7647
Partials 1786 1786
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
d00af63
to
6847399
Compare
9cdd673
to
0869f44
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 found test case where this won't work.
self.get_session, database, table_.table, schema=table_.schema | ||
) | ||
# Access to any datasource is suffice. | ||
for datasource_ in datasources: |
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.
@diegomedina248 I tested this out what I found is the way this reads now, if datasources is empty, i.e., there are no datasets created for this table, they will hit line 1074 and not get access to the schema.
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.
Good catch! I amended the PR to account for it.
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.
Though.. I think the same happens with the current code, unless I'm reading it wrong
56dc739
to
ebc8333
Compare
ebc8333
to
3c7ae32
Compare
@eschutho if you wouldn't mind checking/accepting/amending the change requests, that would be much appreciated. Looks like this'll need a little rebase action as well :D |
I just checked with @yousoph on whether we should be fetching from the schema in the dropdown when not specified in the sql statement, which we're not doing. |
SUMMARY
The schema level restrictions are not working properly in SQL Lab, when the default schema is used. Some DB Engines allow users to execute a query without specifying the Schema, in which default Schema will be queried.
In the permission check, we're assigning the schema from two sources: the query itself, or if it's not present, the schema selected on the left hand side in SQL Lab.
It's the second scenario that's not properly checked, because, if the user has schema permission for the one selected, and if the query can be executed in the engine without specifying the schema explicitly, then the permission check will allow said execution, since there's a permission for the schema.
This PR alters the order of checks, so that we validate that the default schema actually contains the table we're trying to query, and then check the permission on said datasource.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before:
Screen.Recording.2022-06-06.at.17.31.02.mov
After:
Screen.Recording.2022-06-06.at.17.32.41.mov
TESTING INSTRUCTIONS
examples
as database andinformation_schema
as schemaExecute these two queries:
Ensure both fail with a forbidden error.
ADDITIONAL INFORMATION