-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Allow system tables to do system level access control #24726
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 |
|---|---|---|
|
|
@@ -15,11 +15,17 @@ | |
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import io.trino.FullConnectorSession; | ||
| import io.trino.plugin.base.MappedPageSource; | ||
| import io.trino.plugin.base.MappedRecordSet; | ||
| import io.trino.security.AccessControl; | ||
| import io.trino.security.InjectedConnectorAccessControl; | ||
| import io.trino.security.SecurityContext; | ||
| import io.trino.spi.QueryId; | ||
| import io.trino.spi.TrinoException; | ||
| import io.trino.spi.connector.ColumnHandle; | ||
| import io.trino.spi.connector.ColumnMetadata; | ||
| import io.trino.spi.connector.ConnectorAccessControl; | ||
| import io.trino.spi.connector.ConnectorPageSource; | ||
| import io.trino.spi.connector.ConnectorPageSourceProvider; | ||
| import io.trino.spi.connector.ConnectorSession; | ||
|
|
@@ -44,17 +50,22 @@ | |
| import static com.google.common.collect.ImmutableList.toImmutableList; | ||
| import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR; | ||
| import static io.trino.spi.StandardErrorCode.NOT_FOUND; | ||
| import static io.trino.spi.connector.SystemTable.Distribution.ALL_NODES; | ||
| import static java.lang.String.format; | ||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class SystemPageSourceProvider | ||
| implements ConnectorPageSourceProvider | ||
| { | ||
| private final SystemTablesProvider tables; | ||
| private final AccessControl accessControl; | ||
| private final String catalogName; | ||
|
|
||
| public SystemPageSourceProvider(SystemTablesProvider tables) | ||
| public SystemPageSourceProvider(SystemTablesProvider tables, AccessControl accessControl, String catalogName) | ||
| { | ||
| this.tables = requireNonNull(tables, "tables is null"); | ||
| this.accessControl = requireNonNull(accessControl, "accessControl is null"); | ||
| this.catalogName = requireNonNull(catalogName, "catalogName is null"); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -105,8 +116,31 @@ public ConnectorPageSource createPageSource( | |
| TupleDomain<Integer> newConstraint = systemSplit.getConstraint().transformKeys(columnHandle -> | ||
| columnsByName.get(((SystemColumnHandle) columnHandle).columnName())); | ||
|
|
||
| ConnectorAccessControl accessControl1 = new InjectedConnectorAccessControl( | ||
| accessControl, | ||
| new SecurityContext( | ||
| systemTransaction.getTransactionId(), | ||
| ((FullConnectorSession) session).getSession().getIdentity(), | ||
| QueryId.valueOf(session.getQueryId()), | ||
| session.getStart()), | ||
| catalogName); | ||
| try { | ||
| return new MappedPageSource(systemTable.pageSource(systemTransaction.getConnectorTransactionHandle(), session, newConstraint), userToSystemFieldIndex.build()); | ||
| // Do not pass access control for tables that execute on workers | ||
|
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. Why so? I think we should put pass it too. Workers have access control, which could be different than on coordinator but still. Or maybe we could pass Also I think we should not care here about the access control. It is not the proper layer. The thing is in the guice context, and it is used in other places so I think we are fine to use it too here.
Member
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.
Effectively, this works like that because
I'm sorry, I don't understand this comment. Where should we not care about access control? in the
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 believe that is a guice context responsiblity to provide proper implementation of access control. I access control is incorrect on worker, it should not be bounded in guice. If worker is using only part of the of the access control, then it should maybe use something else. My point is that here we are a dealing with a bigger design problem. Basically, I believe no access control should be available on the worker. However it is a preexisting issue that goes well beyond this PR. |
||
| if (systemTable.getDistribution().equals(ALL_NODES)) { | ||
| return new MappedPageSource( | ||
| systemTable.pageSource( | ||
| systemTransaction.getConnectorTransactionHandle(), | ||
| session, | ||
| newConstraint), | ||
| userToSystemFieldIndex.build()); | ||
| } | ||
| return new MappedPageSource( | ||
| systemTable.pageSource( | ||
| systemTransaction.getConnectorTransactionHandle(), | ||
| session, | ||
| newConstraint, | ||
| accessControl1), | ||
| userToSystemFieldIndex.build()); | ||
| } | ||
| catch (UnsupportedOperationException e) { | ||
| return new RecordPageSource(new MappedRecordSet( | ||
|
|
@@ -116,7 +150,8 @@ public ConnectorPageSource createPageSource( | |
| session, | ||
| newConstraint, | ||
| requiredColumns.build(), | ||
| systemSplit), | ||
| systemSplit, | ||
| accessControl1), | ||
| userToSystemFieldIndex.build())); | ||
| } | ||
| } | ||
|
|
@@ -127,7 +162,8 @@ private static RecordSet toRecordSet( | |
| ConnectorSession session, | ||
| TupleDomain<Integer> constraint, | ||
| Set<Integer> requiredColumns, | ||
| ConnectorSplit split) | ||
| ConnectorSplit split, | ||
| ConnectorAccessControl accessControl1) | ||
| { | ||
| return new RecordSet() | ||
| { | ||
|
|
@@ -144,7 +180,11 @@ public List<Type> getColumnTypes() | |
| @Override | ||
| public RecordCursor cursor() | ||
| { | ||
| return table.cursor(sourceTransaction, session, constraint, requiredColumns, split); | ||
| // Do not pass access control for tables that execute on workers | ||
| if (table.getDistribution().equals(ALL_NODES)) { | ||
| return table.cursor(sourceTransaction, session, constraint, requiredColumns, split); | ||
| } | ||
| return table.cursor(sourceTransaction, session, constraint, requiredColumns, split, accessControl1); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.