-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add checkCanGrantExecuteFunctionPrivilege to ConnectorAccessControl #14191
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ | |
| import java.util.Set; | ||
|
|
||
| import static io.trino.SessionTestUtils.TEST_SESSION; | ||
| import static io.trino.spi.function.FunctionKind.TABLE; | ||
| import static io.trino.spi.security.AccessDeniedException.denySelectTable; | ||
| import static io.trino.spi.type.BigintType.BIGINT; | ||
| import static io.trino.testing.TestingEventListenerManager.emptyEventListenerManager; | ||
|
|
@@ -186,6 +187,29 @@ public void testDenyCatalogAccessControl() | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testDenyTableFunctionCatalogAccessControl() | ||
| { | ||
| try (LocalQueryRunner queryRunner = LocalQueryRunner.create(TEST_SESSION)) { | ||
| TransactionManager transactionManager = queryRunner.getTransactionManager(); | ||
| AccessControlManager accessControlManager = createAccessControlManager(transactionManager); | ||
|
|
||
| TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("test"); | ||
| accessControlManager.addSystemAccessControlFactory(accessControlFactory); | ||
| accessControlManager.loadSystemAccessControl("allow-all", ImmutableMap.of()); | ||
|
|
||
| queryRunner.createCatalog(TEST_CATALOG_NAME, MockConnectorFactory.create(), ImmutableMap.of()); | ||
| accessControlManager.setConnectorAccessControlProvider(CatalogServiceProvider.singleton(TEST_CATALOG_HANDLE, Optional.of(new DenyConnectorAccessControl()))); | ||
|
|
||
| assertThatThrownBy(() -> transaction(transactionManager, accessControlManager) | ||
| .execute(transactionId -> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be What about testing checkCanExecuteFunction?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is already checked in other tests |
||
| accessControlManager.checkCanGrantExecuteFunctionPrivilege(context(transactionId), TABLE, new QualifiedObjectName(TEST_CATALOG_NAME, "example_schema", "executed_function"), Identity.ofUser("bob"), true); | ||
| })) | ||
| .isInstanceOf(TrinoException.class) | ||
| .hasMessageMatching("Access Denied: 'user_name' cannot grant 'example_schema\\.executed_function' execution to user 'bob'"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testColumnMaskOrdering() | ||
| { | ||
|
|
@@ -449,6 +473,20 @@ public void testAllowExecuteFunction() | |
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAllowExecuteTableFunction() | ||
| { | ||
| TransactionManager transactionManager = createTestTransactionManager(); | ||
| AccessControlManager accessControlManager = createAccessControlManager(transactionManager); | ||
| accessControlManager.loadSystemAccessControl("allow-all", ImmutableMap.of()); | ||
|
|
||
| transaction(transactionManager, accessControlManager) | ||
| .execute(transactionId -> { | ||
| accessControlManager.checkCanExecuteFunction(context(transactionId), TABLE, new QualifiedObjectName(TEST_CATALOG_NAME, "example_schema", "executed_function")); | ||
| accessControlManager.checkCanGrantExecuteFunctionPrivilege(context(transactionId), TABLE, new QualifiedObjectName(TEST_CATALOG_NAME, "example_schema", "executed_function"), Identity.ofUser("bob"), true); | ||
| }); | ||
| } | ||
|
|
||
| private AccessControlManager createAccessControlManager(TestingEventListenerManager eventListenerManager, List<String> systemAccessControlProperties) | ||
| throws IOException | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -468,6 +468,18 @@ public void checkCanRenameMaterializedView(ConnectorSecurityContext context, Sch | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void checkCanGrantExecuteFunctionPrivilege(ConnectorSecurityContext context, FunctionKind functionKind, SchemaRoutineName functionName, TrinoPrincipal grantee, boolean grantOption) | ||
| { | ||
| switch (functionKind) { | ||
| case SCALAR, AGGREGATE, WINDOW: | ||
| return; | ||
| case TABLE: | ||
| denyExecuteFunction(functionName.toString()); | ||
| } | ||
| throw new UnsupportedOperationException("Unsupported function kind: " + functionKind); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am under impression that this throw is not needed. However, it leaves no question that is a dead code. Or maybe you can use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to say the same, but the return value is |
||
| } | ||
|
|
||
| @Override | ||
| public void checkCanSetMaterializedViewProperties(ConnectorSecurityContext context, SchemaTableName materializedViewName, Map<String, Optional<Object>> properties) | ||
| { | ||
|
|
||
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.
could you please verify that you have access before setting DenyConnectorAccessControl?
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 is checked in
testAllowExecuteTableFunctiontestThere 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.
Yeah, I'd prefer to have these tests duplicated, than not to have it here.
It would underline that
just before setting DenyConnectorAccessControl it was possible to select from that connector. Actually that's @kokosing's style.