-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Support grant GRANT_PRIV on database or table level #1472
Changes from 4 commits
9779ea5
dbce92b
fcfff24
a706f9a
9b7f369
49c7ca2
789947e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,25 +88,36 @@ public void analyze(Analyzer analyzer) throws AnalysisException { | |
} | ||
|
||
// can not revoke NODE_PRIV from any user | ||
for (PaloPrivilege paloPrivilege : privileges) { | ||
if (paloPrivilege == PaloPrivilege.NODE_PRIV) { | ||
throw new AnalysisException("Can not revoke NODE_PRIV from any users or roles"); | ||
} | ||
if (privileges.contains(PaloPrivilege.NODE_PRIV)) { | ||
throw new AnalysisException("Can not revoke NODE_PRIV from any users or roles"); | ||
} | ||
|
||
// ADMIN_PRIV and GRANT_PRIV can only be revoked as global | ||
// ADMIN_PRIV can only be revoked on GLOBAL level | ||
if (tblPattern.getPrivLevel() != PrivLevel.GLOBAL) { | ||
for (PaloPrivilege paloPrivilege : privileges) { | ||
if (paloPrivilege == PaloPrivilege.ADMIN_PRIV || paloPrivilege == PaloPrivilege.GRANT_PRIV) { | ||
throw new AnalysisException( | ||
"Can not revoke ADMIN_PRIV or GRANT_PRIV from specified database or table. Only support from *.*"); | ||
} | ||
if (privileges.contains(PaloPrivilege.ADMIN_PRIV)) { | ||
throw new AnalysisException("Can not revoke ADMIN_PRIV from specified database or table. Only support from *.*"); | ||
} | ||
} | ||
|
||
if (!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(), PrivPredicate.GRANT)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, | ||
"REVOKE"); | ||
if (role != null) { | ||
// only user with GLOBAL level's GRANT_PRIV can revoke privileges to roles. | ||
if (!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(), PrivPredicate.GRANT)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "REVOKE"); | ||
} | ||
} else { | ||
// revoke from a certain user | ||
// 1. check if current user has GLOBAL level GRANT_PRIV. | ||
// 2. or if current user has DATABASE level GRANT_PRIV if grant to certain database. | ||
if (tblPattern.getPrivLevel() == PrivLevel.GLOBAL) { | ||
if (!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(), PrivPredicate.GRANT)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "GRANT"); | ||
} | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about table level? And grant and revoke has same logic? Does these two class reuse some code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, Grant and Revoke should use same logic here, I will unify them. |
||
if (!Catalog.getCurrentCatalog().getAuth().checkDbPriv(ConnectContext.get(), | ||
tblPattern.getQuolifiedDb(), PrivPredicate.GRANT)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "GRANT"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think TablePattern is a confusing name. It's better you can rename it in later PR