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 SQL syntax for GRANT/REVOKE on schema #4396

Merged
merged 5 commits into from
Nov 2, 2020

Conversation

lukasz-walkiewicz
Copy link
Member

No description provided.

@cla-bot cla-bot bot added the cla-signed label Jul 9, 2020
@lukasz-walkiewicz
Copy link
Member Author

Resolves #4327

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.

We need some connector independent tests. Maybe you could use MockConnector for that. It would be nice to make sure it works end to end, before we start using this for connectors. What do you think?

Looks good in general. Few comments.

@kokosing
Copy link
Member

kokosing commented Jul 9, 2020

@martint Can you please double check the syntax?

@lhofhansl
Copy link
Member

I do not quite understand the point of this.

We do not have any connector that can support this, and it's not even clear to how to add it existing connectors:

  • for Hive we'd diverge from the Hive can do. IMHO that's OK, but we argued earlier that that's not OK.
  • for other connector (say Postgres), how would this work? We would likely not want to configure a catalog with a Postgres superuser, but only a "normal" user. So grant/revoke would have to happen in Postgres outside of Presto.

Don't get me wrong. I'd love to add this for Hive and other connectors. It would make our lives easier here, just not clear how to splice this through to the connectors.

@kokosing
Copy link
Member

We do not have any connector that can support this

We are thinking about implementing this in Starburst.

it's not even clear to how to add it existing connectors:

I am not sure I followed the previous discussion. I think we can revisit adding this to Hive SQL standard authorization.

for other connector (say Postgres), how would this work?

I didn't think hard about this, but to me it would simply translate to Postgres equivalent statements of GRANT and REVOKE to SCHEMA.

We would likely not want to configure a catalog with a Postgres superuser, but only a "normal" user.

The best would be to use impersonation, credentials passthrough or extra credentials so user bob in Presto becomes bob in Postgres.

Don't get me wrong

I don't. I appreciate when someone is questioning the idea before implementation. It could save hours of work.

@lukasz-walkiewicz lukasz-walkiewicz force-pushed the grant-on-schema branch 2 times, most recently from 73b3488 to d0ec877 Compare July 17, 2020 07:57
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.

This looks nice. Few comments.

@martint
Copy link
Member

martint commented Jul 27, 2020

Syntax-wise, this is not in the SQL spec, but it's consistent with it:

<grant privilege statement> ::=
GRANT <privileges> TO <grantee> [ { <comma> <grantee> }... ]
      [ WITH HIERARCHY OPTION ]
      [ WITH GRANT OPTION ]
      [ GRANTED BY <grantor> ]

<privileges> ::=
  <object privileges> ON <object name>

<object name> ::= 
      [ TABLE ] <table name>
    | DOMAIN <domain name>
    | COLLATION <collation name>
    | CHARACTER SET <character set name> 
    | TRANSLATION <transliteration name> 
    | TYPE <schema-resolved user-defined 
    | SEQUENCE <sequence generator name> 
    | <specific routine designator>

What I think needs to be discussed are the semantics of this operation, given that it introduces a behavior on hierarchical objects that isn't contemplated by the spec. I.e., does revoking a privilege on a schema imply a revocation of privileges over all tables in the schema? Does performing a SELECT require checking permissions both on the table and the schema? Etc...

For reference, the spec describes SELECT permissions as applying to columns, not tables. Doing a GRANT SELECT ON TABLE t is a way to say "grant SELECT on current and future columns of the table". GRANT SELECT(x) ON TABLE t means "grant SELECT only on column x of table t".

2) SELECT (<column name>) specifies the SELECT privilege on the indicated column and implies one or more column privilege descriptor.
[...]
4) SELECT with neither <privilege column list> nor <privilege method list> specifies the SELECT privilege on all columns of T including any columns subsequently added to T and implies a table privilege descriptor and one or more column privilege descriptors. If T is a table of a structured type TY, then SELECT also specifies the SELECT privilege on all methods of the type TY, including any methods subsequently added to the type TY, and implies one or more table/method privilege descriptors.

It records the privilege in a table privilege descriptor for the purpose of applying the privilege to columns that are added afterwards, but only the column privilege descriptors are consulted when querying. From section "6.7 ":

ii) Otherwise, the current privileges shall include SELECT on the column referenced by CR.

@kokosing
Copy link
Member

WITH HIERARCHY OPTION

What does it mean?

does revoking a privilege on a schema imply a revocation of privileges over all tables in the schema

Schema privilege is to me independent to other privileges. So revoking should not affect any other privileges that user currently has.

So

GRANT SELECT on s.t TO bob;
 -- bob can select from s.t
GRANT SELECT SCHEMA s TO bob;
 -- bob can select from s.t
REVOKE SELECT SCHEMA s FROM bob;
 -- bob can select from s.t
REVOKE SELECT on s.t FROM bob;
-- bob can no longer select from s.t

Doing a GRANT SELECT ON TABLE t is a way to say "grant SELECT on current and future columns of the table".

So doing GRANT SELECT ON SCHEMA s is a way to say "grant SELECT on current and future columns of all current and future tables of SCHEMA s"

Does performing a SELECT require checking permissions both on the table and the schema?

No, because the above (GRANT SELECT ON SCHEMA translates to grant SELECT on columns).

What I think needs to be discussed are the semantics of this operation,

One more point. We try to follow data source semantics when writing connectors. So Hive connector should behave like Hive. So should we do the same thing here for access control. For example should allow to have different semantics when hive.security=sql-standard or hive.security=other-authorization-polices-service so we follow the behavior of sql-standard and other-authorization-polices-service in hive?

@lukasz-walkiewicz lukasz-walkiewicz force-pushed the grant-on-schema branch 2 times, most recently from f359386 to c7792cd Compare August 26, 2020 17:00
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.

This looks decent. Nice! Just few comments otherwise looks good.

@martint Please take a look

presto-docs/src/main/sphinx/sql/grant.rst Outdated Show resolved Hide resolved
presto-docs/src/main/sphinx/sql/revoke.rst Outdated Show resolved Hide resolved
presto-docs/src/main/sphinx/sql/grant.rst Show resolved Hide resolved
presto-docs/src/main/sphinx/sql/revoke.rst Show resolved Hide resolved
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class TestGrant
Copy link
Member

Choose a reason for hiding this comment

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

Please also add tests for SHOW GRANTS and information_schema.table_privileges while using GRANT/REVOKE ON SCHEMA

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.

@martint Would you like to take a look?

};
}

private static Session sessionOf(String username)
Copy link
Member

Choose a reason for hiding this comment

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

just session?

};
}

private static Session sessionOf(String username)
Copy link
Member

Choose a reason for hiding this comment

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

session?

@kokosing kokosing merged commit 2ef8248 into trinodb:master Nov 2, 2020
@kokosing
Copy link
Member

kokosing commented Nov 2, 2020

Merged, thanks!

@kokosing kokosing mentioned this pull request Nov 2, 2020
10 tasks
@lukasz-walkiewicz lukasz-walkiewicz deleted the grant-on-schema branch November 2, 2020 14:31
@martint martint added this to the 346 milestone Nov 5, 2020
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