Skip to content

Commit 263c23b

Browse files
authored
Pipe: Fixed the auth implementation error (#16847)
* fix * fix * non-geneic * fix
1 parent f68c49e commit 263c23b

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

integration-test/src/test/java/org/apache/iotdb/pipe/it/single/IoTDBPipePermissionIT.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
package org.apache.iotdb.pipe.it.single;
2121

22-
import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
23-
import org.apache.iotdb.confignode.rpc.thrift.TShowPipeReq;
2422
import org.apache.iotdb.db.it.utils.TestUtils;
2523
import org.apache.iotdb.it.framework.IoTDBTestRunner;
2624
import org.apache.iotdb.itbase.category.MultiClusterIT1;
@@ -33,6 +31,7 @@
3331
import org.junit.runner.RunWith;
3432

3533
import java.sql.Connection;
34+
import java.sql.ResultSet;
3635
import java.sql.SQLException;
3736
import java.sql.Statement;
3837
import java.util.Arrays;
@@ -44,7 +43,7 @@
4443
public class IoTDBPipePermissionIT extends AbstractPipeSingleIT {
4544
@Test
4645
public void testSinkPermission() {
47-
TestUtils.executeNonQuery(env, "create user `thulab` 'passwd'", null);
46+
TestUtils.executeNonQuery(env, "create user `thulab` 'StrngPsWd@623451'", null);
4847

4948
// Shall fail if username is specified without password
5049
try (final Connection connection = env.getConnection(BaseEnv.TABLE_SQL_DIALECT);
@@ -90,7 +89,8 @@ public void testSinkPermission() {
9089
// Successfully alter
9190
try (final Connection connection = env.getConnection(BaseEnv.TABLE_SQL_DIALECT);
9291
final Statement statement = connection.createStatement()) {
93-
statement.execute("alter pipe a2b modify sink ('username'='thulab', 'password'='passwd')");
92+
statement.execute(
93+
"alter pipe a2b modify sink ('username'='thulab', 'password'='StrngPsWd@623451')");
9494
} catch (final SQLException e) {
9595
e.printStackTrace();
9696
fail("Alter pipe shall not fail if user and password are specified");
@@ -156,14 +156,12 @@ public void testSinkPermission() {
156156
}
157157

158158
// A user shall only see its own pipe
159-
try (final SyncConfigNodeIServiceClient client =
160-
(SyncConfigNodeIServiceClient) env.getLeaderConfigNodeConnection()) {
161-
Assert.assertEquals(
162-
1,
163-
client
164-
.showPipe(new TShowPipeReq().setIsTableModel(true).setUserName("thulab"))
165-
.pipeInfoList
166-
.size());
159+
try (final Connection connection =
160+
env.getConnection("thulab", "StrngPsWd@623451", BaseEnv.TABLE_SQL_DIALECT);
161+
final Statement statement = connection.createStatement()) {
162+
final ResultSet result = statement.executeQuery("show pipes");
163+
Assert.assertTrue(result.next());
164+
Assert.assertFalse(result.next());
167165
} catch (Exception e) {
168166
fail(e.getMessage());
169167
}
@@ -181,7 +179,8 @@ public void testSinkPermissionWithHistoricalDataAndTablePattern() {
181179
BaseEnv.TABLE_SQL_DIALECT,
182180
env,
183181
Arrays.asList(
184-
"create user thulab 'passwD@123456'", "grant INSERT on test.test1 to user thulab"),
182+
"create user thulab 'StrngPsWd@623451@123456'",
183+
"grant INSERT on test.test1 to user thulab"),
185184
null);
186185

187186
// Write some data
@@ -196,7 +195,7 @@ public void testSinkPermissionWithHistoricalDataAndTablePattern() {
196195
"create pipe a2b "
197196
+ "with source ('database'='test1', 'table'='test1') "
198197
+ "with processor('processor'='rename-database-processor', 'processor.new-db-name'='test') "
199-
+ "with sink ('sink'='write-back-sink', 'username'='thulab', 'password'='passwD@123456')");
198+
+ "with sink ('sink'='write-back-sink', 'username'='thulab', 'password'='StrngPsWd@623451@123456')");
200199
} catch (final SQLException e) {
201200
e.printStackTrace();
202201
fail("Create pipe without user shall succeed if use the current session");

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ public void testInformationSchema() throws SQLException {
575575
Assert.assertThrows(
576576
SQLException.class, () -> statement.execute("select * from config_nodes"));
577577
Assert.assertThrows(SQLException.class, () -> statement.execute("select * from data_nodes"));
578+
Assert.assertThrows(
579+
SQLException.class, () -> statement.executeQuery("select * from pipe_plugins"));
578580

579581
// Filter out not self-created pipes
580582
TestUtils.assertResultSetEqual(
@@ -583,12 +585,6 @@ public void testInformationSchema() throws SQLException {
583585
Collections.emptySet());
584586

585587
// No auth needed
586-
TestUtils.assertResultSetEqual(
587-
statement.executeQuery(
588-
"select * from pipe_plugins where plugin_name = 'IOTDB-THRIFT-SINK'"),
589-
"plugin_name,plugin_type,class_name,plugin_jar,",
590-
Collections.singleton(
591-
"IOTDB-THRIFT-SINK,Builtin,org.apache.iotdb.commons.pipe.agent.plugin.builtin.sink.iotdb.thrift.IoTDBThriftSink,null,"));
592588

593589
TestUtils.assertResultSetEqual(
594590
statement.executeQuery(

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/InformationSchemaContentSupplierFactory.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation;
2929
import org.apache.iotdb.common.rpc.thrift.TEndPoint;
3030
import org.apache.iotdb.commons.audit.UserEntity;
31+
import org.apache.iotdb.commons.client.exception.ClientManagerException;
3132
import org.apache.iotdb.commons.conf.IoTDBConstant;
3233
import org.apache.iotdb.commons.exception.IoTDBRuntimeException;
3334
import org.apache.iotdb.commons.exception.auth.AccessDeniedException;
@@ -82,6 +83,7 @@
8283
import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
8384
import org.apache.iotdb.rpc.TSStatusCode;
8485

86+
import org.apache.thrift.TException;
8587
import org.apache.tsfile.block.column.ColumnBuilder;
8688
import org.apache.tsfile.common.conf.TSFileConfig;
8789
import org.apache.tsfile.enums.TSDataType;
@@ -143,7 +145,7 @@ public static Iterator<TsBlock> getSupplier(
143145
case InformationSchema.PIPES:
144146
return new PipeSupplier(dataTypes, userEntity.getUsername());
145147
case InformationSchema.PIPE_PLUGINS:
146-
return new PipePluginSupplier(dataTypes);
148+
return new PipePluginSupplier(dataTypes, userEntity);
147149
case InformationSchema.TOPICS:
148150
return new TopicSupplier(dataTypes, userEntity);
149151
case InformationSchema.SUBSCRIPTIONS:
@@ -603,8 +605,10 @@ public boolean hasNext() {
603605
private static class PipePluginSupplier extends TsBlockSupplier {
604606
private final Iterator<PipePluginMeta> iterator;
605607

606-
private PipePluginSupplier(final List<TSDataType> dataTypes) throws Exception {
608+
private PipePluginSupplier(final List<TSDataType> dataTypes, final UserEntity entity)
609+
throws ClientManagerException, TException {
607610
super(dataTypes);
611+
accessControl.checkUserGlobalSysPrivilege(entity);
608612
try (final ConfigNodeClient client =
609613
ConfigNodeClientManager.getInstance().borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {
610614
iterator =

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,6 @@ protected IConfigTask visitStopPipe(StopPipe node, MPPQueryContext context) {
12701270
@Override
12711271
protected IConfigTask visitShowPipes(ShowPipes node, MPPQueryContext context) {
12721272
context.setQueryType(QueryType.READ);
1273-
accessControl.checkUserGlobalSysPrivilege(context);
12741273
return new ShowPipeTask(node, context.getSession().getUserName());
12751274
}
12761275

0 commit comments

Comments
 (0)