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

[#5146] fix(core): Support to rename and delete metadata object in the authorization plugin #5321

Merged
merged 6 commits into from
Oct 31, 2024

Conversation

jerqi
Copy link
Contributor

@jerqi jerqi commented Oct 28, 2024

What changes were proposed in this pull request?

Support to rename and delete metadata object in the authorization plugin

Why are the changes needed?

Fix: #5146

Does this PR introduce any user-facing change?

No.

How was this patch tested?

add new IT and UT

@jerqi jerqi changed the title Issue 5146 [#5146] fix(core): Support to rename and delete metadata object in the authorization plugin Oct 28, 2024
@jerqi jerqi marked this pull request as draft October 28, 2024 11:31
@jerqi jerqi self-assigned this Oct 28, 2024
@jerqi jerqi added the branch-0.7 Automatically cherry-pick commit to branch-0.7 label Oct 28, 2024
@jerqi jerqi force-pushed the ISSUE-5146 branch 6 times, most recently from 699500c to 243f4a2 Compare October 29, 2024 08:42
@jerqi jerqi closed this Oct 29, 2024
@jerqi jerqi reopened this Oct 29, 2024
@@ -588,6 +798,67 @@ void testAllowUseSchemaPrivilege() throws InterruptedException {
metalake.deleteRole(roleName);
}

@Test
void testDenyPrivileges() throws InterruptedException {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @xunliu

@jerqi jerqi force-pushed the ISSUE-5146 branch 2 times, most recently from 85ae637 to 63355f9 Compare October 30, 2024 11:02
@jerqi jerqi marked this pull request as ready for review October 30, 2024 12:05
@@ -527,6 +536,208 @@ void testDeleteAndRecreateRole() throws InterruptedException {
metalake.deleteRole(roleName);
}

@Test
void testDeleteAndRecreateMetadataObject() throws InterruptedException {
// Create a role with CREATE_SCHEMA privilege
Copy link
Member

Choose a reason for hiding this comment

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

I think need to add sparkSession.sql(SQL_CREATE_SCHEMA); in the here to throw doesn't have permission.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


// Clean up
catalog.asSchemas().dropSchema(schemaName, true);
metalake.deleteRole(roleName);
Copy link
Member

Choose a reason for hiding this comment

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

I think need to add these tests in the here to throw doesn't have permission.

  1. SQL_CREATE_SCHEMA
  2. SQL_DROP_SCHEMA

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

waitForUpdatingPolicies();

// Create a schema
sparkSession.sql(SQL_CREATE_SCHEMA);
Copy link
Member

Choose a reason for hiding this comment

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

I think need to add sparkSession.sql(SQL_CREATA_TABLE); in the here to throw doesn't have permission.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// Create a schema
sparkSession.sql(SQL_CREATE_SCHEMA);

// Set owner
Copy link
Member

Choose a reason for hiding this comment

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

I think need to add sparkSession.sql(SQL_DROP_SCHEMA); in the here to throw doesn't have permission.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// Create a schema and a table
sparkSession.sql(SQL_CREATE_SCHEMA);
sparkSession.sql(SQL_USE_SCHEMA);
sparkSession.sql(SQL_CREATE_TABLE);
Copy link
Member

Choose a reason for hiding this comment

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

I think need to add these tests in the here

  1. SQL_INSERT_TABLE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added another test case.

Comment on lines +85 to +86
// Schema doesn't support to rename operation now. So we don't need to change
// authorization plugin privileges, too.
Copy link
Member

Choose a reason for hiding this comment

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

I think need call authorization plugin interface in the here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Schema doesn't support to rename.

}

@Override
public boolean dropTable(NameIdentifier ident) {
return dispatcher.dropTable(ident);
boolean dropped = dispatcher.dropTable(ident);
AuthorizationUtils.removeAuthorizationPluginPrivileges(ident, Entity.EntityType.TABLE);
Copy link
Member

Choose a reason for hiding this comment

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

removeAuthorizationPluginPrivileges look like remove AuthorizationPlugin's Privileges, maybe can change to authorizationPluginRemovePrivileges or removePrivilegesInAuthorizationPlugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

prefer option 1.

Comment on lines 123 to 124
AuthorizationUtils.authorizationPluginRemovePrivileges(ident, Entity.EntityType.CATALOG);
return dispatcher.dropCatalog(ident);
Copy link
Member

Choose a reason for hiding this comment

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

I think maybe we can call dropCatalog(ident, /*default value*/) in there, to avoid duplicate call return dispatcher.dropCatalog(ident); ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.

}

@Override
public boolean dropTable(NameIdentifier ident) {
return dispatcher.dropTable(ident);
boolean dropped = dispatcher.dropTable(ident);
AuthorizationUtils.authorizationPluginRemovePrivileges(ident, Entity.EntityType.TABLE);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we needs add judgement in here

if (dropped) {
    AuthorizationUtils.authorizationPluginRemovePrivileges(ident, Entity.EntityType.TABLE);
}

Also other place have same problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we succeed to delete the table but fail to delete the policy in the authorization plugin. We can repeat to execute the operation to delete the policy but dispatcher may return zero.

waitForUpdatingPolicies();
Assertions.assertThrows(AccessControlException.class, () -> sparkSession.sql(SQL_INSERT_TABLE));
Assertions.assertThrows(
AccessControlException.class, () -> sparkSession.sql(SQL_SELECT_TABLE).collectAsList());
Copy link
Member

Choose a reason for hiding this comment

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

I think better to check all SQL operations.

  1. SQL_CREATE_SCHEMA
  2. SQL_USE_SCHEMA
  3. SQL_CREATE_TABLE
  4. SQL_INSERT_TABLE
  5. SQL_SELECT_TABLE
  6. SQL_UPDATE_TABLE
  7. SQL_DELETE_TABLE
  8. SQL_DROP_TABLE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.

Assertions.assertThrows(AccessControlException.class, () -> sparkSession.sql(SQL_INSERT_TABLE));
Assertions.assertThrows(
AccessControlException.class, () -> sparkSession.sql(SQL_SELECT_TABLE).collectAsList());

Copy link
Member

Choose a reason for hiding this comment

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

I think better to check all SQL operations.

  1. SQL_CREATE_SCHEMA
  2. SQL_USE_SCHEMA
  3. SQL_CREATE_TABLE
  4. SQL_INSERT_TABLE
  5. SQL_SELECT_TABLE
  6. SQL_UPDATE_TABLE
  7. SQL_DELETE_TABLE
  8. SQL_DROP_TABLE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.

// Delete the role and fail to create schema
metalake.deleteRole(roleName);
waitForUpdatingPolicies();
;
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this ;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.

Copy link
Member

@xunliu xunliu left a comment

Choose a reason for hiding this comment

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

LGTM

@xunliu xunliu merged commit 2fd6ec1 into apache:main Oct 31, 2024
26 checks passed
github-actions bot pushed a commit that referenced this pull request Oct 31, 2024
…e authorization plugin (#5321)

### What changes were proposed in this pull request?

Support to rename and delete metadata object in the authorization plugin

### Why are the changes needed?

Fix: #5146 

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
add new IT and UT
@jerqi jerqi deleted the ISSUE-5146 branch October 31, 2024 11:10
mplmoknijb pushed a commit to mplmoknijb/gravitino that referenced this pull request Nov 6, 2024
… in the authorization plugin (apache#5321)

### What changes were proposed in this pull request?

Support to rename and delete metadata object in the authorization plugin

### Why are the changes needed?

Fix: apache#5146 

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
add new IT and UT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch-0.7 Automatically cherry-pick commit to branch-0.7
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Subtask] Delete a securable object, we should delete the owner and roles on this securable object
2 participants