-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Verify SQL MERGE access control checks #13664
Verify SQL MERGE access control checks #13664
Conversation
0ecc938
to
ff18825
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.
Other than the formatting issue, looks good
testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java
Outdated
Show resolved
Hide resolved
ff18825
to
4560ff9
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.
These should move to TestAccessControl
, as discussed offline. We don't need test data since we are only testing access control checks, not the merge functionality. I created #13665 which allows testing the positive case.
4560ff9
to
c342350
Compare
@electrum suggested that I move this test to I added another commit to the start of my PR that moves the MERGE access control checks up to the top of @electrum produced an ersatz implementation of MERGE for Blackhole, and maybe that makes sense as a followup. But at this point, I’m mildly in favor of merging my existing PR, now with the commit that does access checks earlier. |
I don't see how that PR can work, because the body of |
It works because the Black Hole connector doesn't store or produce data (unless you ask it to produce nulls), so there is nothing to match or update. You can see that |
c342350
to
fbec671
Compare
I rebased on top of tip master, which has @electrum's ersatz implementation of MERGE for the Blackhole connector. That let me remove the test from I think this now satisfies the concerns raised, and is ready to merge. |
.findFirst() | ||
.ifPresent(mergeCase -> accessControl.checkCanDeleteFromTable(session.toSecurityContext(), tableName)); | ||
|
||
ImmutableSet.Builder<String> allUpdateColumnNamesBuilder = ImmutableSet.builder(); |
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.
Nit: we can use HashSet
here with the variable named allUpdateColumnNames
since we are just building this to pass to a function. Using an immutable builder is overkill and makes the code harder to read.
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.
Changed.
|
||
assertUpdate(format("CREATE TABLE %s (nation_name VARCHAR, region_name VARCHAR)", targetTable)); | ||
|
||
assertUpdate(format("INSERT INTO %s (nation_name, region_name) VALUES ('FRANCE', 'EUROPE'), ('ALGERIA', 'AFRICA'), ('GERMANY', 'EUROPE')", targetTable), 3); |
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.
No need to insert data, since we aren't testing the actual merge functionality, and the blackhole connector will discard the data anyway. (so it's confusing to the reader as to why we do 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.
Removed.
assertUpdate("DROP TABLE " + targetTable); | ||
} | ||
|
||
private void withPrivilegeDenied(String tableName, TestingPrivilegeType type, Runnable runnable) |
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.
We shouldn't need this method
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.
Removed.
|
||
// Show that without SELECT on the source table, the MERGE fails regardless of which case is included | ||
for (String mergeCase : ImmutableList.of(deleteCase, updateCase, insertCase)) { | ||
withPrivilegeDenied(sourceTable, SELECT_COLUMN, () -> |
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.
Use assertAccessDenied
, like the other tests in this class.
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.
Changed.
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 overall. A few minor comments. Thanks for updating this.
Blackhole should be able to run the final |
fbec671
to
2574eb0
Compare
Added. |
This commit adds a MERGE test in TestAccessControl that verifies that in order execute a MERGE, you must have appropriate access control rights. Specifically, if there is a source table, you must have SELECT on the table columns referenced; if the MERGE does inserts, you must have INSERT on the target table; if the MERGE does deletes you must have DELETE on the target table; and if the MERGE does updates, you must have UPDATE on the target table.
2574eb0
to
6ddca49
Compare
Thanks! |
Description
This commit adds a MERGE test in BaseConnectorTest that verifies
that in order execute a MERGE, you must have appropriate access
control rights. Specifically, if there is a source table, you must
have SELECT on the table columns referenced; if the MERGE does
inserts, you must have INSERT on the target table; if the MERGE
does deletes you must have DELETE on the target table; and if
the MERGE does updates, you must have UPDATE on the target
table.
It is an added test.
None of the above.
Related issues, pull requests, and links
Documentation
(x) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.
Release notes
(x) No release notes entries required.
( ) Release notes entries required with the following suggested text: