-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add generic SET AUTHORIZATION #21794
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 generic SET AUTHORIZATION #21794
Conversation
19b0949 to
bbb067b
Compare
|
Would that help with this issue? |
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. |
bbb067b to
a8153d8
Compare
|
I did that some time ago but got no response https://trinodb.slack.com/archives/CGB0QHWSW/p1712241258245569 |
a8153d8 to
5b3c06c
Compare
5b3c06c to
67040b4
Compare
|
This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua |
|
I assume you are still working on this @djsstarburst |
Yes, @mosabua. |
67040b4 to
0bb9bea
Compare
0bb9bea to
5ed9185
Compare
|
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! |
dain
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.
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.
core/trino-grammar/src/main/antlr4/io/trino/grammar/sql/SqlBase.g4
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/execution/SetAuthorizationTask.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/execution/SetAuthorizationTask.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/test/java/io/trino/sql/parser/TestSqlParser.java
Outdated
Show resolved
Hide resolved
9205917 to
a39beac
Compare
@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
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.
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.
core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/metadata/SystemSecurityMetadata.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/metadata/SystemSecurityMetadata.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/security/AccessControl.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/security/AccessControlManager.java
Outdated
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/security/SystemAccessControl.java
Outdated
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/security/SystemAccessControl.java
Outdated
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/security/AccessDeniedException.java
Outdated
Show resolved
Hide resolved
...-plugin-toolkit/src/main/java/io/trino/plugin/base/security/AllowAllSystemAccessControl.java
Outdated
Show resolved
Hide resolved
7374ecc to
35814ce
Compare
35814ce to
7b96454
Compare
|
@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: @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. |
|
@djsstarburst see #10593, there are some (other) options there |
core/trino-grammar/src/main/antlr4/io/trino/grammar/sql/SqlBase.g4
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/security/AccessControlManager.java
Outdated
Show resolved
Hide resolved
core/trino-parser/src/main/java/io/trino/sql/parser/AstBuilder.java
Outdated
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/security/AccessDeniedException.java
Outdated
Show resolved
Hide resolved
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.
@electrum what do you think about this change?
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.
FTR, I removed this line, and will add any dependency methods that are found to be missing.
7b96454 to
4f454b0
Compare
dain
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.
Other than the build failure, and the outstanding question for @electrum, this looks good to me
4f454b0 to
a5154d6
Compare
3a0a10c to
47f1383
Compare
|
@electrum can you please take a look? It looks this PR waits on your feedback only (see #21794 (review)). |
|
The comment for me was addressed. This can proceed. |
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.
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.
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 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.
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.
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.
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.
We already support arbitrary entity kinds in GRANT, REVOKE and DENY, so it perfectly makes sense to have it here as well.
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.
MATERIALIZED VIEW is missing here, maybe we should simply remove it from the grammar?
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.
No, it's not missing. MATERIALIZED VIEW is treated as a VIEW. See line 512 of AstBuilder.
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 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?
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.
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.
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.
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.
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.
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.
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.
Materialized view is also missing 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.
No, it's not missing. MATERIALIZED VIEW is treated as a VIEW. See line 512 of AstBuilder.
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.
Are there any entities that are not catalog related?
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.
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.
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.
Can we use io.trino.metadata.QualifiedObjectName instead of List<String>?
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.
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.
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.
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.
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 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.
47f1383 to
93ffec9
Compare
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.
93ffec9 to
d8c5587
Compare
|
@djsstarburst Thank you! Merged. |
Thank YOU @kokosing for your review! |
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: