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

Roles management #12383

Merged
merged 62 commits into from
Feb 27, 2019
Merged

Roles management #12383

merged 62 commits into from
Feb 27, 2019

Conversation

@wenleix
Copy link
Contributor

wenleix commented Feb 25, 2019

Why trinodb/trino#90 adds ~8000 lines while this PR only adds ~7800 lines ? :P

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

"Introduce CREATE ROLE and DROP ROLE statements"

Looks good.

There are some minor difference with trinodb/trino@d177e3b :

  • PUBLIC is no longer added as reserved word.
  • DateFormat.tokens is not shown in PrestoSQL
  • TestSqlParserErrorHandling.java has slightly different change.

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

The following commits looks good by comparing with trinodb/trino#90

  • "Move PrincipalType to presto-spi "
  • "Expose Create/Drop/List roles methods in SPI"
  • "Introduce .information_schema.roles table"
  • "Assign admin role to subset of users in FileHiveMetastore"

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

"Implement Create/Drop/List roles in Hive connector"

Looks good % minor difference with trinodb/trino@22de2d8:

  • PrestoSQL's version also have some changes to RecordingHiveMetastore.java
  • PrestoSQL's version also have some changes to 'TestRecordingHiveMetastore.javaandUnimplementedHiveMetastore.java`

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

  • "Introduce GRANT/REVOKE roles statements" - Looks good.
  • "Add Grant/Revoke/List roles authorization to the SPI" - Looks good % PrestoSQL's version has some change to ForwardingConnectorAccessControl.java: trinodb/trino@03101af

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

  • "Introduce APPLICABLE_ROLES view" : Looks good

  • "Implement Grant/Revoke/ListApplicableRoles in Hive": Looks good % minor difference comparing with trinodb/trino@006216d:

    • PrestoSQL's version has change to RecordingHiveMetastore.java, TestRecordingHiveMetastore.java and UnimplementedHiveMetastore.java
    • Changes to TestRoles.java are slightly different.

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

  • Refactor GRANT/REVOKE in Hive:

Looks good except familiar minor differences in trinodb/trino@35b85b4

  • RecordingHiveMetastore.java, TestRecordingHiveMetastore.java, UnimplementedHiveMetastore.java

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

  • "Introduce access control for GRANT/REVOKE ROLE": Looks good. What the RoleGrant in trinodb/trino@487fe85 ?

  • "Prepare metastore interface to accept ROLE for GRANT/REVOKE" : Looks good except minor diff:

    • I didn't see the removal to HivePrincipal.java in trinodb/trino@f892c99
    • the same RecordingHiveMetastore.java change ;)

@arhimondr
Copy link
Member Author

* `TestSqlParserErrorHandling.java` has slightly different change.

For some reason a test was duplicated in prestosql

@arhimondr
Copy link
Member Author

arhimondr commented Feb 26, 2019

@wenleix

Why prestosql/presto#90 adds ~8000 lines while this PR only adds ~7800 lines ? :P

I picked that from the #11645, as literally cherry picking of 65 commits from the prestosql is too much of work. It is curious where the 150 additions were lost. We have 100 more removals. Maybe some difference because of rebasing / repackaging and slightly different base?

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

The first 6 commits (up to "Implement Create/Drop/List roles in Hive connector") looks good.

For "Implement Create/Drop/List roles in Hive connector": It looks like changes in TestRecordingHiveMetastore.java is missing (compared with trinodb/trino@22de2d8)

@wenleix
Copy link
Contributor

wenleix commented Feb 26, 2019

Looks like file ClientSelectedRole.java is missing from Implement SET ROLE (compared with trinodb/trino@e02bdab)

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

Commits "Introduce GRANT/REVOKE roles statements" to "Introduce ConnectorIdentity " looks good.

Commit "Implement SET ROLE" seems to have some minor difference.

@arhimondr
Copy link
Member Author

@wenleix

For "Implement Create/Drop/List roles in Hive connector": It looks like changes in TestRecordingHiveMetastore.java is missing (compared with prestosql/presto@22de2d8)

This change is missing in that commit in prestosql. Probably while rebasing the prestosql version they didn't compile every commit.

@arhimondr
Copy link
Member Author

@wenleix

Looks like file ClientSelectedRole.java is missing from Implement SET ROLE (compared with prestosql/presto@e02bdab)

In prestosql they removed SPI from the presto-client dependencies. That's why they had to copy the SelectedRole class to the presto-client package.

@@ -327,11 +327,9 @@ public Session beginTransactionId(TransactionId transactionId, TransactionManage
for (Entry<String, SelectedRole> entry : identity.getRoles().entrySet()) {
String catalogName = entry.getKey();
SelectedRole role = entry.getValue();

Copy link
Contributor

@wenleix wenleix Feb 26, 2019

Choose a reason for hiding this comment

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

This commit seems doing nothing . But let's keep consistent with PrestoSQL ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

What commit is that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Found it: Store catalog selected roles in Identity. Let me drop it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Sorry for forgetting to use "Add Review" mode...

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

"Introduce ENABLED_ROLES view": Some minor comments.

@@ -196,7 +196,7 @@ private synchronized void addCatalogConnector(String catalogName, ConnectorId co

MaterializedConnector informationSchemaConnector = new MaterializedConnector(
createInformationSchemaConnectorId(connectorId),
new InformationSchemaConnector(catalogName, nodeManager, metadataManager, accessControlManager));
new InformationSchemaConnector(catalogName, nodeManager, metadataManager, accessControlManager, transactionManager));
Copy link
Contributor

Choose a reason for hiding this comment

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

This change and InformationSchemaConnector.java doesn't appear in trinodb/trino@7baabd1 :). Maybe again get dropped on PrestoSQL side.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, good catch


public InformationSchemaPageSourceProvider(Metadata metadata, AccessControl accessControl)
public InformationSchemaPageSourceProvider(Metadata metadata, AccessControl accessControl, TransactionManager transactionManager)
Copy link
Contributor

Choose a reason for hiding this comment

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

This change does't appear in trinodb/trino@7baabd1 . -- also doesn't seem useful?

@@ -198,7 +198,7 @@ private static ConnectorId registerBogusConnector(CatalogManager catalogManager,
connectorId,
connector,
createInformationSchemaConnectorId(connectorId),
new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl),
new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl, transactionManager),
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like trinodb/trino@7baabd1 removed all the transactionManager related stuff.

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

"Add access control checks for SHOW ROLES" : minor diff with trinodb/trino@e2a2ff0

Also looks like changes to ReadOnlyAccessControl.java doesn't show up in this PR.

}

@Override
public Set<String> filterRoles(Identity identity, String catalogName, Set<String> roles)
Copy link
Contributor

Choose a reason for hiding this comment

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

This method was dropped in trinodb/trino@e2a2ff0

/**
* Filter the list of roles to those visible to the identity in the given catalog.
*/
default Set<String> filterRoles(Identity identity, String catalogName, Set<String> roles)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

"Access control for SHOW ROLE GRANTS and SHOW CURRENT ROLES". Minor diff against trinodb/trino@4f4b268#diff-cc0689ca452d7c2209c27e411d80c45aR177

@@ -187,15 +187,4 @@ public void checkCanGrantTablePrivilege(Identity identity, Privilege privilege,
public void checkCanRevokeTablePrivilege(Identity identity, Privilege privilege, CatalogSchemaTableName table, PrestoPrincipal revokee, boolean grantOptionFor)
{
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't see this change in trinodb/trino@4f4b268 . Maybe they already implement in different commit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Recovered in Add access control checks for SHOW ROLES

@@ -110,15 +110,4 @@ public void checkCanShowSchemas(Identity identity, String catalogName)
public void checkCanShowTablesMetadata(Identity identity, CatalogSchemaName schema)
{
}

Copy link
Contributor

Choose a reason for hiding this comment

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

same for this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Recovered in Add access control checks for SHOW ROLES

@@ -205,4 +205,22 @@ public void checkCanSetRole(ConnectorTransactionHandle transactionHandle, Connec
{
delegate().checkCanSetRole(transactionHandle, identity, role, catalogName);
}

@Override
public void checkCanShowRoles(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, String catalogName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually that is mistake. This method has to be moved to the Add access control checks for SHOW ROLES

@@ -302,22 +301,4 @@ default void checkCanRevokeTablePrivilege(Identity identity, Privilege privilege
{
denyRevokeTablePrivilege(privilege.toString(), table.toString());
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

same for this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Restored in Add access control checks for SHOW ROLES

@wenleix
Copy link
Contributor

wenleix commented Feb 26, 2019

Finish "human diff" the following commits:

  • Introduce GRANT/REVOKE roles statements
  • Add Grant/Revoke/List roles authorization to the SPI
  • Introduce APPLICABLE_ROLES view
  • Implement Grant/Revoke/ListApplicableRoles in Hive
  • Refactor GRANT/REVOKE in Hive
  • Introduce access control for GRANT/REVOKE ROLE
  • Prepare metastore interface to accept ROLE for GRANT/REVOKE
  • Introduce SET ROLE statement
  • Introduce ConnectorIdentity
  • Implement SET ROLE
  • Make HiveQueryRunner default user have admin role
  • Set admin role before setting system properties in storage format test
  • Store catalog selected roles in Identity
  • Implement SET ROLE in Hive Connector
  • Accept ROLE in GRANT/REVOKE Privileges statements
  • Add SHOW ROLES to the parser
  • Add access control checks for SHOW ROLES
  • Add docs for SHOW ROLES
  • Product tests for SHOW ROLES
  • Add SHOW CURRENT ROLES
  • Add SHOW ROLE GRANTS syntax
  • Add listRoleGrants to the SPI
  • Implement listRoleGrants() in Hive
  • Implement SHOW ROLE GRANTS rewrite
  • Add docs for SHOW ROLE GRANTS
  • Access control for SHOW ROLE GRANTS and SHOW CURRENT ROLES

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

"Add grantor_type and grantee_type columns to table_privileges"

minor diff to trinodb/trino@6735d23

}
catch (Exception e) {
Logger.get(getClass()).warn(e, "failed to drop table/view");
}
}

private void cleanupRoles()
Copy link
Contributor

Choose a reason for hiding this comment

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

trinodb/trino@6735d23 adds annotation @Test(groups = {AUTHORIZATION, PROFILE_SPECIFIC_TESTS})

Copy link
Contributor

@wenleix wenleix left a comment

Choose a reason for hiding this comment

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

"More product tests for SET ROLE":

one line different with trinodb/trino@aec0671

@@ -563,6 +564,119 @@ public void testShowRoleGrants()
row("role1"));
}

@Test(groups = {ROLES, AUTHORIZATION, PROFILE_SPECIFIC_TESTS})
Copy link
Contributor

Choose a reason for hiding this comment

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

trinodb/trino@aec0671 also renamed testAccessControl to testCreateDropRoleAccessControl . Although seems unrelated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. Let's keep the name.

@wenleix
Copy link
Contributor

wenleix commented Feb 26, 2019

Finish "human diff" the following commits against trinodb/trino#90

  • Remove redundant checkDatabasePermission methods
  • Reorder methods in SqlStandardAccessControl
  • Rename getGrantOptionForPrivilege to hasGrantOptionForPrivilege
  • Remove hive privilege null check
  • Allow all for admin role
  • Introduce isTableOwner method for readability
  • Simplify checkTablePermission
  • Refactor canCreateView security checks
  • Consider enabled roles for permissions
  • Refactor HivePrivilegeInfo
  • Move parsePrivilege to MetastoreUtil
  • Add grantor to HivePrivilegeInfo
  • Add grantor_type and grantee_type columns to table_privileges
  • More product tests for SET ROLE
  • Document role management

Andrii Rosa and others added 27 commits February 27, 2019 12:03
Admin user has all the available permissions for all the entities
implicitly. So it may be considered as a database and table "owner"
for all tables and databases. Also it has all the SELECT, INSERT, DELETE
permissions implicitly.
hasGrantOptionForPrivilege cannot be used in security checks for createView
because it doesn't consider the session role.
Verify that role set with `SET ROLE` is considering during the access check.
Previously when SqlStandardAccessControl was checking if given role is
enabled, it listed all role grants and check if that role is is among
all listed role grants.
Now it list all role grants until it finds that role.
This way table privileges are enumerated lazily.
Currently Presto shows that the owner of a table
has ALL privileges, even after some privileges are revoked.
This commit fixes this issue by listing only privileges
actually present in the metastore.
Presto currently lists only privilges of the
tables owned by the current user, even after the
admin role is set. This commit fixes this and lists all
privileges for admins.
When tables of the same name exist across different schemas, Presto lists privileges
of the table from all schemas instead of the single schema mentioned in the
SHOW GRANTS query. This commit fixes the issue.
`equals()` did not compare some fields (like `roles`). Also, it compared `principal` even though `Identity#equals` does not do that. To avoid any ambiguity, `equals()` gets disabled, along with `hashCode`.
@arhimondr arhimondr merged commit bfeb574 into prestodb:master Feb 27, 2019
@arhimondr arhimondr deleted the roles branch February 27, 2019 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants