You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "hongzhi-gao (via GitHub)" <gi...@apache.org> on 2026/09/08 09:04:58 UTC

[PR] Support standard TLS and mTLS in the C++ client [iotdb]

hongzhi-gao opened a new pull request, #18601:
URL: https://github.com/apache/iotdb/pull/18601

   (no comment)


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support standard TLS and mTLS in the C++ client [iotdb]

Posted by "HTHou (via GitHub)" <gi...@apache.org>.
HTHou commented on code in PR #18601:
URL: https://github.com/apache/iotdb/pull/18601#discussion_r3963937521


##########
iotdb-client/client-cpp/src/session/Session.cpp:
##########
@@ -1188,9 +1190,11 @@ void Session::close() {
       impl_->defaultSessionConnection_.reset();
     }
   } catch (...) {
+    impl_->nodesSupplier_.reset();
     impl_->isClosed_ = true;
     throw;
   }
+  impl_->nodesSupplier_.reset();

Review Comment:
   [P2] Check the Session state before dereferencing nodesSupplier_ in the query path. With lazy initialization in open() and this reset in close(), nodesSupplier_ can now be null. However, Impl::getQuerySessionConnection() still calls nodesSupplier_->getQueryEndPoint() before reaching getDefaultSessionConnection(), which performs the closed-session check. Consequently, executeQueryStatement() before open(), after close(), or after a failed open() dereferences a null pointer instead of throwing the existing connection exception. The C API's exception handler cannot catch this crash either. Please check the Session state before accessing the supplier and add regression coverage for these three cases. The same issue is reproducible from the call sequence Session session("127.0.0.1", 6667); session.executeQueryStatement("SHOW VERSION"); without needing a running server.



##########
.github/workflows/multi-language-client.yml:
##########
@@ -198,9 +198,15 @@ jobs:
         # (was causing problems on windows, but could cause problem on linux, when updating the thrift module)
         run: |
           if [[ "${{ matrix.os }}" == "windows-2025-vs2026" ]]; then
-            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am -Dcmake.generator="Visual Studio 18 2026"
+            # The Windows standalone server scripts do not terminate reliably on hosted runners.
+            # Keep the Windows compile/link/package validation here; TLS/mTLS server ITs run on Unix.
+            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am -DskipTests -Diotdb.openssl.from.source=OFF -Dcmake.generator="Visual Studio 18 2026"
+          elif [[ "${{ runner.os }}" == "Windows" ]]; then
+            # The Windows standalone server scripts do not terminate reliably on hosted runners.
+            # Keep the Windows compile/link/package validation here; TLS/mTLS server ITs run on Unix.
+            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am -DskipTests -Diotdb.openssl.from.source=OFF

Review Comment:
   Adding -DskipTests to both Windows jobs removes all existing C++ test coverage, including the server-independent sessionUtilsTest, rather than just the TLS/mTLS phases affected by standalone-server shutdown. Also, every platform now passes -Diotdb.openssl.from.source=OFF, so a green PR check no longer exercises the default source-build path or the new macOS relocation logic; client-cpp-package.yml does not run on pull_request. Could we retain the independent Windows tests, restore server tests once shutdown is fixed, and include at least one default-provider build/relocation check before merge?



##########
iotdb-client/client-cpp/test/cpp/RpcSslIotdbE2eTest.cpp:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.
+ */
+
+#include <catch.hpp>
+
+#include <cstdlib>
+#include <memory>
+#include <string>
+
+#include "Session.h"
+#include "SessionBuilder.h"
+#include "SessionC.h"
+#include "SessionDataSet.h"
+#include "SessionPool.h"
+#include "TableSessionBuilder.h"
+
+namespace {
+
+std::string fixture(const std::string& name) {
+  return std::string(IOTDB_TEST_FIXTURES_DIR) + "/tls/" + name;
+}
+
+bool mutualTlsEnabled() {
+  const char* value = std::getenv("IOTDB_CPP_SSL_MUTUAL_AUTH");
+  return value != nullptr && std::string(value) == "1";
+}
+
+template <typename Builder> void configureTls(Builder& builder) {
+  builder.useSSL(true)->trustCertFilePath(fixture("ca.crt"));
+  if (mutualTlsEnabled()) {
+    builder.clientCertificateFilePath(fixture("client.crt"))
+        ->clientPrivateKeyFilePath(fixture("client.key"));
+  }
+}
+
+SslConfig sslConfig() {
+  SslConfig config;
+  config.useSsl = true;
+  config.trustCertFilePath = fixture("ca.crt");
+  if (mutualTlsEnabled()) {
+    config.clientCertificateFilePath = fixture("client.crt");
+    config.clientPrivateKeyFilePath = fixture("client.key");
+  }
+  return config;
+}
+
+void requireDataSet(std::unique_ptr<SessionDataSet> dataSet) {
+  REQUIRE(dataSet != nullptr);
+  REQUIRE(dataSet->hasNext());
+  REQUIRE(dataSet->next() != nullptr);
+  dataSet->closeOperationHandle();
+}
+
+void requireCDataSet(CSessionDataSet* dataSet) {
+  REQUIRE(dataSet != nullptr);
+  REQUIRE(ts_dataset_has_next(dataSet));
+  CRowRecord* row = ts_dataset_next(dataSet);
+  REQUIRE(row != nullptr);
+  ts_row_record_destroy(row);
+  ts_dataset_destroy(dataSet);
+}
+
+} // namespace
+
+TEST_CASE("C++ APIs communicate with a TLS-enabled IoTDB", "[tls]") {
+  SessionBuilder treeBuilder;
+  treeBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(treeBuilder);
+  auto treeSession = treeBuilder.build();
+  requireDataSet(treeSession->executeQueryStatement("SHOW VERSION"));
+  treeSession->close();
+
+  TableSessionBuilder tableBuilder;
+  tableBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(tableBuilder);
+  auto tableSession = tableBuilder.build();
+  requireDataSet(tableSession->executeQueryStatement("SHOW VERSION"));
+  tableSession->close();
+
+  SessionPoolBuilder poolBuilder;
+  poolBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(poolBuilder);
+  auto pool = poolBuilder.build();
+  auto pooledDataSet = pool->executeQueryStatement("SHOW VERSION");
+  REQUIRE(pooledDataSet->hasNext());
+  REQUIRE(pooledDataSet->next() != nullptr);
+  pool->close();
+}
+
+TEST_CASE("C APIs communicate with a TLS-enabled IoTDB", "[tls]") {
+  const std::string certificatePath = fixture("client.crt");
+  const std::string privateKeyPath = fixture("client.key");
+  const char* cert = mutualTlsEnabled() ? certificatePath.c_str() : nullptr;
+  const char* key = mutualTlsEnabled() ? privateKeyPath.c_str() : nullptr;
+
+  CSession* treeSession = ts_session_new("127.0.0.1", 6667, "root", "root");
+  REQUIRE(treeSession != nullptr);
+  REQUIRE(ts_session_set_ssl_config(treeSession, fixture("ca.crt").c_str(), cert, key) == TS_OK);
+  REQUIRE(ts_session_open(treeSession) == TS_OK);
+  CSessionDataSet* treeDataSet = nullptr;
+  REQUIRE(ts_session_execute_query(treeSession, "SHOW VERSION", &treeDataSet) == TS_OK);
+  requireCDataSet(treeDataSet);
+  REQUIRE(ts_session_close(treeSession) == TS_OK);
+  ts_session_destroy(treeSession);
+
+  CTableSession* tableSession = ts_table_session_new_with_ssl(
+      "127.0.0.1", 6667, "root", "root", "", fixture("ca.crt").c_str(), cert, key);
+  REQUIRE(tableSession != nullptr);
+  CSessionDataSet* tableDataSet = nullptr;
+  REQUIRE(ts_table_session_execute_query(tableSession, "SHOW VERSION", &tableDataSet) == TS_OK);
+  requireCDataSet(tableDataSet);
+  REQUIRE(ts_table_session_close(tableSession) == TS_OK);
+  ts_table_session_destroy(tableSession);
+}
+
+TEST_CASE("TLS node discovery uses the final SSL configuration and supports failover", "[tls]") {
+  std::vector<std::string> bootstrapNodes = {"127.0.0.1:1", "127.0.0.1:6667"};
+  Session session(bootstrapNodes, "root", "root");
+  session.setSslConfig(sslConfig());
+  session.open();
+  requireDataSet(session.executeQueryStatement("SHOW VERSION"));

Review Comment:
   This test does not establish that TLS node discovery or post-connection failover works: the reachable address is already in bootstrapNodes, and initDefaultSessionConnection() can connect to it even if every discovery request fails. Thus the original stale-SSL-config issue could still pass this test. Could we assert that discovery learns an endpoint absent from the bootstrap list, then make the initial endpoint unavailable and verify a query succeeds through the discovered endpoint? A focused test with controlled discovery responses would also work if a multi-node integration test is too costly.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support standard TLS and mTLS in the C++ client [iotdb]

Posted by "HTHou (via GitHub)" <gi...@apache.org>.
HTHou commented on PR #18601:
URL: https://github.com/apache/iotdb/pull/18601#issuecomment-5583187001

   Thanks for splitting standard TLS/mTLS support into a separate PR and keeping OpenSSL as the default. I found two issues that I think should be addressed before merging:
   
   1. **[P1] Make the macOS OpenSSL libraries relocatable.**
   
      With source builds now enabled by default in [`FetchOpenSSL.cmake`](https://github.com/apache/iotdb/blob/f90b72280a4b90b9df5def02dff52e1d40bf90b6/iotdb-client/client-cpp/cmake/FetchOpenSSL.cmake#L42), OpenSSL's [Darwin build rules](https://github.com/openssl/openssl/blob/openssl-3.5.8/Configurations/shared-info.pl#L46-L50) embed an absolute install name under the build directory's `_deps/openssl/install/lib/`. The packaging code copies the dylibs but does not rewrite their install names or dependent-library references. Setting `@loader_path` as an RPATH on `iotdb_session` does not resolve absolute library references. As a result, tests on the build machine can pass while the extracted SDK fails to load on another machine with `Library not loaded`.
   
      Could we make these references relative using `@rpath`/`@loader_path`, including the dependency from libssl to libcrypto, and test the extracted SDK with the original OpenSSL build/install directory unavailable?
   
   2. **[P2] Propagate changes from `setSslConfig()` to node discovery.**
   
      [`Session::setSslConfig()`](https://github.com/apache/iotdb/blob/f90b72280a4b90b9df5def02dff52e1d40bf90b6/iotdb-client/client-cpp/src/session/Session.cpp#L648) only updates `impl_->sslConfig_`. However, the Session constructor has already created and started a `NodesSupplier`, which holds its own copy of the previous SSL configuration. With the new C API sequence `ts_session_new()` -> `ts_session_set_ssl_config()` -> `ts_session_open()`, the main connection uses TLS, but background node discovery continues attempting plaintext connections. Discovery therefore fails against a TLS-only server, leaving the endpoint list stale and preventing failover to newly added nodes that were not in the initial list.
   
      Could we defer starting node discovery until `open()`, or safely recreate it when the SSL configuration changes? A TLS/mTLS test that verifies endpoint discovery and failover would cover this path; the current single-node `SHOW VERSION` tests do not.
   
   These findings are based on static review of `f90b7228`; I have not run a full build or the integration tests locally.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support standard TLS and mTLS in the C++ client [iotdb]

Posted by "HTHou (via GitHub)" <gi...@apache.org>.
HTHou merged PR #18601:
URL: https://github.com/apache/iotdb/pull/18601


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support standard TLS and mTLS in the C++ client [iotdb]

Posted by "hongzhi-gao (via GitHub)" <gi...@apache.org>.
hongzhi-gao commented on code in PR #18601:
URL: https://github.com/apache/iotdb/pull/18601#discussion_r3974925366


##########
.github/workflows/multi-language-client.yml:
##########
@@ -198,9 +198,15 @@ jobs:
         # (was causing problems on windows, but could cause problem on linux, when updating the thrift module)
         run: |
           if [[ "${{ matrix.os }}" == "windows-2025-vs2026" ]]; then
-            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am -Dcmake.generator="Visual Studio 18 2026"
+            # The Windows standalone server scripts do not terminate reliably on hosted runners.
+            # Keep the Windows compile/link/package validation here; TLS/mTLS server ITs run on Unix.
+            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am -DskipTests -Diotdb.openssl.from.source=OFF -Dcmake.generator="Visual Studio 18 2026"
+          elif [[ "${{ runner.os }}" == "Windows" ]]; then
+            # The Windows standalone server scripts do not terminate reliably on hosted runners.
+            # Keep the Windows compile/link/package validation here; TLS/mTLS server ITs run on Unix.
+            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am -DskipTests -Diotdb.openssl.from.source=OFF

Review Comment:
   Fixed. `-DskipTests` was removed from the Windows jobs, and the non-interactive launcher path now allows the plain/TLS/mTLS server phases to complete. macOS PR CI uses the default source-built OpenSSL path, exercising the relocation logic.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support standard TLS and mTLS in the C++ client [iotdb]

Posted by "hongzhi-gao (via GitHub)" <gi...@apache.org>.
hongzhi-gao commented on code in PR #18601:
URL: https://github.com/apache/iotdb/pull/18601#discussion_r3974925363


##########
iotdb-client/client-cpp/src/session/Session.cpp:
##########
@@ -1188,9 +1190,11 @@ void Session::close() {
       impl_->defaultSessionConnection_.reset();
     }
   } catch (...) {
+    impl_->nodesSupplier_.reset();
     impl_->isClosed_ = true;
     throw;
   }
+  impl_->nodesSupplier_.reset();

Review Comment:
   Fixed in `362dce4`. `getQuerySessionConnection()` now validates the default connection before accessing `nodesSupplier_`. Regression tests cover queries before `open()`, after a failed `open()`, and after `close()`.



##########
.github/workflows/multi-language-client.yml:
##########
@@ -198,9 +198,15 @@ jobs:
         # (was causing problems on windows, but could cause problem on linux, when updating the thrift module)
         run: |
           if [[ "${{ matrix.os }}" == "windows-2025-vs2026" ]]; then
-            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am -Dcmake.generator="Visual Studio 18 2026"
+            # The Windows standalone server scripts do not terminate reliably on hosted runners.
+            # Keep the Windows compile/link/package validation here; TLS/mTLS server ITs run on Unix.
+            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am -DskipTests -Diotdb.openssl.from.source=OFF -Dcmake.generator="Visual Studio 18 2026"
+          elif [[ "${{ runner.os }}" == "Windows" ]]; then
+            # The Windows standalone server scripts do not terminate reliably on hosted runners.
+            # Keep the Windows compile/link/package validation here; TLS/mTLS server ITs run on Unix.
+            ./mvnw clean verify -P with-cpp -pl iotdb-client/client-cpp -am -DskipTests -Diotdb.openssl.from.source=OFF

Review Comment:
   Fixed in `362dce4`. `-DskipTests` was removed from the Windows jobs, and the non-interactive launcher path now allows the plain/TLS/mTLS server phases to complete. macOS PR CI uses the default source-built OpenSSL path, exercising the relocation logic.



##########
iotdb-client/client-cpp/test/cpp/RpcSslIotdbE2eTest.cpp:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.
+ */
+
+#include <catch.hpp>
+
+#include <cstdlib>
+#include <memory>
+#include <string>
+
+#include "Session.h"
+#include "SessionBuilder.h"
+#include "SessionC.h"
+#include "SessionDataSet.h"
+#include "SessionPool.h"
+#include "TableSessionBuilder.h"
+
+namespace {
+
+std::string fixture(const std::string& name) {
+  return std::string(IOTDB_TEST_FIXTURES_DIR) + "/tls/" + name;
+}
+
+bool mutualTlsEnabled() {
+  const char* value = std::getenv("IOTDB_CPP_SSL_MUTUAL_AUTH");
+  return value != nullptr && std::string(value) == "1";
+}
+
+template <typename Builder> void configureTls(Builder& builder) {
+  builder.useSSL(true)->trustCertFilePath(fixture("ca.crt"));
+  if (mutualTlsEnabled()) {
+    builder.clientCertificateFilePath(fixture("client.crt"))
+        ->clientPrivateKeyFilePath(fixture("client.key"));
+  }
+}
+
+SslConfig sslConfig() {
+  SslConfig config;
+  config.useSsl = true;
+  config.trustCertFilePath = fixture("ca.crt");
+  if (mutualTlsEnabled()) {
+    config.clientCertificateFilePath = fixture("client.crt");
+    config.clientPrivateKeyFilePath = fixture("client.key");
+  }
+  return config;
+}
+
+void requireDataSet(std::unique_ptr<SessionDataSet> dataSet) {
+  REQUIRE(dataSet != nullptr);
+  REQUIRE(dataSet->hasNext());
+  REQUIRE(dataSet->next() != nullptr);
+  dataSet->closeOperationHandle();
+}
+
+void requireCDataSet(CSessionDataSet* dataSet) {
+  REQUIRE(dataSet != nullptr);
+  REQUIRE(ts_dataset_has_next(dataSet));
+  CRowRecord* row = ts_dataset_next(dataSet);
+  REQUIRE(row != nullptr);
+  ts_row_record_destroy(row);
+  ts_dataset_destroy(dataSet);
+}
+
+} // namespace
+
+TEST_CASE("C++ APIs communicate with a TLS-enabled IoTDB", "[tls]") {
+  SessionBuilder treeBuilder;
+  treeBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(treeBuilder);
+  auto treeSession = treeBuilder.build();
+  requireDataSet(treeSession->executeQueryStatement("SHOW VERSION"));
+  treeSession->close();
+
+  TableSessionBuilder tableBuilder;
+  tableBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(tableBuilder);
+  auto tableSession = tableBuilder.build();
+  requireDataSet(tableSession->executeQueryStatement("SHOW VERSION"));
+  tableSession->close();
+
+  SessionPoolBuilder poolBuilder;
+  poolBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(poolBuilder);
+  auto pool = poolBuilder.build();
+  auto pooledDataSet = pool->executeQueryStatement("SHOW VERSION");
+  REQUIRE(pooledDataSet->hasNext());
+  REQUIRE(pooledDataSet->next() != nullptr);
+  pool->close();
+}
+
+TEST_CASE("C APIs communicate with a TLS-enabled IoTDB", "[tls]") {
+  const std::string certificatePath = fixture("client.crt");
+  const std::string privateKeyPath = fixture("client.key");
+  const char* cert = mutualTlsEnabled() ? certificatePath.c_str() : nullptr;
+  const char* key = mutualTlsEnabled() ? privateKeyPath.c_str() : nullptr;
+
+  CSession* treeSession = ts_session_new("127.0.0.1", 6667, "root", "root");
+  REQUIRE(treeSession != nullptr);
+  REQUIRE(ts_session_set_ssl_config(treeSession, fixture("ca.crt").c_str(), cert, key) == TS_OK);
+  REQUIRE(ts_session_open(treeSession) == TS_OK);
+  CSessionDataSet* treeDataSet = nullptr;
+  REQUIRE(ts_session_execute_query(treeSession, "SHOW VERSION", &treeDataSet) == TS_OK);
+  requireCDataSet(treeDataSet);
+  REQUIRE(ts_session_close(treeSession) == TS_OK);
+  ts_session_destroy(treeSession);
+
+  CTableSession* tableSession = ts_table_session_new_with_ssl(
+      "127.0.0.1", 6667, "root", "root", "", fixture("ca.crt").c_str(), cert, key);
+  REQUIRE(tableSession != nullptr);
+  CSessionDataSet* tableDataSet = nullptr;
+  REQUIRE(ts_table_session_execute_query(tableSession, "SHOW VERSION", &tableDataSet) == TS_OK);
+  requireCDataSet(tableDataSet);
+  REQUIRE(ts_table_session_close(tableSession) == TS_OK);
+  ts_table_session_destroy(tableSession);
+}
+
+TEST_CASE("TLS node discovery uses the final SSL configuration and supports failover", "[tls]") {
+  std::vector<std::string> bootstrapNodes = {"127.0.0.1:1", "127.0.0.1:6667"};
+  Session session(bootstrapNodes, "root", "root");
+  session.setSslConfig(sslConfig());
+  session.open();
+  requireDataSet(session.executeQueryStatement("SHOW VERSION"));

Review Comment:
   Fixed in `eec6aba`. The session bootstraps with `127.0.0.1:6667`, while TLS discovery returns the absent `localhost:6667` endpoint. The test closes the initial connection, runs `SHOW VERSION`, and verifies that a new TLS connection was established to the discovered endpoint. Both TLS and mTLS variants pass locally.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support standard TLS and mTLS in the C++ client [iotdb]

Posted by "hongzhi-gao (via GitHub)" <gi...@apache.org>.
hongzhi-gao commented on PR #18601:
URL: https://github.com/apache/iotdb/pull/18601#issuecomment-5611777216

   > Thanks for splitting standard TLS/mTLS support into a separate PR and keeping OpenSSL as the default. I found two issues that I think should be addressed before merging:
   > 
   > 1. **[P1] Make the macOS OpenSSL libraries relocatable.**
   >    With source builds now enabled by default in [`FetchOpenSSL.cmake`](https://github.com/apache/iotdb/blob/f90b72280a4b90b9df5def02dff52e1d40bf90b6/iotdb-client/client-cpp/cmake/FetchOpenSSL.cmake#L42), OpenSSL's [Darwin build rules](https://github.com/openssl/openssl/blob/openssl-3.5.8/Configurations/shared-info.pl#L46-L50) embed an absolute install name under the build directory's `_deps/openssl/install/lib/`. The packaging code copies the dylibs but does not rewrite their install names or dependent-library references. Setting `@loader_path` as an RPATH on `iotdb_session` does not resolve absolute library references. As a result, tests on the build machine can pass while the extracted SDK fails to load on another machine with `Library not loaded`.
   >    Could we make these references relative using `@rpath`/`@loader_path`, including the dependency from libssl to libcrypto, and test the extracted SDK with the original OpenSSL build/install directory unavailable?
   > 2. **[P2] Propagate changes from `setSslConfig()` to node discovery.**
   >    [`Session::setSslConfig()`](https://github.com/apache/iotdb/blob/f90b72280a4b90b9df5def02dff52e1d40bf90b6/iotdb-client/client-cpp/src/session/Session.cpp#L648) only updates `impl_->sslConfig_`. However, the Session constructor has already created and started a `NodesSupplier`, which holds its own copy of the previous SSL configuration. With the new C API sequence `ts_session_new()` -> `ts_session_set_ssl_config()` -> `ts_session_open()`, the main connection uses TLS, but background node discovery continues attempting plaintext connections. Discovery therefore fails against a TLS-only server, leaving the endpoint list stale and preventing failover to newly added nodes that were not in the initial list.
   >    Could we defer starting node discovery until `open()`, or safely recreate it when the SSL configuration changes? A TLS/mTLS test that verifies endpoint discovery and failover would cover this path; the current single-node `SHOW VERSION` tests do not.
   > 
   > These findings are based on static review of `f90b7228`; I have not run a full build or the integration tests locally.
   
   Thanks for the review. Both original findings are addressed: Darwin OpenSSL IDs and dependencies are rewritten to @rpath and the package smoke test hides the original install directory; NodesSupplier initialization is deferred until open() so it receives the final SSL configuration. The follow-up fixes and coverage are summarized in the inline replies.


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support standard TLS and mTLS in the C++ client [iotdb]

Posted by "hongzhi-gao (via GitHub)" <gi...@apache.org>.
hongzhi-gao commented on code in PR #18601:
URL: https://github.com/apache/iotdb/pull/18601#discussion_r3974925363


##########
iotdb-client/client-cpp/src/session/Session.cpp:
##########
@@ -1188,9 +1190,11 @@ void Session::close() {
       impl_->defaultSessionConnection_.reset();
     }
   } catch (...) {
+    impl_->nodesSupplier_.reset();
     impl_->isClosed_ = true;
     throw;
   }
+  impl_->nodesSupplier_.reset();

Review Comment:
   Fixed . `getQuerySessionConnection()` now validates the default connection before accessing `nodesSupplier_`. Regression tests cover queries before `open()`, after a failed `open()`, and after `close()`.



##########
iotdb-client/client-cpp/test/cpp/RpcSslIotdbE2eTest.cpp:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.
+ */
+
+#include <catch.hpp>
+
+#include <cstdlib>
+#include <memory>
+#include <string>
+
+#include "Session.h"
+#include "SessionBuilder.h"
+#include "SessionC.h"
+#include "SessionDataSet.h"
+#include "SessionPool.h"
+#include "TableSessionBuilder.h"
+
+namespace {
+
+std::string fixture(const std::string& name) {
+  return std::string(IOTDB_TEST_FIXTURES_DIR) + "/tls/" + name;
+}
+
+bool mutualTlsEnabled() {
+  const char* value = std::getenv("IOTDB_CPP_SSL_MUTUAL_AUTH");
+  return value != nullptr && std::string(value) == "1";
+}
+
+template <typename Builder> void configureTls(Builder& builder) {
+  builder.useSSL(true)->trustCertFilePath(fixture("ca.crt"));
+  if (mutualTlsEnabled()) {
+    builder.clientCertificateFilePath(fixture("client.crt"))
+        ->clientPrivateKeyFilePath(fixture("client.key"));
+  }
+}
+
+SslConfig sslConfig() {
+  SslConfig config;
+  config.useSsl = true;
+  config.trustCertFilePath = fixture("ca.crt");
+  if (mutualTlsEnabled()) {
+    config.clientCertificateFilePath = fixture("client.crt");
+    config.clientPrivateKeyFilePath = fixture("client.key");
+  }
+  return config;
+}
+
+void requireDataSet(std::unique_ptr<SessionDataSet> dataSet) {
+  REQUIRE(dataSet != nullptr);
+  REQUIRE(dataSet->hasNext());
+  REQUIRE(dataSet->next() != nullptr);
+  dataSet->closeOperationHandle();
+}
+
+void requireCDataSet(CSessionDataSet* dataSet) {
+  REQUIRE(dataSet != nullptr);
+  REQUIRE(ts_dataset_has_next(dataSet));
+  CRowRecord* row = ts_dataset_next(dataSet);
+  REQUIRE(row != nullptr);
+  ts_row_record_destroy(row);
+  ts_dataset_destroy(dataSet);
+}
+
+} // namespace
+
+TEST_CASE("C++ APIs communicate with a TLS-enabled IoTDB", "[tls]") {
+  SessionBuilder treeBuilder;
+  treeBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(treeBuilder);
+  auto treeSession = treeBuilder.build();
+  requireDataSet(treeSession->executeQueryStatement("SHOW VERSION"));
+  treeSession->close();
+
+  TableSessionBuilder tableBuilder;
+  tableBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(tableBuilder);
+  auto tableSession = tableBuilder.build();
+  requireDataSet(tableSession->executeQueryStatement("SHOW VERSION"));
+  tableSession->close();
+
+  SessionPoolBuilder poolBuilder;
+  poolBuilder.host("127.0.0.1")->rpcPort(6667)->username("root")->password("root");
+  configureTls(poolBuilder);
+  auto pool = poolBuilder.build();
+  auto pooledDataSet = pool->executeQueryStatement("SHOW VERSION");
+  REQUIRE(pooledDataSet->hasNext());
+  REQUIRE(pooledDataSet->next() != nullptr);
+  pool->close();
+}
+
+TEST_CASE("C APIs communicate with a TLS-enabled IoTDB", "[tls]") {
+  const std::string certificatePath = fixture("client.crt");
+  const std::string privateKeyPath = fixture("client.key");
+  const char* cert = mutualTlsEnabled() ? certificatePath.c_str() : nullptr;
+  const char* key = mutualTlsEnabled() ? privateKeyPath.c_str() : nullptr;
+
+  CSession* treeSession = ts_session_new("127.0.0.1", 6667, "root", "root");
+  REQUIRE(treeSession != nullptr);
+  REQUIRE(ts_session_set_ssl_config(treeSession, fixture("ca.crt").c_str(), cert, key) == TS_OK);
+  REQUIRE(ts_session_open(treeSession) == TS_OK);
+  CSessionDataSet* treeDataSet = nullptr;
+  REQUIRE(ts_session_execute_query(treeSession, "SHOW VERSION", &treeDataSet) == TS_OK);
+  requireCDataSet(treeDataSet);
+  REQUIRE(ts_session_close(treeSession) == TS_OK);
+  ts_session_destroy(treeSession);
+
+  CTableSession* tableSession = ts_table_session_new_with_ssl(
+      "127.0.0.1", 6667, "root", "root", "", fixture("ca.crt").c_str(), cert, key);
+  REQUIRE(tableSession != nullptr);
+  CSessionDataSet* tableDataSet = nullptr;
+  REQUIRE(ts_table_session_execute_query(tableSession, "SHOW VERSION", &tableDataSet) == TS_OK);
+  requireCDataSet(tableDataSet);
+  REQUIRE(ts_table_session_close(tableSession) == TS_OK);
+  ts_table_session_destroy(tableSession);
+}
+
+TEST_CASE("TLS node discovery uses the final SSL configuration and supports failover", "[tls]") {
+  std::vector<std::string> bootstrapNodes = {"127.0.0.1:1", "127.0.0.1:6667"};
+  Session session(bootstrapNodes, "root", "root");
+  session.setSslConfig(sslConfig());
+  session.open();
+  requireDataSet(session.executeQueryStatement("SHOW VERSION"));

Review Comment:
   Fixed. The session bootstraps with `127.0.0.1:6667`, while TLS discovery returns the absent `localhost:6667` endpoint. The test closes the initial connection, runs `SHOW VERSION`, and verifies that a new TLS connection was established to the discovered endpoint. Both TLS and mTLS variants pass locally.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Support standard TLS and mTLS in the C++ client [iotdb]

Posted by "hongzhi-gao (via GitHub)" <gi...@apache.org>.
hongzhi-gao commented on PR #18601:
URL: https://github.com/apache/iotdb/pull/18601#issuecomment-5611753014

   Thanks for the review. Both original findings are addressed: Darwin OpenSSL IDs and dependencies are rewritten to @rpath and the package smoke test hides the original install directory; NodesSupplier initialization is deferred until open() so it receives the final SSL configuration. The follow-up fixes and coverage are summarized in the inline replies.


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org