-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Propagate function lifecycle events to SystemSecurityMetadata #24696
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
Conversation
f3b4bf0 to
ceca747
Compare
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.
With views it's done differently - there's a tableCreated callback function, which is (presumably) used to update the ownership. The setXOwner methods are called in response to ALTER X SET AUTHORIZATION commands, instead (which we don't have here). Note that the actual function is created by the connector metadata, which is a factor too.
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 test is fine, but it could take some inspiration for the existing tests for views. For example, those tests are also checking things like: the access to the underlying resources (here: my_test_function_inner) is only checked on query/execute, not during creation. Though it could be different for functions.
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.
nit. ImmutableSet.of
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.
I think you need to follow the convention here. Instead of saying what you want to do on event, you should simply emit the event and handle what you want in the implementation.
So you should emit events, when function is created, dropped or renamed. Like for any other object.
d70bdfa to
9566b40
Compare
abc7ec8 to
6bd0903
Compare
ksobolew
left a 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.
Apart from nits LGTM
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.
Nit: keep formatting consistent
| @Override | |
| public void functionCreated(Session session, CatalogSchemaFunctionName function, TrinoPrincipal principal) | |
| {} | |
| @Override | |
| public void functionCreated(Session session, CatalogSchemaFunctionName function, TrinoPrincipal principal) {} |
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.
These callbacks should be done as the last thing, specifically after the actual update (here: after metadata.createLanguageFunction is called)
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.
It is called later, here we just prepare a lambda function, it is invoked much 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.
I'm sorry, I don't see any lambda...
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.
nvm, my bad i looked at a wrong place, sorry for the confusion
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.
| @Override | |
| public void functionCreated(Session session, CatalogSchemaFunctionName function, TrinoPrincipal principal) | |
| { } | |
| @Override | |
| public void functionCreated(Session session, CatalogSchemaFunctionName function, TrinoPrincipal principal) {} |
ffe40a9 to
48488b8
Compare
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.
I mean these two statements should be switched, per convention at least:
| if (catalogMetadata.getSecurityManagement() == SYSTEM) { | |
| systemSecurityMetadata.functionCreated( | |
| session, | |
| new CatalogSchemaFunctionName(catalogHandle.getCatalogName().toString(), schemaFunctionName), | |
| new TrinoPrincipal(PrincipalType.USER, session.getUser())); | |
| } | |
| metadata.createLanguageFunction(session.toConnectorSession(catalogHandle), schemaFunctionName, function, replace); | |
| metadata.createLanguageFunction(session.toConnectorSession(catalogHandle), schemaFunctionName, function, replace); | |
| if (catalogMetadata.getSecurityManagement() == SYSTEM) { | |
| systemSecurityMetadata.functionCreated( | |
| session, | |
| new CatalogSchemaFunctionName(catalogHandle.getCatalogName().toString(), schemaFunctionName), | |
| new TrinoPrincipal(PrincipalType.USER, session.getUser())); | |
| } |
bc2bc9f to
23c06c4
Compare
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.
Is there an operation which this method should be used by? There's not ALTER FUNCTION .. SET AUTHORIZATION for functions so I don't think there is such operation.
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.
What's principal for? Isn't session enough to get the identity of the creator of the function?
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.
following convention from other methods
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.
ok i got it, fixed, thanks
8c12f07 to
35808fb
Compare
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.
(identity, function)
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.
Is this needed if there's also:
assertAccessAllowed(
functionOwnerSession,
"CREATE FUNCTION memory.default.my_test_function_inner (x integer) RETURNS bigint RETURN x + 42");?
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.
yes, io.trino.security.TestingSystemSecurityMetadata#functionCreated is empty
This was suggested by @ksobolew to follow the convention
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.
it was during offline conversation when I asked him about #24696 (comment) and #24696 (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.
How about a check with the default session?
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.
What would be the point of such a test? Verification if a function can be created is out of scope for this commit
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.
It's a fairly complicated test case so maybe it's worth adding a few comments.
As I understand here the default session gets access denied because the function owner got access denied on the inner function, correct?
920046d to
8832645
Compare
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.
Please improve a commit message and pull request title and description. It is more about propagating events of function creation than handling onwnership.
core/trino-main/src/main/java/io/trino/metadata/DisabledSystemSecurityMetadata.java
Outdated
Show resolved
Hide resolved
8832645 to
b6ded27
Compare
kokosing
left a 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.
Please fix the PR description to not to mention anything about ownerhship.
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.
I don't think it is correct testing of the functionality you have introduced. You need to check if events are propagated. It has not much to do with "ownership". It is a different layer. You need a test similar to io.trino.execution.TestBeginQuery. Then you don't need any changes in TestingAccessControlManager too.
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.
I have discussed this with @lukasz-walkiewicz and now I understand why it was added.
Please use functionCreated and functionDropped in testing access control and extract the case with DENY to inner function as separate test case. This test is getting quite complex as we are reusing entities for different test cases.
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.
I was about to add another test
fe976ee to
1d94fd5
Compare
ksobolew
left a 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.
Looks like now we have more extensive tests for functions than for views :)
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.
| .setIdentity(Identity.forUser(functionOwner) | |
| .build()) | |
| .setIdentity(Identity.ofUser(functionOwner)) |
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.
Nit: just to be extra-safe, you could add an assertion that with the same denied privilege you are not allowed to call the inner function directly
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.
Did you mean to deny it here?
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.
fixed
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.
I'm not sure this is what @kokosing had in mind, but this name is not right. It's more about roles than denying.
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.
| .setIdentity(Identity.forUser(functionOwner1) | |
| .build()) | |
| .setIdentity(Identity.ofUser(functionOwner1)) |
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.
| .setIdentity(Identity.forUser(functionOwner2) | |
| .build()) | |
| .setIdentity(Identity.ofUser(functionOwner2)) |
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.
Isn't this test duplicated now?
1d94fd5 to
c55ff9f
Compare
ksobolew
left a 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.
Re-approved from my side :)
| @Test | ||
| public void testAllowCallFunction() | ||
| { | ||
| reset(); |
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.
nit. it already pre-exisiting, but we could do this as part of @Before method. Maybe an idea for a follow-up?
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.
PTAL #24852
|
Thank you! Merged. |
Description
Propagate function lifecycle events sucha as create function and drop function to SystemSecurityMetadata
Additional context and related issues
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text: