[opt](resource-tag) root and admin user can use any resource tag by default (#28088)

In #25331, I change the behavior of user's default resource tag, that is, if a user does not set resource tag,
it can only use default resource tag.
This PR change this logic. The normal user can only use default resource tag if resource tag is not set,
but root and admin user can use any resource tag if resource tag is not set.
This commit is contained in:
Mingyu Chen
2023-12-07 11:22:30 +08:00
committed by GitHub
parent 8df94f0d07
commit 3a7a8bb107
6 changed files with 14 additions and 10 deletions

View File

@ -110,10 +110,6 @@ public class CommonUserProperties implements Writable {
}
public Set<Tag> getResourceTags() {
// If resource tags in user properties is empty, use default backend tag.
if (resourceTags.isEmpty()) {
return Sets.newHashSet(Tag.DEFAULT_BACKEND_TAG);
}
return resourceTags;
}

View File

@ -29,6 +29,7 @@ import org.apache.doris.load.DppConfig;
import org.apache.doris.resource.Tag;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -123,7 +124,15 @@ public class UserPropertyMgr implements Writable {
if (existProperty == null) {
return UserProperty.INVALID_RESOURCE_TAGS;
}
return existProperty.getCopiedResourceTags();
Set<Tag> tags = existProperty.getCopiedResourceTags();
// only root and admin can return empty tag.
// empty tag means user can access all backends.
// for normal user, if tag is empty, use default tag.
if (tags.isEmpty() && !(qualifiedUser.equalsIgnoreCase(Auth.ROOT_USER)
|| qualifiedUser.equalsIgnoreCase(Auth.ADMIN_USER))) {
tags = Sets.newHashSet(Tag.DEFAULT_BACKEND_TAG);
}
return tags;
}
public Pair<String, DppConfig> getLoadClusterInfo(String qualifiedUser, String cluster) throws DdlException {