JackieTien97 commented on code in PR #19125:
URL: https://github.com/apache/iotdb/pull/19125#discussion_r4510373797


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/session/SessionManager.java:
##########
@@ -226,6 +226,88 @@ public BasicOpenSessionResp login(
     return openSessionResp;
   }
 
+  /**
+   * Opens a session without password verification for trusted internal client 
RPC callers.
+   *
+   * <p>This path is reachable only through the multiplexed client RPC service 
on the DataNode
+   * internal endpoint, which belongs to the trusted cluster/inter-node 
surface described in {@code
+   * THREAT_MODEL.md}. It intentionally does not emit failed-login audit 
records because it performs
+   * no credential verification; access is controlled by the network/transport 
boundary rather than
+   * by user login auditing.
+   */
+  public BasicOpenSessionResp loginInternal(
+      final IClientSession session,
+      final String username,
+      final String zoneId,
+      final TSProtocolVersion tsProtocolVersion,
+      final IoTDBConstant.ClientVersion clientVersion,
+      final SqlDialect sqlDialect) {
+    final BasicOpenSessionResp openSessionResp = new BasicOpenSessionResp();
+    final long userId = AuthorityChecker.getUserId(username).orElse(-1L);
+    if (userId == -1) {
+      final TSStatus status =
+          RpcUtils.getStatus(
+              TSStatusCode.USER_NOT_EXIST,
+              String.format(
+                  
DataNodeMiscMessages.MISC_EXCEPTION_USER_S_DOES_NOT_EXIST_0CE725D8, username));
+      
openSessionResp.sessionId(-1).setCode(status.getCode()).setMessage(status.getMessage());
+      return openSessionResp;
+    }
+
+    final TSStatus loginPolicyStatus =
+        AuthorityChecker.getAccessControl().allowUserToLogin(username);
+    if (loginPolicyStatus.getCode() != 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+      openSessionResp
+          .sessionId(-1)
+          .setCode(loginPolicyStatus.getCode())
+          .setMessage(loginPolicyStatus.getMessage());
+      return openSessionResp;
+    }
+
+    if (!tsProtocolVersion.equals(CURRENT_RPC_VERSION)) {
+      openSessionResp
+          .sessionId(-1)
+          .setCode(TSStatusCode.INCOMPATIBLE_VERSION.getStatusCode())
+          .setMessage(
+              DataNodeMiscMessages.VERSION_INCOMPATIBLE_PLEASE_UPGRADE_TO + 
IoTDBConstant.VERSION);
+      return openSessionResp;
+    }
+
+    session.setInternalRpcSession(true);
+    session.setSqlDialect(sqlDialect);
+    supplySession(session, userId, username, ZoneId.of(zoneId), clientVersion);
+    final String logInMessage = 
DataNodeMiscMessages.EXCEPTION_LOGIN_SUCCESSFULLY_1C2EF670;
+    openSessionResp
+        .sessionId(session.getId())
+        .setCode(TSStatusCode.SUCCESS_STATUS.getStatusCode())
+        .setMessage(logInMessage);
+    AUDIT_LOGGER.log(
+        new AuditLogFields(
+            userId,
+            username,
+            session.getClientAddress(),
+            AuditEventType.LOGIN,

Review Comment:
   This writes the same audit record as a password login in `login`: the same 
`AuditEventType.LOGIN`, the same result and the same message. An auditor can't 
tell that this session was opened on the internal endpoint without any 
credential check. These logins should be distinguishable from normal ones, for 
example with a dedicated `AuditEventType`, or at least a separate message 
constant saying the session was opened through the internal RPC endpoint 
without password verification.



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/service/DataNodeInternalRPCServiceTest.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.service;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.mpp.rpc.thrift.IDataNodeRPCService;
+import org.apache.iotdb.rpc.RpcServiceConstants;
+import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.service.rpc.thrift.IClientRPCService;
+import org.apache.iotdb.service.rpc.thrift.TSOpenSessionReq;
+import org.apache.iotdb.service.rpc.thrift.TSOpenSessionResp;
+import org.apache.iotdb.service.rpc.thrift.TSProtocolVersion;
+
+import org.apache.thrift.TMultiplexedProcessor;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.protocol.TMultiplexedProtocol;
+import org.apache.thrift.transport.TMemoryBuffer;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class DataNodeInternalRPCServiceTest {
+
+  @Test
+  public void testMultiplexedClientAndDefaultInternalRoutes() throws Exception 
{
+    final IClientRPCService.Iface clientHandler = 
mock(IClientRPCService.Iface.class);
+    final IDataNodeRPCService.Iface controlHandler = 
mock(IDataNodeRPCService.Iface.class);
+    final TSOpenSessionResp openSessionResp =
+        new TSOpenSessionResp(
+                new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()),
+                TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V3)
+            .setSessionId(10);
+    when(clientHandler.openSession(any())).thenReturn(openSessionResp);
+    when(controlHandler.testConnectionEmptyRPC())
+        .thenReturn(new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()));
+
+    final TMultiplexedProcessor processor = new TMultiplexedProcessor();

Review Comment:
   This test now builds its own `TMultiplexedProcessor`, so it only checks 
Thrift's routing against mocks. If `DataNodeInternalRPCService.initTProcessor` 
registered the wrong processor or dropped the default route, this would still 
pass. Either restore a small factory method that the service and this test both 
call, or remove this test and rely on the ITs.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/session/SessionManager.java:
##########
@@ -226,6 +226,88 @@ public BasicOpenSessionResp login(
     return openSessionResp;
   }
 
+  /**
+   * Opens a session without password verification for trusted internal client 
RPC callers.
+   *
+   * <p>This path is reachable only through the multiplexed client RPC service 
on the DataNode
+   * internal endpoint, which belongs to the trusted cluster/inter-node 
surface described in {@code
+   * THREAT_MODEL.md}. It intentionally does not emit failed-login audit 
records because it performs
+   * no credential verification; access is controlled by the network/transport 
boundary rather than
+   * by user login auditing.
+   */
+  public BasicOpenSessionResp loginInternal(
+      final IClientSession session,
+      final String username,
+      final String zoneId,
+      final TSProtocolVersion tsProtocolVersion,
+      final IoTDBConstant.ClientVersion clientVersion,
+      final SqlDialect sqlDialect) {
+    final BasicOpenSessionResp openSessionResp = new BasicOpenSessionResp();
+    final long userId = AuthorityChecker.getUserId(username).orElse(-1L);
+    if (userId == -1) {
+      final TSStatus status =
+          RpcUtils.getStatus(
+              TSStatusCode.USER_NOT_EXIST,
+              String.format(
+                  
DataNodeMiscMessages.MISC_EXCEPTION_USER_S_DOES_NOT_EXIST_0CE725D8, username));
+      
openSessionResp.sessionId(-1).setCode(status.getCode()).setMessage(status.getMessage());
+      return openSessionResp;
+    }
+
+    final TSStatus loginPolicyStatus =
+        AuthorityChecker.getAccessControl().allowUserToLogin(username);
+    if (loginPolicyStatus.getCode() != 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {

Review Comment:
   Neither rejection path in this method (the unknown user above, and the login 
policy here) has a test yet.



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/internal/subscription/InternalSubscriptionTablePullConsumerBuilder.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.client.internal.subscription;
+
+import org.apache.iotdb.session.i18n.SessionMessages;
+import 
org.apache.iotdb.session.subscription.consumer.ISubscriptionTablePullConsumer;
+import 
org.apache.iotdb.session.subscription.consumer.table.SubscriptionTablePullConsumerBuilder;
+
+/**
+ * Server-side builder for table subscription pull consumers.
+ *
+ * <p>Callers must configure an explicit internal RPC seed endpoint with host 
and port.
+ */
+public class InternalSubscriptionTablePullConsumerBuilder
+    extends SubscriptionTablePullConsumerBuilder {
+
+  @Override
+  protected ISubscriptionTablePullConsumer createConsumer() {
+    if (host == null || host.isEmpty() || port == null || port <= 0) {

Review Comment:
   Nothing tests this check. The auto-fetch checks in the session builders have 
lost their test as well: `InternalBuildersTest` was removed in 666e7203f5 with 
no replacement. None of these rejections needs a cluster, so one small unit 
test could cover them all.



##########
iotdb-client/subscription/src/main/java/org/apache/iotdb/session/subscription/consumer/base/AbstractSubscriptionConsumer.java:
##########
@@ -601,6 +632,8 @@ AbstractSubscriptionProvider 
constructProviderAndHandshake(final TEndPoint endPo
             this.heartbeatIntervalMs,
             this.connectionTimeoutInMs);
     provider.setConsumerInstanceId(consumerInstanceId);
+    provider.setRpcServiceName(getRpcServiceName());
+    provider.setSslConfig(useSSL, trustStore, trustStorePwd, keyStore, 
keyStorePwd, sslProtocol);

Review Comment:
   `SubscriptionSslConfigTest` was removed in 666e7203f5 when 
`configureProvider` was inlined, so nothing tests these settings reaching the 
provider anymore, from either the builder or `Properties`. The PR description 
still lists SSL propagation as part of this change. Please keep a test for it. 
Restoring the package-private `configureProvider` as the seam would be enough.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to