Skip to content

Commit 0f22239

Browse files
authored
Added privilege for information_schema & Removed the privilege requirement for show pipePlugins
1 parent 2ffe340 commit 0f22239

File tree

12 files changed

+200
-126
lines changed

12 files changed

+200
-126
lines changed

integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBMaintainAuthIT.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,10 @@ public void maintainAuthTest() {
165165
PASSWORD);
166166

167167
// case 12: show queries
168-
// user1 with select on information_schema.queries
169-
tableAssertTestFail(
170-
"SHOW QUERIES",
171-
TSStatusCode.NO_PERMISSION.getStatusCode()
172-
+ ": Access Denied: No permissions for this operation, only root user is allowed",
173-
USER_1,
174-
PASSWORD);
175-
// user2 without select on information_schema.queries
176-
tableAssertTestFail(
177-
"SHOW QUERIES",
178-
TSStatusCode.NO_PERMISSION.getStatusCode()
179-
+ ": Access Denied: No permissions for this operation, only root user is allowed",
180-
USER_2,
181-
PASSWORD);
168+
// non-root users can access its own queries
169+
expectedHeader =
170+
new String[] {"query_id", "start_time", "datanode_id", "elapsed_time", "statement", "user"};
171+
tableQueryNoVerifyResultTest("show queries", expectedHeader, USER_2, PASSWORD);
182172

183173
// case 13: kill query
184174
// user2

integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,50 @@ public void testInformationSchema() throws SQLException {
514514
"ColumnName,DataType,Category,",
515515
new HashSet<>(Arrays.asList("word,STRING,TAG,", "reserved,INT32,ATTRIBUTE,")));
516516

517-
// Currently only root can query information_schema
517+
// Only root user is allowed
518+
Assert.assertThrows(SQLException.class, () -> statement.execute("select * from regions"));
519+
Assert.assertThrows(SQLException.class, () -> statement.execute("select * from pipes"));
520+
Assert.assertThrows(SQLException.class, () -> statement.execute("select * from topics"));
518521
Assert.assertThrows(
519-
SQLException.class,
520-
() -> {
521-
statement.execute("select * from databases");
522-
});
522+
SQLException.class, () -> statement.execute("select * from subscriptions"));
523+
Assert.assertThrows(
524+
SQLException.class, () -> statement.execute("select * from configurations"));
525+
526+
// No auth needed
527+
TestUtils.assertResultSetEqual(
528+
statement.executeQuery(
529+
"select * from pipe_plugins where plugin_name = 'IOTDB-THRIFT-SINK'"),
530+
"plugin_name,plugin_type,class_name,plugin_jar,",
531+
Collections.singleton(
532+
"IOTDB-THRIFT-SINK,Builtin,org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.iotdb.thrift.IoTDBThriftConnector,null,"));
533+
534+
TestUtils.assertResultSetEqual(
535+
statement.executeQuery(
536+
"select model_id from information_schema.models where model_type = 'BUILT_IN_FORECAST'"),
537+
"model_id,",
538+
new HashSet<>(
539+
Arrays.asList(
540+
"_timerxl,",
541+
"_STLForecaster,",
542+
"_NaiveForecaster,",
543+
"_ARIMA,",
544+
"_ExponentialSmoothing,")));
545+
546+
TestUtils.assertResultSetEqual(
547+
statement.executeQuery(
548+
"select distinct(function_type) from information_schema.functions"),
549+
"function_type,",
550+
new HashSet<>(
551+
Arrays.asList(
552+
"built-in scalar function,",
553+
"built-in aggregate function,",
554+
"built-in table function,")));
555+
556+
TestUtils.assertResultSetEqual(
557+
statement.executeQuery(
558+
"select * from information_schema.keywords where reserved > 0 limit 1"),
559+
"word,reserved,",
560+
Collections.singleton("AINODES,1,"));
523561
}
524562

525563
try (final Connection connection =
@@ -715,6 +753,8 @@ public void testDBAuth() throws SQLException {
715753
final Statement adminStmt = adminCon.createStatement()) {
716754
adminStmt.execute("create user test 'password'");
717755
adminStmt.execute("create database db");
756+
adminStmt.execute(
757+
"create pipe a2b with source('double-living'='true') with sink ('sink'='write-back-sink')");
718758
}
719759

720760
try (final Connection userCon =
@@ -724,6 +764,10 @@ public void testDBAuth() throws SQLException {
724764
userStmt.executeQuery("show databases"),
725765
"Database,TTL(ms),SchemaReplicationFactor,DataReplicationFactor,TimePartitionInterval,",
726766
Collections.singleton("information_schema,INF,null,null,null,"));
767+
TestUtils.assertResultSetEqual(
768+
userStmt.executeQuery("select * from information_schema.databases"),
769+
"database,ttl(ms),schema_replication_factor,data_replication_factor,time_partition_interval,schema_region_group_num,data_region_group_num,",
770+
Collections.singleton("information_schema,INF,null,null,null,null,null,"));
727771
}
728772

729773
try (final Connection adminCon = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);

integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableIT.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,15 @@ public void testTableAuth() throws SQLException {
636636
try (final Connection userCon =
637637
EnvFactory.getEnv().getConnection("test", "password", BaseEnv.TABLE_SQL_DIALECT);
638638
final Statement userStmt = userCon.createStatement()) {
639-
Assert.assertThrows(
640-
SQLException.class,
641-
() -> {
642-
userStmt.execute("select * from db.test");
643-
});
639+
Assert.assertThrows(SQLException.class, () -> userStmt.execute("select * from db.test"));
640+
TestUtils.assertResultSetEqual(
641+
userStmt.executeQuery("select * from information_schema.tables where database = 'db'"),
642+
"database,table_name,ttl(ms),status,comment,table_type,",
643+
Collections.emptySet());
644+
TestUtils.assertResultSetEqual(
645+
userStmt.executeQuery("select * from information_schema.columns where database = 'db'"),
646+
"database,table_name,column_name,datatype,category,status,comment,",
647+
Collections.emptySet());
644648
}
645649

646650
try (final Connection adminCon = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);

0 commit comments

Comments
 (0)