HTHou commented on code in PR #18345:
URL: https://github.com/apache/iotdb/pull/18345#discussion_r3671769767


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertBaseStatement.java:
##########
@@ -205,6 +206,19 @@ public List<PartialPath> getPaths() {
     return Collections.emptyList();
   }
 
+  public Stream<PartialPath> getPathsStream() {
+    if (measurements == null) {
+      return Stream.empty();
+    }
+    return Arrays.stream(measurements)
+        .filter(Objects::nonNull)
+        .map(devicePath::concatAsMeasurementPath);
+  }

Review Comment:
   devicePath is a required invariant for every non-empty insert statement and 
is populated before authorization. The previous getPaths and getDevicePaths 
flow also failed when it was absent. Returning an empty stream would turn an 
invalid target into an empty authorization scope, so the fail-fast behavior is 
intentional.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/TreeAccessCheckVisitor.java:
##########
@@ -1136,25 +1136,31 @@ private TSStatus checkShowOrCountDatabasePermission(
   @Override
   public TSStatus visitInsertBase(InsertBaseStatement statement, 
TreeAccessCheckContext context) {
     
context.setAuditLogOperation(AuditLogOperation.DML).setPrivilegeType(PrivilegeType.WRITE_DATA);
-    for (PartialPath path : statement.getDevicePaths()) {
-      // External users cannot modify the audit database.
-      if (includeByAuditTreeDB(path)
-          && 
!context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)) {
-        
AUDIT_LOGGER.recordObjectAuthenticationAuditLog(context.setResult(false), 
path::toString);
-        return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode())
-            
.setMessage(getUnsupportedAuditDatabaseOperationMessage(TREE_MODEL_AUDIT_DATABASE));
-      }
+    // External users cannot modify the audit database.
+    final PartialPath unsupportedAuditPath =
+        context.getUsername().equals(AuthorityChecker.INTERNAL_AUDIT_USER)
+            ? null
+            : statement
+                .getDevicePathsStream()
+                .filter(Audit::includeByAuditTreeDB)
+                .findFirst()
+                .orElse(null);

Review Comment:
   This is covered by the same devicePath invariant at the statement boundary. 
The previous loop also passed every device path directly to 
includeByAuditTreeDB. Filtering null here would silently skip validation of an 
invalid insert target, so no visitor-level null filter is added.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to