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

[CALCITE-5681] Support authorization via GRANT and REVOKE DDL commands #3726

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

Conversation

macroguo-ghy
Copy link
Contributor

Copy link

sonarcloud bot commented Mar 12, 2024

"org.apache.calcite.sql.SqlCreate"
"org.apache.calcite.sql.SqlDrop"
"org.apache.calcite.sql.SqlTruncate"
"org.apache.calcite.sql.ddl.SqlCreateTableLike"
"org.apache.calcite.sql.ddl.SqlDdlNodes"
"org.apache.calcite.sql.ddl.SqlAuthCommand"
Copy link
Contributor

Choose a reason for hiding this comment

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

maintain alphabetical order?

truncateStatementParserMethods: [
"SqlTruncateTable"
]

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is similar to others, also add corresponding remarks.


@Test void testGrantForSchema() {
final String sql = "grant update, delete on all tables in schema s1 to u1, u2";
final String expected = "GRANT UPDATE, DELETE ON ALL TABLES IN SCHEMA `S1` TO `U1`, `U2`";
Copy link
Contributor

Choose a reason for hiding this comment

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

Add more unit tests for different scenarios, like 'ALL TABLES IN ROOT SCHEMA'

grantStatement:
GRANT
{
privilege [, privilege ]*
Copy link
Contributor

Choose a reason for hiding this comment

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

Can describe the types of privilege

REVOKE
{
privilege [, privilege ]*
| ALL [ PRIVILEGES ]
Copy link
Contributor

Choose a reason for hiding this comment

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

Small question: although Postgres supports this syntax, does calcite require this flexible syntax, as most databases handle it strictly?

Using a stricter syntax makes it less selective for the user and can be more explicit for the user.

}
ON
{
[ TABLE ] table [, table ]*
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Are only the TABLE type currently considered for resource types? Is this syntax more generic, such as using resource_type, which lists supported types: TABLE
  2. Can ALL TABLES IN SCHEMA be equivalently represented as the SCHEMA resource type?


#### Granting and revoking privileges

You can grant and revoke privileges on tables, views and materialized views.
Copy link
Contributor

Choose a reason for hiding this comment

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

'tables, views and materialized views', do all their types use TABLE?

* that represents a user. CalcitePrincipal ignore the case of the
* name when comparing two principals.
*/
public class CalcitePrincipal implements Principal, Comparable<CalcitePrincipal> {
Copy link
Contributor

Choose a reason for hiding this comment

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

To refer to a user can use UserPrincipal

@@ -71,6 +74,9 @@ public abstract class CalciteSchema {
protected final NameSet functionNames;
protected final NameMap<FunctionEntry> nullaryFunctionMap;
protected final NameMap<CalciteSchema> subSchemaMap;

// tableName -> (user, access)
protected final NameMap<Map<Principal, SqlAccessType>> privilegeMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

Whether to use a separate class to maintain the relationship between Principal, SqlAccessType, and resource_type(TABLE/SCHEMA/FUNCTION...).
Using this way resource types can be more general and facilitate subsequent expansion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants