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 4011f69162e branch-4.2: [fix](load) Remove deprecated auth_code
handling #70446 (#71091)
4011f69162e is described below
commit 4011f69162e1f8a081519ce6de208a345e365f2e
Author: Xin Liao <[email protected]>
AuthorDate: Tue Dec 1 08:33:29 2026 +0800
branch-4.2: [fix](load) Remove deprecated auth_code handling #70446 (#71091)
Pick apache/doris#70446
---
be/src/common/utils.h | 12 +-
be/src/load/group_commit/group_commit_mgr.cpp | 6 +-
be/src/load/group_commit/wal/wal_table.cpp | 6 +-
.../routine_load/routine_load_task_executor.cpp | 2 -
be/src/service/http/action/http_stream.cpp | 3 +-
be/src/service/http/http_common.h | 1 -
be/src/service/http/utils.cpp | 13 +-
.../runtime/routine_load_task_executor_test.cpp | 56 ++++++
be/test/service/http/http_utils_test.cpp | 46 +++--
be/test/service/http/stream_load_test.cpp | 35 ++++
.../org/apache/doris/load/StreamLoadHandler.java | 12 +-
.../doris/load/routineload/KafkaTaskInfo.java | 3 +-
.../doris/load/routineload/RoutineLoadJob.java | 8 -
.../apache/doris/service/FrontendServiceImpl.java | 39 ++--
.../apache/doris/load/StreamLoadHandlerTest.java | 17 +-
.../doris/service/FrontendServiceImplTest.java | 210 ++++++++++++++-------
.../test_dml_stream_load_be_auth_docker.groovy | 14 +-
17 files changed, 304 insertions(+), 179 deletions(-)
diff --git a/be/src/common/utils.h b/be/src/common/utils.h
index e0e1b1ad9dd..b5470cc7548 100644
--- a/be/src/common/utils.h
+++ b/be/src/common/utils.h
@@ -41,8 +41,6 @@ struct AuthInfo {
std::string passwd;
std::string cluster;
std::string user_ip;
- // -1 as unset
- int64_t auth_code = -1; // deprecated
std::string token;
std::string cert_pem;
@@ -59,14 +57,8 @@ struct AuthInfo {
template <class T>
void set_request_auth(T* req, const AuthInfo& auth) {
req->user = auth.user; // always set user, because it may be used by FE
- // auth code is deprecated and should be removed in 3.1
- if (auth.auth_code != -1) {
- // if auth_code is set, no need to set other info
- req->__set_auth_code(auth.auth_code);
- // user name and passwd is unused, but they are required field.
- // so they have to be set.
- req->passwd = "";
- } else if (auth.token != "") {
+ // Internal loads, including Routine Load and WAL replay, use the FE token.
+ if (!auth.token.empty()) {
req->__isset.token = true;
req->token = auth.token;
} else {
diff --git a/be/src/load/group_commit/group_commit_mgr.cpp
b/be/src/load/group_commit/group_commit_mgr.cpp
index 57b42ce4c08..b51f9b6a0bb 100644
--- a/be/src/load/group_commit/group_commit_mgr.cpp
+++ b/be/src/load/group_commit/group_commit_mgr.cpp
@@ -494,7 +494,7 @@ Status GroupCommitTable::_create_group_commit_load(
request.__set_load_sql(ss.str());
request.__set_loadId(tload_id);
request.__set_label(label);
- request.__set_token("group_commit"); // this is a fake, fe not check
it now
+ request.__set_token(_exec_env->cluster_info()->curr_auth_token);
request.__set_max_filter_ratio(1.0);
request.__set_strictMode(false);
request.__set_partial_update(false);
@@ -608,8 +608,6 @@ Status GroupCommitTable::_finish_group_commit_load(int64_t
db_id, int64_t table_
});
// commit txn
TLoadTxnCommitRequest request;
- // deprecated and should be removed in 3.1, use token instead
- request.__set_auth_code(0);
request.__set_token(_exec_env->cluster_info()->curr_auth_token);
request.__set_db_id(db_id);
request.__set_table_id(table_id);
@@ -661,8 +659,6 @@ Status GroupCommitTable::_finish_group_commit_load(int64_t
db_id, int64_t table_
} else {
// abort txn
TLoadTxnRollbackRequest request;
- // deprecated and should be removed in 3.1, use token instead
- request.__set_auth_code(0);
request.__set_token(_exec_env->cluster_info()->curr_auth_token);
request.__set_db_id(db_id);
request.__set_txnId(txn_id);
diff --git a/be/src/load/group_commit/wal/wal_table.cpp
b/be/src/load/group_commit/wal/wal_table.cpp
index 24a6c9b28fe..a6a3a7fbf8e 100644
--- a/be/src/load/group_commit/wal/wal_table.cpp
+++ b/be/src/load/group_commit/wal/wal_table.cpp
@@ -22,6 +22,7 @@
#include "io/fs/local_file_system.h"
#include "io/fs/stream_load_pipe.h"
+#include "load/group_commit/wal/wal_file_reader.h"
#include "load/group_commit/wal/wal_manager.h"
#include "runtime/fragment_mgr.h"
#include "service/http/action/http_stream.h"
@@ -179,9 +180,6 @@ bool WalTable::_need_replay(std::shared_ptr<WalInfo>
wal_info) {
Status WalTable::_try_abort_txn(int64_t db_id, std::string& label) {
TLoadTxnRollbackRequest request;
- // this is a fake, fe not check it now
- // should be removed in 3.1, use token instead
- request.__set_auth_code(0);
request.__set_token(_exec_env->cluster_info()->curr_auth_token);
request.__set_db_id(db_id);
request.__set_label(label);
@@ -276,8 +274,6 @@ Status WalTable::_handle_stream_load(int64_t wal_id, const
std::string& wal,
// wait stream load finish
RETURN_IF_ERROR(ctx->load_status_future.get());
if (ctx->status.ok()) {
- // deprecated and should be removed in 3.1, use token instead.
- ctx->auth.auth_code = wal_id;
st = _exec_env->stream_load_executor()->commit_txn(ctx.get());
} else {
st = ctx->status;
diff --git a/be/src/load/routine_load/routine_load_task_executor.cpp
b/be/src/load/routine_load/routine_load_task_executor.cpp
index 8364de65e03..19246183771 100644
--- a/be/src/load/routine_load/routine_load_task_executor.cpp
+++ b/be/src/load/routine_load/routine_load_task_executor.cpp
@@ -247,8 +247,6 @@ Status RoutineLoadTaskExecutor::submit_task(const
TRoutineLoadTask& task) {
ctx->db = task.db;
ctx->table = task.tbl;
ctx->label = task.label;
- // deprecated, removed in 3.1, use auth token instead.
- ctx->auth.auth_code = task.auth_code;
ctx->auth.token = _exec_env->cluster_info()->curr_auth_token;
if (task.__isset.max_interval_s) {
diff --git a/be/src/service/http/action/http_stream.cpp
b/be/src/service/http/action/http_stream.cpp
index ae005e37cdd..bf4d9ba06f4 100644
--- a/be/src/service/http/action/http_stream.cpp
+++ b/be/src/service/http/action/http_stream.cpp
@@ -356,9 +356,8 @@ Status HttpStreamAction::process_put(HttpRequest* http_req,
request.__set_memtable_on_sink_node(value);
}
} else {
- request.__set_token(ctx->auth.token);
request.__set_load_sql(ctx->sql_str);
- ctx->auth.token = "";
+ // WAL replay reuses this context for commit or rollback, so keep its
token.
}
set_request_auth(&request, ctx->auth);
request.__set_loadId(ctx->id.to_thrift());
diff --git a/be/src/service/http/http_common.h
b/be/src/service/http/http_common.h
index f250e22a278..a51149ded40 100644
--- a/be/src/service/http/http_common.h
+++ b/be/src/service/http/http_common.h
@@ -68,7 +68,6 @@ static const std::string HTTP_TXN_OPERATION_KEY =
"txn_operation";
static const std::string HTTP_MEMTABLE_ON_SINKNODE = "memtable_on_sink_node";
static const std::string HTTP_LOAD_STREAM_PER_NODE = "load_stream_per_node";
static const std::string HTTP_WAL_ID_KY = "wal_id";
-static const std::string HTTP_AUTH_CODE = "auth_code"; // deprecated
static const std::string HTTP_GROUP_COMMIT = "group_commit";
static const std::string HTTP_CLOUD_CLUSTER = "cloud_cluster";
static const std::string HTTP_EMPTY_FIELD_AS_NULL = "empty_field_as_null";
diff --git a/be/src/service/http/utils.cpp b/be/src/service/http/utils.cpp
index 8f49505981c..e4adec5c73d 100644
--- a/be/src/service/http/utils.cpp
+++ b/be/src/service/http/utils.cpp
@@ -43,6 +43,7 @@
#include "service/http/http_method.h"
#include "service/http/http_request.h"
#include "service/http/http_status.h"
+#include "util/debug_points.h"
#include "util/md5.h"
#include "util/path_util.h"
#include "util/security.h"
@@ -89,8 +90,6 @@ bool parse_basic_auth(const HttpRequest& req, std::string*
user, std::string* pa
bool parse_basic_auth(const HttpRequest& req, AuthInfo* auth) {
// deprecated, removed in 3.1, use AUTH_TOKEN
const auto& token = req.header("token");
- // deprecated, removed in 3.1, use AUTH_TOKEN
- const auto& auth_code = req.header(HTTP_AUTH_CODE);
const auto& auth_token = req.header(HttpHeaders::AUTH_TOKEN);
std::tuple<std::string, std::string, std::string> tmp;
@@ -111,16 +110,6 @@ bool parse_basic_auth(const HttpRequest& req, AuthInfo*
auth) {
auth->token = token; // deprecated
} else if (!auth_token.empty()) {
auth->token = auth_token;
- } else if (!auth_code.empty()) {
- // auth_code comes straight from a request header, a malformed one is
just an
- // invalid credential and must not throw out of the http callback. The
value is a
- // credential that is_sensitive_header() masks elsewhere, so it is not
logged.
- auto parsed_auth_code = safe_stoll(auth_code, HTTP_AUTH_CODE);
- if (!parsed_auth_code.has_value()) {
- LOG(WARNING) << "parse auth code failed, malformed " <<
HTTP_AUTH_CODE << " header";
- return false;
- }
- auth->auth_code = parsed_auth_code.value(); // deprecated
} else if (!valid_basic_auth) {
return false;
}
diff --git a/be/test/runtime/routine_load_task_executor_test.cpp
b/be/test/runtime/routine_load_task_executor_test.cpp
index c50a010c01e..50027397675 100644
--- a/be/test/runtime/routine_load_task_executor_test.cpp
+++ b/be/test/runtime/routine_load_task_executor_test.cpp
@@ -26,14 +26,19 @@
#include <librdkafka/rdkafkacpp.h>
#include <unistd.h>
+#include <future>
#include <map>
#include "common/config.h"
#include "common/status.h"
+#include "common/utils.h"
#include "gtest/gtest_pred_impl.h"
#include "load/stream_load/new_load_stream_mgr.h"
+#include "load/stream_load/stream_load_context.h"
#include "load/stream_load/stream_load_executor.h"
#include "runtime/exec_env.h"
+#include "util/defer_op.h"
+#include "util/threadpool.h"
namespace doris {
@@ -73,6 +78,57 @@ public:
}
};
+TEST_F(RoutineLoadTaskExecutorTest, LegacyTaskUsesHeartbeatToken) {
+ const auto original_pool_size = config::max_routine_load_thread_pool_size;
+ config::max_routine_load_thread_pool_size = 1;
+ Defer restore_config {[&] { config::max_routine_load_thread_pool_size =
original_pool_size; }};
+ _env->cluster_info()->curr_auth_token = "routine-load-token";
+ RoutineLoadTaskExecutor executor(_env);
+ ASSERT_TRUE(executor.init(1024 * 1024).ok());
+
+ // Hold the worker so the submitted task can be inspected before execution.
+ std::promise<void> started;
+ std::promise<void> resume;
+ auto resumed = resume.get_future();
+ Defer stop_executor {[&] {
+ resume.set_value();
+ executor.stop();
+ }};
+ ASSERT_TRUE(executor.get_thread_pool()
+ .submit_func([&] {
+ started.set_value();
+ resumed.wait();
+ })
+ .ok());
+ started.get_future().wait();
+
+ TRoutineLoadTask task;
+ task.type = TLoadSourceType::KAFKA;
+ task.__set_auth_code(12345); // Required field sent by older FEs.
+ task.__set_id(TUniqueId());
+ task.__set_txn_id(4);
+ task.__set_db("db1");
+ task.__set_tbl("tbl1");
+ ASSERT_TRUE(executor.submit_task(task).ok());
+ std::lock_guard<std::mutex> lock(executor._lock);
+ auto ctx = executor._task_map.at(UniqueId(task.id));
+ TStreamLoadPutRequest plan;
+ set_request_auth(&plan, ctx->auth);
+ TLoadTxnCommitRequest commit;
+ _env->stream_load_executor()->get_commit_request(ctx.get(), commit);
+ TLoadTxnRollbackRequest rollback;
+ set_request_auth(&rollback, ctx->auth);
+ EXPECT_EQ("routine-load-token", plan.token);
+ EXPECT_EQ(plan.token, commit.token);
+ EXPECT_EQ(plan.token, rollback.token);
+ EXPECT_TRUE(plan.__isset.token);
+ EXPECT_TRUE(commit.__isset.token);
+ EXPECT_TRUE(rollback.__isset.token);
+ EXPECT_FALSE(plan.__isset.auth_code);
+ EXPECT_FALSE(commit.__isset.auth_code);
+ EXPECT_FALSE(rollback.__isset.auth_code);
+}
+
TEST_F(RoutineLoadTaskExecutorTest, exec_task) {
TRoutineLoadTask task;
task.type = TLoadSourceType::KAFKA;
diff --git a/be/test/service/http/http_utils_test.cpp
b/be/test/service/http/http_utils_test.cpp
index 9f7942043a4..5d579876026 100644
--- a/be/test/service/http/http_utils_test.cpp
+++ b/be/test/service/http/http_utils_test.cpp
@@ -16,6 +16,7 @@
// under the License.
#include <event2/http.h>
+#include <gen_cpp/FrontendService_types.h>
#include <gtest/gtest-message.h>
#include <gtest/gtest-test-part.h>
@@ -23,11 +24,9 @@
#include "common/utils.h"
#include "gtest/gtest_pred_impl.h"
-#include "service/http/http_common.h"
#include "service/http/http_headers.h"
#include "service/http/http_request.h"
#include "service/http/utils.h"
-#include "util/string_util.h"
#include "util/url_coding.h"
struct evhttp_request;
@@ -46,6 +45,16 @@ public:
}
private:
+ template <typename Request>
+ void check_token_request(const AuthInfo& auth) {
+ Request request;
+ set_request_auth(&request, auth);
+ EXPECT_TRUE(request.__isset.token);
+ EXPECT_EQ("internal-token", request.token);
+ EXPECT_EQ("admin", request.user);
+ EXPECT_FALSE(request.__isset.auth_code);
+ }
+
evhttp_request* _evhttp_req = nullptr;
};
@@ -98,23 +107,36 @@ TEST_F(HttpUtilsTest, parse_basic_auth) {
}
}
-TEST_F(HttpUtilsTest, parse_auth_code) {
- {
+TEST_F(HttpUtilsTest, deprecated_auth_code_does_not_replace_credentials) {
+ for (const auto* value : {"0", "1234567890123", "-1", "not_a_number"}) {
HttpRequest req(_evhttp_req);
+ req._headers.emplace("auth_code", value);
+ AuthInfo missing_auth;
+ EXPECT_FALSE(parse_basic_auth(req, &missing_auth));
+
req._headers.emplace(HttpHeaders::AUTHORIZATION,
encode_basic_auth("doris", "passwd"));
- req._headers.emplace(HTTP_AUTH_CODE, "1234567890123");
AuthInfo auth;
EXPECT_TRUE(parse_basic_auth(req, &auth));
- EXPECT_EQ(1234567890123, auth.auth_code);
+ TLoadTxnBeginRequest request;
+ set_request_auth(&request, auth);
+ EXPECT_EQ("doris", request.user);
+ EXPECT_EQ("passwd", request.passwd);
+ EXPECT_FALSE(request.__isset.auth_code);
+ EXPECT_FALSE(request.__isset.token);
}
- {
- // a malformed auth code is rejected instead of throwing out of the
http callback
+}
+
+TEST_F(HttpUtilsTest, internal_token_is_forwarded_with_user) {
+ for (const auto& header : {std::string("token"), HttpHeaders::AUTH_TOKEN})
{
HttpRequest req(_evhttp_req);
- req._headers.emplace(HttpHeaders::AUTHORIZATION,
encode_basic_auth("doris", "passwd"));
- req._headers.emplace(HTTP_AUTH_CODE, "not_a_number");
+ req._headers.emplace(header, "internal-token");
+ req._headers.emplace("auth_code", "0");
+ req._headers.emplace(HttpHeaders::AUTHORIZATION,
encode_basic_auth("admin", "unused"));
AuthInfo auth;
- EXPECT_FALSE(parse_basic_auth(req, &auth));
- EXPECT_EQ(-1, auth.auth_code);
+ ASSERT_TRUE(parse_basic_auth(req, &auth));
+ check_token_request<TStreamLoadPutRequest>(auth);
+ check_token_request<TLoadTxnCommitRequest>(auth);
+ check_token_request<TLoadTxnRollbackRequest>(auth);
}
}
diff --git a/be/test/service/http/stream_load_test.cpp
b/be/test/service/http/stream_load_test.cpp
index 1405092f401..763923cb645 100644
--- a/be/test/service/http/stream_load_test.cpp
+++ b/be/test/service/http/stream_load_test.cpp
@@ -22,6 +22,7 @@
#include <memory>
#include "common/config.h"
+#include "common/utils.h"
#include "event2/buffer.h"
#include "event2/event.h"
#include "event2/http.h"
@@ -29,6 +30,8 @@
#include "evhttp.h"
#include "load/group_commit/wal/wal_manager.h"
#include "load/stream_load/stream_load_context.h"
+#include "load/stream_load/stream_load_executor.h"
+#include "runtime/cluster_info.h"
#include "runtime/exec_env.h"
#include "service/http/action/http_stream.h"
#include "service/http/ev_http_server.h"
@@ -55,6 +58,38 @@ void http_request_done_cb(struct evhttp_request* req, void*
arg) {
event_base_loopbreak((struct event_base*)arg);
}
+TEST_F(StreamLoadTest, WalPlanningFailurePreservesTokenForRetryAndRollback) {
+ auto* env = ExecEnv::GetInstance();
+ auto* original_cluster_info = env->cluster_info();
+ ClusterInfo cluster_info;
+ env->set_cluster_info(&cluster_info);
+ Defer restore_cluster_info {[&] {
env->set_cluster_info(original_cluster_info); }};
+ auto ctx = std::make_shared<StreamLoadContext>(env);
+ ctx->auth.user = "admin";
+ ctx->auth.token = "internal-wal-token";
+ ctx->sql_str = "insert into wal_replay select * from http_stream()";
+ HttpStreamAction action(env);
+
+ // No FE address: planning fails after constructing the request, before
any RPC.
+ EXPECT_FALSE(action.process_put(nullptr, ctx).ok());
+ EXPECT_EQ("internal-wal-token", ctx->auth.token);
+ EXPECT_FALSE(action.process_put(nullptr, ctx).ok());
+ EXPECT_EQ("internal-wal-token", ctx->auth.token);
+
+ TLoadTxnCommitRequest commit;
+ StreamLoadExecutor executor(env);
+ executor.get_commit_request(ctx.get(), commit);
+ EXPECT_TRUE(commit.__isset.token);
+ EXPECT_EQ("internal-wal-token", commit.token);
+ EXPECT_FALSE(commit.__isset.auth_code);
+
+ TLoadTxnRollbackRequest rollback;
+ set_request_auth(&rollback, ctx->auth);
+ EXPECT_TRUE(rollback.__isset.token);
+ EXPECT_EQ(commit.token, rollback.token);
+ EXPECT_FALSE(rollback.__isset.auth_code);
+}
+
TEST_F(StreamLoadTest, TestHeader) {
// 1G
auto wal_mgr = WalManager::create_unique(ExecEnv::GetInstance(),
config::group_commit_wal_path);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/load/StreamLoadHandler.java
b/fe/fe-core/src/main/java/org/apache/doris/load/StreamLoadHandler.java
index 7dfa5a1c1ab..84fd30a1eb7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/load/StreamLoadHandler.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/load/StreamLoadHandler.java
@@ -79,20 +79,18 @@ public class StreamLoadHandler {
private Boolean isMultiTableRequest;
private AtomicInteger multiTableFragmentInstanceIdIndex;
private TStreamLoadPutResult result;
- private String clientAddr;
private Database db;
private List<OlapTable> tables = Lists.newArrayList();
private long timeoutMs;
private List fragmentParams = Lists.newArrayList();
public StreamLoadHandler(TStreamLoadPutRequest request, AtomicInteger
indexId,
- TStreamLoadPutResult result, String clientAddr) {
+ TStreamLoadPutResult result) {
this.request = request;
this.timeoutMs = request.isSetThriftRpcTimeoutMs() ?
request.getThriftRpcTimeoutMs() : 5000;
this.isMultiTableRequest = indexId != null;
this.multiTableFragmentInstanceIdIndex = indexId;
this.result = result;
- this.clientAddr = clientAddr;
}
/**
@@ -139,9 +137,9 @@ public class StreamLoadHandler {
return;
}
- ctx.setRemoteIP(request.isSetAuthCode() ? clientAddr :
request.getUserIp());
+ ctx.setRemoteIP(request.getUserIp());
String userName =
ClusterNamespace.getNameFromFullName(request.getUser());
- if (!request.isSetToken() && !request.isSetAuthCode() &&
!Strings.isNullOrEmpty(userName)) {
+ if (!request.isSetToken() && !Strings.isNullOrEmpty(userName)) {
ctx.setCurrentUserIdentity(resolveCloudLoadUserIdentity(userName));
}
if (request.isSetBackendId()) {
@@ -151,9 +149,9 @@ public class StreamLoadHandler {
throw new UserException("Backend " + backendId + " does not
exist");
}
String computeGroup = backend.getCloudClusterName();
- // Token/auth-code and user-less internal loads keep their
existing trusted path. Regular
+ // Token and user-less internal loads keep their existing trusted
path. Regular
// stream loads must still validate compute group privilege,
existence, and status.
- if (request.isSetToken() || request.isSetAuthCode() ||
Strings.isNullOrEmpty(userName)) {
+ if (request.isSetToken() || Strings.isNullOrEmpty(userName)) {
ctx.setCloudCluster(computeGroup);
} else {
((CloudEnv)
Env.getCurrentEnv()).changeCloudCluster(computeGroup, ctx);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/load/routineload/KafkaTaskInfo.java
b/fe/fe-core/src/main/java/org/apache/doris/load/routineload/KafkaTaskInfo.java
index 375f96c5e98..8311ba2f446 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/load/routineload/KafkaTaskInfo.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/load/routineload/KafkaTaskInfo.java
@@ -101,7 +101,8 @@ public class KafkaTaskInfo extends RoutineLoadTaskInfo {
String label = Joiner.on("-").join(routineLoadJob.getName(),
routineLoadJob.getId(), DebugUtil.printId(id), txnId);
tRoutineLoadTask.setLabel(label);
- tRoutineLoadTask.setAuthCode(routineLoadJob.getAuthCode());
+ // Required by older BE task readers; new BEs use the heartbeat token.
+ tRoutineLoadTask.setAuthCode(0);
TKafkaLoadInfo tKafkaLoadInfo = new TKafkaLoadInfo();
tKafkaLoadInfo.setTopic(routineLoadJob.getTopic());
tKafkaLoadInfo.setBrokers(routineLoadJob.getBrokerList());
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/load/routineload/RoutineLoadJob.java
b/fe/fe-core/src/main/java/org/apache/doris/load/routineload/RoutineLoadJob.java
index c0f98aa2960..62a47433429 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/load/routineload/RoutineLoadJob.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/load/routineload/RoutineLoadJob.java
@@ -178,8 +178,6 @@ public abstract class RoutineLoadJob
protected long dbId;
@SerializedName("tbid")
protected long tableId;
- // this code is used to verify be task request
- protected long authCode;
// protected RoutineLoadDesc routineLoadDesc; // optional
protected PartitionNames partitions; // optional
protected ImportColumnDescs columnDescs; // optional
@@ -313,7 +311,6 @@ public abstract class RoutineLoadJob
this.name = name;
this.dbId = dbId;
this.tableId = tableId;
- this.authCode = 0;
this.userIdentity = userIdentity;
if (ConnectContext.get() != null) {
@@ -341,7 +338,6 @@ public abstract class RoutineLoadJob
this(id, dataSourceType);
this.name = name;
this.dbId = dbId;
- this.authCode = 0;
this.userIdentity = userIdentity;
this.isMultiTable = true;
@@ -565,10 +561,6 @@ public abstract class RoutineLoadJob
return state;
}
- public long getAuthCode() {
- return authCode;
- }
-
public long getEndTimestamp() {
return endTimestamp;
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
index 34f9eafe8ae..8d8f6c003fe 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
@@ -1468,9 +1468,7 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
}
private TLoadTxnBeginResult loadTxnBeginImpl(TLoadTxnBeginRequest request,
String clientIp) throws UserException {
- if (request.isSetAuthCode()) {
- // TODO: deprecated, removed in 3.1, use token instead.
- } else if (Strings.isNullOrEmpty(request.getToken())) {
+ if (Strings.isNullOrEmpty(request.getToken())) {
checkSingleTablePasswordAndPrivs(request.getUser(),
request.getPasswd(), request.getDb(),
request.getTbl(), request.getUserIp(), PrivPredicate.LOAD,
toForwardedCertificateInfo(request.getCertBasedAuth()));
@@ -1739,9 +1737,7 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
}
private void loadTxnPreCommitImpl(TLoadTxnCommitRequest request) throws
UserException {
- if (request.isSetAuthCode()) {
- // TODO: deprecated, removed in 3.1, use token instead.
- } else if (request.isSetToken()) {
+ if (request.isSetToken()) {
if (!checkToken(request.getToken())) {
throw new AuthenticationException("Invalid token");
}
@@ -1929,9 +1925,7 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
// return true if commit success and publish success, return false if
publish
// timeout
private boolean loadTxnCommitImpl(TLoadTxnCommitRequest request) throws
UserException {
- if (request.isSetAuthCode()) {
- // TODO: deprecated, removed in 3.1, use token instead.
- } else if (request.isSetToken()) {
+ if (request.isSetToken()) {
checkTokenOrThrow(request.getToken());
} else {
if (CollectionUtils.isNotEmpty(request.getTbls())) {
@@ -2068,9 +2062,7 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
List<Table> tableList =
db.getTablesOnIdOrderOrThrowException(tableIdList);
// Step 3: check auth
- if (request.isSetAuthCode()) {
- // TODO: deprecated, removed in 3.1, use token instead.
- } else if (request.isSetToken()) {
+ if (request.isSetToken()) {
checkTokenOrThrow(request.getToken());
} else {
List<String> tables =
tableList.stream().map(Table::getName).collect(Collectors.toList());
@@ -2154,9 +2146,7 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
}
private void loadTxnRollbackImpl(TLoadTxnRollbackRequest request) throws
UserException {
- if (request.isSetAuthCode()) {
- // TODO: deprecated, removed in 3.1, use token instead.
- } else if (request.isSetToken()) {
+ if (request.isSetToken()) {
checkTokenOrThrow(request.getToken());
} else {
// multi table load
@@ -2273,9 +2263,7 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
List<Table> tableList =
db.getTablesOnIdOrderOrThrowException(tableIdList);
// Step 3: check auth
- if (request.isSetAuthCode()) {
- // TODO: deprecated, removed in 3.1, use token instead.
- } else if (request.isSetToken()) {
+ if (request.isSetToken()) {
checkTokenOrThrow(request.getToken());
} else {
List<String> tables =
tableList.stream().map(Table::getName).collect(Collectors.toList());
@@ -2308,9 +2296,7 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
return;
}
- if (request.isSetAuthCode()) {
- // TODO: deprecated, removed in 3.1, use token instead.
- } else if (Strings.isNullOrEmpty(request.getToken())) {
+ if (Strings.isNullOrEmpty(request.getToken())) {
checkSingleTablePasswordAndPrivs(request.getUser(),
request.getPasswd(), request.getDb(),
request.getTbl(), request.getUserIp(), PrivPredicate.LOAD,
toForwardedCertificateInfo(request.getCertBasedAuth()));
@@ -2392,7 +2378,7 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
TStatus status = new TStatus(TStatusCode.OK);
result.setStatus(status);
- StreamLoadHandler streamLoadHandler = new StreamLoadHandler(request,
null, result, clientAddr);
+ StreamLoadHandler streamLoadHandler = new StreamLoadHandler(request,
null, result);
try {
checkGroupCommitStreamLoadAuth(request);
@@ -2464,8 +2450,7 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
List planFragmentParamsList = new ArrayList<>();
multiTableFragmentInstanceIdIndexMap.putIfAbsent(request.getTxnId(),
new AtomicInteger(1));
AtomicInteger index =
multiTableFragmentInstanceIdIndexMap.get(request.getTxnId());
- StreamLoadHandler streamLoadHandler = new StreamLoadHandler(request,
index, null,
-
getClientAddrAsString());
+ StreamLoadHandler streamLoadHandler = new StreamLoadHandler(request,
index, null);
try {
streamLoadHandler.generatePlan();
planFragmentParamsList.addAll(streamLoadHandler.getFragmentParams());
@@ -2543,12 +2528,12 @@ public class FrontendServiceImpl implements
FrontendService.Iface {
ConnectContext ctx = ConnectContext.get();
- if (request.isSetAuthCode()) {
- // TODO: deprecated, removed in 3.1, use token instead.
- } else if (Strings.isNullOrEmpty(request.getToken())) {
+ if (Strings.isNullOrEmpty(request.getToken())) {
checkSingleTablePasswordAndPrivs(request.getUser(),
request.getPasswd(), request.getDb(),
request.getTbl(),
request.getUserIp(), PrivPredicate.LOAD);
+ } else {
+ checkTokenOrThrow(request.getToken());
}
if (request.isSetMemtableOnSinkNode()) {
ctx.getSessionVariable().enableMemtableOnSinkNode =
request.isMemtableOnSinkNode();
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/load/StreamLoadHandlerTest.java
b/fe/fe-core/src/test/java/org/apache/doris/load/StreamLoadHandlerTest.java
index 438b89bf9a5..d806cc143c0 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/load/StreamLoadHandlerTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/load/StreamLoadHandlerTest.java
@@ -92,7 +92,7 @@ public class StreamLoadHandlerTest {
ConnectContext.remove();
StreamLoadHandler handler = new StreamLoadHandler(
- request, null, new TStreamLoadPutResult(), "127.0.0.1");
+ request, null, new TStreamLoadPutResult());
handler.setCloudCluster();
Assert.assertEquals("backend_compute_group",
@@ -164,6 +164,7 @@ public class StreamLoadHandlerTest {
request.setPasswd("test_password");
request.setBackendId(backend.getId());
request.setCloudCluster("header_compute_group");
+ request.setAuthCode(0);
request.setGroupCommitMode("sync_mode");
try (MockedStatic<Env> mockedEnv = Mockito.mockStatic(Env.class)) {
@@ -173,7 +174,7 @@ public class StreamLoadHandlerTest {
ConnectContext.remove();
StreamLoadHandler handler = new StreamLoadHandler(
- request, null, new TStreamLoadPutResult(), "127.0.0.1");
+ request, null, new TStreamLoadPutResult());
try {
handler.setCloudCluster();
Assert.fail("group commit should validate compute group
privilege");
@@ -196,7 +197,7 @@ public class StreamLoadHandlerTest {
TStreamLoadPutRequest request = new TStreamLoadPutRequest();
request.setBackendId(20L);
StreamLoadHandler handler = new StreamLoadHandler(
- request, null, new TStreamLoadPutResult(), "127.0.0.1");
+ request, null, new TStreamLoadPutResult());
TPipelineFragmentParams params =
buildStreamLoadParams(createSingleBucketSink());
handler.assignAdaptiveRandomBucket(params);
@@ -214,7 +215,7 @@ public class StreamLoadHandlerTest {
TStreamLoadPutRequest request = new TStreamLoadPutRequest();
request.setBackendId(10L);
StreamLoadHandler handler = new StreamLoadHandler(
- request, null, new TStreamLoadPutResult(), "127.0.0.1");
+ request, null, new TStreamLoadPutResult());
TPipelineFragmentParams params =
buildStreamLoadParams(createSingleBucketSink());
handler.assignAdaptiveRandomBucket(params);
@@ -232,7 +233,7 @@ public class StreamLoadHandlerTest {
request.setDb("test_db");
request.setTbl("test_tbl");
StreamLoadHandler handler = new StreamLoadHandler(
- request, null, new TStreamLoadPutResult(), "127.0.0.1");
+ request, null, new TStreamLoadPutResult());
TPipelineFragmentParams params =
buildStreamLoadParams(createSingleBucketSink());
handler.assignAdaptiveRandomBucket(params);
@@ -251,7 +252,7 @@ public class StreamLoadHandlerTest {
TStreamLoadPutRequest request = new TStreamLoadPutRequest();
request.setBackendId(20L);
StreamLoadHandler handler = new StreamLoadHandler(
- request, null, new TStreamLoadPutResult(), "127.0.0.1");
+ request, null, new TStreamLoadPutResult());
TOlapTableSink sink = createSingleBucketSink();
sink.getPartition().getPartitions().get(0).unsetLoadTabletIdx();
@@ -268,7 +269,7 @@ public class StreamLoadHandlerTest {
TStreamLoadPutRequest request = new TStreamLoadPutRequest();
request.setBackendId(20L);
StreamLoadHandler handler = new StreamLoadHandler(
- request, null, new TStreamLoadPutResult(), "127.0.0.1");
+ request, null, new TStreamLoadPutResult());
TOlapTableSink sink = createSingleBucketSink();
sink.getPartition().setPartitionsIsFake(true);
@@ -285,7 +286,7 @@ public class StreamLoadHandlerTest {
TStreamLoadPutRequest request = new TStreamLoadPutRequest();
request.setBackendId(20L);
StreamLoadHandler handler = new StreamLoadHandler(
- request, null, new TStreamLoadPutResult(), "127.0.0.1");
+ request, null, new TStreamLoadPutResult());
TPipelineFragmentParams params = new TPipelineFragmentParams();
TPlanFragment fragment = new TPlanFragment();
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java
b/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java
index 1f844252a76..1da679b919d 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java
@@ -60,6 +60,7 @@ import org.apache.doris.thrift.TGetTablesResult;
import org.apache.doris.thrift.TGetTabletReplicaInfosRequest;
import org.apache.doris.thrift.TGetTabletReplicaInfosResult;
import org.apache.doris.thrift.TListTableStatusResult;
+import org.apache.doris.thrift.TLoadTxnBeginRequest;
import org.apache.doris.thrift.TLoadTxnCommitRequest;
import org.apache.doris.thrift.TLoadTxnRollbackRequest;
import org.apache.doris.thrift.TMaxComputeBlockIdRequest;
@@ -94,7 +95,6 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.jupiter.api.Assertions;
import org.junit.rules.ExpectedException;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
@@ -591,16 +591,16 @@ public class FrontendServiceImplTest {
InsertOverwriteUtil.addTempPartitions(table,
Collections.singletonList(table.getName()),
Collections.singletonList("replace_snapshot_temp"));
Partition tempPartition = table.getPartition("replace_snapshot_temp",
true);
- Assertions.assertNotNull(tempPartition);
-
Assertions.assertNull(table.getPartitionInfo().getItem(tempPartition.getId()));
+ Assert.assertNotNull(tempPartition);
+
Assert.assertNull(table.getPartitionInfo().getItem(tempPartition.getId()));
TOlapTablePartition result = snapshotReplacePartition(table,
tempPartition.getId());
- Assertions.assertEquals(tempPartition.getId(), result.getId());
- Assertions.assertEquals(1, result.getIndexesSize());
- Assertions.assertEquals(1, result.getNumBuckets());
- Assertions.assertFalse(result.isSetStartKeys());
- Assertions.assertFalse(result.isSetEndKeys());
- Assertions.assertFalse(result.isSetInKeys());
+ Assert.assertEquals(tempPartition.getId(), result.getId());
+ Assert.assertEquals(1, result.getIndexesSize());
+ Assert.assertEquals(1, result.getNumBuckets());
+ Assert.assertFalse(result.isSetStartKeys());
+ Assert.assertFalse(result.isSetEndKeys());
+ Assert.assertFalse(result.isSetInKeys());
}
@Test
@@ -617,14 +617,14 @@ public class FrontendServiceImplTest {
InsertOverwriteUtil.addTempPartitions(table,
Collections.singletonList("p1"),
Collections.singletonList("replace_snapshot_temp"));
Partition tempPartition =
table.getPartition("replace_snapshot_temp", true);
- Assertions.assertNotNull(tempPartition);
-
Assertions.assertNotNull(table.getPartitionInfo().getItem(tempPartition.getId()));
+ Assert.assertNotNull(tempPartition);
+
Assert.assertNotNull(table.getPartitionInfo().getItem(tempPartition.getId()));
TOlapTablePartition result = snapshotReplacePartition(table,
tempPartition.getId());
- Assertions.assertEquals(tempPartition.getId(), result.getId());
+ Assert.assertEquals(tempPartition.getId(), result.getId());
if (partitionType.equals("RANGE")) {
- Assertions.assertEquals(10,
result.getEndKeys().get(0).getIntLiteral().getValue());
+ Assert.assertEquals(10,
result.getEndKeys().get(0).getIntLiteral().getValue());
} else {
- Assertions.assertEquals(1,
result.getInKeys().get(0).get(0).getIntLiteral().getValue());
+ Assert.assertEquals(1,
result.getInKeys().get(0).get(0).getIntLiteral().getValue());
}
// Model a missing item without removing the temporary Partition
object.
@@ -636,10 +636,11 @@ public class FrontendServiceImplTest {
table.writeUnlock();
}
try {
- InvocationTargetException exception =
Assertions.assertThrows(InvocationTargetException.class,
+ InvocationTargetException exception =
Assert.assertThrows(InvocationTargetException.class,
() -> snapshotReplacePartition(table,
tempPartition.getId()));
- UserException cause =
Assertions.assertInstanceOf(UserException.class, exception.getCause());
- Assertions.assertEquals("partition item of " +
tempPartition.getId()
+ Assert.assertTrue(exception.getCause() instanceof
UserException);
+ UserException cause = (UserException) exception.getCause();
+ Assert.assertEquals("partition item of " +
tempPartition.getId()
+ " was dropped concurrently while building replace
partition result, please retry",
cause.getDetailMessage());
} finally {
@@ -661,7 +662,7 @@ public class FrontendServiceImplTest {
try {
List<?> snapshots = (List<?>) method.invoke(null, table,
Collections.singletonList(partitionId),
false, false, "replace partition");
- Assertions.assertEquals(1, snapshots.size());
+ Assert.assertEquals(1, snapshots.size());
Field field =
snapshots.get(0).getClass().getDeclaredField("tPartition");
field.setAccessible(true);
return (TOlapTablePartition) field.get(snapshots.get(0));
@@ -785,12 +786,12 @@ public class FrontendServiceImplTest {
TShowUserRequest adminRequest = new TShowUserRequest();
adminRequest.setCurrentUserIdent(UserIdentity.ROOT.toThrift());
List<List<String>> adminRows =
impl.showUser(adminRequest).getUserinfoList();
- Assertions.assertTrue(adminRows.size() >= 2, "admin should see all
accounts");
- Assertions.assertTrue(adminRows.stream().anyMatch(r ->
"show_user_a".equals(r.get(userNameIdx))));
- Assertions.assertTrue(adminRows.stream().anyMatch(r ->
"show_user_b".equals(r.get(userNameIdx))));
+ Assert.assertTrue("admin should see all accounts", adminRows.size() >=
2);
+ Assert.assertTrue(adminRows.stream().anyMatch(r ->
"show_user_a".equals(r.get(userNameIdx))));
+ Assert.assertTrue(adminRows.stream().anyMatch(r ->
"show_user_b".equals(r.get(userNameIdx))));
for (List<String> row : adminRows) {
- Assertions.assertEquals("***", row.get(authStringIdx));
- Assertions.assertEquals("***", row.get(historyPwIdx));
+ Assert.assertEquals("***", row.get(authStringIdx));
+ Assert.assertEquals("***", row.get(historyPwIdx));
}
// A non-privileged user only sees their own row, with the password
columns masked, so
@@ -799,10 +800,10 @@ public class FrontendServiceImplTest {
userRequest.setCurrentUserIdent(
UserIdentity.createAnalyzedUserIdentWithIp("show_user_a",
"%").toThrift());
List<List<String>> userRows =
impl.showUser(userRequest).getUserinfoList();
- Assertions.assertEquals(1, userRows.size());
- Assertions.assertEquals("show_user_a",
userRows.get(0).get(userNameIdx));
- Assertions.assertEquals("***", userRows.get(0).get(authStringIdx));
- Assertions.assertEquals("***", userRows.get(0).get(historyPwIdx));
+ Assert.assertEquals(1, userRows.size());
+ Assert.assertEquals("show_user_a", userRows.get(0).get(userNameIdx));
+ Assert.assertEquals("***", userRows.get(0).get(authStringIdx));
+ Assert.assertEquals("***", userRows.get(0).get(historyPwIdx));
// Same name, different host are distinct accounts: a non-privileged
caller must see only
// its exact user@host row, not the same-named account bound to
another host.
@@ -812,13 +813,13 @@ public class FrontendServiceImplTest {
dupRequest.setCurrentUserIdent(
UserIdentity.createAnalyzedUserIdentWithIp("dup_host_user",
"192.168.0.1").toThrift());
List<List<String>> dupRows =
impl.showUser(dupRequest).getUserinfoList();
- Assertions.assertEquals(1, dupRows.size());
- Assertions.assertEquals("dup_host_user",
dupRows.get(0).get(userNameIdx));
- Assertions.assertEquals("192.168.0.1", dupRows.get(0).get(0));
+ Assert.assertEquals(1, dupRows.size());
+ Assert.assertEquals("dup_host_user", dupRows.get(0).get(userNameIdx));
+ Assert.assertEquals("192.168.0.1", dupRows.get(0).get(0));
// Fail closed: a request without a caller identity (e.g. a
pre-upgrade BE that does not
// set the field) exposes no rows rather than leaking every account.
- Assertions.assertTrue(impl.showUser(new
TShowUserRequest()).getUserinfoList().isEmpty());
+ Assert.assertTrue(impl.showUser(new
TShowUserRequest()).getUserinfoList().isEmpty());
}
@Test
@@ -1048,61 +1049,122 @@ public class FrontendServiceImplTest {
}
@Test
- public void testLoadTxnCommitRejectsInvalidToken() {
+ public void testLoadPlanningAndPreCommitRejectInvalidToken() {
+ for (boolean legacyAuthCode : new boolean[] {false, true}) {
+ FrontendServiceImpl impl = Mockito.spy(new
FrontendServiceImpl(exeEnv));
+ Mockito.doReturn(false).when(impl).checkToken("bad-token");
+ TLoadTxnBeginRequest begin = new
TLoadTxnBeginRequest().setToken("bad-token");
+ TLoadTxnCommitRequest preCommit = new
TLoadTxnCommitRequest().setToken("bad-token");
+ TStreamLoadPutRequest plan = new
TStreamLoadPutRequest().setToken("bad-token");
+ if (legacyAuthCode) {
+ begin.setAuthCode(0);
+ preCommit.setAuthCode(0);
+ plan.setAuthCode(0);
+ }
+ assertInvalidToken(impl, "loadTxnBeginImpl", begin, "127.0.0.1");
+ assertInvalidToken(impl, "loadTxnPreCommitImpl", preCommit);
+ assertInvalidToken(impl, "httpStreamPutImpl", plan, new
TStreamLoadPutResult());
+ }
+ }
+
+ @Test
+ public void testLegacyAuthCodeStillRequiresPassword() throws TException {
+ FrontendServiceImpl impl = new FrontendServiceImpl(exeEnv);
+ TLoadTxnBeginRequest request = new TLoadTxnBeginRequest()
+
.setUser("root").setPasswd("wrong_password").setUserIp("127.0.0.1")
+
.setDb("test").setTbl("missing_table").setLabel("legacy_auth_code").setAuthCode(0);
+
Assert.assertTrue(impl.loadTxnBegin(request).getStatus().getErrorMsgs().get(0)
+ .contains("Access denied"));
+ }
+
+ @Test
+ public void testInternalTokenWithLegacyAuthCodePassesAuthentication()
throws TException {
FrontendServiceImpl impl = Mockito.spy(new
FrontendServiceImpl(exeEnv));
- TLoadTxnCommitRequest request = new TLoadTxnCommitRequest();
- request.setToken("bad-token");
- Mockito.doReturn(false).when(impl).checkToken("bad-token");
+ Mockito.doReturn(true).when(impl).checkToken("internal-token");
+ TLoadTxnBeginRequest request = new TLoadTxnBeginRequest()
+ .setToken("internal-token").setAuthCode(0);
+ // An empty label is rejected only after successful authentication.
+
Assert.assertTrue(impl.loadTxnBegin(request).getStatus().getErrorMsgs().get(0)
+ .contains("empty label"));
+ Mockito.verify(impl).checkToken("internal-token");
+ }
- assertInvalidToken(impl, "loadTxnCommitImpl", request);
+ @Test
+ public void testLoadTxnCommitRejectsInvalidToken() {
+ for (boolean legacyAuthCode : new boolean[] {false, true}) {
+ FrontendServiceImpl impl = Mockito.spy(new
FrontendServiceImpl(exeEnv));
+ TLoadTxnCommitRequest request = new TLoadTxnCommitRequest();
+ if (legacyAuthCode) {
+ request.setAuthCode(0);
+ }
+ request.setToken("bad-token");
+ Mockito.doReturn(false).when(impl).checkToken("bad-token");
+
+ assertInvalidToken(impl, "loadTxnCommitImpl", request);
+ }
}
@Test
public void testLoadTxnRollbackRejectsInvalidToken() {
- FrontendServiceImpl impl = Mockito.spy(new
FrontendServiceImpl(exeEnv));
- TLoadTxnRollbackRequest request = new TLoadTxnRollbackRequest();
- request.setToken("bad-token");
- Mockito.doReturn(false).when(impl).checkToken("bad-token");
+ for (boolean legacyAuthCode : new boolean[] {false, true}) {
+ FrontendServiceImpl impl = Mockito.spy(new
FrontendServiceImpl(exeEnv));
+ TLoadTxnRollbackRequest request = new TLoadTxnRollbackRequest();
+ if (legacyAuthCode) {
+ request.setAuthCode(0);
+ }
+ request.setToken("bad-token");
+ Mockito.doReturn(false).when(impl).checkToken("bad-token");
- assertInvalidToken(impl, "loadTxnRollbackImpl", request);
+ assertInvalidToken(impl, "loadTxnRollbackImpl", request);
+ }
}
@Test
public void testCommitTxnRejectsInvalidToken() {
- FrontendServiceImpl impl = Mockito.spy(new
FrontendServiceImpl(exeEnv));
- TCommitTxnRequest request = new TCommitTxnRequest();
- request.setUser("root");
- request.setPasswd("");
- request.setDb("test");
- request.setTxnId(100L);
- request.setCommitInfos(Collections.emptyList());
- request.setToken("bad-token");
- Mockito.doReturn(false).when(impl).checkToken("bad-token");
-
- mockTransactionForTokenValidation(100L);
- try {
- assertInvalidToken(impl, "commitTxnImpl", request);
- } finally {
- closeTransactionValidationMock();
+ for (boolean legacyAuthCode : new boolean[] {false, true}) {
+ FrontendServiceImpl impl = Mockito.spy(new
FrontendServiceImpl(exeEnv));
+ TCommitTxnRequest request = new TCommitTxnRequest();
+ request.setUser("root");
+ request.setPasswd("");
+ request.setDb("test");
+ request.setTxnId(100L);
+ request.setCommitInfos(Collections.emptyList());
+ if (legacyAuthCode) {
+ request.setAuthCode(0);
+ }
+ request.setToken("bad-token");
+ Mockito.doReturn(false).when(impl).checkToken("bad-token");
+
+ mockTransactionForTokenValidation(100L);
+ try {
+ assertInvalidToken(impl, "commitTxnImpl", request);
+ } finally {
+ closeTransactionValidationMock();
+ }
}
}
@Test
public void testRollbackTxnRejectsInvalidToken() {
- FrontendServiceImpl impl = Mockito.spy(new
FrontendServiceImpl(exeEnv));
- TRollbackTxnRequest request = new TRollbackTxnRequest();
- request.setUser("root");
- request.setPasswd("");
- request.setDb("test");
- request.setTxnId(100L);
- request.setToken("bad-token");
- Mockito.doReturn(false).when(impl).checkToken("bad-token");
+ for (boolean legacyAuthCode : new boolean[] {false, true}) {
+ FrontendServiceImpl impl = Mockito.spy(new
FrontendServiceImpl(exeEnv));
+ TRollbackTxnRequest request = new TRollbackTxnRequest();
+ request.setUser("root");
+ request.setPasswd("");
+ request.setDb("test");
+ request.setTxnId(100L);
+ if (legacyAuthCode) {
+ request.setAuthCode(0);
+ }
+ request.setToken("bad-token");
+ Mockito.doReturn(false).when(impl).checkToken("bad-token");
- mockTransactionForTokenValidation(100L);
- try {
- assertInvalidToken(impl, "rollbackTxnImpl", request);
- } finally {
- closeTransactionValidationMock();
+ mockTransactionForTokenValidation(100L);
+ try {
+ assertInvalidToken(impl, "rollbackTxnImpl", request);
+ } finally {
+ closeTransactionValidationMock();
+ }
}
}
@@ -1158,7 +1220,8 @@ public class FrontendServiceImplTest {
.setTbl(table)
.setUserIp("127.0.0.1")
.setLoadId(new TUniqueId(1L, 1L))
- .setGroupCommitMode("async_mode");
+ .setGroupCommitMode("async_mode")
+ .setAuthCode(0);
}
private MockedStatic<Env> transactionValidationEnvMock;
@@ -1194,11 +1257,12 @@ public class FrontendServiceImplTest {
}
}
- private void assertInvalidToken(FrontendServiceImpl impl, String
methodName, Object request) {
+ private void assertInvalidToken(FrontendServiceImpl impl, String
methodName, Object... args) {
try {
- Method method =
FrontendServiceImpl.class.getDeclaredMethod(methodName, request.getClass());
+ Class<?>[] types =
Arrays.stream(args).map(Object::getClass).toArray(Class<?>[]::new);
+ Method method =
FrontendServiceImpl.class.getDeclaredMethod(methodName, types);
method.setAccessible(true);
- method.invoke(impl, request);
+ method.invoke(impl, args);
Assert.fail("expected invalid token");
} catch (InvocationTargetException e) {
Assert.assertTrue(e.getCause() instanceof AuthenticationException);
diff --git
a/regression-test/suites/auth_call/test_dml_stream_load_be_auth_docker.groovy
b/regression-test/suites/auth_call/test_dml_stream_load_be_auth_docker.groovy
index 10d0388ea0c..d1e04b4da1b 100644
---
a/regression-test/suites/auth_call/test_dml_stream_load_be_auth_docker.groovy
+++
b/regression-test/suites/auth_call/test_dml_stream_load_be_auth_docker.groovy
@@ -96,6 +96,7 @@ suite("test_dml_stream_load_be_auth_off_docker",
"docker,auth_call") {
"-u", "${authUser}:${pwd}",
"-H", "txn_id:${txnId}",
"-H", "txn_operation:${txnOperation}",
+ "-H", "auth_code:0",
"http://${beHttpAddress}/api/${dbName}/${table}/_stream_load_2pc"
]
logger.info("stream load 2pc target: ${beHttpAddress}, table:
${table}, "
@@ -150,16 +151,16 @@ suite("test_dml_stream_load_be_auth_off_docker",
"docker,auth_call") {
"""
assertLoadFailed(streamLoad(tableUser, beHttpAddress, tableName,
"off_denied_before_grant",
- false, []))
+ false, ["auth_code:0"]))
sql """GRANT LOAD_PRIV ON ${dbName}.${tableName} TO ${tableUser}"""
assertLoadSuccess(streamLoad(tableUser, beHttpAddress, tableName,
"off_table_grant_be",
- false, []))
+ false, ["auth_code:0"]))
assertLoadSuccess(streamLoad(tableUser, feHttpAddress, tableName,
"off_table_grant_fe",
true, []))
def prepared = assertLoadSuccess(streamLoad(tableUser,
beHttpAddress, tableName,
- "off_table_grant_2pc", false, ["two_phase_commit:true"]))
+ "off_table_grant_2pc", false, ["two_phase_commit:true",
"auth_code:0"]))
def committed = streamLoad2pc(tableUser, tableName,
prepared.TxnId, "commit")
assertEquals(200, committed[0])
assertEquals("Success", parseJson(committed[1]).status)
@@ -242,6 +243,7 @@ suite("test_dml_stream_load_be_auth_on_docker",
"docker,auth_call") {
"-u", "${authUser}:${pwd}",
"-H", "txn_id:${txnId}",
"-H", "txn_operation:${txnOperation}",
+ "-H", "auth_code:0",
"http://${beHttpAddress}/api/${dbName}/${table}/_stream_load_2pc"
]
logger.info("stream load 2pc target: ${beHttpAddress}, table:
${table}, "
@@ -296,16 +298,16 @@ suite("test_dml_stream_load_be_auth_on_docker",
"docker,auth_call") {
"""
assertLoadFailed(streamLoad(tableUser, beHttpAddress, tableName,
"on_denied_before_grant",
- false, []))
+ false, ["auth_code:0"]))
sql """GRANT LOAD_PRIV ON ${dbName}.${tableName} TO ${tableUser}"""
assertLoadSuccess(streamLoad(tableUser, beHttpAddress, tableName,
"on_table_grant_be",
- false, []))
+ false, ["auth_code:0"]))
assertLoadSuccess(streamLoad(tableUser, feHttpAddress, tableName,
"on_table_grant_fe",
true, []))
def prepared = assertLoadSuccess(streamLoad(tableUser,
beHttpAddress, tableName,
- "on_table_grant_2pc", false, ["two_phase_commit:true"]))
+ "on_table_grant_2pc", false, ["two_phase_commit:true",
"auth_code:0"]))
def committed = streamLoad2pc(tableUser, tableName,
prepared.TxnId, "commit")
assertEquals(200, committed[0])
assertEquals("Success", parseJson(committed[1]).status)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]