-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Enable check query integrity permission check for all query types #26096
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
Merged
kevintang2022
merged 1 commit into
prestodb:master
from
kevintang2022:enable-query-integrity-check-for-all-types
Oct 3, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...rc/main/java/com/facebook/presto/security/DenyQueryIntegrityCheckSystemAccessControl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.facebook.presto.security; | ||
|
|
||
| import com.facebook.presto.common.QualifiedObjectName; | ||
| import com.facebook.presto.spi.CatalogSchemaTableName; | ||
| import com.facebook.presto.spi.MaterializedViewDefinition; | ||
| import com.facebook.presto.spi.analyzer.ViewDefinition; | ||
| import com.facebook.presto.spi.security.AccessControlContext; | ||
| import com.facebook.presto.spi.security.Identity; | ||
| import com.facebook.presto.spi.security.SystemAccessControl; | ||
| import com.facebook.presto.spi.security.SystemAccessControlFactory; | ||
|
|
||
| import java.security.Principal; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| import static com.facebook.presto.spi.security.AccessDeniedException.denyQueryIntegrityCheck; | ||
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class DenyQueryIntegrityCheckSystemAccessControl | ||
| implements SystemAccessControl | ||
| { | ||
| public static final String NAME = "deny-query-integrity-check"; | ||
|
|
||
| private static final DenyQueryIntegrityCheckSystemAccessControl INSTANCE = new DenyQueryIntegrityCheckSystemAccessControl(); | ||
|
|
||
| public static class Factory | ||
| implements SystemAccessControlFactory | ||
| { | ||
| @Override | ||
| public String getName() | ||
| { | ||
| return NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public SystemAccessControl create(Map<String, String> config) | ||
| { | ||
| requireNonNull(config, "config is null"); | ||
| checkArgument(config.isEmpty(), "This access controller does not support any configuration properties"); | ||
| return INSTANCE; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void checkQueryIntegrity(Identity identity, AccessControlContext context, String query, Map<QualifiedObjectName, ViewDefinition> viewDefinitions, Map<QualifiedObjectName, MaterializedViewDefinition> materializedViewDefinitions) | ||
| { | ||
| denyQueryIntegrityCheck(); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkCanSetUser(Identity identity, AccessControlContext context, Optional<Principal> principal, String userName) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void checkCanSetSystemSessionProperty(Identity identity, AccessControlContext context, String propertyName) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void checkCanAccessCatalog(Identity identity, AccessControlContext context, String catalogName) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> filterCatalogs(Identity identity, AccessControlContext context, Set<String> catalogs) | ||
| { | ||
| return catalogs; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<String> filterSchemas(Identity identity, AccessControlContext context, String catalogName, Set<String> schemaNames) | ||
| { | ||
| return schemaNames; | ||
| } | ||
|
|
||
| @Override | ||
| public void checkCanCreateTable(Identity identity, AccessControlContext context, CatalogSchemaTableName table) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void checkCanShowCreateTable(Identity identity, AccessControlContext context, CatalogSchemaTableName table) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void checkCanSelectFromColumns(Identity identity, AccessControlContext context, CatalogSchemaTableName table, Set<String> columns) | ||
| { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ests/src/test/java/com/facebook/presto/tests/TestCheckAccessPermissionsForQueryTypes.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.facebook.presto.tests; | ||
|
|
||
| import com.facebook.presto.security.DenyQueryIntegrityCheckSystemAccessControl; | ||
| import com.facebook.presto.testing.QueryRunner; | ||
| import com.facebook.presto.tests.tpch.TpchQueryRunnerBuilder; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| public class TestCheckAccessPermissionsForQueryTypes | ||
| extends AbstractTestQueryFramework | ||
| { | ||
| @Override | ||
| protected QueryRunner createQueryRunner() | ||
| throws Exception | ||
| { | ||
| DistributedQueryRunner queryRunner = TpchQueryRunnerBuilder.builder() | ||
| .setAccessControlProperties(ImmutableMap.of("access-control.name", DenyQueryIntegrityCheckSystemAccessControl.NAME)).build(); | ||
|
|
||
| queryRunner.loadSystemAccessControl(); | ||
|
|
||
| return queryRunner; | ||
| } | ||
|
|
||
| @Override | ||
| protected QueryRunner createExpectedQueryRunner() | ||
| throws Exception | ||
| { | ||
| QueryRunner queryRunner = TpchQueryRunnerBuilder.builder().build(); | ||
| return queryRunner; | ||
| } | ||
|
|
||
| @Test | ||
| public void testCheckQueryIntegrityCalls() | ||
| { | ||
| assertAccessDenied("select * from orders", ".*Query integrity check failed.*"); | ||
| assertAccessDenied("analyze orders", ".*Query integrity check failed.*"); | ||
| assertAccessDenied("explain analyze select * from orders", ".*Query integrity check failed.*"); | ||
| assertAccessDenied("explain select * from orders", ".*Query integrity check failed.*"); | ||
| assertAccessDenied("explain (type validate) select * from orders", ".*Query integrity check failed.*"); | ||
| assertAccessDenied("CREATE TABLE test_empty (a BIGINT)", ".*Query integrity check failed.*"); | ||
| assertAccessDenied("use tpch.tiny", ".*Query integrity check failed.*"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
sorry, I'm still confused here. doesn't this remove the queryintegrity check for all analysis, not just explain? So where is it getting called instead?
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.
CQI check does not need to be called in analysis. I think I mistakenly added this when moving the CQI call from Dispatch phase -> After analysis phase.
After adding this PR, all the QueryExecution implementations will call CQI. If you look at SqlQueryExecution, AccessControlCheckerExecution, DDLDefinitionExecution, SessionDefinitionExecution, they all call either CQI or checkAccessPermissions.
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.
As mentioned in this comment, if I don't remove this, then it will just call the CQI for every nesting of explain:
#26096 (comment)
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.
thanks for the explanation. I'll wait for the tests to be added, but the change looks good.