Gabriel39 commented on code in PR #71174:
URL: https://github.com/apache/doris/pull/71174#discussion_r4749897638
##########
fe/fe-core/src/main/java/org/apache/doris/rpc/BackendServiceClient.java:
##########
@@ -46,20 +51,46 @@ public static boolean supportsPrivateFileKeys() {
private final PBackendServiceGrpc.PBackendServiceBlockingStub blockingStub;
private final ManagedChannel channel;
private final long execPlanTimeout;
+ private final boolean internalRpc;
+ private volatile long authBackendId;
public BackendServiceClient(TNetworkAddress address, String resolvedIp,
Executor executor) {
this(address, resolvedIp, executor, true);
}
public BackendServiceClient(TNetworkAddress address, String resolvedIp,
Executor executor, boolean internalRpc) {
this.address = address;
+ this.internalRpc = internalRpc;
channel = CHANNEL_PROVIDER.createChannel(address, resolvedIp,
executor, internalRpc);
stub = PBackendServiceGrpc.newFutureStub(channel);
blockingStub = PBackendServiceGrpc.newBlockingStub(channel);
// execPlanTimeout should be greater than future.get timeout,
otherwise future will throw ExecutionException
execPlanTimeout = Config.remote_fragment_exec_timeout_ms + 5000;
}
+ private PBackendServiceGrpc.PBackendServiceFutureStub
authenticatedStub(String method, MessageLite request) {
+ // Remote-worker providers own the remote cluster's authorization.
Never attach this
+ // cluster's identity to a channel selected for an external catalog.
+ if (!internalRpc) {
+ return stub;
Review Comment:
Addressed by ab9083cb1c and revalidated with this update. Native remote
exec/prepare/start carry receiving backend and cluster IDs into signing;
receiving BEs explicitly trust the originating FE public keys. The auth-enabled
native remote lifecycle regression passes SELECT, join and INSERT SELECT paths,
and rejects a plan issued for the wrong cluster. Private-RPC TLS regression
also passes.
##########
be/src/util/internal_rpc_request_auth.cpp:
##########
@@ -0,0 +1,180 @@
+// 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/internal_rpc_request_auth.h"
+
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/zero_copy_stream.h>
+#include <google/protobuf/message_lite.h>
+#include <openssl/evp.h>
+#include <openssl/x509.h>
+
+#include <array>
+#include <charconv>
+#include <memory>
+#include <string>
+#include <system_error>
+
+namespace doris {
+namespace {
+
+using DigestContext = std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)>;
+using PublicKey = std::unique_ptr<EVP_PKEY, decltype(&EVP_PKEY_free)>;
+
+class DigestOutputStream final : public
google::protobuf::io::ZeroCopyOutputStream {
+public:
+ explicit DigestOutputStream(EVP_MD_CTX* context) : _context(context) {}
+
+ bool Next(void** data, int* size) override {
+ if (!flush()) {
+ return false;
+ }
+ *data = _buffer.data();
+ *size = static_cast<int>(_buffer.size());
+ _used = *size;
+ _count += *size;
+ return true;
+ }
+
+ void BackUp(int count) override {
+ _used -= count;
+ _count -= count;
+ }
+
+ int64_t ByteCount() const override { return _count; }
+
+ bool flush() {
+ const bool ok = EVP_DigestUpdate(_context, _buffer.data(), _used) == 1;
+ _used = 0;
+ return ok;
+ }
+
+private:
+ EVP_MD_CTX* _context;
+ std::array<unsigned char, 4096> _buffer {};
+ int _used = 0;
+ int64_t _count = 0;
+};
+
+std::string encode_base64(std::string_view input) {
+ std::string encoded(4 * ((input.size() + 2) / 3) + 1, '\0');
+ const int size = EVP_EncodeBlock(reinterpret_cast<unsigned
char*>(encoded.data()),
+ reinterpret_cast<const unsigned
char*>(input.data()),
+ static_cast<int>(input.size()));
+ encoded.resize(size);
+ return encoded;
+}
+
+bool decode_base64(std::string_view input, std::string* output) {
+ // Both supported encodings are small and padded. Reject malformed,
oversized or
+ // non-canonical headers rather than feeding arbitrary allocations into
OpenSSL.
+ if (input.empty() || input.size() > 128 || input.size() % 4 != 0) {
+ return false;
+ }
+ output->resize(input.size() / 4 * 3);
+ int size = EVP_DecodeBlock(reinterpret_cast<unsigned
char*>(output->data()),
+ reinterpret_cast<const unsigned
char*>(input.data()),
+ static_cast<int>(input.size()));
+ if (size < 0) {
+ return false;
+ }
+ size -= input.back() == '=';
+ size -= input.size() > 1 && input[input.size() - 2] == '=';
+ output->resize(size);
+ return encode_base64(*output) == input;
+}
+
+} // namespace
+
+static bool verify_digest(std::string_view hash, std::string_view method,
int64_t backend_id,
+ std::string_view public_key, std::string_view
timestamp,
+ std::string_view signature, int64_t now_ms) {
+ int64_t issued_at = 0;
+ auto parsed = std::from_chars(timestamp.data(), timestamp.data() +
timestamp.size(), issued_at);
+ // A captured authorization must not remain valid indefinitely. Validate
range before
+ // subtraction so even attacker-controlled INT64_MIN/MAX timestamps cannot
overflow.
+ if (parsed.ec != std::errc() || parsed.ptr != timestamp.data() +
timestamp.size() ||
+ issued_at < 0 || issued_at < now_ms - (method == "open_scanner" ?
900000 : 60000) ||
Review Comment:
Addressed by ab9083cb1c and revalidated with this update. Exported scanner
capabilities retain the existing snapshot/split lifetime instead of a fixed
15-minute lower timestamp cutoff, while signatures, receiver cluster binding
and trusted-key revocation remain enforced. BE tests cover delayed opens, and
the real lifecycle suite reopens the same opaque plan after issuer restart.
Delayed-open lifetime is checked with controlled unit-test timestamps; runtime
coverage verifies persisted plan reuse after restart.
##########
fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java:
##########
@@ -3417,6 +3418,7 @@ public TFrontendPingFrontendResult
ping(TFrontendPingFrontendRequest request) th
result.setLocalResourceGroup(Config.local_resource_group);
result.setLastStartupTime(exeEnv.getStartupTime());
result.setProcessUUID(exeEnv.getProcessUUID());
+
result.setRpcPublicKey(InternalRpcRequestSigner.getInstance().getPublicKey());
Review Comment:
The remaining overlapping recovery case is fixed in 6cffe7a4c2. Startup
requires a heartbeat acknowledgment of its startup journal position even when
all workers are unreachable; the test round-trips the actual HbPackage
serialization. FE heartbeat results are applied before building the BE
authority snapshot, so recovery publishes current keys before marking a BE
alive. The four-FE/one-BE regression now joins a fresh FE while the sole BE is
down, recovers that BE and checks the first connection/data query, follower
restart, promotion and old-master recovery. It never retries backend or
authorization errors.
##########
fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java:
##########
@@ -513,7 +514,8 @@ public HeartbeatResponse call() {
System.currentTimeMillis(),
Version.DORIS_BUILD_VERSION + "-" +
Version.DORIS_BUILD_SHORT_HASH,
ExecuteEnv.getInstance().getStartupTime(),
ExecuteEnv.getInstance().getDiskInfos(),
- ExecuteEnv.getInstance().getProcessUUID(),
Config.local_resource_group);
+ ExecuteEnv.getInstance().getProcessUUID(),
Config.local_resource_group)
+
.withRpcPublicKey(InternalRpcRequestSigner.getInstance().getPublicKey());
Review Comment:
Fixed in 6cffe7a4c2. Self detection now matches host and edit-log port, and
a known peer is pinged at its own RPC port. Unknown or colliding colocated
endpoints return BAD without contacting the local socket, while different-host
bootstrap retains the existing fallback. The new eight-case heartbeat test
exercises the real handler and round, including distinct keys, failed endpoints
and initial/replacement authority publication. Four target assertions fail on
the original code. Colocated startup continues to require a known distinct RPC
endpoint.
--
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]