Skip to content

Commit 25c86c2

Browse files
authored
reject grant/revoke author statement on audit database
1 parent 70b9643 commit 25c86c2

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBAuthIT.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,4 +1678,42 @@ public void testSecurityPrivilege() {
16781678
fail(e.getMessage());
16791679
}
16801680
}
1681+
1682+
@Test
1683+
public void testAudit() {
1684+
try (Connection connection = EnvFactory.getEnv().getConnection();
1685+
Statement statement = connection.createStatement()) {
1686+
try {
1687+
statement.execute("grant read_data on root.__audit to user user2");
1688+
} catch (SQLException e) {
1689+
assertEquals(
1690+
"803: Access Denied: Cannot grant or revoke any privileges to root.__audit",
1691+
e.getMessage());
1692+
}
1693+
try {
1694+
statement.execute("revoke read_data on root.__audit from user user2");
1695+
} catch (SQLException e) {
1696+
assertEquals(
1697+
"803: Access Denied: Cannot grant or revoke any privileges to root.__audit",
1698+
e.getMessage());
1699+
}
1700+
try {
1701+
statement.execute("grant read_data on root.__audit to role role1");
1702+
} catch (SQLException e) {
1703+
assertEquals(
1704+
"803: Access Denied: Cannot grant or revoke any privileges to root.__audit",
1705+
e.getMessage());
1706+
}
1707+
try {
1708+
statement.execute("revoke read_data on root.__audit from role role1");
1709+
} catch (SQLException e) {
1710+
assertEquals(
1711+
"803: Access Denied: Cannot grant or revoke any privileges to root.__audit",
1712+
e.getMessage());
1713+
}
1714+
} catch (SQLException e) {
1715+
e.printStackTrace();
1716+
fail(e.getMessage());
1717+
}
1718+
}
16811719
}

integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBRelationalAuthIT.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,4 +568,41 @@ public void testAlterNonExistingUser() throws SQLException {
568568
}
569569
}
570570
}
571+
572+
@Test
573+
public void testAudit() throws SQLException {
574+
try (Connection adminCon = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
575+
Statement adminStmt = adminCon.createStatement()) {
576+
try {
577+
adminStmt.execute("grant select on database __audit to user user2");
578+
} catch (SQLException e) {
579+
assertEquals(
580+
"803: Access Denied: Cannot grant or revoke any privileges to __audit", e.getMessage());
581+
}
582+
try {
583+
adminStmt.execute("grant select on table __audit.t1 to user user2");
584+
} catch (SQLException e) {
585+
assertEquals(
586+
"803: Access Denied: Cannot grant or revoke any privileges to __audit", e.getMessage());
587+
}
588+
try {
589+
adminStmt.execute("revoke select on table __audit.t1 from user user2");
590+
} catch (SQLException e) {
591+
assertEquals(
592+
"803: Access Denied: Cannot grant or revoke any privileges to __audit", e.getMessage());
593+
}
594+
try {
595+
adminStmt.execute("grant select on table __audit.t1 to role role1");
596+
} catch (SQLException e) {
597+
assertEquals(
598+
"803: Access Denied: Cannot grant or revoke any privileges to __audit", e.getMessage());
599+
}
600+
try {
601+
adminStmt.execute("revoke select on table __audit.t1 from role role1");
602+
} catch (SQLException e) {
603+
assertEquals(
604+
"803: Access Denied: Cannot grant or revoke any privileges to __audit", e.getMessage());
605+
}
606+
}
607+
}
571608
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/RelationalAuthorStatement.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.apache.iotdb.common.rpc.thrift.TSStatus;
2222
import org.apache.iotdb.commons.auth.entity.PrivilegeType;
23+
import org.apache.iotdb.commons.schema.table.Audit;
2324
import org.apache.iotdb.commons.schema.table.InformationSchema;
2425
import org.apache.iotdb.commons.utils.AuthUtils;
2526
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
@@ -423,6 +424,11 @@ public TSStatus checkStatementIsValid(String currentUser) {
423424
return AuthorityChecker.getTSStatus(
424425
false, "Cannot grant or revoke any privileges to information_schema");
425426
}
427+
if (Audit.TABLE_MODEL_AUDIT_DATABASE.equals(database)) {
428+
return AuthorityChecker.getTSStatus(
429+
false,
430+
"Cannot grant or revoke any privileges to " + Audit.TABLE_MODEL_AUDIT_DATABASE);
431+
}
426432
break;
427433
case GRANT_USER_TB:
428434
case GRANT_ROLE_TB:
@@ -436,6 +442,11 @@ public TSStatus checkStatementIsValid(String currentUser) {
436442
return AuthorityChecker.getTSStatus(
437443
false, "Cannot grant or revoke any privileges to information_schema");
438444
}
445+
if (Audit.TABLE_MODEL_AUDIT_DATABASE.equals(database)) {
446+
return AuthorityChecker.getTSStatus(
447+
false,
448+
"Cannot grant or revoke any privileges to " + Audit.TABLE_MODEL_AUDIT_DATABASE);
449+
}
439450
break;
440451
default:
441452
break;

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/sys/AuthorStatement.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.iotdb.common.rpc.thrift.TSStatus;
2323
import org.apache.iotdb.commons.path.PartialPath;
24+
import org.apache.iotdb.commons.schema.table.Audit;
2425
import org.apache.iotdb.commons.utils.AuthUtils;
2526
import org.apache.iotdb.commons.utils.CommonDateTimeUtils;
2627
import org.apache.iotdb.db.auth.AuthorityChecker;
@@ -340,6 +341,11 @@ public TSStatus checkStatementIsValid(String currentUser) {
340341
return AuthorityChecker.getTSStatus(
341342
false, "Cannot grant/revoke privileges of admin user");
342343
}
344+
List<PartialPath> paths = getNodeNameList();
345+
if (paths.stream().anyMatch(Audit::includeByAuditTreeDB)) {
346+
return AuthorityChecker.getTSStatus(
347+
false, "Cannot grant or revoke any privileges to " + Audit.TREE_MODEL_AUDIT_DATABASE);
348+
}
343349
break;
344350
}
345351
return RpcUtils.SUCCESS_STATUS;

0 commit comments

Comments
 (0)