github-actions[bot] commented on code in PR #70693:
URL: https://github.com/apache/doris/pull/70693#discussion_r4599498778
##########
fe/fe-core/src/main/java/org/apache/doris/common/OssThriftClientTransportProvider.java:
##########
@@ -26,8 +29,9 @@
public class OssThriftClientTransportProvider implements
ThriftClientTransportProvider {
@Override
public TTransport createTransport(TNetworkAddress address, int timeoutMs,
boolean nonBlocking) throws Exception {
- return nonBlocking
- ? new TFramedTransport(new TSocket(address.hostname,
address.port, timeoutMs))
+ TSocket socket = PrivateRpcTls.enabled(Protocol.THRIFT)
Review Comment:
[P2] Keep broker heartbeat and filesystem transports consistent
GenericPool also backs ClientPool.brokerPool, so this switch encrypts every
broker heartbeat when private Thrift TLS is enabled. The broker filesystem SPI
still constructs a plain TSocket in BrokerClientFactory for the same
BrokerMgr-selected host/port. A normal plaintext broker consequently fails
heartbeat, is marked dead, and becomes unavailable to FileSystemFactory; making
the broker require TLS instead breaks filesystem operations. Select transport
by endpoint purpose or apply one consistent broker policy across both pools,
with coverage through the heartbeat and filesystem paths. Excluding thrift also
disables the FE/BE private Thrift transport.
##########
be/src/util/private_rpc_tls.cpp:
##########
@@ -0,0 +1,307 @@
+// 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 "util/private_rpc_tls.h"
+
+#include <brpc/channel.h>
+#include <brpc/server.h>
+#include <brpc/ssl_options.h>
+#include <thrift/transport/TSSLServerSocket.h>
+#include <thrift/transport/TSSLSocket.h>
+#include <thrift/transport/TTransportException.h>
+
+#include <algorithm>
+#include <exception>
+#include <filesystem>
+#include <limits>
+#include <memory>
+#include <system_error>
+#include <utility>
+
+#include "common/config.h"
+#include "util/string_util.h"
+#include "util/thrift_server.h"
+
+namespace doris::rpc_tls {
+namespace {
+
+Status validate_configuration() {
+ // Optional certificates cannot authenticate peers carrying private
file-key RPC payloads.
+ if (config::tls_verify_mode != "verify_fail_if_no_peer_cert" ||
+ config::tls_certificate_path.empty() ||
config::tls_private_key_path.empty() ||
+ config::tls_ca_certificate_path.empty()) {
+ return Status::InvalidArgument(
+ "Private RPC TLS requires a certificate, private key, CA and
mutual auth");
+ }
+ if (config::tls_cert_refresh_interval_seconds != 0 ||
+ !config::tls_peer_cert_required_san_dns.empty() ||
+ !config::tls_private_key_password.empty()) {
+ return Status::NotSupported(
+ "Private RPC TLS requires static PEM identities and CA-scoped
peer trust");
+ }
+ // BRPC accepts either paths or inline PEM. Only operator-owned local
files may reach that API,
+ // so malformed key input cannot be treated as an inline certificate and
echoed by its parser.
+ for (const auto* path : {&config::tls_certificate_path,
&config::tls_private_key_path,
+ &config::tls_ca_certificate_path}) {
+ std::error_code error;
+ if (!std::filesystem::is_regular_file(*path, error)) {
+ return Status::InvalidArgument(
+ "Private RPC TLS requires readable local identity files");
+ }
+ }
+ return Status::OK();
+}
+
+class HandshakeSocket final : public apache::thrift::transport::TSSLSocket {
+public:
+ HandshakeSocket(std::shared_ptr<apache::thrift::transport::SSLContext>
context,
+ const std::string& host, int port, int timeout)
+ : TSSLSocket(std::move(context), host, port),
_handshake_timeout(timeout) {}
+
+ HandshakeSocket(std::shared_ptr<apache::thrift::transport::SSLContext>
context,
+ THRIFT_SOCKET socket, std::shared_ptr<THRIFT_SOCKET>
interrupt, int timeout)
+ : TSSLSocket(std::move(context), socket, std::move(interrupt)),
+ _handshake_timeout(timeout) {}
+
+ void open() override {
+ const int connect_timeout = connTimeout_;
+ setConnTimeout(bounded_timeout(connect_timeout));
+ try {
+ TSSLSocket::open();
+ setConnTimeout(connect_timeout);
+ authenticate_peer();
+ } catch (...) {
+ setConnTimeout(connect_timeout);
+ TSSLSocket::close();
+ throw;
+ }
+ }
+
+ bool peek() override {
+ // Pool probes after close() must report a closed transport without
starting another handshake.
+ if (!TSocket::isOpen()) {
+ return false;
+ }
+ authenticate_peer();
+ return TSSLSocket::peek();
+ }
+
+ uint32_t read(uint8_t* buffer, uint32_t size) override {
+ authenticate_peer();
+ return TSSLSocket::read(buffer, size);
+ }
+
+ void write(const uint8_t* buffer, uint32_t size) override {
+ authenticate_peer();
+ TSSLSocket::write(buffer, size);
+ }
+
+ uint32_t write_partial(const uint8_t* buffer, uint32_t size) override {
+ authenticate_peer();
+ return TSSLSocket::write_partial(buffer, size);
+ }
+
+ void flush() override {
+ // Thrift closes input and output transports separately, so the second
flush must stay harmless.
+ if (!TSocket::isOpen()) {
+ TSSLSocket::flush();
+ return;
+ }
+ authenticate_peer();
+ TSSLSocket::flush();
+ }
+
+private:
+ int bounded_timeout(int timeout) const {
+ return timeout > 0 ? std::min(timeout, _handshake_timeout) :
_handshake_timeout;
+ }
+
+ void authenticate_peer() {
+ if (checkHandshake()) {
+ return;
+ }
+ // Unlimited RPC reads must not let a TCP-only peer occupy a worker
during TLS authentication.
+ // Restore the RPC timeouts before reading the first application byte
after authentication.
+ const int read_timeout = recvTimeout_;
+ const int write_timeout = sendTimeout_;
+ setRecvTimeout(bounded_timeout(read_timeout));
+ setSendTimeout(bounded_timeout(write_timeout));
+ try {
+ initializeHandshake();
+ } catch (...) {
+ TSSLSocket::close();
+ setRecvTimeout(read_timeout);
+ setSendTimeout(write_timeout);
+ throw;
+ }
+ setRecvTimeout(read_timeout);
+ setSendTimeout(write_timeout);
+ }
+
+ const int _handshake_timeout;
+};
+
+class HandshakeSocketFactory final : public
apache::thrift::transport::TSSLSocketFactory {
+public:
+ explicit HandshakeSocketFactory(int timeout)
+ : TSSLSocketFactory(apache::thrift::transport::TLSv1_2),
_handshake_timeout(timeout) {}
+
+ using TSSLSocketFactory::createSocket;
+
+ std::shared_ptr<apache::thrift::transport::TSSLSocket> createSocket(const
std::string& host,
+ int
port) override {
+ auto socket = std::make_shared<HandshakeSocket>(ctx_, host, port,
_handshake_timeout);
+ socket->server(false);
+
socket->access(std::make_shared<apache::thrift::transport::DefaultClientAccessManager>());
Review Comment:
[P1] Preserve the logical FE hostname for native TLS validation
The production ClientCacheHelper::_create_client replaces hostport.hostname
with resolved_ip before constructing ThriftClient, so this factory receives an
IP even when the FE was registered by FQDN. Thrift's DefaultClientAccessManager
compares DNS SAN/CN against that stored host. For example, fe1.example
resolving to 10.0.0.1 with a trusted DNS:fe1.example certificate now fails
authorization, breaking BE-to-FE calls such as fetchSplitBatch. Carry the
original certificate identity separately from the resolved connect address,
including on reopen. The direct-provider tests use an IP SAN and do not cover
this cache path.
##########
be/src/util/oss/client_connection_provider.cpp:
##########
@@ -17,15 +17,19 @@
#include "util/client_connection_provider.h"
+#include "util/private_rpc_tls.h"
+
namespace doris::client {
Status configure_brpc_channel_options(brpc::ChannelOptions* options) {
- (void)options;
- return Status::OK();
+ return rpc_tls::configure_channel(options);
Review Comment:
[P2] Keep RPC function transports consistent with FE validation
This provider is also called by BrpcClientCache<PFunctionService_Stub>, used
by RPCFnImpl and RPC aggregate functions. Enabling private BRPC TLS therefore
switches external function calls to the cluster's TLS policy, but
CreateFunctionCommand.checkRPCUdf still connects to the same endpoint with
usePlaintext(). An existing plaintext RPC function passes CREATE validation and
then fails at execution; changing its server to require TLS makes validation
fail instead. Distinguish internal backend channels from external function
channels, or update both function-client paths consistently. Excluding brpc
also disables the private transport being enabled here.
--
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]