Skip to content

Conversation

@djsagain
Copy link
Member

@djsagain djsagain commented May 1, 2024

This commit adds machinery to set the owner of arbitrary entities, by extending the syntax of
ALTER (SCHEMA | TABLE | VIEW) qualifiedName SET AUTHORIZATION to support arbitrary owningKinds in place of SCHEMA, TABLE or VIEW. Checks that a specific SET AUTHORIZATION is legal is done by AccessControl.checkCanSetEntityAuthorization, also defined by SystemAccessControl. Setting the owner is done by Metadata.setEntityAuthorization and
SystemSecurityMetadata.setEntityAuthorization.

Description

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.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label May 1, 2024
@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from 19b0949 to bbb067b Compare May 2, 2024 13:38
@lozbrown
Copy link
Contributor

lozbrown commented May 7, 2024

Would that help with this issue?

#21450

@djsagain
Copy link
Member Author

djsagain commented May 7, 2024

Would that help with this issue?

#21450

No, I don't think this change will help. Materialized views must have owners when they are created. Perhaps you could post to the Trino #troubleshooting Slack channel about this.

@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from bbb067b to a8153d8 Compare May 7, 2024 15:49
@lozbrown
Copy link
Contributor

lozbrown commented May 7, 2024

I did that some time ago but got no response

https://trinodb.slack.com/archives/CGB0QHWSW/p1712241258245569

@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from a8153d8 to 5b3c06c Compare May 19, 2024 18:57
@djsagain djsagain requested a review from martint May 20, 2024 12:47
@djsagain djsagain marked this pull request as ready for review May 20, 2024 12:53
@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from 5b3c06c to 67040b4 Compare June 4, 2024 15:20
@github-actions
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 Jun 25, 2024
@mosabua mosabua added stale-ignore Use this label on PRs that should be ignored by the stale bot so they are not flagged or closed. and removed stale labels Jun 25, 2024
@mosabua
Copy link
Member

mosabua commented Jun 25, 2024

I assume you are still working on this @djsstarburst

@djsagain
Copy link
Member Author

I assume you are still working on this @djsstarburst

Yes, @mosabua.

@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from 67040b4 to 0bb9bea Compare August 4, 2024 14:20
@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from 0bb9bea to 5ed9185 Compare October 10, 2024 16:18
@djsagain
Copy link
Member Author

Hi @martint. We discussed this PR, and you took a quick look at it last spring. I just brought it up-to-date with tip master.

Could you please take another look and see if it can be approved? Thanks!

Copy link
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.

I would like to take a different approach to this PR. Instead of retaining the existing set*Authorization we remove them entirelly. Then in the SPI we have default implementation of setEntityAuthorization we switch over the entities and call the exisitng methods. Then we mark the existing 3 methods as deprecated for removal. We would do the same thing for the security checks.

The main, notable, difference with the existing code would be that we no longer perform an existance check before doing the authorization assignment. I think that is ok. If we decide we want that later we can add a generic entitiy exists mehtod.

@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch 2 times, most recently from 9205917 to a39beac Compare November 21, 2024 21:42
@djsagain
Copy link
Member Author

I would like to take a different approach to this PR.

@dain - - I've tried to do what you suggested, and I've pushed out the result. But I'm not certain I've gotten the details right. Please take another quick look.

dain
dain previously requested changes Dec 9, 2024
Copy link
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.

You are getting there. In all modules other than SPI, we should simply remove the methods. In the SPI we leave the methods, but mark them @Deprecated(forRemoval=ture). This means the nothing else in Trino is allowed to call this method. The new method will have a default implementation that calls through to the old deprecated implementations (likely needs the deprecation check suppressed for that method). This way existing implementations should still work, but it forces them to update. Then in a few months we remove the deprecated methods entirelly.

@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch 3 times, most recently from 7374ecc to 35814ce Compare December 18, 2024 18:53
@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from 35814ce to 7b96454 Compare February 17, 2025 18:11
@djsagain
Copy link
Member Author

@homar raised the question of whether there should be a way in SQL to see the owner of an entity. AIUI that would require some new syntax, maybe something like:

SHOW AUTHORIZATION ON ownedEntityKind qualifiedName BY principal

@martint and @dain - - Do you think it's worthwhile to extend this PR to add something like that? If we think it's worth doing, we would have to decide on the visibility rules for owners of entities.

@ksobolew
Copy link
Contributor

@djsstarburst see #10593, there are some (other) options there

@djsagain
Copy link
Member Author

@djsstarburst see #10593, there are some (other) options there

Good point; maybe exposing ownership as columns in the information_schema makes sense. I don't really have an opinion, but I'll be @martint does.

Copy link
Member

Choose a reason for hiding this comment

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

@electrum what do you think about this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

FTR, I removed this line, and will add any dependency methods that are found to be missing.

@dain dain dismissed their stale review February 28, 2025 19:52

Changes implemented

@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from 7b96454 to 4f454b0 Compare March 2, 2025 15:36
Copy link
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.

Other than the build failure, and the outstanding question for @electrum, this looks good to me

@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from 4f454b0 to a5154d6 Compare March 3, 2025 14:25
@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch 3 times, most recently from 3a0a10c to 47f1383 Compare March 12, 2025 21:32
@kokosing
Copy link
Member

@electrum can you please take a look? It looks this PR waits on your feedback only (see #21794 (review)).

@electrum
Copy link
Member

The comment for me was addressed. This can proceed.

Copy link
Member

Choose a reason for hiding this comment

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

MATERIALIZED VIEW was not supported before. I think it would be nice to add it in separate commit, or at least mention this in the commit message that it is something it is now possible to set owner for materialized view.

EDIT: I see that it is missing in the implementation so let's simply remove it from the grammar.

Copy link
Member

Choose a reason for hiding this comment

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

What is the use case for identifier? Does it mean that user is able to pass anything, syntax will be fine, but we will fail to execute that?

Also I have some hard time to understand why identifier is something for that. Usually identifier is a name of the thing not a type of the thing.

I would prefer to remove this from this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason for the identifier is that this is an extension mechanism, and therefore Trino can't know what entity kinds will be used.

This can't be removed from the PR - - the extension mechanism is the entire reason for the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

We already support arbitrary entity kinds in GRANT, REVOKE and DENY, so it perfectly makes sense to have it here as well.

Copy link
Member

Choose a reason for hiding this comment

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

MATERIALIZED VIEW is missing here, maybe we should simply remove it from the grammar?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's not missing. MATERIALIZED VIEW is treated as a VIEW. See line 512 of AstBuilder.

Copy link
Member

Choose a reason for hiding this comment

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

Please correct me if I am wrong. Previously we were also able to set an owner for MATERIALIZED view because it was just had it for the view. Now we do the same but we change the syntax that MATERIALIZED keyword can be added but it is not necessary.

So my question is why are you adding MATERIALIZED keyword? Why not to keep existing behaviour?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! You are absolutely right - - using the MATERIALIZED keyword in the SET AUTHORIZATION grammar is a bug.

Fixed in the grammar and in AstBuilder.visitSetAuthorization.

Copy link
Member

Choose a reason for hiding this comment

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

Can we enum for ownedKind. I would prefer the name entityType. Or let's use the name from the grammar OwnedEntityKind.

Notice that using enum will help us to do static code analysis to make sure we cover all the cases by using the switch statement. It will be useful when one would like to add new entries.

Copy link
Member Author

Choose a reason for hiding this comment

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

As mentioned we cannot use an enum, because this is an extension mechanism, and Trino itself can't know all the entity kinds used by all extension uses.

Copy link
Member

Choose a reason for hiding this comment

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

Materialized view is also missing here.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's not missing. MATERIALIZED VIEW is treated as a VIEW. See line 512 of AstBuilder.

Copy link
Member

Choose a reason for hiding this comment

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

Are there any entities that are not catalog related?

Copy link
Member Author

Choose a reason for hiding this comment

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

Clients of the extension mechanism can define entity kinds that not contained in catalogs. For example, the extension mechanism can be used to support ownership of roles, which are not contained in catalogs.

Copy link
Member

Choose a reason for hiding this comment

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

Can we use io.trino.metadata.QualifiedObjectName instead of List<String>?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, we can't use QualifiedObjectName because it is based on the assumption that all ownable entity kinds are contained in a catalog and schema.

Copy link
Contributor

Choose a reason for hiding this comment

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

See also io.trino.spi.connector.EntityKindAndName, which is a pair of String entityKind and List<String> name. BTW, perhaps we could use it here as well.

Copy link
Member Author

@djsagain djsagain Mar 27, 2025

Choose a reason for hiding this comment

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

This is a reasonable suggestion, and is consistent with checkCanGrantEntityPrivilege.

I made this change everywhere except denySetEntityAuthorization. I didn't make it there because there are quite a few of calls.

[Later]

I ended up making the change for denySetEntityAuthorization as well, since that is more consistent.

@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from 47f1383 to 93ffec9 Compare March 26, 2025 23:38
This commit adds machinery to set the owner of arbitrary
entities, by extending the syntax of
ALTER (SCHEMA | TABLE | VIEW) qualifiedName SET AUTHORIZATION
to support arbitrary owningKinds in place of SCHEMA, TABLE or
VIEW.  Checks that a specific SET AUTHORIZATION is legal
is done by AccessControl.checkCanSetEntityAuthorization,
also defined by SystemAccessControl.  Setting the owner
is done by Metadata.setEntityAuthorization and
SystemSecurityMetadata.setEntityAuthorization.
@djsagain djsagain force-pushed the david.stryker/add-generic-set-authorization branch from 93ffec9 to d8c5587 Compare March 27, 2025 01:12
@kokosing kokosing merged commit 1a81b69 into trinodb:master Mar 27, 2025
94 checks passed
@kokosing
Copy link
Member

@djsstarburst Thank you! Merged.

@github-actions github-actions bot added this to the 475 milestone Mar 27, 2025
@djsagain
Copy link
Member Author

Thank you! Merged.

Thank YOU @kokosing for your review!

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

Labels

cla-signed stale-ignore Use this label on PRs that should be ignored by the stale bot so they are not flagged or closed. syntax-needs-review

Development

Successfully merging this pull request may close these issues.

7 participants