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

Adding schema access rules to file based system access control #15886

Merged
merged 1 commit into from
Apr 28, 2021

Conversation

agrawalreetika
Copy link
Member

@agrawalreetika agrawalreetika commented Mar 30, 2021

Currently, file-based system access control allows defining catalog level rule. As a part of these changes, schema access rules can be included with file-based system access control for the below operations -

  • checkCanCreateSchema : If the user has access to the catalog and is also schema owner, then access is provided.
  • checkCanDropSchema : If the user has access to the catalog and is also schema owner, then access is provided.
  • checkCanRenameSchema : If the user has access to the catalog and is also schema owner, then access is provided.
== RELEASE NOTES ==

Security Changes

- Add ability to set schema access rules in file-based system access control

@aweisberg
Copy link
Contributor

Can you link to the PR? It's a better source of context then the commit trinodb/trino#3766 Also the linked commit is not actually on Trino master.

Copy link
Contributor

@aweisberg aweisberg left a comment

Choose a reason for hiding this comment

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

Thanks!

Some simplification we can take from Trino and the tests seem to be a bit different and incomplete compared to what Trino is currently doing.

@@ -224,6 +227,10 @@ public void checkCanCreateSchema(Identity identity, AccessControlContext context
if (!canAccessCatalog(identity, schema.getCatalogName(), ALL)) {
denyCreateSchema(schema.toString());
}

Copy link
Contributor

Choose a reason for hiding this comment

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

If you ignore the linked diff and look at just how Trino is operating today they dropped the canAccessCatalog check here and pushed it into isSchemaOwner() which is simpler.

trinodb/trino#5039

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure sounds good. I will place a catalog access check with the isSchemaOwner() method itself.

@@ -232,6 +239,10 @@ public void checkCanDropSchema(Identity identity, AccessControlContext context,
if (!canAccessCatalog(identity, schema.getCatalogName(), ALL)) {
denyDropSchema(schema.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 as above

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted

@@ -240,6 +251,10 @@ public void checkCanRenameSchema(Identity identity, AccessControlContext context
if (!canAccessCatalog(identity, schema.getCatalogName(), ALL)) {
denyRenameSchema(schema.toString(), newSchemaName);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

And here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Noted

@@ -385,4 +400,19 @@ public void checkCanRevokeTablePrivilege(Identity identity, AccessControlContext
denyRevokeTablePrivilege(privilege.toString(), table.toString());
}
}

private boolean isSchemaOwner(Identity identity, String schemaName)
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.

Noted

@@ -169,6 +169,73 @@ public void testSchemaOperations()
}));
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

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

We seem to deviate a lot on the tests? Are there "extra" tests that we don't need to cover? Can we do a better job of synchronizing?

Copy link
Member Author

Choose a reason for hiding this comment

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

@aweisberg I have tried covering all positive and negative tests for all the 3 schema operations. If you think something is missing here, I can add more tests to this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can see why we deviated in several ways like not supporting groups and thus not needing to test groups.

If you fix the assertThrows I think it will be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

@aweisberg I have made the required changes.

accessControlManager.checkCanCreateSchema(transactionId, admin, context, new CatalogSchemaName("some-catalog", "some-schema"));
});

assertThrows(AccessDeniedException.class, () -> transaction(transactionManager, accessControlManager).execute(transactionId -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does one assertThrows have a bunch of different things in it? It will stop executing after the first one fails?

Copy link
Member Author

Choose a reason for hiding this comment

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

Made the changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are three cases now where there were five previously? It looks like it isn't validating whether the catalog can be accessed since coverage shows no cases where it is denied because the user can't access the catalog.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes look like those got removed while making other changes in test, added them back.

@agrawalreetika agrawalreetika force-pushed the filebased-schemaRules branch 3 times, most recently from b75a2c3 to f345b1c Compare April 14, 2021 03:21
Copy link
Contributor

@aweisberg aweisberg left a comment

Choose a reason for hiding this comment

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

It's still not testing the catalog ownership check. You can see because if you step through in the debugger it will never stop at return false in the test cases for schema. It does happen to do it in the read only catalog case, but I don't want to depend on testing unrelated functionality to cover it.

Sorry I know I am being picky here.

@agrawalreetika
Copy link
Member Author

@aweisberg I had added tests for catalog ownership check via read-only catalog access as you mentioned. In all the other cases AccessManager would redirect checks for Accesscatalog to checkCanAccessCatalog. Please review and let me know if any other changes are required.

@aweisberg
Copy link
Contributor

@arhimondr @rschlussel This is ready for review/merge.

@rschlussel rschlussel merged commit ea8e5f4 into prestodb:master Apr 28, 2021
@agrawalreetika agrawalreetika deleted the filebased-schemaRules branch April 28, 2021 15:52
@bhhari bhhari mentioned this pull request May 11, 2021
5 tasks
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.

3 participants