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

Add setFunctionOwner to SystemSecurityMetadata #24696

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

homar
Copy link
Member

@homar homar commented Jan 13, 2025

Description

Possibility to set ownership was already present for tables and views, so I am adding it to functions

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:

## Section
* Add support for functions ownership 

@cla-bot cla-bot bot added the cla-signed label Jan 13, 2025
@homar homar force-pushed the homar/add_setFunctionOwner branch 3 times, most recently from ca57a41 to f3b4bf0 Compare January 15, 2025 19:16
@homar homar force-pushed the homar/add_setFunctionOwner branch from f3b4bf0 to ceca747 Compare January 16, 2025 09:57
@homar homar changed the title test Add setFunctionOwner to SystemSecurityMetadata Jan 16, 2025
@homar homar marked this pull request as ready for review January 16, 2025 10:03
@homar homar requested review from ksobolew, kokosing and Dith3r January 16, 2025 10:03
Comment on lines -2715 to +2724
metadata.createLanguageFunction(session.toConnectorSession(catalogHandle), name.asSchemaFunctionName(), function, replace);
SchemaFunctionName schemaFunctionName = name.asSchemaFunctionName();
if (catalogMetadata.getSecurityManagement() == SYSTEM) {
systemSecurityMetadata.setFunctionOwner(
session,
new CatalogSchemaFunctionName(catalogHandle.getCatalogName().toString(), schemaFunctionName),
new TrinoPrincipal(PrincipalType.USER, session.getUser()));
}

metadata.createLanguageFunction(session.toConnectorSession(catalogHandle), schemaFunctionName, function, replace);
Copy link
Contributor

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.

@@ -552,6 +552,44 @@ public void testJoinBaseTableWithView()
assertAccessAllowed(viewOwnerSession, "DROP VIEW " + viewName);
}

@Test
public void testFunctionOwners()
Copy link
Contributor

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.

String functionOwner = "function_owner";
TrinoPrincipal functionOwnerPrincipal = new TrinoPrincipal(USER, functionOwner);

systemSecurityMetadata.grantRoles(getSession(), Set.of("function_owner_role"), Set.of(functionOwnerPrincipal), false, Optional.empty());
Copy link
Member

Choose a reason for hiding this comment

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

nit. ImmutableSet.of

@@ -195,6 +195,10 @@ public Optional<Identity> getFunctionRunAsIdentity(Session session, CatalogSchem
return Optional.empty();
}

@Override
public void setFunctionOwner(Session session, CatalogSchemaFunctionName view, TrinoPrincipal principal)
Copy link
Member

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.

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.

4 participants