HwangDongJun commented on code in PR #12831:
URL: https://github.com/apache/gluten/pull/12831#discussion_r4369322573


##########
cpp/velox/utils/TlsTrustStore.cc:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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 "utils/TlsTrustStore.h"
+
+#include <glog/logging.h>
+#include <cctype>
+#include <cstdlib>
+#include <filesystem>
+
+namespace gluten {
+
+namespace {
+
+namespace fs = std::filesystem;
+
+bool isRegularFile(const std::string& path) {
+  std::error_code ec;
+  return fs::is_regular_file(path, ec) && !ec;
+}
+
+// OpenSSL finds certificates in a directory only through files named <8 hex 
digits>.<digit>, created by
+// `openssl rehash`.
+bool isHashedCertificateName(const std::string& name) {
+  if (name.size() < 10 || name[8] != '.') {
+    return false;
+  }
+  for (size_t i = 0; i < 8; ++i) {
+    if (!std::isxdigit(static_cast<unsigned char>(name[i]))) {
+      return false;
+    }
+  }
+  for (size_t i = 9; i < name.size(); ++i) {
+    if (!std::isdigit(static_cast<unsigned char>(name[i]))) {
+      return false;
+    }
+  }
+  return true;
+}
+
+bool hasHashedCertificate(const std::string& dir) {
+  std::error_code ec;
+  fs::directory_iterator it(dir, 
fs::directory_options::skip_permission_denied, ec);
+  if (ec) {
+    return false;
+  }
+  for (const auto& entry : it) {
+    if (isHashedCertificateName(entry.path().filename().string())) {
+      return true;
+    }
+  }
+  return false;
+}
+
+std::optional<std::string> getEnv(const char* name) {
+  const char* value = std::getenv(name);
+  return value != nullptr ? std::optional<std::string>(value) : std::nullopt;
+}
+
+} // namespace
+
+const TlsSearchPaths& systemTlsSearchPaths() {
+  static const TlsSearchPaths paths{
+      "/etc/ssl/cert.pem",
+      "/etc/ssl/certs",
+      {
+          "/etc/ssl/certs/ca-certificates.crt", // Debian, Ubuntu, Alpine
+          "/etc/pki/tls/certs/ca-bundle.crt", // RHEL, CentOS, Rocky, Alma, 
Fedora
+          "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", // RHEL family, 
what the link above points to
+          "/etc/ssl/ca-bundle.pem", // openSUSE
+      }};
+  return paths;
+}

Review Comment:
   Update: changed after all, in c819e9c1a. The defaults are now read with 
X509_get_default_cert_file() / X509_get_default_cert_dir(), and the OpenSSL 
include directories are taken from the OpenSSL::Crypto target (or 
OPENSSL_INCLUDE_DIR). This matters for a VCPKG_DYNAMIC_OPENSSL=ON build, where 
the system OpenSSL can have another openssldir. CI compiles it for x86 and ARM, 
and the unit tests pass. In the pods the statically linked OpenSSL returns 
/etc/ssl/cert.pem and /etc/ssl/certs on Rocky 8.9/9.3, AlmaLinux 8.10 and 
Ubuntu 22.04/24.04, so nothing changes there. I could not test a dynamic 
OpenSSL build.



##########
cpp/velox/compute/VeloxBackend.cc:
##########
@@ -191,6 +192,9 @@ void VeloxBackend::init(
 
   hiveConnectorConfig_ = createHiveConnectorConfig(backendConf_);
 
+  // Make sure the statically linked OpenSSL can find trusted certificates 
before any filesystem creates an HTTP client.
+  ensureTlsTrustStore();

Review Comment:
   Update: the call now sits right after glog is initialized, at the beginning 
of VeloxBackend::init (a90489e7c). On top of the reasoning above I checked it: 
glibc's setenv takes a lock but getenv does not, and adding a new variable 
reallocates the environ array, which is the case that matters here. In the JDK 
17 sources the JVM only reads the environment at startup and when writing a 
crash report, and the JIT compiler threads never read it. I preloaded a 
getenv/setenv tracer in local-mode runs on Rocky 8.9 and Ubuntu 22.04 (20 runs, 
40 with the move included): setenv(SSL_CERT_FILE) takes about 10 us, no getenv 
call from another thread happened inside that window or within 100 us of it, 
and the closest read by another thread was the JVM startup one, about 6 s 
earlier. This is observation, not a proof: only local mode, only calls that go 
through getenv, and I could not test a distributed run. The only way to remove 
the risk completely is not to call setenv at all, which is why the que
 stion in my earlier comment about keeping the second commit is still open.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to