Skip to content

Commit 8890c20

Browse files
committed
The grant option check for path privileges was not correctly logged in the audit log
1 parent e879c54 commit 8890c20

File tree

1 file changed

+59
-25
lines changed

1 file changed

+59
-25
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/TreeAccessCheckVisitor.java

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
import java.util.Collections;
168168
import java.util.List;
169169
import java.util.Objects;
170+
import java.util.StringJoiner;
170171
import java.util.function.Supplier;
171172
import java.util.stream.Collectors;
172173

@@ -668,31 +669,12 @@ public TSStatus visitAuthor(AuthorStatement statement, TreeAccessCheckContext co
668669
auditObject)) {
669670
return RpcUtils.SUCCESS_STATUS;
670671
}
671-
for (String s : statement.getPrivilegeList()) {
672-
PrivilegeType privilegeType = PrivilegeType.valueOf(s.toUpperCase());
673-
if (privilegeType.isSystemPrivilege()) {
674-
if (!checkHasGlobalAuth(context, privilegeType, auditObject, true)) {
675-
return AuthorityChecker.getTSStatus(
676-
false,
677-
"Has no permission to execute "
678-
+ authorType
679-
+ ", please ensure you have these privileges and the grant option is TRUE when granted)");
680-
}
681-
} else if (privilegeType.isPathPrivilege()) {
682-
if (!AuthorityChecker.checkPathPermissionGrantOption(
683-
context.getUsername(), privilegeType, statement.getNodeNameList())) {
684-
return AuthorityChecker.getTSStatus(
685-
false,
686-
"Has no permission to execute "
687-
+ authorType
688-
+ ", please ensure you have these privileges and the grant option is TRUE when granted)");
689-
}
690-
} else {
691-
return AuthorityChecker.getTSStatus(
692-
false, "Not support Relation statement in tree sql_dialect");
693-
}
694-
}
695-
return RpcUtils.SUCCESS_STATUS;
672+
return checkPermissionsWithGrantOption(
673+
context,
674+
Arrays.stream(statement.getPrivilegeList())
675+
.map(PrivilegeType::valueOf)
676+
.collect(Collectors.toList()),
677+
statement.getNodeNameList());
696678
default:
697679
throw new IllegalArgumentException("Unknown authorType: " + authorType);
698680
}
@@ -1997,6 +1979,58 @@ protected boolean checkHasGlobalAuth(
19971979
return result;
19981980
}
19991981

1982+
protected TSStatus checkPermissionsWithGrantOption(
1983+
IAuditEntity auditEntity, List<PrivilegeType> privilegeList, List<PartialPath> paths) {
1984+
Supplier<String> supplier =
1985+
() -> {
1986+
StringJoiner joiner = new StringJoiner(" ");
1987+
if (paths != null) {
1988+
paths.forEach(path -> joiner.add(path.getFullPath()));
1989+
}
1990+
return joiner.toString();
1991+
};
1992+
auditEntity.setPrivilegeTypes(privilegeList);
1993+
if (AuthorityChecker.SUPER_USER.equals(auditEntity.getUsername())) {
1994+
recordObjectAuthenticationAuditLog(auditEntity.setResult(true), supplier);
1995+
return SUCCEED;
1996+
}
1997+
TSStatus status = SUCCEED;
1998+
for (PrivilegeType privilegeType : privilegeList) {
1999+
if (privilegeType.isSystemPrivilege()) {
2000+
if (!AuthorityChecker.checkSystemPermissionGrantOption(
2001+
auditEntity.getUsername(), privilegeType)) {
2002+
status =
2003+
AuthorityChecker.getTSStatus(
2004+
false,
2005+
"Has no permission to execute "
2006+
+ privilegeType
2007+
+ ", please ensure you have these privileges and the grant option is TRUE when granted)");
2008+
break;
2009+
}
2010+
} else if (privilegeType.isPathPrivilege()) {
2011+
if (!AuthorityChecker.checkPathPermissionGrantOption(
2012+
auditEntity.getUsername(), privilegeType, paths)) {
2013+
status =
2014+
AuthorityChecker.getTSStatus(
2015+
false,
2016+
"Has no permission to execute "
2017+
+ privilegeType
2018+
+ ", please ensure you have these privileges and the grant option is TRUE when granted)");
2019+
break;
2020+
}
2021+
} else {
2022+
status =
2023+
AuthorityChecker.getTSStatus(
2024+
false, "Not support Relation statement in tree sql_dialect");
2025+
break;
2026+
}
2027+
}
2028+
recordObjectAuthenticationAuditLog(
2029+
auditEntity.setResult(status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()),
2030+
supplier);
2031+
return status;
2032+
}
2033+
20002034
protected TSStatus checkWriteOnReadOnlyPath(IAuditEntity auditEntity, PartialPath path) {
20012035
if (includeByAuditTreeDB(path)
20022036
&& !AuthorityChecker.INTERNAL_AUDIT_USER.equals(path.getFullPath())) {

0 commit comments

Comments
 (0)