[fix](auth) fix overwrite logic of user with domain (#27002)

Reproduce:
DBA do following operations:
1. create user user1@['domain'];   // the domain will be resolved as 2 ip: ip1 and ip2;
2. create user user1@'ip1';
3. wait at least 10 second
4. grant all on *.*.* to user1@'ip1';  // will return error: user1@'ip1' does not exist

This is because the daemon thread DomainResolver resolve the "domain" and overwrite the `user1@'ip1'`
which is created by DBA.

This PR fix it.
This commit is contained in:
Mingyu Chen
2023-11-15 18:19:54 +08:00
committed by GitHub
parent d3fd923447
commit 52d7725b36
3 changed files with 39 additions and 1 deletions

View File

@ -453,7 +453,7 @@ public class Auth implements Writable {
// create user
try {
//we should not throw AnalysisException at here,so transfer it
// we should not throw AnalysisException at here,so transfer it
userManager.createUser(userIdent, password, null, false);
} catch (PatternMatcherException e) {
throw new DdlException("create user failed,", e);

View File

@ -183,6 +183,12 @@ public class UserManager implements Writable {
throws PatternMatcherException {
if (userIdentityExist(userIdent, true)) {
User userByUserIdentity = getUserByUserIdentity(userIdent);
if (!userByUserIdentity.isSetByDomainResolver() && setByResolver) {
// If the user is NOT created by domain resolver,
// and the current operation is done by DomainResolver,
// we should not override it, just return
return userByUserIdentity;
}
userByUserIdentity.setPassword(pwd);
userByUserIdentity.setSetByDomainResolver(setByResolver);
return userByUserIdentity;