This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 61a35e19dc1 [fix](https) Backport FE HTTPS forwarding fixes to
branch-4.2 (#70475)
61a35e19dc1 is described below
commit 61a35e19dc1398e76af4ad13a76e988e7f78e6a7
Author: Mingyu Chen (Rayner) <[email protected]>
AuthorDate: Tue Nov 24 17:27:05 2026 +0800
[fix](https) Backport FE HTTPS forwarding fixes to branch-4.2 (#70475)
### Background
FE REST endpoints such as `get_load_state` forward follower requests to
the master. Internal FE clients also serve checkpoint synchronization,
manager operations and audit loading. HTTPS deployments need those
clients to select a matching protocol, port and trust store.
### What problem does this PR solve?
Issue Number: #70425
Related PR: #60921 (original FE HTTPS support), #64697 (required
follow-up fixes), #63918 (companion BE small-file support), #64670 (port
helper already present), #70472 (branch-4.1 companion backport)
PR Type: Bugfix
Problem Summary:
Backport #60921 and its required companion fixes #64697 and #63918 to
branch-4.2. An HTTPS request to a follower currently forwards to the
master's HTTP port and returns an error envelope. The patch selects the
HTTPS endpoint, trusts certificates from the FE HTTPS keystore, keeps BE
stream-load redirects on HTTP, and allows BE small-file downloads to use
the HTTPS port advertised by the FE.
### Details
- **Change map:** 371 changed lines in production code and 301 in tests;
no generated files or documentation. The production changes cover
internal FE URLs and clients, FE-keystore trust, FE-to-BE redirect
selection, audit loading, and the companion BE small-file retry.
- **Frequency:** HTTPS requests that require follower-to-master
forwarding fail when the HTTP and HTTPS listeners use different ports.
- **Root cause:** The original forwarding code combines the incoming
HTTPS scheme with `getMasterHttpPort()`, which advertises the HTTP port
on this branch.
- **Why existing tests missed it:** The forwarding unit-test shortcut
uses the request's own endpoint. The upstream URL, client-selection and
redirect tests cover the individual behaviors, but there is no real
multi-FE HTTPS integration test in this backport.
- **Fix:** Reuse `HttpURLUtil.buildInternalFeUrl()` and the upstream
internal TLS client. Include #64697 so FE HTTPS trust does not depend on
the separate MySQL truststore and HTTP BE requests keep using a plain
client. Include #63918 because the heartbeat now advertises `https_port`
to BEs.
- **Other paths and branches:** The branch-4.1 companion backport is
#70472. Master already contains the upstream fixes. This PR does not
target branch-4.0 or branch-4.1.4.
### Testing
- `mvn -B -pl fe-core checkstyle:check` (from `fe/`): passed, zero
violations.
- `bash run-fe-ut.sh --run
'org.apache.doris.common.util.HttpURLUtilTest,org.apache.doris.common.util.InternalHttpsUtilsTest,org.apache.doris.httpv2.rest.RestBaseControllerTest,org.apache.doris.httpv2.rest.manager.HttpUtilsTest,org.apache.doris.system.HeartbeatMgrTest,org.apache.doris.nereids.minidump.MinidumpUtTest'`:
passed, 20 tests reported, 19 passed and one existing skipped test; no
failures or errors.
- `build-support/check-format.sh` with clang-format 16: passed; the
companion branch already ran the formatter on the identical BE source.
- `build-support/run-clang-tidy.sh --base HEAD --build-dir
be/build_ASAN`: no warnings on the changed C++ lines. This branch
predates the helper, so the master helper was run from a temporary file
with its repository-root path set explicitly. It used the compilation
database generated by the branch-4.1 build in the same checkout; the
changed BE translation unit is identical on both backports.
- `git diff --cached --check`: passed.
- Full BE build was attempted on the companion branch-4.1 backport
(#70472): configuration succeeded, but compilation failed in unchanged
ANN/runtime-profile code because LLVM 22 diagnoses `__COUNTER__` as a
C2y extension under `-Werror`. A full BE build was not repeated on
branch-4.2; linking and runtime tests are not verified.
- No live cluster, multi-FE HTTPS integration, or BE HTTPS download test
was run. The header-hygiene helper is absent from this release branch.
### Notes for Reviewers
Conflict resolution preserves the branch's existing FE metadata
authentication token, log redaction, JMockit-based heartbeat tests,
audit-log GZIP compression, and minidump-test assertions. The existing
`getHttpPort()` helper is retained once; upstream URL tests are appended
to the existing token tests. In the BE retry, failure to truncate the
partial download returns an error instead of continuing with an invalid
temporary file.
Review checks:
- Goal and scope: the forwarding defect is addressed through the
upstream shared URL/client path; companion changes prevent known
regressions from a partial pick.
- Concurrency and lifecycle: the upstream volatile, synchronized
SSL-context cache and per-request client ownership are preserved; cached
certificates require an FE restart after rotation.
- Configuration: no new options or defaults. Internal FE URLs use the
local `enable_https` and listener port, so FE protocol/port settings
must be uniform and the HTTPS keystore must contain the relevant trusted
certificates or CA chain.
- Compatibility: no Thrift/protobuf IDs, persisted formats or
transaction semantics change. Deploy the companion BE support before
relying on HTTPS-port heartbeats during a rolling upgrade.
- Parallel paths and conditions: FE forwarding, metadata synchronization
and manager clients use the shared helpers; BE redirects and BE manager
requests retain HTTP.
- Tests and expected output: upstream unit tests are retained, with no
handwritten regression output. Real follower/master HTTPS and BE HTTPS
download integration tests remain unexecuted locally.
- Observability and performance: existing exception logging is retained;
SSL-context initialization remains cached, and plain HTTP does not
construct the HTTPS client.
- Data writes and FE/BE propagation: label-state and transaction logic
are unchanged; the existing heartbeat port field carries the selected FE
listener, paired with the BE fallback.
### Release note
Fix FE HTTPS forwarding from followers to the master, including
load-state queries. Internal FE communication and audit loading use the
configured HTTPS listener and keystore; BE stream-load redirects
continue to use HTTP, and small-file downloads support HTTPS-enabled
FEs.
### Check List (For Author)
- Behavior changed: Yes (see Details).
- Does this need documentation: No new configuration; deployment
assumptions are recorded above.
- Pre-submission status: Partially verified: FE unit tests, Java style,
C++ formatting and changed-line static analysis pass; full BE build
remains unverified after the companion backport encountered the local
LLVM 22 warning above, and live HTTPS integration remains unverified.
### AI Disclosure
- Tool: Codex (GPT-6).
- Generated: Backport conflict resolutions, a BE error-propagation
adjustment, and this description. Other code and tests originate in the
linked upstream PRs.
- Human review: Pending maintainer review.
Co-authored-by: Sivarajan Narayanan <[email protected]>
---
be/src/runtime/small_file_mgr.cpp | 47 +++++---
.../main/java/org/apache/doris/catalog/Env.java | 21 ++--
.../org/apache/doris/common/util/HttpURLUtil.java | 20 ++++
.../doris/common/util/InternalHttpsUtils.java | 120 +++++++++++++++++++++
.../doris/httpv2/controller/SessionController.java | 5 +-
.../org/apache/doris/httpv2/meta/MetaService.java | 5 +-
.../org/apache/doris/httpv2/rest/LoadAction.java | 9 +-
.../doris/httpv2/rest/RestBaseController.java | 54 +++++++++-
.../doris/httpv2/rest/manager/ClusterAction.java | 4 +-
.../doris/httpv2/rest/manager/HttpUtils.java | 22 ++--
.../doris/httpv2/rest/manager/NodeAction.java | 15 ++-
.../httpv2/rest/manager/QueryProfileAction.java | 4 +-
.../java/org/apache/doris/master/Checkpoint.java | 11 +-
.../java/org/apache/doris/master/MetaHelper.java | 6 +-
.../doris/nereids/minidump/MinidumpUtils.java | 7 +-
.../doris/plugin/audit/AuditStreamLoader.java | 16 ++-
.../java/org/apache/doris/system/HeartbeatMgr.java | 5 +-
.../apache/doris/common/util/HttpURLUtilTest.java | 46 ++++++++
.../doris/common/util/InternalHttpsUtilsTest.java | 65 +++++++++++
.../doris/httpv2/rest/RestBaseControllerTest.java | 19 ++++
.../doris/httpv2/rest/manager/HttpUtilsTest.java | 94 ++++++++++++++++
.../doris/nereids/minidump/MinidumpUtTest.java | 43 ++++++++
.../org/apache/doris/system/HeartbeatMgrTest.java | 34 ++++++
23 files changed, 609 insertions(+), 63 deletions(-)
diff --git a/be/src/runtime/small_file_mgr.cpp
b/be/src/runtime/small_file_mgr.cpp
index bfcded942f3..246171cdc96 100644
--- a/be/src/runtime/small_file_mgr.cpp
+++ b/be/src/runtime/small_file_mgr.cpp
@@ -25,6 +25,7 @@
#include <glog/logging.h>
#include <stdint.h>
#include <stdio.h>
+#include <unistd.h>
#include <cstring>
#include <memory>
@@ -166,19 +167,15 @@ Status SmallFileMgr::_download_file(int64_t file_id,
const std::string& md5,
return Status::InternalError("fail to open file");
}
- HttpClient client;
-
- std::stringstream url_ss;
ClusterInfo* cluster_info = _exec_env->cluster_info();
- url_ss << cluster_info->master_fe_addr.hostname << ":" <<
cluster_info->master_fe_http_port
- << "/api/get_small_file?"
- << "file_id=" << file_id << "&token=" << cluster_info->token;
+ // Small file download is the only BE→FE path that uses HTTP (not
Thrift/RPC).
+ // master_fe_http_port is set to https_port when enable_https=true (see
HeartbeatMgr).
+ // The ~1ms fallback overhead is acceptable; small file downloads are
infrequent.
+ const std::string host_port = cluster_info->master_fe_addr.hostname + ":" +
+
std::to_string(cluster_info->master_fe_http_port);
+ const std::string query = "/api/get_small_file?file_id=" +
std::to_string(file_id) +
+ "&token=" + cluster_info->token;
- std::string url = url_ss.str();
-
- LOG(INFO) << "download file from: " << url;
-
- RETURN_IF_ERROR(client.init(url));
Status status;
Md5Digest digest;
auto download_cb = [&status, &tmp_file, &fp, &digest](const void* data,
size_t length) {
@@ -192,7 +189,33 @@ Status SmallFileMgr::_download_file(int64_t file_id, const
std::string& md5,
}
return true;
};
- RETURN_IF_ERROR(client.execute(download_cb));
+
+ std::string url = "http://" + host_port + query;
+ LOG(INFO) << "download file from: " << url;
+ HttpClient client;
+ RETURN_IF_ERROR(client.init(url));
+ Status execute_status = client.execute(download_cb);
+
+ if (!execute_status.ok()) {
+ rewind(fp.get());
+ if (ftruncate(fileno(fp.get()), 0) != 0) {
+ return Status::InternalError("fail to truncate temp file for https
retry, errno={}",
+ errno);
+ }
+ status = Status::OK();
+ digest = Md5Digest();
+
+ url = "https://" + host_port + query;
+ LOG(INFO) << "HTTP failed, retrying with HTTPS: " << url;
+ HttpClient https_client;
+ RETURN_IF_ERROR(https_client.init(url));
+ // Skip TLS cert verification: internal cluster traffic only; file
integrity
+ // is guaranteed independently by MD5 checksum verification below.
+ https_client.use_untrusted_ssl();
+ execute_status = https_client.execute(download_cb);
+ }
+
+ RETURN_IF_ERROR(execute_status);
RETURN_IF_ERROR(status);
digest.digest();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index 97c3e7208e1..a49497d5ee4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -1422,8 +1422,7 @@ public class Env {
getClusterIdFromStorage(storage);
token = storage.getToken();
try {
- String url = "http://" + NetUtils
-
.getHostPortInAccessibleFormat(rightHelperNode.getHost(), Config.http_port) +
"/check";
+ String url =
HttpURLUtil.buildInternalFeUrl(rightHelperNode.getHost(), "/check", null);
HttpURLConnection conn =
HttpURLUtil.getConnectionWithNodeIdent(url);
conn.setConnectTimeout(2 * 1000);
conn.setReadTimeout(2 * 1000);
@@ -1521,9 +1520,8 @@ public class Env {
try {
// For upgrade compatibility, the host parameter name remains
the same
// and the new hostname parameter is added
- String url = "http://" +
NetUtils.getHostPortInAccessibleFormat(helperNode.getHost(), Config.http_port)
- + "/role?host=" + selfNode.getHost()
- + "&port=" + selfNode.getPort();
+ String queryParams = "host=" + selfNode.getHost() + "&port=" +
selfNode.getPort();
+ String url =
HttpURLUtil.buildInternalFeUrl(helperNode.getHost(), "/role", queryParams);
HttpURLConnection conn =
HttpURLUtil.getConnectionWithNodeIdent(url);
if (conn.getResponseCode() != 200) {
LOG.warn("failed to get fe node type from helper node: {}.
response code: {}", helperNode,
@@ -1557,7 +1555,8 @@ public class Env {
}
LOG.info("get fe node type {}, name {} from {}:{}:{}", role,
nodeName,
- helperNode.getHost(), helperNode.getHost(),
Config.http_port);
+ helperNode.getHost(), helperNode.getPort(),
+ HttpURLUtil.getHttpPort());
rightHelperNode = helperNode;
break;
}
@@ -1786,7 +1785,7 @@ public class Env {
toMasterProgress = "log master info";
this.masterInfo = new
MasterInfo(Env.getCurrentEnv().getSelfNode().getHost(),
- Config.http_port,
+ HttpURLUtil.getHttpPort(),
Config.rpc_port);
editLog.logMasterInfo(masterInfo);
LOG.info("logMasterInfo:{}", masterInfo);
@@ -2227,8 +2226,7 @@ public class Env {
protected boolean getVersionFileFromHelper(HostInfo helperNode) throws
IOException {
try {
- String url = "http://" +
NetUtils.getHostPortInAccessibleFormat(helperNode.getHost(), Config.http_port)
- + "/version";
+ String url = HttpURLUtil.buildInternalFeUrl(helperNode.getHost(),
"/version", null);
File dir = new File(this.imageDir);
MetaHelper.getRemoteFile(url, HTTP_TIMEOUT_SECOND * 1000,
MetaHelper.getFile(Storage.VERSION_FILE, dir));
@@ -2247,8 +2245,7 @@ public class Env {
localImageVersion = storage.getLatestImageSeq();
try {
- String hostPort =
NetUtils.getHostPortInAccessibleFormat(helperNode.getHost(), Config.http_port);
- String infoUrl = "http://" + hostPort + "/info";
+ String infoUrl =
HttpURLUtil.buildInternalFeUrl(helperNode.getHost(), "/info", null);
ResponseBody<StorageInfo> responseBody = MetaHelper
.doGet(infoUrl, HTTP_TIMEOUT_SECOND * 1000,
StorageInfo.class);
if (responseBody.getCode() != RestApiStatusCode.OK.code) {
@@ -2258,7 +2255,7 @@ public class Env {
StorageInfo info = responseBody.getData();
long version = info.getImageSeq();
if (version > localImageVersion) {
- String url = "http://" + hostPort + "/image?version=" +
version;
+ String url =
HttpURLUtil.buildInternalFeUrl(helperNode.getHost(), "/image", "version=" +
version);
String filename = Storage.IMAGE + "." + version;
File dir = new File(this.imageDir);
MetaHelper.getRemoteFile(url, Config.sync_image_timeout_second
* 1000,
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/common/util/HttpURLUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/common/util/HttpURLUtil.java
index 67948e8b31a..5e746800b1a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/util/HttpURLUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/HttpURLUtil.java
@@ -25,11 +25,13 @@ import org.apache.doris.system.SystemInfoService.HostInfo;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
+import javax.net.ssl.HttpsURLConnection;
public class HttpURLUtil {
@@ -38,6 +40,12 @@ public class HttpURLUtil {
SecurityChecker.getInstance().startSSRFChecking(request);
URL url = new URL(request);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ if (conn instanceof HttpsURLConnection && Config.enable_https) {
+ HttpsURLConnection httpsConn = (HttpsURLConnection) conn;
+
httpsConn.setSSLSocketFactory(InternalHttpsUtils.getSslContext().getSocketFactory());
+ httpsConn.setHostnameVerifier(NoopHostnameVerifier.INSTANCE);
+ }
+
// Must use Env.getServingEnv() instead of getCurrentEnv(),
// because here we need to obtain selfNode through the official
service catalog.
HostInfo selfNode = Env.getServingEnv().getSelfNode();
@@ -73,4 +81,16 @@ public class HttpURLUtil {
return Config.enable_https ? Config.https_port : Config.http_port;
}
+ public static String buildInternalFeUrl(String host, String path, String
queryParams) {
+ String protocol = Config.enable_https ? "https" : "http";
+ int port = getHttpPort();
+
+ String url = protocol + "://" +
NetUtils.getHostPortInAccessibleFormat(host, port) + path;
+ if (queryParams != null && !queryParams.isEmpty()) {
+ url += "?" + queryParams;
+ }
+
+ return url;
+ }
+
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/common/util/InternalHttpsUtils.java
b/fe/fe-core/src/main/java/org/apache/doris/common/util/InternalHttpsUtils.java
new file mode 100644
index 00000000000..47f0cebd9a3
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/common/util/InternalHttpsUtils.java
@@ -0,0 +1,120 @@
+// 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.
+
+package org.apache.doris.common.util;
+
+import org.apache.doris.common.Config;
+
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.security.KeyStore;
+import java.security.cert.Certificate;
+import java.util.Collections;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+/**
+ * SSL-aware HTTP client for internal FE communication (loopback and FE-to-FE).
+ *
+ * <p>Trusts this FE's own HTTPS keystore ({@code Config.key_store_path}), not
+ * {@code Config.mysql_ssl_default_ca_certificate} (a separate store for MySQL
SSL). Trusts every
+ * cert in the keystore's chains, so a bundled CA also validates other nodes'
certs it signed.
+ */
+public class InternalHttpsUtils {
+ private static volatile SSLContext cachedSslContext = null;
+
+ private static final Logger LOG =
LogManager.getLogger(InternalHttpsUtils.class);
+
+ /**
+ * Returns the cached SSLContext, building it from the FE's own HTTPS
keystore on first call.
+ */
+ public static SSLContext getSslContext() {
+ if (cachedSslContext == null) {
+ synchronized (InternalHttpsUtils.class) {
+ if (cachedSslContext == null) {
+ cachedSslContext = buildSslContext();
+ }
+ }
+ }
+ return cachedSslContext;
+ }
+
+ private static SSLContext buildSslContext() {
+ try {
+ KeyStore keyStore = KeyStore.getInstance(Config.key_store_type);
+ try (InputStream stream =
Files.newInputStream(Paths.get(Config.key_store_path))) {
+ keyStore.load(stream, Config.key_store_password.toCharArray());
+ }
+
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(
+ TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(buildTrustStore(keyStore));
+
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ sslContext.init(null, tmf.getTrustManagers(), null);
+ return sslContext;
+ } catch (Exception e) {
+ LOG.error("Failed to build SSLContext from FE HTTPS keystore: {}",
+ Config.key_store_path, e);
+ throw new RuntimeException(
+ "Failed to build SSLContext from FE HTTPS keystore: "
+ + Config.key_store_path, e);
+ }
+ }
+
+ // Extracts every cert in every chain, since KeyStore.getCertificate()
only returns the leaf.
+ private static KeyStore buildTrustStore(KeyStore keyStore) throws
Exception {
+ KeyStore trustStore = KeyStore.getInstance(Config.key_store_type);
+ trustStore.load(null, null);
+ int certIndex = 0;
+ for (String alias : Collections.list(keyStore.aliases())) {
+ Certificate[] chain = keyStore.getCertificateChain(alias);
+ if (chain == null) {
+ Certificate cert = keyStore.getCertificate(alias);
+ if (cert != null) {
+ trustStore.setCertificateEntry("cert-" + certIndex++,
cert);
+ }
+ continue;
+ }
+ for (Certificate cert : chain) {
+ trustStore.setCertificateEntry("cert-" + certIndex++, cert);
+ }
+ }
+ return trustStore;
+ }
+
+ /**
+ * Returns an HTTP client configured with the FE CA truststore and
hostname verification disabled.
+ */
+ public static CloseableHttpClient createValidatedHttpClient() {
+ SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(
+ getSslContext(),
+ NoopHostnameVerifier.INSTANCE);
+
+ return HttpClients.custom()
+ .setSSLSocketFactory(sslFactory)
+ .build();
+ }
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/SessionController.java
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/SessionController.java
index 94be8e17376..a753305106a 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/SessionController.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/SessionController.java
@@ -20,6 +20,7 @@ package org.apache.doris.httpv2.controller;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.SchemaTable;
import org.apache.doris.catalog.Table;
+import org.apache.doris.common.util.HttpURLUtil;
import org.apache.doris.httpv2.entity.ResponseBody;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
import org.apache.doris.httpv2.rest.RestBaseController;
@@ -118,8 +119,8 @@ public class SessionController extends RestBaseController {
Frontend frontend)
throws IOException {
Map<String, String> header = Maps.newHashMap();
header.put(NodeAction.AUTHORIZATION,
request.getHeader(NodeAction.AUTHORIZATION));
- String res =
HttpUtils.doGet(String.format("http://%s:%s/rest/v1/session",
- frontend.getHost(), Env.getCurrentEnv().getMasterHttpPort()),
header);
+ String res = HttpUtils.doGet(HttpURLUtil.buildInternalFeUrl(
+ frontend.getHost(), "/rest/v1/session", null), header);
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> jsonMap = objectMapper.readValue(res,
new TypeReference<Map<String, Object>>() {});
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/meta/MetaService.java
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/meta/MetaService.java
index 3e9cea55cdf..fe88e854d35 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/httpv2/meta/MetaService.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/httpv2/meta/MetaService.java
@@ -196,7 +196,10 @@ public class MetaService extends RestBaseController {
clientHost, clientPort, machine, portStr);
clientHost = Strings.isNullOrEmpty(clientHost) ? machine : clientHost;
- String url = "http://" +
NetUtils.getHostPortInAccessibleFormat(clientHost, Integer.valueOf(portStr))
+ // Use the master-supplied port: Checkpoint sends getHttpPort()
(https_port when
+ // enable_https=true), so scheme and port must stay consistent.
+ String scheme = Config.enable_https ? "https" : "http";
+ String url = scheme + "://" +
NetUtils.getHostPortInAccessibleFormat(clientHost, port)
+ "/image?version=" + versionStr;
String filename = Storage.IMAGE + "." + versionStr;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/LoadAction.java
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/LoadAction.java
index 08d36c159cd..a52f48d1651 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/LoadAction.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/LoadAction.java
@@ -356,7 +356,7 @@ public class LoadAction extends RestBaseController {
LOG.info("redirect stream load 2PC action to destination={}, db:
{}, txn: {}, operation: {}",
redirectAddr.toString(), dbName,
request.getHeader(TXN_ID_KEY), txnOperation);
- RedirectView redirectView = redirectTo(request, redirectAddr);
+ RedirectView redirectView = redirectToBackend(request,
redirectAddr);
return redirectView;
} catch (Exception e) {
@@ -689,9 +689,10 @@ public class LoadAction extends RestBaseController {
private Object createRedirectResponse(HttpServletRequest request,
HttpServletResponse response,
TNetworkAddress redirectAddr, boolean isStreamLoad, String dbName,
String tableName, String label)
throws IOException {
- String redirectUrl = buildRedirectUrl(request, redirectAddr);
+ String redirectUrl = buildRedirectUrlToBackend(request, redirectAddr,
request.getRequestURI(),
+ request.getQueryString());
if (!shouldUseBoundedDrainForStreamLoad(isStreamLoad)) {
- return redirectTo(request, redirectAddr);
+ return redirectToBackend(request, redirectAddr);
}
writeTemporaryRedirect(response, redirectUrl);
DrainDecision drainDecision =
decideDrainDecisionForStreamLoadRedirect(request);
@@ -843,7 +844,7 @@ public class LoadAction extends RestBaseController {
if (!Strings.isNullOrEmpty(queryString)) {
redirectQuery = queryString + "&" + redirectQuery;
}
- String redirectUrl = buildRedirectUrl(request, addr, modifiedPath,
redirectQuery);
+ String redirectUrl = buildRedirectUrlToBackend(request, addr,
modifiedPath, redirectQuery);
LOG.info("Redirect stream load forward url: {}, forward_to: {}",
"http://" + addr.getHostname() + ":" + addr.getPort() +
modifiedPath, forwardTarget);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/RestBaseController.java
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/RestBaseController.java
index bf75cca2c13..53ed6c844bf 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/RestBaseController.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/RestBaseController.java
@@ -23,6 +23,8 @@ import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.Config;
import org.apache.doris.common.FeConstants;
import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.HttpURLUtil;
+import org.apache.doris.common.util.InternalHttpsUtils;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.httpv2.controller.BaseController;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
@@ -37,6 +39,7 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jline.internal.Nullable;
import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpEntity;
@@ -44,6 +47,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.view.RedirectView;
@@ -53,10 +57,12 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.stream.Collectors;
+import javax.net.ssl.HttpsURLConnection;
public class RestBaseController extends BaseController {
@@ -95,6 +101,17 @@ public class RestBaseController extends BaseController {
protected String buildRedirectUrl(HttpServletRequest request,
TNetworkAddress addr, String requestPath,
String queryString) {
+ return buildRedirectUrl(request.getScheme(), request, addr,
requestPath, queryString);
+ }
+
+ // BE's stream-load listener never terminates TLS, so BE-bound redirects
must stay "http".
+ protected String buildRedirectUrlToBackend(HttpServletRequest request,
TNetworkAddress addr,
+ String requestPath, String queryString) {
+ return buildRedirectUrl("http", request, addr, requestPath,
queryString);
+ }
+
+ private String buildRedirectUrl(String scheme, HttpServletRequest request,
TNetworkAddress addr,
+ String requestPath, String queryString) {
String userInfo = null;
if (!Strings.isNullOrEmpty(request.getHeader("Authorization"))) {
ActionAuthorizationInfo authInfo = getAuthorizationInfo(request);
@@ -103,13 +120,13 @@ public class RestBaseController extends BaseController {
}
try {
// Preserve the original request path to avoid re-encoding an
already encoded URI path.
- URI authorityUri = new URI(request.getScheme(), userInfo,
addr.getHostname(),
+ URI authorityUri = new URI(scheme, userInfo, addr.getHostname(),
addr.getPort(), null, null, null);
String redirectUrl = authorityUri.toASCIIString() + requestPath;
if (!Strings.isNullOrEmpty(queryString)) {
redirectUrl += "?" + queryString;
}
- LOG.info("Redirect url: {}", request.getScheme() + "://" +
addr.getHostname() + ":"
+ LOG.info("Redirect url: {}", scheme + "://" + addr.getHostname() +
":"
+ addr.getPort() + requestPath);
return redirectUrl;
} catch (Exception e) {
@@ -131,6 +148,15 @@ public class RestBaseController extends BaseController {
return redirectView;
}
+ // Use for redirects whose destination is a BE (e.g. stream load), which
never speaks HTTPS.
+ public RedirectView redirectToBackend(HttpServletRequest request,
TNetworkAddress addr) {
+ RedirectView redirectView = new RedirectView(
+ buildRedirectUrlToBackend(request, addr,
request.getRequestURI(), request.getQueryString()));
+ redirectView.setContentType("text/html;charset=utf-8");
+
redirectView.setStatusCode(org.springframework.http.HttpStatus.TEMPORARY_REDIRECT);
+ return redirectView;
+ }
+
public String getRedirectUrL(HttpServletRequest request, TNetworkAddress
addr) {
return buildRedirectUrl(request, addr);
}
@@ -277,8 +303,8 @@ public class RestBaseController extends BaseController {
redirectUrl =
getRedirectUrL(request, new
TNetworkAddress(request.getServerName(), request.getServerPort()));
} else {
- redirectUrl = getRedirectUrL(request,
- new TNetworkAddress(env.getMasterHost(),
env.getMasterHttpPort()));
+ redirectUrl = HttpURLUtil.buildInternalFeUrl(
+ env.getMasterHost(), request.getRequestURI(),
request.getQueryString());
}
String method = request.getMethod();
@@ -298,7 +324,25 @@ public class RestBaseController extends BaseController {
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
- RestTemplate restTemplate = new RestTemplate();
+ RestTemplate restTemplate;
+ if (Config.enable_https) {
+ SimpleClientHttpRequestFactory factory = new
SimpleClientHttpRequestFactory() {
+ @Override
+ protected void prepareConnection(HttpURLConnection conn,
String httpMethod)
+ throws IOException {
+ if (conn instanceof HttpsURLConnection) {
+ HttpsURLConnection https = (HttpsURLConnection)
conn;
+ https.setSSLSocketFactory(
+
InternalHttpsUtils.getSslContext().getSocketFactory());
+
https.setHostnameVerifier(NoopHostnameVerifier.INSTANCE);
+ }
+ super.prepareConnection(conn, httpMethod);
+ }
+ };
+ restTemplate = new RestTemplate(factory);
+ } else {
+ restTemplate = new RestTemplate();
+ }
ResponseEntity<Object> responseEntity;
switch (method) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/ClusterAction.java
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/ClusterAction.java
index 391d7c85163..2c49a3b7178 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/ClusterAction.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/ClusterAction.java
@@ -20,6 +20,7 @@ package org.apache.doris.httpv2.rest.manager;
import org.apache.doris.catalog.Env;
import org.apache.doris.cloud.system.CloudSystemInfoService;
import org.apache.doris.common.Config;
+import org.apache.doris.common.util.HttpURLUtil;
import org.apache.doris.common.util.NetUtils;
import
org.apache.doris.httpv2.controller.BaseController.ActionAuthorizationInfo;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
@@ -71,7 +72,8 @@ public class ClusterAction extends RestBaseController {
result.put("mysql", frontends.stream().map(ip -> NetUtils
.getHostPortInAccessibleFormat(ip,
Config.query_port)).collect(Collectors.toList()));
result.put("http", frontends.stream().map(ip -> NetUtils
- .getHostPortInAccessibleFormat(ip,
Config.http_port)).collect(Collectors.toList()));
+ .getHostPortInAccessibleFormat(ip,
+
HttpURLUtil.getHttpPort())).collect(Collectors.toList()));
result.put("arrow flight sql server", frontends.stream().map(
ip -> NetUtils.getHostPortInAccessibleFormat(ip,
Config.arrow_flight_sql_port))
.collect(Collectors.toList()));
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/HttpUtils.java
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/HttpUtils.java
index eae838060b4..43df88ee548 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/HttpUtils.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/HttpUtils.java
@@ -20,6 +20,8 @@ package org.apache.doris.httpv2.rest.manager;
import org.apache.doris.catalog.Env;
import org.apache.doris.common.Config;
import org.apache.doris.common.Pair;
+import org.apache.doris.common.util.HttpURLUtil;
+import org.apache.doris.common.util.InternalHttpsUtils;
import org.apache.doris.common.util.Util;
import org.apache.doris.httpv2.entity.ResponseBody;
import org.apache.doris.persist.gson.GsonUtils;
@@ -51,7 +53,7 @@ import java.util.Objects;
import java.util.stream.Collectors;
/*
- * used to forward http requests from manager to be.
+ * Used for internal HTTP(S) communication between FE nodes and from manager
to BE.
*/
public class HttpUtils {
private static final Logger LOG = LogManager.getLogger(HttpUtils.class);
@@ -60,18 +62,21 @@ public class HttpUtils {
static final int DEFAULT_TIME_OUT_MS = 2000;
public static List<Pair<String, Integer>> getFeList() {
+ int port = HttpURLUtil.getHttpPort();
return Env.getCurrentEnv().getFrontends(null)
- .stream().filter(Frontend::isAlive).map(fe ->
Pair.of(fe.getHost(), Config.http_port))
+ .stream().filter(Frontend::isAlive).map(fe ->
Pair.of(fe.getHost(), port))
.collect(Collectors.toList());
}
static boolean isCurrentFe(String ip, int port) {
HostInfo hostInfo = Env.getCurrentEnv().getSelfNode();
- return hostInfo.isSame(new HostInfo(ip, port));
+ // Compare against the actual HTTP/HTTPS port, not the edit_log_port
held by selfNode.
+ int selfPort = HttpURLUtil.getHttpPort();
+ return hostInfo.getHost().equals(ip) && selfPort == port;
}
public static String concatUrl(Pair<String, Integer> ipPort, String path,
Map<String, String> arguments) {
- StringBuilder url = new StringBuilder("http://")
+ StringBuilder url = new StringBuilder(Config.enable_https ? "https://"
: "http://")
.append(ipPort.first).append(":").append(ipPort.second).append(path);
boolean isFirst = true;
for (Map.Entry<String, String> entry : arguments.entrySet()) {
@@ -130,8 +135,13 @@ public class HttpUtils {
}
private static String executeRequest(HttpRequestBase request) throws
IOException {
- CloseableHttpClient client = HttpClientBuilder.create().build();
- return client.execute(request, httpResponse ->
EntityUtils.toString(httpResponse.getEntity()));
+ // Pick client by this request's own scheme, since this method also
serves plain http BE calls.
+ boolean useHttpsClient =
"https".equalsIgnoreCase(request.getURI().getScheme());
+ try (CloseableHttpClient client = useHttpsClient
+ ? InternalHttpsUtils.createValidatedHttpClient()
+ : HttpClientBuilder.create().build()) {
+ return client.execute(request, httpResponse ->
EntityUtils.toString(httpResponse.getEntity()));
+ }
}
static String parseResponse(String response) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/NodeAction.java
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/NodeAction.java
index af3ee28722c..fcb3a58a5d5 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/NodeAction.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/NodeAction.java
@@ -27,6 +27,7 @@ import org.apache.doris.common.Pair;
import org.apache.doris.common.ThreadPoolManager;
import org.apache.doris.common.proc.ProcResult;
import org.apache.doris.common.proc.ProcService;
+import org.apache.doris.common.util.HttpURLUtil;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.ha.FrontendNodeType;
@@ -240,8 +241,9 @@ public class NodeAction extends RestBaseController {
}
private static List<String> getFeList() {
+ int port = HttpURLUtil.getHttpPort();
return Env.getCurrentEnv().getFrontends(null).stream()
- .map(fe ->
NetUtils.getHostPortInAccessibleFormat(fe.getHost(), Config.http_port))
+ .map(fe ->
NetUtils.getHostPortInAccessibleFormat(fe.getHost(), port))
.collect(Collectors.toList());
}
@@ -380,7 +382,10 @@ public class NodeAction extends RestBaseController {
Pair<String, Integer> hostPort = hostPorts.get(i);
String address =
NetUtils.getHostPortInAccessibleFormat(hostPort.first, hostPort.second);
configRequestDoneSignal.addMark(address, -1);
- String url = "http://" + address + questPath;
+ // FE nodes use HTTPS when enabled; BE nodes always use plain HTTP
+ // (BEs do not participate in the FE internal HTTPS scheme)
+ String scheme = (Config.enable_https && "FE".equals(nodeType)) ?
"https://" : "http://";
+ String url = scheme + address + questPath;
httpExecutor.submit(
new HttpConfigInfoTask(url, hostPort, authorization,
nodeType, confNames, configRequestDoneSignal,
configInfoTotal.get(i)));
@@ -504,7 +509,8 @@ public class NodeAction extends RestBaseController {
List<Map<String, String>> failedTotal = Lists.newArrayList();
List<NodeConfigs> nodeConfigList = parseSetConfigNodes(requestBody,
failedTotal);
List<Pair<String, Integer>> aliveFe =
Env.getCurrentEnv().getFrontends(null).stream().filter(Frontend::isAlive)
- .map(fe -> Pair.of(fe.getHost(),
Config.http_port)).collect(Collectors.toList());
+ .map(fe -> Pair.of(fe.getHost(),
+
HttpURLUtil.getHttpPort())).collect(Collectors.toList());
checkNodeIsAlive(nodeConfigList, aliveFe, failedTotal);
Map<String, String> header = Maps.newHashMap();
@@ -576,7 +582,8 @@ public class NodeAction extends RestBaseController {
private String concatFeSetConfigUrl(NodeConfigs nodeConfigs, boolean
isPersist) {
StringBuilder sb = new StringBuilder();
Pair<String, Integer> hostPort = nodeConfigs.getHostPort();
-
sb.append("http://").append(hostPort.first).append(":").append(hostPort.second).append("/api/_set_config");
+ sb.append(Config.enable_https ? "https://" : "http://")
+
.append(hostPort.first).append(":").append(hostPort.second).append("/api/_set_config");
Map<String, String> configs = nodeConfigs.getConfigs(isPersist);
boolean addAnd = false;
for (Map.Entry<String, String> entry : configs.entrySet()) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
index 27b955522ae..d0aae7d1a0e 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
@@ -20,7 +20,6 @@ package org.apache.doris.httpv2.rest.manager;
import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.AuthenticationException;
-import org.apache.doris.common.Config;
import org.apache.doris.common.Pair;
import org.apache.doris.common.Status;
import org.apache.doris.common.proc.CurrentQueryStatisticsProcDir;
@@ -28,6 +27,7 @@ import org.apache.doris.common.proc.ProcResult;
import org.apache.doris.common.profile.ProfileManager;
import org.apache.doris.common.profile.ProfileManager.ProfileElement;
import org.apache.doris.common.profile.SummaryProfile;
+import org.apache.doris.common.util.HttpURLUtil;
import org.apache.doris.common.util.NetUtils;
import
org.apache.doris.httpv2.controller.BaseController.ActionAuthorizationInfo;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
@@ -196,7 +196,7 @@ public class QueryProfileAction extends RestBaseController {
// add node information
for (List<String> query : queries) {
query.set(1,
NetUtils.getHostPortInAccessibleFormat(Env.getCurrentEnv().getSelfNode().getHost(),
- Config.http_port));
+ HttpURLUtil.getHttpPort()));
}
if (!Strings.isNullOrEmpty(search)) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/master/Checkpoint.java
b/fe/fe-core/src/main/java/org/apache/doris/master/Checkpoint.java
index a73e14c59d9..245c643f4c0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/master/Checkpoint.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/master/Checkpoint.java
@@ -33,7 +33,6 @@ import org.apache.doris.common.Config;
import org.apache.doris.common.FeConstants;
import org.apache.doris.common.util.HttpURLUtil;
import org.apache.doris.common.util.MasterDaemon;
-import org.apache.doris.common.util.NetUtils;
import org.apache.doris.httpv2.entity.ResponseBody;
import org.apache.doris.httpv2.rest.RestApiStatusCode;
import org.apache.doris.metric.MetricRepo;
@@ -230,10 +229,10 @@ public class Checkpoint extends MasterDaemon {
// skip master itself
continue;
}
- int port = Config.http_port;
+ int port = HttpURLUtil.getHttpPort();
- String url = "http://" +
NetUtils.getHostPortInAccessibleFormat(host, port) + "/put?version=" +
replayedJournalId
- + "&port=" + port;
+ String queryParams = "version=" + replayedJournalId + "&port="
+ port;
+ String url = HttpURLUtil.buildInternalFeUrl(host, "/put",
queryParams);
LOG.info("Put image:{}", url);
try {
@@ -287,7 +286,6 @@ public class Checkpoint extends MasterDaemon {
// skip master itself
continue;
}
- int port = Config.http_port;
String idURL;
HttpURLConnection conn = null;
try {
@@ -297,7 +295,7 @@ public class Checkpoint extends MasterDaemon {
* any non-master node's current replayed journal
id. otherwise,
* this lagging node can never get the deleted
journal.
*/
- idURL = "http://" +
NetUtils.getHostPortInAccessibleFormat(host, port) + "/journal_id";
+ idURL = HttpURLUtil.buildInternalFeUrl(host,
"/journal_id", null);
conn =
HttpURLUtil.getConnectionWithNodeIdent(idURL);
conn.setConnectTimeout(CONNECT_TIMEOUT_SECOND *
1000);
conn.setReadTimeout(READ_TIMEOUT_SECOND * 1000);
@@ -307,6 +305,7 @@ public class Checkpoint extends MasterDaemon {
minOtherNodesJournalId = id;
}
} catch (Throwable e) {
+ int port = HttpURLUtil.getHttpPort();
throw new
CheckpointException(String.format("Exception when getting current replayed"
+ " journal id. host=%s, port=%d", host,
port), e);
} finally {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/master/MetaHelper.java
b/fe/fe-core/src/main/java/org/apache/doris/master/MetaHelper.java
index 553d2905649..73fceec8b39 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/master/MetaHelper.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/master/MetaHelper.java
@@ -151,7 +151,11 @@ public class MetaHelper {
Map<String, String> headers = HttpURLUtil.getNodeIdentHeaders();
LOG.info("meta helper, url: {}, timeout: {}, header names: {}", url,
timeout, headers.keySet());
String response = HttpUtils.doGet(url, headers, timeout);
- return parseResponse(response, clazz);
+ try {
+ return parseResponse(response, clazz);
+ } catch (Exception e) {
+ throw new IOException("Failed to parse response from " + url + ".
Response: " + response, e);
+ }
}
// download file from remote node
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/minidump/MinidumpUtils.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/minidump/MinidumpUtils.java
index a065a85e982..f3cef707907 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/minidump/MinidumpUtils.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/minidump/MinidumpUtils.java
@@ -28,6 +28,7 @@ import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.proc.FrontendsProcNode;
import org.apache.doris.common.util.DebugUtil;
+import org.apache.doris.common.util.HttpURLUtil;
import org.apache.doris.nereids.NereidsPlanner;
import org.apache.doris.nereids.StatementContext;
import org.apache.doris.nereids.glue.LogicalPlanAdapter;
@@ -104,9 +105,11 @@ public class MinidumpUtils {
public static void saveMinidumpString(JSONObject minidump, String querId) {
String dumpPath = MinidumpUtils.DUMP_PATH + File.separator + "_" +
querId;
String feAddress =
FrontendsProcNode.getCurrentFrontendVersion(Env.getCurrentEnv()).getHost();
- int feHttpPort = Config.http_port;
+ int feHttpPort = HttpURLUtil.getHttpPort();
+ String scheme = Config.enable_https ? "https" : "http";
MinidumpUtils.DUMP_FILE_FULL_PATH = dumpPath + ".json";
- MinidumpUtils.HTTP_GET_STRING = "http://" + feAddress + ":" +
feHttpPort + "/api/minidump?query_id=" + querId;
+ MinidumpUtils.HTTP_GET_STRING = scheme + "://" + feAddress + ":" +
feHttpPort
+ + "/api/minidump?query_id=" + querId;
String jsonMinidump = minidump.toString(4);
try (FileWriter file = new
FileWriter(MinidumpUtils.DUMP_FILE_FULL_PATH)) {
file.write(jsonMinidump);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/plugin/audit/AuditStreamLoader.java
b/fe/fe-core/src/main/java/org/apache/doris/plugin/audit/AuditStreamLoader.java
index f0a5e1979e2..ea8560a7653 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/plugin/audit/AuditStreamLoader.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/plugin/audit/AuditStreamLoader.java
@@ -21,8 +21,11 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.InternalSchema;
import org.apache.doris.common.Config;
import org.apache.doris.common.FeConstants;
+import org.apache.doris.common.util.HttpURLUtil;
+import org.apache.doris.common.util.InternalHttpsUtils;
import org.apache.doris.qe.GlobalVariable;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -37,24 +40,24 @@ import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream;
+import javax.net.ssl.HttpsURLConnection;
public class AuditStreamLoader {
private static final Logger LOG =
LogManager.getLogger(AuditStreamLoader.class);
- private static String loadUrlPattern = "http://%s/api/%s/%s/_stream_load?";
// timeout for both connection and read. 10 seconds is long enough.
private static final int HTTP_TIMEOUT_MS = 10000;
private static final String COMPRESS_TYPE = "gz";
- private String hostPort;
private String db;
private String auditLogTbl;
private String auditLogLoadUrlStr;
private String feIdentity;
public AuditStreamLoader() {
- this.hostPort = "127.0.0.1:" + Config.http_port;
this.db = FeConstants.INTERNAL_DB_NAME;
this.auditLogTbl = AuditLoader.AUDIT_LOG_TABLE;
- this.auditLogLoadUrlStr = String.format(loadUrlPattern, hostPort, db,
auditLogTbl);
+ String scheme = Config.enable_https ? "https" : "http";
+ String hostPort = "127.0.0.1:" + HttpURLUtil.getHttpPort();
+ this.auditLogLoadUrlStr = scheme + "://" + hostPort + "/api/" + db +
"/" + auditLogTbl + "/_stream_load?";
// currently, FE identity is FE's IP:port, so we replace the "." and
":" to make it suitable for label
this.feIdentity =
Env.getCurrentEnv().getSelfNode().getIdent().replaceAll("\\.",
"_").replaceAll(":", "_");
}
@@ -63,6 +66,11 @@ public class AuditStreamLoader {
String urlStr, String label, String clusterToken) throws
IOException {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ if (conn instanceof HttpsURLConnection && Config.enable_https) {
+ HttpsURLConnection httpsConn = (HttpsURLConnection) conn;
+
httpsConn.setSSLSocketFactory(InternalHttpsUtils.getSslContext().getSocketFactory());
+ httpsConn.setHostnameVerifier(NoopHostnameVerifier.INSTANCE);
+ }
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("PUT");
conn.setRequestProperty("token", clusterToken);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java
b/fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java
index 1f646622e68..7781ee952a3 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/system/HeartbeatMgr.java
@@ -27,6 +27,7 @@ import org.apache.doris.common.ThreadPoolManager;
import org.apache.doris.common.UserException;
import org.apache.doris.common.Version;
import org.apache.doris.common.util.DebugPointUtil;
+import org.apache.doris.common.util.HttpURLUtil;
import org.apache.doris.common.util.MasterDaemon;
import org.apache.doris.persist.HbPackage;
import org.apache.doris.resource.Tag;
@@ -99,7 +100,9 @@ public class HeartbeatMgr extends MasterDaemon {
TMasterInfo tMasterInfo = new TMasterInfo(
new TNetworkAddress(FrontendOptions.getLocalHostAddress(),
Config.rpc_port), clusterId, epoch);
tMasterInfo.setToken(token);
- tMasterInfo.setHttpPort(Config.http_port);
+ // small_file_mgr at BE downloads from FE using this port,
+ // by trying http then fallback to https(for http_port=0 cases).
+ tMasterInfo.setHttpPort(HttpURLUtil.getHttpPort());
long flags = heartbeatFlags.getHeartbeatFlags();
tMasterInfo.setHeartbeatFlags(flags);
if (Config.isCloudMode()) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/common/util/HttpURLUtilTest.java
b/fe/fe-core/src/test/java/org/apache/doris/common/util/HttpURLUtilTest.java
index a3f98e8f026..5d2099c5c61 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/common/util/HttpURLUtilTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/common/util/HttpURLUtilTest.java
@@ -90,4 +90,50 @@ public class HttpURLUtilTest {
Assert.assertEquals("cluster-token",
connection.getRequestProperty(MetaBaseAction.TOKEN));
}
}
+
+ @Test
+ public void testBuildInternalFeUrlHttp() {
+ Config.enable_https = false;
+ Config.http_port = 8030;
+
+ String url = HttpURLUtil.buildInternalFeUrl("192.168.1.10", "/put",
"version=123&port=8030");
+
Assert.assertEquals("http://192.168.1.10:8030/put?version=123&port=8030", url);
+ }
+
+ @Test
+ public void testBuildInternalFeUrlHttps() {
+ Config.enable_https = true;
+ Config.https_port = 8050;
+
+ String url = HttpURLUtil.buildInternalFeUrl("192.168.1.10", "/put",
"version=123&port=8050");
+
Assert.assertEquals("https://192.168.1.10:8050/put?version=123&port=8050", url);
+ }
+
+ @Test
+ public void testBuildInternalFeUrlNoQueryParams() {
+ Config.enable_https = false;
+ Config.http_port = 8030;
+
+ String url = HttpURLUtil.buildInternalFeUrl("192.168.1.10",
"/journal_id", null);
+ Assert.assertEquals("http://192.168.1.10:8030/journal_id", url);
+ }
+
+ @Test
+ public void testBuildInternalFeUrlEmptyQueryParams() {
+ Config.enable_https = false;
+ Config.http_port = 8030;
+
+ String url = HttpURLUtil.buildInternalFeUrl("192.168.1.10",
"/version", "");
+ Assert.assertEquals("http://192.168.1.10:8030/version", url);
+ }
+
+ @Test
+ public void testBuildInternalFeUrlHttpsWithIPv6() {
+ Config.enable_https = true;
+ Config.https_port = 8050;
+
+ String url = HttpURLUtil.buildInternalFeUrl("fe80::1", "/role",
"host=fe80::2&port=9010");
+ Assert.assertTrue(url.startsWith("https://"));
+ Assert.assertTrue(url.contains("/role?host=fe80::2&port=9010"));
+ }
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/common/util/InternalHttpsUtilsTest.java
b/fe/fe-core/src/test/java/org/apache/doris/common/util/InternalHttpsUtilsTest.java
new file mode 100644
index 00000000000..d082420d839
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/common/util/InternalHttpsUtilsTest.java
@@ -0,0 +1,65 @@
+// 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.
+
+package org.apache.doris.common.util;
+
+import org.apache.doris.common.Config;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+
+public class InternalHttpsUtilsTest {
+
+ private String originalKeyStorePath;
+
+ @Before
+ public void setUp() throws Exception {
+ originalKeyStorePath = Config.key_store_path;
+ // Reset the cached SSLContext before each test so tests are
independent.
+ resetCachedSslContext();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ Config.key_store_path = originalKeyStorePath;
+ resetCachedSslContext();
+ }
+
+ private void resetCachedSslContext() throws Exception {
+ Field field =
InternalHttpsUtils.class.getDeclaredField("cachedSslContext");
+ field.setAccessible(true);
+ field.set(null, null);
+ }
+
+ @Test
+ public void testGetSslContextThrowsWhenCertMissing() {
+ Config.key_store_path =
"/non/existent/path/doris_ssl_certificate.keystore";
+ try {
+ InternalHttpsUtils.getSslContext();
+ Assert.fail("Expected RuntimeException when cert file does not
exist");
+ } catch (RuntimeException e) {
+ // Error message must mention the cert path so operators know what
to fix.
+ Assert.assertTrue("Error message should contain cert path",
+ e.getMessage() != null
+ &&
e.getMessage().contains("/non/existent/path/doris_ssl_certificate.keystore"));
+ }
+ }
+}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/RestBaseControllerTest.java
b/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/RestBaseControllerTest.java
index b838e25ef50..a42a389c911 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/RestBaseControllerTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/RestBaseControllerTest.java
@@ -54,11 +54,30 @@ public class RestBaseControllerTest {
Assert.assertEquals("http://be-host:8040/api/db%2Ftbl/_stream_load",
redirectUrl);
}
+ @Test
+ public void
testBuildRedirectUrlToBackendForcesHttpEvenWhenRequestIsHttps() {
+ // BE never terminates TLS, so the redirect must stay "http"
regardless of request scheme.
+ HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(request.getScheme()).thenReturn("https");
+ Mockito.when(request.getHeader("Authorization")).thenReturn(null);
+
+ TestRestController controller = new TestRestController();
+ String redirectUrl =
controller.buildRedirectUrlToBackendForTest(request,
+ new TNetworkAddress("be-host", 8040),
"/api/db/tbl/_stream_load", "k=v");
+
+ Assert.assertEquals("http://be-host:8040/api/db/tbl/_stream_load?k=v",
redirectUrl);
+ }
+
// Expose the protected helper so the redirect URL can be verified
directly.
private static class TestRestController extends RestBaseController {
private String buildRedirectUrlForTest(HttpServletRequest request,
TNetworkAddress addr,
String requestPath, String queryString) {
return buildRedirectUrl(request, addr, requestPath, queryString);
}
+
+ private String buildRedirectUrlToBackendForTest(HttpServletRequest
request, TNetworkAddress addr,
+ String requestPath, String queryString) {
+ return buildRedirectUrlToBackend(request, addr, requestPath,
queryString);
+ }
}
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/manager/HttpUtilsTest.java
b/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/manager/HttpUtilsTest.java
new file mode 100644
index 00000000000..2efaf4ca7ba
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/manager/HttpUtilsTest.java
@@ -0,0 +1,94 @@
+// 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.
+
+package org.apache.doris.httpv2.rest.manager;
+
+import org.apache.doris.common.Config;
+import org.apache.doris.common.util.InternalHttpsUtils;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+public class HttpUtilsTest {
+
+ // Port 1 refuses connections on loopback, so no real HTTP(S) server is
needed.
+ private static final String REFUSED_PORT_URL_HTTP =
"http://127.0.0.1:1/ping";
+ private static final String REFUSED_PORT_URL_HTTPS =
"https://127.0.0.1:1/ping";
+
+ private boolean originalEnableHttps;
+ private String originalKeyStorePath;
+
+ @Before
+ public void setUp() throws Exception {
+ originalEnableHttps = Config.enable_https;
+ originalKeyStorePath = Config.key_store_path;
+ resetCachedSslContext();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ Config.enable_https = originalEnableHttps;
+ Config.key_store_path = originalKeyStorePath;
+ resetCachedSslContext();
+ }
+
+ private void resetCachedSslContext() throws Exception {
+ Field field =
InternalHttpsUtils.class.getDeclaredField("cachedSslContext");
+ field.setAccessible(true);
+ field.set(null, null);
+ }
+
+ @Test
+ public void
testExecuteRequestUsesPlainClientForHttpUrlEvenWhenHttpsEnabled() throws
Exception {
+ Config.enable_https = true;
+ Config.key_store_path =
"/non/existent/path/doris_ssl_certificate.keystore";
+ resetCachedSslContext();
+
+ try {
+ HttpUtils.doGet(REFUSED_PORT_URL_HTTP, null);
+ Assert.fail("Expected a connection failure against the refused
port");
+ } catch (RuntimeException e) {
+ Assert.fail("Should not have attempted to build the HTTPS client
for an http:// URL: "
+ + e.getMessage());
+ } catch (IOException expected) {
+ // Plain client hit the network and failed there, never touching
the broken keystore.
+ }
+ }
+
+ @Test
+ public void testExecuteRequestUsesHttpsClientForHttpsUrl() throws
Exception {
+ Config.enable_https = true;
+ Config.key_store_path =
"/non/existent/path/doris_ssl_certificate.keystore";
+ resetCachedSslContext();
+
+ try {
+ HttpUtils.doGet(REFUSED_PORT_URL_HTTPS, null);
+ Assert.fail("Expected SSLContext build failure before any
connection attempt");
+ } catch (RuntimeException e) {
+ Assert.assertTrue("Failure should come from the missing keystore,
not an unrelated error",
+ e.getMessage() != null &&
e.getMessage().contains("doris_ssl_certificate.keystore"));
+ } catch (IOException e) {
+ Assert.fail("Expected the HTTPS client's keystore failure, not a
network-level error: "
+ + e.getMessage());
+ }
+ }
+}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/minidump/MinidumpUtTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/minidump/MinidumpUtTest.java
index 5ed150b1e36..40aa9d0b7ce 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/minidump/MinidumpUtTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/minidump/MinidumpUtTest.java
@@ -17,12 +17,18 @@
package org.apache.doris.nereids.minidump;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.Config;
+import org.apache.doris.common.proc.FrontendsProcNode;
import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.system.Frontend;
import org.json.JSONObject;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
/**
* Used for add unit test of minidump
@@ -50,4 +56,41 @@ class MinidumpUtTest {
JSONObject resultPlan = MinidumpUtils.executeSql("select 1");
Assertions.assertNotNull(resultPlan);
}
+
+ @Test
+ public void testSaveMinidumpStringUsesHttpsWhenEnabled() {
+ Frontend fe = Mockito.mock(Frontend.class);
+ Mockito.when(fe.getHost()).thenReturn("192.168.1.1");
+ Env mockEnv = Mockito.mock(Env.class);
+
+ boolean originalEnableHttps = Config.enable_https;
+ int originalHttpPort = Config.http_port;
+ int originalHttpsPort = Config.https_port;
+ try (MockedStatic<Env> envStatic = Mockito.mockStatic(Env.class);
+ MockedStatic<FrontendsProcNode> procStatic =
Mockito.mockStatic(FrontendsProcNode.class)) {
+ envStatic.when(Env::getCurrentEnv).thenReturn(mockEnv);
+ procStatic.when(() ->
FrontendsProcNode.getCurrentFrontendVersion(mockEnv)).thenReturn(fe);
+
+ // enable_https=true: URL must use https scheme and https_port
+ Config.enable_https = true;
+ Config.https_port = 8050;
+ Config.http_port = 0;
+ MinidumpUtils.saveMinidumpString(new JSONObject(), "query-001");
+ String url = MinidumpUtils.getHttpGetString();
+ Assertions.assertTrue(url.startsWith("https://"), "Expected https
scheme but got: " + url);
+ Assertions.assertTrue(url.contains(":8050/"), "Expected https_port
8050 but got: " + url);
+
+ // enable_https=false: URL must use http scheme and http_port
+ Config.enable_https = false;
+ Config.http_port = 8030;
+ MinidumpUtils.saveMinidumpString(new JSONObject(), "query-002");
+ url = MinidumpUtils.getHttpGetString();
+ Assertions.assertTrue(url.startsWith("http://"), "Expected http
scheme but got: " + url);
+ Assertions.assertTrue(url.contains(":8030/"), "Expected http_port
8030 but got: " + url);
+ } finally {
+ Config.enable_https = originalEnableHttps;
+ Config.http_port = originalHttpPort;
+ Config.https_port = originalHttpsPort;
+ }
+ }
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/system/HeartbeatMgrTest.java
b/fe/fe-core/src/test/java/org/apache/doris/system/HeartbeatMgrTest.java
index 0ce265c083b..62f1452a0e5 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/system/HeartbeatMgrTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/system/HeartbeatMgrTest.java
@@ -35,6 +35,7 @@ import org.apache.doris.thrift.TBrokerPingBrokerRequest;
import org.apache.doris.thrift.TFrontendPingFrontendRequest;
import org.apache.doris.thrift.TFrontendPingFrontendResult;
import org.apache.doris.thrift.TFrontendPingFrontendStatusCode;
+import org.apache.doris.thrift.TMasterInfo;
import org.apache.doris.thrift.TNetworkAddress;
import org.apache.doris.thrift.TPaloBrokerService;
@@ -49,8 +50,10 @@ import org.junit.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.atomic.AtomicReference;
public class HeartbeatMgrTest {
@@ -245,4 +248,35 @@ public class HeartbeatMgrTest {
}
}
+ @Test
+ public void testSetMasterHttpPort() throws Exception {
+ int originalHttpPort = Config.http_port;
+ int originalHttpsPort = Config.https_port;
+ boolean originalEnableHttps = Config.enable_https;
+
+ try {
+ HeartbeatMgr mgr = new HeartbeatMgr(null, false);
+ Field masterInfoField =
HeartbeatMgr.class.getDeclaredField("masterInfo");
+ masterInfoField.setAccessible(true);
+
+ // enable_https=false: must send http_port to BEs
+ Config.enable_https = false;
+ Config.http_port = 8030;
+ Config.https_port = 8050;
+ mgr.setMaster(1, "token", 1L);
+ AtomicReference<TMasterInfo> masterInfo =
+ (AtomicReference<TMasterInfo>) masterInfoField.get(null);
+ Assert.assertEquals(8030, masterInfo.get().getHttpPort());
+
+ // enable_https=true: must send https_port to BEs so
small_file_mgr can connect
+ Config.enable_https = true;
+ mgr.setMaster(1, "token", 1L);
+ masterInfo = (AtomicReference<TMasterInfo>)
masterInfoField.get(null);
+ Assert.assertEquals(8050, masterInfo.get().getHttpPort());
+ } finally {
+ Config.http_port = originalHttpPort;
+ Config.https_port = originalHttpsPort;
+ Config.enable_https = originalEnableHttps;
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]