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

Allow hive table owner to change ownership #23842

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

Conversation

guyco33
Copy link
Member

@guyco33 guyco33 commented Oct 20, 2024

Description

Hive sql-standard security mode restricts the possibility to change ownership to admin users only, making the authorization rules almost useless.

With this PR, Hive table owners will be able to transfer the ownership to other users, similar to community databases like Postgres.

For views, only admin users will be able to transfer ownership, as by letting owners to do it, a security breach will happen while they might transfer the ownership to users that able to select sensitive masked columns (or more filtered rows) and expose themself to data that they are not allowed to query.

Actually the option for transferring ownership to other users can be achieved by letting the new owner a grant to show view code and recreate the view and become the new owner.

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:

## hive-connector
* Allow table owner to change ownership with sql-standard security mode. ({issue}`23842`)

@cla-bot cla-bot bot added the cla-signed label Oct 20, 2024
@github-actions github-actions bot added the hive Hive connector label Oct 20, 2024
@guyco33 guyco33 requested a review from kokosing October 20, 2024 13:06
@findinpath
Copy link
Contributor

@guyco33 pls sketch a bit a scenario where it makes sense to change ownership of the hive table/view and outline the current limitations of the system without your change.
Also pls consider referencing Hive documentation (if any) on how this functionality is achieved there.

@kokosing
Copy link
Member

This is related to #16691

@@ -317,7 +317,7 @@ public void checkCanAlterColumn(ConnectorSecurityContext context, SchemaTableNam
@Override
public void checkCanSetTableAuthorization(ConnectorSecurityContext context, SchemaTableName tableName, TrinoPrincipal principal)
{
if (!isAdmin(context)) {
if (!isTableOwner(context, tableName)) {
Copy link
Member

Choose a reason for hiding this comment

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

This is insecure. IMO it would introduce a vector attack for Trino that was removed in #10351 (it is on purpose not having all details).

It is not enough to see you can own the object, but we need to make sure that to what users we can grant it. See some thinking here #16691 (review)

Copy link
Member Author

@guyco33 guyco33 Oct 24, 2024

Choose a reason for hiding this comment

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

Table owner can grant any permission to any user including the WITH GRANT OPTION, so I don't understand how changing ownership that actually add the privilege to DROP the table will add a new security risk.

Same for views. If the view security mode was set to DEFINER than all masking functions and filter rules will run on behalf of the new owner privileges, so if the new owner is blocked from viewing some specific sensitive columns, all executed queries on the view will result with masked data.
Views with INVOKER security mode are executed with the privileges of the authenticated users running the queries - so no issue here.

Copy link
Member

Choose a reason for hiding this comment

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

if the new owner is blocked from viewing some specific sensitive columns

Yes. But access could be different and so it could happen that things that here not visible to original user are now accessible to that user by querying the view they created and altered (transferred ownerhsip).

Copy link
Member Author

Choose a reason for hiding this comment

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

But access could be different and so it could happen that things that here not visible to original user are now accessible to that user by querying the view they created and altered

You are right. The view owner can change the ownership to any privileged user, so we should allow it only for views created with INVOKER security mode

Copy link
Member

Choose a reason for hiding this comment

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

so we should allow it only for views created with INVOKER security mode

I am not a fan of such conditions. I would prefer to have secure security model instead. However I am not sure if it is doable in hive sql-standard.

Copy link
Member Author

Choose a reason for hiding this comment

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

Views can be recreated by a user with proper privileges to become the new owner, so I can skip this change for views and keep it for tables only.

@guyco33
Copy link
Member Author

guyco33 commented Oct 25, 2024

pls sketch a bit a scenario where it makes sense to change ownership of the hive table/view

We are using hive with sql-standard security mode as we have a common hive schema used by all users to create their private tables in a way that only the owners have privileges unless they explicitly grant permissions to other users or hive roles - (using the GRANT ... PRIVILEGES ON ... sql command)
We want the owners to be able to transfer the ownership to other users when they leave their role or when they want the tables to be populated by other applicative users.

Currently there is no option to transfer table ownership by the table owner.
Same for views, but since there is a security breach with changing views' ownership, we can implement it by allowing the new owner with the SHOW CREATE VIEW permission (by granting SELECT ... WITH GRANT OPTION) , so it will be able to recreate the view and become the new owner.

@guyco33 guyco33 changed the title Allow hive table/view owner to change ownership Allow hive table owner to change ownership Oct 25, 2024
@guyco33 guyco33 requested a review from kokosing October 25, 2024 11:56
Copy link
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.

Please squash the commits.

@dain would you like to take a look? We have discussed this issue in the past. @guyco33 wants to allow SET AUTHORIZATION for tables only, which seems IMO to be safe.

@guyco33 guyco33 force-pushed the allow_owner_set_authorization branch from 48d5664 to c0d8a16 Compare October 28, 2024 12:05
@guyco33 guyco33 force-pushed the allow_owner_set_authorization branch from c0d8a16 to a2a8dd5 Compare October 28, 2024 14:14
Copy link

This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua

@github-actions github-actions bot added the stale label Nov 18, 2024
Copy link

github-actions bot commented Dec 9, 2024

Closing this pull request, as it has been stale for six weeks. Feel free to re-open at any time.

@github-actions github-actions bot closed this Dec 9, 2024
@mosabua mosabua reopened this Jan 11, 2025
@mosabua
Copy link
Member

mosabua commented Jan 11, 2025

Given that this is already approved by @kokosing I am reopening. Hopefully @dain can chime in and then we decide to merge or update as needed.

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

Successfully merging this pull request may close these issues.

4 participants