File tree Expand file tree Collapse file tree 4 files changed +92
-0
lines changed
integration-test/src/test/java/org/apache/iotdb/db/it/auth
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 2020
2121import org .apache .iotdb .common .rpc .thrift .TSStatus ;
2222import org .apache .iotdb .commons .auth .entity .PrivilegeType ;
23+ import org .apache .iotdb .commons .schema .table .Audit ;
2324import org .apache .iotdb .commons .schema .table .InformationSchema ;
2425import org .apache .iotdb .commons .utils .AuthUtils ;
2526import 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 ;
Original file line number Diff line number Diff line change 2121
2222import org .apache .iotdb .common .rpc .thrift .TSStatus ;
2323import org .apache .iotdb .commons .path .PartialPath ;
24+ import org .apache .iotdb .commons .schema .table .Audit ;
2425import org .apache .iotdb .commons .utils .AuthUtils ;
2526import org .apache .iotdb .commons .utils .CommonDateTimeUtils ;
2627import 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 ;
You can’t perform that action at this time.
0 commit comments