Skip to content

Commit 8cb4b9b

Browse files
authored
Reduced the auth log when paths are too many (#16825)
* partial * test
1 parent 19ebbe3 commit 8cb4b9b

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,17 @@ public static TSStatus getTSStatus(
304304
prompt.append(neededPrivilege);
305305
prompt.append(" on [");
306306
prompt.append(pathList.get(noPermissionIndexList.get(0)));
307-
for (int i = 1; i < noPermissionIndexList.size(); i++) {
307+
final int size =
308+
Math.min(
309+
noPermissionIndexList.size(),
310+
CommonDescriptor.getInstance().getConfig().getPathLogMaxSize());
311+
for (int i = 1; i < size; i++) {
308312
prompt.append(", ");
309313
prompt.append(pathList.get(noPermissionIndexList.get(i)));
310314
}
315+
if (size < noPermissionIndexList.size()) {
316+
prompt.append(", ...");
317+
}
311318
prompt.append("]");
312319
return new TSStatus(TSStatusCode.NO_PERMISSION.getStatusCode()).setMessage(prompt.toString());
313320
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.db.auth;
21+
22+
import org.apache.iotdb.commons.auth.entity.PrivilegeType;
23+
import org.apache.iotdb.commons.conf.CommonConfig;
24+
import org.apache.iotdb.commons.conf.CommonDescriptor;
25+
import org.apache.iotdb.commons.exception.IllegalPathException;
26+
import org.apache.iotdb.commons.path.MeasurementPath;
27+
28+
import org.junit.Assert;
29+
import org.junit.Test;
30+
31+
import java.util.Arrays;
32+
33+
public class AuthorityCheckerTest {
34+
35+
@Test
36+
public void testLogReduce() throws IllegalPathException {
37+
final CommonConfig config = CommonDescriptor.getInstance().getConfig();
38+
final int oldSize = config.getPathLogMaxSize();
39+
config.setPathLogMaxSize(1);
40+
Assert.assertEquals(
41+
"No permissions for this operation, please add privilege WRITE_DATA on [root.db.device.s1, ...]",
42+
AuthorityChecker.getTSStatus(
43+
Arrays.asList(0, 1),
44+
Arrays.asList(
45+
new MeasurementPath("root.db.device.s1"),
46+
new MeasurementPath("root.db.device.s2")),
47+
PrivilegeType.WRITE_DATA)
48+
.getMessage());
49+
config.setPathLogMaxSize(oldSize);
50+
}
51+
}

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ public class CommonConfig {
472472
private PrivilegeLevel auditableOperationLevel = PrivilegeLevel.GLOBAL;
473473

474474
private String auditableOperationResult = "SUCCESS, FAIL";
475+
private int pathLogMaxSize = 100;
475476

476477
CommonConfig() {
477478
// Empty constructor
@@ -2531,6 +2532,14 @@ public void setLog2SizeClassGroup(int log2SizeClassGroup) {
25312532
this.log2SizeClassGroup = log2SizeClassGroup;
25322533
}
25332534

2535+
public int getPathLogMaxSize() {
2536+
return pathLogMaxSize;
2537+
}
2538+
2539+
public void setPathLogMaxSize(int pathLogMaxSize) {
2540+
this.pathLogMaxSize = pathLogMaxSize;
2541+
}
2542+
25342543
/**
25352544
* @param querySamplingRateLimit query_sample_throughput_bytes_per_sec
25362545
*/

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ public void loadCommonProps(TrimProperties properties) throws IOException {
276276
"cluster_device_limit_threshold",
277277
String.valueOf(config.getDeviceLimitThreshold()))));
278278

279+
config.setPathLogMaxSize(
280+
Integer.parseInt(
281+
properties.getProperty(
282+
"path_log_max_size", String.valueOf(config.getPathLogMaxSize()))));
283+
279284
loadRetryProperties(properties);
280285
loadBinaryAllocatorProps(properties);
281286
}

0 commit comments

Comments
 (0)