Add invoker security mode for views#12082
Add invoker security mode for views#12082electrum wants to merge 1 commit intoprestodb:masterfrom electrum:view-security
Conversation
|
cc @martint |
|
Is this semantics defined by SQL standard or this is Presto extension? |
| @JsonProperty("columns") List<ViewColumn> columns, | ||
| @JsonProperty("owner") Optional<String> owner) | ||
| @JsonProperty("owner") Optional<String> owner, | ||
| @JsonProperty("runAsInvoker") boolean runAsInvoker) |
There was a problem hiding this comment.
Do i understand correctly that existing view definitions will be parsed correctly because Jackson defaults missing boolean properties to false?
There was a problem hiding this comment.
Am i right that ViewDefinition is what gets persisted in a Metastore?
if so, we should have tests like:
json literal → deserialization → check parsed correctly
to ensure backwards compat with view definitions stored by older Presto vesions
There was a problem hiding this comment.
Yes, existing views will parse correctly. Good point -- I will add a test for existing views.
| this.columns = ImmutableList.copyOf(requireNonNull(columns, "columns is null")); | ||
| this.owner = requireNonNull(owner, "owner is null"); | ||
| this.runAsInvoker = runAsInvoker; | ||
| checkArgument(!runAsInvoker || !owner.isPresent(), "owner cannot be present with runAsInvoker"); |
There was a problem hiding this comment.
Why owner was optional until now?
other than that, i would expect checkArgument(runAsInvoker == !owner.isPresent() here
There was a problem hiding this comment.
It was optional because legacy views from before owner was added will not have them. I will also add a test for that.
There was a problem hiding this comment.
That's what i suspected. Having a test would have a bonus advantage that it would self-document
| { | ||
| Optional<CreateView.Security> security = Optional.empty(); | ||
| if (context.DEFINER() != null) { | ||
| security = Optional.of(CreateView.Security.DEFINER); |
There was a problem hiding this comment.
In case of an { INNER? | OUTER } case, AstBuilder applies "defaulting", i.e. determines that the Join is INNER when not explicitly specified.
Please explain why you don't follow the same path for CREATE VIEW. This would simplify the code, with the obvious drawback that SqlFormatter wouldn't be able to reconstruct the original text 1-1 (not sure if this is important though). Any other reasons?
There was a problem hiding this comment.
@martint has the opinion that in general, the AST should be a faithful representation of the SQL syntax and not have knowledge of semantics. Where to draw the line is a bit arbitrary. For example, we agree that "noise words" like the optional AS clause for table aliases can be omitted. I'll let him comment further.
rschlussel
left a comment
There was a problem hiding this comment.
Can you add more description to the commit message (like what's in the docs).
Also, is the syntax defined by the SQL standard? I think it's a bit clunky because it doesn't make sense when you read it aloud as a sentence. So if it's not required to be exactly this way, I'd prefer something more similar what we have for table properties WITH SECURITY =<security_type>.
| if (view != null) { | ||
| ViewDefinition definition = deserializeView(view.getViewData()); | ||
| if (view.getOwner().isPresent()) { | ||
| if (view.getOwner().isPresent() && !definition.isRunAsInvoker()) { |
There was a problem hiding this comment.
how could a view have an owner if runAsInvoker is also set?
There was a problem hiding this comment.
This is ConnectorViewDefinition which comes from the connector, not the serialized view. Connectors will set this unconditionally (they have no knowledge of the view security model). For example, in Hive, this is always set to the table owner returned by the metastore.
There was a problem hiding this comment.
Ah, I think I understand now. Let me now if this is correct.
Viewdata doesn't contain information about the owner (for legacy views only?), so it's passed only with the connector view information. Therefore we need some other field to say whether we want to get the view owner from the connector or not, and that's why we you added the "runAsInvoker" boolean.
| @JsonProperty("columns") List<ViewColumn> columns, | ||
| @JsonProperty("owner") Optional<String> owner) | ||
| @JsonProperty("owner") Optional<String> owner, | ||
| @JsonProperty("runAsInvoker") boolean runAsInvoker) |
There was a problem hiding this comment.
What's the difference between when owner is empty and runAsInvoker is false and when owner is empty and runAsInvoker is true?
There was a problem hiding this comment.
Legacy views from before owner was added will have neither of these fields. I had originally wanted to simply use "owner not present" to indicate invoker security, but that doesn't work due to legacy views.
There was a problem hiding this comment.
But what's the difference in behavior? Won't both of them use regular access control?
There was a problem hiding this comment.
I believe you answered your own question above.
|
This is a Presto extension to the SQL standard. The grammar is based on the standard for SQL routines which support both modes. |
|
Here's an example of the standard syntax for Note that the word |
|
FWIW, Oracle has equivalent functionality using Teradata, SQL Server and PostgreSQL seem not to have the functionality. |
|
@findepi Nice find, I missed that. Should we use that syntax instead, both for familiarity/compatibility, and given that it is now the likely choice if the behavior is ever standardized? |
|
I was having similar thoughts as @findepi. Views are not “invoked” or “called”, so the term “invoker” doesn’t seem appropriate. There’s also the more neutral “authid” syntax in some databases (I don’tremember if it was oracle, db2 or sql server that had it) |
|
Oracle uses |
|
SQL Server has a It looks like the syntax would be one of
There is appeal to having a
|
|
This is how the
But when thinking about |
|
What about: ? That way From the other hand, maybe repeating |
|
Coming back to this with fresh eyes, I think we should copy the Oracle syntax for creating views, both for user familiarity and because it is the likely choice to be standardized (if this feature ever is). |
No description provided.