Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public class Auth implements Writable {

private PasswordPolicyManager passwdPolicyManager = new PasswordPolicyManager();

// Prepared point-query plans use this process-local epoch to avoid repeating built-in
// privilege checks while no authorization state has changed.
private transient volatile long authorizationVersion;

private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();

private void readLock() {
Expand All @@ -136,6 +140,19 @@ private void writeUnlock() {
lock.writeLock().unlock();
}

private void markAuthorizationChanged() {
authorizationVersion++;
}

public long getAuthorizationVersion() {
return authorizationVersion;
}

/** Whether this version covers every role which can affect authorization decisions. */
public boolean isAuthorizationVersionReliable() {
return !isLdapAuthEnabled();
}

public enum PrivLevel {
GLOBAL, CATALOG, DATABASE, TABLE, RESOURCE, WORKLOAD_GROUP, CLUSTER, STAGE, STORAGE_VAULT
}
Expand Down Expand Up @@ -587,6 +604,7 @@ private void createUserInternal(UserIdentity userIdent, String roleName, byte[]
if (role != null) {
userRoleManager.addUserRole(userIdent, roleName);
}
markAuthorizationChanged();
// other user properties
propertyMgr.addUserResource(userIdent.getQualifiedUser());
MetricRepo.updateUserConnectionMaxMetric(this, userIdent.getQualifiedUser(),
Expand Down Expand Up @@ -641,6 +659,7 @@ private void dropUserInternal(UserIdentity userIdent, boolean ignoreIfNonExists,
roleManager.removeDefaultRole(userIdent);
// drop user role
userRoleManager.dropUser(userIdent);
markAuthorizationChanged();
passwdPolicyManager.dropUser(userIdent);
userManager.removeUser(userIdent);
if (CollectionUtils.isEmpty(userManager.getUserByName(userIdent.getQualifiedUser()))) {
Expand Down Expand Up @@ -755,6 +774,7 @@ private void grantInternal(UserIdentity userIdent, String role, TablePattern tbl
}
Role newRole = new Role(role, tblPattern, privs, colPrivileges);
roleManager.addOrMergeRole(newRole, false /* err on exist */);
markAuthorizationChanged();
if (!isReplay) {
PrivInfo info = new PrivInfo(userIdent, tblPattern, privs, null, role, colPrivileges);
Env.getCurrentEnv().getEditLog().logGrantPriv(info);
Expand Down Expand Up @@ -806,6 +826,7 @@ private void grantInternal(UserIdentity userIdent, String role, ResourcePattern

Role newRole = new Role(role, resourcePattern, privs);
roleManager.addOrMergeRole(newRole, false /* err on exist */);
markAuthorizationChanged();

if (!isReplay) {
PrivInfo info = new PrivInfo(userIdent, resourcePattern, privs, null, role);
Expand Down Expand Up @@ -837,6 +858,7 @@ private void grantInternal(UserIdentity userIdent, String role, WorkloadGroupPat

Role newRole = new Role(role, workloadGroupPattern, privs);
roleManager.addOrMergeRole(newRole, false /* err on exist */);
markAuthorizationChanged();

if (!isReplay) {
PrivInfo info = new PrivInfo(userIdent, workloadGroupPattern, privs, null, role);
Expand All @@ -862,6 +884,7 @@ private void grantInternal(UserIdentity userIdent, List<String> roles, boolean i
}
}
userRoleManager.addUserRoles(userIdent, roles);
markAuthorizationChanged();
if (!isReplay) {
PrivInfo info = new PrivInfo(userIdent, roles);
Env.getCurrentEnv().getEditLog().logGrantPriv(info);
Expand Down Expand Up @@ -952,6 +975,7 @@ private void revokeInternal(UserIdentity userIdent, String role, TablePattern tb
}
// revoke privs from role
roleManager.revokePrivs(role, tblPattern, privs, colPrivileges, errOnNonExist);
markAuthorizationChanged();

if (!isReplay) {
PrivInfo info = new PrivInfo(userIdent, tblPattern, privs, null, role, colPrivileges);
Expand All @@ -973,6 +997,7 @@ private void revokeInternal(UserIdentity userIdent, String role, ResourcePattern

// revoke privs from role
roleManager.revokePrivs(role, resourcePattern, privs, errOnNonExist);
markAuthorizationChanged();

if (!isReplay) {
PrivInfo info = new PrivInfo(userIdent, resourcePattern, privs, null, role);
Expand All @@ -994,6 +1019,7 @@ private void revokeInternal(UserIdentity userIdent, String role, WorkloadGroupPa

// revoke privs from role
roleManager.revokePrivs(role, workloadGroupPattern, privs, errOnNonExist);
markAuthorizationChanged();

if (!isReplay) {
PrivInfo info = new PrivInfo(userIdent, workloadGroupPattern, privs, null, role);
Expand All @@ -1019,6 +1045,7 @@ private void revokeInternal(UserIdentity userIdent, List<String> roles, boolean
}
}
userRoleManager.removeUserRoles(userIdent, roles);
markAuthorizationChanged();
if (!isReplay) {
PrivInfo info = new PrivInfo(userIdent, roles);
Env.getCurrentEnv().getEditLog().logRevokePriv(info);
Expand Down Expand Up @@ -1134,6 +1161,7 @@ private void createRoleInternal(String role, boolean ignoreIfExists, String comm
}

roleManager.addOrMergeRole(emptyPrivsRole, true /* err on exist */);
markAuthorizationChanged();

if (!isReplay) {
PrivInfo info = new PrivInfo(role, comment);
Expand Down Expand Up @@ -1167,6 +1195,7 @@ private void dropRoleInternal(String role, boolean ignoreIfNonExists, boolean is

roleManager.dropRole(role, true /* err on non exist */);
userRoleManager.dropRole(role);
markAuthorizationChanged();
if (!isReplay) {
PrivInfo info = new PrivInfo(null, null, null, role, null, null, "");
Env.getCurrentEnv().getEditLog().logDropRole(info);
Expand Down Expand Up @@ -1996,6 +2025,7 @@ private void setRoleToUser(UserIdentity userIdent, String role) throws DdlExcept
userRoleManager.dropUser(userIdent);
userRoleManager.addUserRole(userIdent, role);
userRoleManager.addUserRole(userIdent, roleManager.getUserDefaultRoleName(userIdent));
markAuthorizationChanged();
}

private void updateUserTlsRequirements(UserIdentity userIdent) throws DdlException {
Expand Down
Loading
Loading