Skip to content
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

Change SQL path to match spec #19160

Merged
merged 14 commits into from
Oct 5, 2023
Merged

Change SQL path to match spec #19160

merged 14 commits into from
Oct 5, 2023

Conversation

dain
Copy link
Member

@dain dain commented Sep 26, 2023

Description

Update the function resolution usage of SQL path to match the specification. The path is now stored in views, and view expression (for pushdown). If the view does not have a path then the only system.builtin is visible. Unauthorized SQL path element are now skipped in function resolution, so authorized functions later in the path are now considered. In order to make thes changes, function security APIs and implementations have been changed as follows

  • No security checks are performed for functions in system.builtin. These functions are considered safe for all users and are typically required for the engine to function properly.
  • Return boolean from catalog access check calls instead of throwing as this is not longer a fatal issues
  • Return boolean from function check calls instead of throwing as this is not longer a fatal issues
  • Merge simple function checks with table function check as functions draw from the same namespace
  • Add canCreateViewWithExecuteFunction for use in ViewAccessControl which replaces the former checkCanGrant method
  • The plugin loader now fails loading if a system or catalog access control defines any of the removed methods as a safety mechanism, so are required for any existing implementations.
  • File based access control is not allowed to have a function kind element in rules, since it is not supported anymore
  • Path is stored with view-like structures, and there are specialized methods on Session to create a new session for the view context.

Release notes

(x) Release notes are required, with the following suggested text:

# Security
* Security checks are no longer executed for functions in `system.builtin`. ({issue}`19160`)
* Function rules in file based access control no longer support function kind.  See documentation for more details.  ({issue}`19160`)

# SPI
* Function security checks now return a boolean instead of throwing an exception. ({issue}`19160`)
* Add SQL path field to `ConnectorViewDefinition`, `ConnectorMaterializedViewDefinition`, and `ViewExpression`. ({issue}`19160`)

@cla-bot cla-bot bot added the cla-signed label Sep 26, 2023
@github-actions github-actions bot added tests:hive hive Hive connector labels Sep 26, 2023
@dain dain force-pushed the sql-path branch 3 times, most recently from 917c7b5 to 0ec7a37 Compare September 29, 2023 04:22
@github-actions github-actions bot added the docs label Sep 29, 2023
@dain dain force-pushed the sql-path branch 6 times, most recently from 960e042 to 6d30d53 Compare October 3, 2023 01:24
@github-actions github-actions bot added the iceberg Iceberg connector label Oct 3, 2023
@dain dain force-pushed the sql-path branch 2 times, most recently from 6747413 to 5b6afe4 Compare October 3, 2023 20:36
@dain dain requested a review from electrum October 3, 2023 22:19
@dain dain changed the title WIP: Sql path cleanup Change SQL path to match spec Oct 4, 2023
@dain dain force-pushed the sql-path branch 3 times, most recently from f5461e8 to 9f84275 Compare October 4, 2023 21:04
dain added 8 commits October 4, 2023 20:48
A single transaction must be used for plan building and assertion
Simplify function access control methods for better integration with
catalog functions.
* Return boolean from catalog access check calls instead of throwing
* Return boolean from function check calls instead of throwing
* Merge simple function checks with table function check
* Add canCreateViewWithExecuteFunction for use in ViewAccessControl
@dain dain merged commit 02c96f8 into trinodb:master Oct 5, 2023
@dain dain deleted the sql-path branch October 5, 2023 05:56
@github-actions github-actions bot added this to the 429 milestone Oct 5, 2023
@findepi
Copy link
Member

findepi commented Oct 18, 2023

Merge simple function checks with table function check as functions draw from the same namespace

I agree that they draw from the same namespace but that doesn't mean implementors want to have same logic.
For example, it's easy to imagine security checks that allow all scalars by default (because scalars are inherently safe due to how they operate on values processed by the query anyway), and disallow all table functions by default (as these are inherently not safe, especially the leaf table functions).

Can you advise how such a logic should be implemented?

Further, the change seems to introduce a side-effect which may be considered a security problem.
In previous Trino version, file-based AC required full catalog access to execute a table function (even if no function rules were defined).

AccessMode requiredCatalogAccess = switch (functionKind) {
case SCALAR, AGGREGATE, WINDOW -> READ_ONLY;
case TABLE -> ALL;
};
Identity identity = context.getIdentity();
return canAccessCatalog(context, functionName.getCatalogName(), requiredCatalogAccess) &&

Trino 429 lowers that to require read only access.
(This hopefully isn't a big deal given all currently existing builtin table function are read-only, but worth calling out as a breaking change in release notes for anyone that has custom table functions in their plugins)

@martint
Copy link
Member

martint commented Oct 18, 2023

(because scalars are inherently safe due to how they operate on values processed by the query anyway), and disallow all table functions by default (as these are inherently not safe, especially the leaf table functions)

This assumption is incorrect. There’s nothing about scalar functions that makes them inherently safe vs table functions. The only difference between them is that one processes single values, while the other processes sequences of values. Both could very easily do unsafe things if they wanted to and their implementation allowed it (e.g., make external calls, read files, etc.)

In fact, one of the changes we’re planning in the future will allow scalar functions to be callable in batches, making them no different than a table function.

{
wrapAccessDeniedException(() -> delegate.checkCanGrantExecuteFunctionPrivilege(context, functionName, invoker, false));
return delegate.canCreateViewWithExecuteFunction(context, functionName);
Copy link
Contributor

@okayhooni okayhooni Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @dain , is it intended to use delegate.canCreateViewWithExecuteFunction() instead of delegate.canExecuteFunction() here..? (I guess it is intended to use VIEW DEFINER permission by default)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed docs hive Hive connector iceberg Iceberg connector
Development

Successfully merging this pull request may close these issues.

5 participants