Skip to content

Add access control for functions based on FunctionKind#12544

Merged
kokosing merged 4 commits intotrinodb:masterfrom
kasiafi:355PTFAccessControl
May 31, 2022
Merged

Add access control for functions based on FunctionKind#12544
kokosing merged 4 commits intotrinodb:masterfrom
kasiafi:355PTFAccessControl

Conversation

@kasiafi
Copy link
Copy Markdown
Member

@kasiafi kasiafi commented May 25, 2022

This is security improvement. It allows to apply different default access rules for functions based on function kind.
This is particularly useful when we add table functions, which are more powerful that other function kinds.

Should be merged before we add table functions:
#12325
#12324
#12502

This is a SPI change:
new ConnectorAccessControl method is added, and existing method is removed. An enum representing the function kind is introduced.

# Security
* Add access control for functions based on function kind.

cc @mosabua @colebow for release notes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method was not used so far. Please simply remove it. The best would be to remove the other method too (the one with function name as String)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@dain the old method was introduced a short while ago. It was only called for table function invocation analysis, but we don't have any table functions yet. I removed it in a separate commit. If you're OK with removing, I'll squash.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kokosing @kasiafi Do I understand correctly that the newly introduced method

    void checkCanExecuteFunction(SecurityContext context, FunctionKind functionKind, QualifiedObjectName functionName);

should eventually replace the old one

    void checkCanExecuteFunction(SecurityContext context, String functionName);

, so that all old functionality for AccessControls remains the same for all FunctionKinds which are not FunctionKind.TABLE?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

eventually -- yes, i think so

note however that currently function names are not qualified yet.

Copy link
Copy Markdown
Member

@dain dain left a comment

Choose a reason for hiding this comment

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

Good stuff! I have two main concerns that we should discuss:

  1. I have a PR coming up that will move FunctionKind to the SPI, so we should talk about maybe just moving that one class now, so we don't end up with two versions in the future.
  2. I'm not sure how to handle the check for table functions in the Hive SQL standard impelemtnation. I'm leaning towards isAdmin, but we could just deny.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the next section of my function refactor, I move function framework from the engine to the SPI. As part of that, I move FunctionKind to io.trino.spi.connector.function. I suggest that we just move (or clone) this class to the new location now... assuming are all happy with my proposed target location.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I moved FunctionKind to io.trino.spi.function. Or did you mean I should create a new package function under connector?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be deny for table functions until file-based-rules are added that cover functions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be deny for table functions until file-based-rules are added that cover functions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be deny for table functions. Later when someone adds a table function for Hive we can discuss how to handle this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure what the behavior should be here. My gut instinct it to restrict this to isAdmin(context) or just deny. I think that is admin is a reasonable first step. Also, I don't think Hive has any table functions right now, so even flat deny should be fine until someone adds one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

restricted to admin

@kasiafi kasiafi force-pushed the 355PTFAccessControl branch 2 times, most recently from c1de7f9 to 7908a08 Compare May 27, 2022 09:12
@kasiafi kasiafi requested review from dain and kokosing May 27, 2022 12:08
Copy link
Copy Markdown
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

I would squash deprecation and method removal into single commit

kasiafi added 4 commits May 28, 2022 10:32
This change adds an AccessControl method for functions using
the function kind. The analogous method without the FunctionKind
argument is removed.

Access control based on function kind is needed because table functions
are much more powerful than other function kinds, so it should be
possible to easily deny executing all table functions while allowing
all other functions.

The new method is currently used only for table funcitons.

This change also adds default implementations of function access control
in SystemAccessControl and ConnectorAccessControl that deny executing
table functions.
@kasiafi kasiafi force-pushed the 355PTFAccessControl branch from 7908a08 to 011687f Compare May 28, 2022 08:42
@kokosing kokosing merged commit 12dda62 into trinodb:master May 31, 2022
@github-actions github-actions bot added this to the 383 milestone May 31, 2022
@colebow
Copy link
Copy Markdown
Member

colebow commented Jun 1, 2022

Do we need to document this yet? Or should we just wait for table functions?

utk-spartan added a commit to razorpay/ranger that referenced this pull request Jun 2, 2022
Incorporate following changes

Introduce access control for functions based on FunctionKind
trinodb/trino#12544
trinodb/trino@12dda62
@kasiafi
Copy link
Copy Markdown
Member Author

kasiafi commented Jun 27, 2022

Do we need to document this yet? Or should we just wait for table functions?

@colebow we should document it, as it is currently used for table functions.
The new method will be eventually used for all kinds of functions (see: #12544 (comment)), but it requires refactoring the way that functions are registered and resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

6 participants