Skip to content

Commit 2a26c6e

Browse files
authored
Pipe: Fixed the bug that auth plan with system privileges can not be transferred (#14489)
1 parent 2076bf6 commit 2a26c6e

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

integration-test/src/test/java/org/apache/iotdb/pipe/it/manual/IoTDBPipeInclusionIT.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public void testAuthInclusionWithPattern() throws Exception {
180180
senderEnv,
181181
Arrays.asList(
182182
"create user `ln_write_user` 'write_pwd'",
183+
"grant manage_database,manage_user,manage_role,use_trigger,use_udf,use_cq,use_pipe on root.** to USER ln_write_user with grant option",
183184
"GRANT READ_DATA, WRITE_DATA ON root.** TO USER ln_write_user;"))) {
184185
return;
185186
}
@@ -189,7 +190,16 @@ public void testAuthInclusionWithPattern() throws Exception {
189190
"LIST PRIVILEGES OF USER ln_write_user",
190191
"ROLE,PATH,PRIVILEGES,GRANT OPTION,",
191192
new HashSet<>(
192-
Arrays.asList(",root.ln.**,READ_DATA,false,", ",root.ln.**,WRITE_DATA,false,")));
193+
Arrays.asList(
194+
",root.**,MANAGE_USER,true,",
195+
",root.**,MANAGE_ROLE,true,",
196+
",root.**,USE_TRIGGER,true,",
197+
",root.**,USE_UDF,true,",
198+
",root.**,USE_CQ,true,",
199+
",root.**,USE_PIPE,true,",
200+
",root.**,MANAGE_DATABASE,true,",
201+
",root.ln.**,READ_DATA,false,",
202+
",root.ln.**,WRITE_DATA,false,")));
193203
}
194204
}
195205

integration-test/src/test/java/org/apache/iotdb/pipe/it/manual/IoTDBPipeMetaHistoricalIT.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ public void testAuthInclusion() throws Exception {
192192
"create role `admin`",
193193
"grant role `admin` to `thulab`",
194194
"grant read on root.** to role `admin`",
195+
"grant manage_database,manage_user,manage_role,use_trigger,use_udf,use_cq,use_pipe on root.** to role `admin`;",
195196
"create schema template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)",
196197
"set schema template t1 to root.ln.wf01",
197198
"create timeseries using schema template on root.ln.wf01.wt01",
@@ -241,7 +242,16 @@ public void testAuthInclusion() throws Exception {
241242
+ ColumnHeaderConstant.GRANT_OPTION
242243
+ ",",
243244
new HashSet<>(
244-
Arrays.asList("admin,root.**,READ_DATA,false,", "admin,root.**,READ_SCHEMA,false,")));
245+
Arrays.asList(
246+
"admin,root.**,MANAGE_USER,false,",
247+
"admin,root.**,MANAGE_ROLE,false,",
248+
"admin,root.**,USE_TRIGGER,false,",
249+
"admin,root.**,USE_UDF,false,",
250+
"admin,root.**,USE_CQ,false,",
251+
"admin,root.**,USE_PIPE,false,",
252+
"admin,root.**,MANAGE_DATABASE,false,",
253+
"admin,root.**,READ_DATA,false,",
254+
"admin,root.**,READ_SCHEMA,false,")));
245255

246256
TestUtils.assertDataAlwaysOnEnv(
247257
receiverEnv,

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/extractor/PipeConfigPhysicalPlanPatternParseVisitor.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.apache.iotdb.confignode.manager.pipe.extractor;
2121

22+
import org.apache.iotdb.commons.auth.entity.PrivilegeType;
2223
import org.apache.iotdb.commons.path.PartialPath;
2324
import org.apache.iotdb.commons.path.PathPatternTree;
2425
import org.apache.iotdb.commons.pipe.datastructure.pattern.IoTDBTreePattern;
@@ -50,6 +51,7 @@
5051
import java.util.List;
5152
import java.util.Map;
5253
import java.util.Optional;
54+
import java.util.Set;
5355
import java.util.stream.Collectors;
5456
import java.util.stream.IntStream;
5557
import java.util.stream.Stream;
@@ -192,15 +194,21 @@ private Optional<ConfigPhysicalPlan> visitPathRelatedAuthorPlan(
192194
.map(pattern::getIntersection)
193195
.flatMap(Collection::stream)
194196
.collect(Collectors.toList());
195-
return !intersectedPaths.isEmpty()
197+
final Set<Integer> permissions =
198+
!intersectedPaths.isEmpty()
199+
? pathRelatedAuthorPlan.getPermissions()
200+
: pathRelatedAuthorPlan.getPermissions().stream()
201+
.filter(permission -> !PrivilegeType.values()[permission].isPathRelevant())
202+
.collect(Collectors.toSet());
203+
return !permissions.isEmpty()
196204
? Optional.of(
197205
new AuthorPlan(
198206
pathRelatedAuthorPlan.getAuthorType(),
199207
pathRelatedAuthorPlan.getUserName(),
200208
pathRelatedAuthorPlan.getRoleName(),
201209
pathRelatedAuthorPlan.getPassword(),
202210
pathRelatedAuthorPlan.getNewPassword(),
203-
pathRelatedAuthorPlan.getPermissions(),
211+
permissions,
204212
pathRelatedAuthorPlan.getGrantOpt(),
205213
intersectedPaths))
206214
: Optional.empty();

0 commit comments

Comments
 (0)