hello-stephen commented on code in PR #71174:
URL: https://github.com/apache/doris/pull/71174#discussion_r4741249339


##########
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:
   [P2] Publish a restarted FE's key before accepting queries
   
   A restarted follower creates a fresh signing key, but this ping exposes it 
only after `Env.isReady()` is true, and `DorisFE` starts its client services 
immediately after `waitForReady()` without waiting for key distribution. 
`HeartbeatMgr.runAfterCatalogReady()` snapshots FE keys before sending both BE 
heartbeats and FE pings, so the iteration that first learns the replacement key 
has already sent the old key to BEs; they receive the new key only in the next 
iteration. Even when a load balancer waits until the master reports the 
follower alive, its queries are rejected with `NOT_AUTHORIZED` until that next 
heartbeat (10 seconds by default). Include signing-key publication in query 
readiness, with an acknowledgment or registration phase, and test restart 
ordering against an auth-enabled BE.



##########
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:
   [P1] Preserve an authenticated path for remote Doris workers
   
   With a non-cloud remote Doris catalog using `use_arrow_flight=false`, 
`CoordinatorContext.getBackendRpcTarget()` and 
`BackendServiceProxy.bindTarget()` select `internalRpc=false`, so this branch 
sends unsigned fragment requests. The stock 
`OssBackendServiceClientChannelProvider` adds no authorization and still 
advertises remote-worker support when private TLS is off. Once the target BE is 
upgraded, its new default-on `_check_request_auth()` therefore rejects every 
remote exec/prepare/start request. Catalog credentials only authenticate 
metadata requests to the remote FE; they supply no execution capability here. 
Provide a working remote authorization path before enabling the receiving gate 
for this supported mode, and cover the stock provider against an auth-enabled 
remote BE.



##########
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:
   [P2] Preserve exported plans across delayed tablet opens
   
   The fixed 900000 ms lifetime invalidates a plan while an existing external 
read can still need it. FE exports one opaque plan for all tablets; 
`DorisReaderExample.readData()` obtains it once and reuses it while draining 
tablets sequentially, allowing 3600 seconds per scanner. If earlier tablets 
take more than 15 minutes, opening the next tablet now inevitably fails with 
`NOT_AUTHORIZED`, even though its signed snapshot and the caller's privileges 
are unchanged. Distributed readers can likewise schedule later splits after 
this deadline. The response exposes neither an expiry contract nor a way to 
renew authorization for the same signed snapshot. Add a lifetime/renewal 
contract compatible with delayed split opens before enforcing this cutoff.



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