Skip to content

Commit 5621279

Browse files
authored
Audit SQL 'COUNT DATABASE' (#16569)
1 parent d65fa92 commit 5621279

2 files changed

Lines changed: 35 additions & 13 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/db/it/audit/IoTDBAuditLogBasicIT.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,12 @@ public static void closeConnectionCompletely(Connection connection) throws Inter
277277
"127.0.0.1",
278278
"OBJECT_AUTHENTICATION",
279279
"QUERY",
280-
"[MANAGE_DATABASE]",
281-
"OBJECT",
280+
"[SYSTEM]",
281+
"GLOBAL",
282282
"true",
283283
"[root.__audit]",
284284
"SHOW DATABASES root.__audit",
285-
"User root (ID=0) requests authority on object root.__audit with result true"),
285+
"User root (ID=0) requests authority on object [root.__audit] with result true"),
286286
Arrays.asList(
287287
"node_1",
288288
"u_0",
@@ -1305,7 +1305,7 @@ public void basicAuditLogTestForTableModel() throws SQLException, InterruptedExc
13051305
Arrays.asList(
13061306
"CREATE DATABASE root.test",
13071307
"show databases",
1308-
// "COUNT databases",
1308+
"COUNT databases",
13091309
"set ttl to root.test.** INF",
13101310
"create timeseries root.test.d1.s1 with datatype=BOOLEAN",
13111311
"create timeseries root.test.d1.s2 with datatype=INT64",
@@ -1425,11 +1425,11 @@ public void basicAuditLogTestForTableModel() throws SQLException, InterruptedExc
14251425
Arrays.asList(
14261426
"root.__audit.log.node_1.u_0",
14271427
"true",
1428-
"OBJECT",
1429-
"[MANAGE_DATABASE]",
1428+
"GLOBAL",
1429+
"[SYSTEM]",
14301430
"[root.__audit]",
14311431
"QUERY",
1432-
"User root (ID=0) requests authority on object root.__audit with result true",
1432+
"User root (ID=0) requests authority on object [root.__audit] with result true",
14331433
"SHOW DATABASES root.__audit",
14341434
"OBJECT_AUTHENTICATION",
14351435
"127.0.0.1",
@@ -1566,15 +1566,29 @@ public void basicAuditLogTestForTableModel() throws SQLException, InterruptedExc
15661566
Arrays.asList(
15671567
"root.__audit.log.node_1.u_0",
15681568
"true",
1569-
"OBJECT",
1570-
"[MANAGE_DATABASE]",
1569+
"GLOBAL",
1570+
"[SYSTEM]",
15711571
"[root.**]",
15721572
"QUERY",
1573-
"User root (ID=0) requests authority on object root.** with result true",
1573+
"User root (ID=0) requests authority on object [root.**] with result true",
15741574
"show databases",
15751575
"OBJECT_AUTHENTICATION",
15761576
"127.0.0.1",
15771577
"root")),
1578+
// Count database
1579+
new AuditLogSet(
1580+
Arrays.asList(
1581+
"root.__audit.log.node_1.u_0",
1582+
"true",
1583+
"GLOBAL",
1584+
"[SYSTEM]",
1585+
"[root.**]",
1586+
"QUERY",
1587+
"User root (ID=0) requests authority on object [root.**] with result true",
1588+
"COUNT databases",
1589+
"OBJECT_AUTHENTICATION",
1590+
"127.0.0.1",
1591+
"root")),
15781592
// Set TTL to database
15791593
new AuditLogSet(
15801594
Arrays.asList(

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,11 +943,10 @@ public TSStatus visitShowStorageGroup(
943943
showDatabaseStatement.getPaths().stream()
944944
.distinct()
945945
.collect(Collectors.toList())
946-
.toString())
947-
.setPrivilegeType(PrivilegeType.MANAGE_DATABASE);
946+
.toString());
948947
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
949948
recordObjectAuthenticationAuditLog(
950-
context.setResult(true), () -> showDatabaseStatement.getPathPattern().toString());
949+
context.setPrivilegeType(PrivilegeType.SYSTEM).setResult(true), context::getDatabase);
951950
return SUCCEED;
952951
}
953952
setCanSeeAuditDB(showDatabaseStatement, context);
@@ -957,7 +956,16 @@ public TSStatus visitShowStorageGroup(
957956
@Override
958957
public TSStatus visitCountStorageGroup(
959958
CountDatabaseStatement countDatabaseStatement, TreeAccessCheckContext context) {
959+
context
960+
.setAuditLogOperation(AuditLogOperation.QUERY)
961+
.setDatabase(
962+
countDatabaseStatement.getPaths().stream()
963+
.distinct()
964+
.collect(Collectors.toList())
965+
.toString());
960966
if (AuthorityChecker.SUPER_USER.equals(context.getUsername())) {
967+
recordObjectAuthenticationAuditLog(
968+
context.setPrivilegeType(PrivilegeType.SYSTEM).setResult(true), context::getDatabase);
961969
return SUCCEED;
962970
}
963971
setCanSeeAuditDB(countDatabaseStatement, context);

0 commit comments

Comments
 (0)