This is an automated email from the ASF dual-hosted git repository.

Caideyipi pushed a commit to branch 
codex/fix-pipe-ttl-authorization-intersection-20261106
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit ce8a21825256a9181b01df1115cf6a8db0d3538d
Author: Caideyipi <[email protected]>
AuthorDate: Fri Nov 6 18:03:39 2026 +0800

    Fix pipe tree privilege path intersections
---
 .../PipeConfigTreePrivilegeParseVisitor.java       | 26 +++++++---
 .../PipeConfigTreePrivilegeParseVisitorTest.java   | 57 +++++++++++++++++++++-
 2 files changed, 74 insertions(+), 9 deletions(-)

diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitor.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitor.java
index aa81c0681ba..46e2c7bf958 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitor.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitor.java
@@ -416,13 +416,12 @@ public class PipeConfigTreePrivilegeParseVisitor
     userEntity.setPrivilegeType(PrivilegeType.READ_SCHEMA);
     final String auditObject = Arrays.toString(setTTLPlan.getPathPattern());
     try {
+      final PartialPath originalPath = new 
PartialPath(setTTLPlan.getPathPattern());
       final List<PartialPath> paths =
-          getAllIntersectedPatterns(
-              new PartialPath(setTTLPlan.getPathPattern()), userEntity, 
setTTLPlan);
-      // The intersectionList is either a singleton list or an empty list, 
because the pipe
-      // pattern and TTL path are each either a prefix path or a full path
-      final boolean result =
-          !paths.isEmpty() && paths.get(0).getNodeLength() == 
setTTLPlan.getPathPattern().length;
+          getAllIntersectedPatterns(originalPath, userEntity, setTTLPlan);
+      // A SetTTLPlan represents one path, so only a single authorization 
intersection can be
+      // transferred without dropping another authorized path or widening the 
requested path.
+      final boolean result = paths.size() == 1 && 
originalPath.include(paths.get(0));
       logger.recordObjectAuthenticationAuditLog(userEntity.setResult(result), 
() -> auditObject);
       return result
           ? Optional.of(new SetTTLPlan(paths.get(0).getNodes(), 
setTTLPlan.getTTL()))
@@ -479,8 +478,19 @@ public class PipeConfigTreePrivilegeParseVisitor
     final PathPatternTree thisPatternTree = new PathPatternTree();
     thisPatternTree.appendPathPattern(partialPath);
     thisPatternTree.constructTree();
-    final PathPatternTree intersectedTree =
-        
thisPatternTree.intersectWithFullPathPrefixTree(getAuthorizedPTree(userEntity));
+    final PathPatternTree intersectedTree = new PathPatternTree();
+    // Intersect each authorization separately so an unmatched prefix cannot 
leave an ancestor
+    // path in the result tree.
+    for (final PartialPath authorizedPath : 
getAuthorizedPTree(userEntity).getAllPathPatterns()) {
+      if (authorizedPath.endWithMultiLevelWildcard()) {
+        partialPath
+            .intersectWithPrefixPattern(authorizedPath)
+            .forEach(intersectedTree::appendPathPattern);
+      } else if (partialPath.matchFullPath(authorizedPath)) {
+        intersectedTree.appendPathPattern(authorizedPath);
+      }
+    }
+    intersectedTree.constructTree();
     if (!skip && !thisPatternTree.equals(intersectedTree)) {
       throw new 
AccessDeniedException(ManagerMessages.NOT_HAS_PRIVILEGE_TO_TRANSFER_PLAN + 
plan);
     }
diff --git 
a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitorTest.java
 
b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitorTest.java
index d88a13a2517..f1ad4050032 100644
--- 
a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitorTest.java
+++ 
b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitorTest.java
@@ -277,6 +277,55 @@ public class PipeConfigTreePrivilegeParseVisitorTest {
             .isPresent());
   }
 
+  @Test
+  public void testTTLTrimToNarrowerAuthorizedPath() {
+    final SetTTLPlan trimmedPlan =
+        (SetTTLPlan)
+            skipVisitor
+                .visitTTL(new SetTTLPlan(new String[] {"root", "db", "**"}, 
100), FAKE_USER_ENTITY)
+                .orElseThrow(AssertionError::new);
+
+    Assert.assertArrayEquals(
+        new String[] {"root", "db", "device", "**"}, 
trimmedPlan.getPathPattern());
+    Assert.assertEquals(100, trimmedPlan.getTTL());
+  }
+
+  @Test
+  public void testTTLSkipsMultipleAuthorizedPaths() {
+    permissionManager.setAuthorizedPaths(
+        List.of(
+            new PartialPath(new String[] {"root", "db", "device1"}),
+            new PartialPath(new String[] {"root", "db", "device2"})));
+
+    Assert.assertFalse(
+        skipVisitor
+            .visitTTL(new SetTTLPlan(new String[] {"root", "db", "**"}, 100), 
FAKE_USER_ENTITY)
+            .isPresent());
+  }
+
+  @Test
+  public void testTTLSkipsAncestorOfAuthorizedPath() {
+    final SetTTLPlan plan = new SetTTLPlan(new String[] {"root", "db"}, 100);
+
+    Assert.assertFalse(skipVisitor.visitTTL(plan, 
FAKE_USER_ENTITY).isPresent());
+    Assert.assertThrows(
+        AccessDeniedException.class, () -> throwVisitor.visitTTL(plan, 
FAKE_USER_ENTITY));
+  }
+
+  @Test
+  public void testTTLWithFullPathAuthorization() {
+    final String[] path = new String[] {"root", "db", "device"};
+    permissionManager.setAuthorizedPaths(Collections.singletonList(new 
PartialPath(path)));
+    final SetTTLPlan plan = new SetTTLPlan(path, 100);
+
+    for (final PipeConfigTreePrivilegeParseVisitor visitor : 
List.of(skipVisitor, throwVisitor)) {
+      final SetTTLPlan authorizedPlan =
+          (SetTTLPlan) visitor.visitTTL(plan, 
FAKE_USER_ENTITY).orElseThrow(AssertionError::new);
+      Assert.assertArrayEquals(path, authorizedPlan.getPathPattern());
+      Assert.assertEquals(100, authorizedPlan.getTTL());
+    }
+  }
+
   @Test
   public void 
testSourcePrivilegeTrimDoesNotFallbackToTableDefaultForTreePlan() throws 
Exception {
     final PipeConfigRegionWritePlanEvent unauthorizedTreeEvent =
@@ -322,6 +371,8 @@ public class PipeConfigTreePrivilegeParseVisitorTest {
 
     private BiFunction<String, PrivilegeUnion, Boolean> checkUserPrivileges =
         (userName, privilegeUnion) -> true;
+    private List<PartialPath> authorizedPaths =
+        Collections.singletonList(new PartialPath(new String[] {"root", "db", 
"device", "**"}));
 
     public TestPermissionManager() {
       super(null, null);
@@ -344,11 +395,15 @@ public class PipeConfigTreePrivilegeParseVisitorTest {
     public PathPatternTree fetchRawAuthorizedPTree(
         final String userName, final PrivilegeType type) {
       final PathPatternTree tree = new PathPatternTree();
-      tree.appendPathPattern(new PartialPath(new String[] {"root", "db", 
"device", "**"}));
+      authorizedPaths.forEach(tree::appendPathPattern);
       tree.constructTree();
       return tree;
     }
 
+    private void setAuthorizedPaths(final List<PartialPath> authorizedPaths) {
+      this.authorizedPaths = authorizedPaths;
+    }
+
     @Override
     public TPermissionInfoResp checkRoleOfUser(String username, String 
rolename) {
       return Objects.equals(username, rolename)

Reply via email to