Skip to content

Commit 8ce7d72

Browse files
authored
fix: make clients use always send auth info (#3906)
* fix: make clients use auth by default * fix: let skip auth flag only affect verify
1 parent 1632b3a commit 8ce7d72

6 files changed

Lines changed: 23 additions & 31 deletions

File tree

src/auth/brpc_authenticator.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "auth_utils.h"
2020
#include "butil/endpoint.h"
21+
#include "nameserver/system_table.h"
2122

2223
namespace openmldb::authn {
2324

@@ -37,6 +38,9 @@ int BRPCAuthenticator::GenerateCredential(std::string* auth_str) const {
3738

3839
int BRPCAuthenticator::VerifyCredential(const std::string& auth_str, const butil::EndPoint& client_addr,
3940
brpc::AuthContext* out_ctx) const {
41+
if (FLAGS_skip_grant_tables) {
42+
return 0;
43+
}
4044
if (auth_str.length() < 2) {
4145
return -1;
4246
}

src/cmd/openmldb.cc

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,12 @@ void StartNameServer() {
149149
brpc::ServerOptions options;
150150
std::unique_ptr<openmldb::auth::UserAccessManager> user_access_manager;
151151
std::unique_ptr<openmldb::authn::BRPCAuthenticator> server_authenticator;
152-
if (!FLAGS_skip_grant_tables) {
153-
user_access_manager =
154-
std::make_unique<openmldb::auth::UserAccessManager>(name_server->GetSystemTableIterator());
155-
server_authenticator = std::make_unique<openmldb::authn::BRPCAuthenticator>(
156-
[&user_access_manager](const std::string& host, const std::string& username, const std::string& password) {
157-
return user_access_manager->IsAuthenticated(host, username, password);
158-
});
159-
options.auth = server_authenticator.get();
160-
}
152+
user_access_manager = std::make_unique<openmldb::auth::UserAccessManager>(name_server->GetSystemTableIterator());
153+
server_authenticator = std::make_unique<openmldb::authn::BRPCAuthenticator>(
154+
[&user_access_manager](const std::string& host, const std::string& username, const std::string& password) {
155+
return user_access_manager->IsAuthenticated(host, username, password);
156+
});
157+
options.auth = server_authenticator.get();
161158

162159
options.num_threads = FLAGS_thread_pool_size;
163160
brpc::Server server;
@@ -259,14 +256,12 @@ void StartTablet() {
259256
std::unique_ptr<openmldb::auth::UserAccessManager> user_access_manager;
260257
std::unique_ptr<openmldb::authn::BRPCAuthenticator> server_authenticator;
261258

262-
if (!FLAGS_skip_grant_tables) {
263-
user_access_manager = std::make_unique<openmldb::auth::UserAccessManager>(tablet->GetSystemTableIterator());
264-
server_authenticator = std::make_unique<openmldb::authn::BRPCAuthenticator>(
265-
[&user_access_manager](const std::string& host, const std::string& username, const std::string& password) {
266-
return user_access_manager->IsAuthenticated(host, username, password);
267-
});
268-
options.auth = server_authenticator.get();
269-
}
259+
user_access_manager = std::make_unique<openmldb::auth::UserAccessManager>(tablet->GetSystemTableIterator());
260+
server_authenticator = std::make_unique<openmldb::authn::BRPCAuthenticator>(
261+
[&user_access_manager](const std::string& host, const std::string& username, const std::string& password) {
262+
return user_access_manager->IsAuthenticated(host, username, password);
263+
});
264+
options.auth = server_authenticator.get();
270265
options.num_threads = FLAGS_thread_pool_size;
271266
brpc::Server server;
272267
if (server.AddService(tablet, brpc::SERVER_DOESNT_OWN_SERVICE) != 0) {

src/nameserver/name_server_impl.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,12 +1520,10 @@ bool NameServerImpl::Init(const std::string& zk_cluster, const std::string& zk_p
15201520
task_vec_.resize(FLAGS_name_server_task_max_concurrency + FLAGS_name_server_task_concurrency_for_replica_cluster);
15211521
task_thread_pool_.DelayTask(FLAGS_make_snapshot_check_interval,
15221522
boost::bind(&NameServerImpl::SchedMakeSnapshot, this));
1523-
if (!FLAGS_skip_grant_tables) {
1524-
std::shared_ptr<::openmldb::nameserver::TableInfo> table_info;
1525-
while (
1526-
!GetTableInfo(::openmldb::nameserver::USER_INFO_NAME, ::openmldb::nameserver::INTERNAL_DB, &table_info)) {
1527-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
1528-
}
1523+
std::shared_ptr<::openmldb::nameserver::TableInfo> table_info;
1524+
while (
1525+
!GetTableInfo(::openmldb::nameserver::USER_INFO_NAME, ::openmldb::nameserver::INTERNAL_DB, &table_info)) {
1526+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
15291527
}
15301528
return true;
15311529
}
@@ -5593,7 +5591,7 @@ void NameServerImpl::OnLocked() {
55935591
PDLOG(WARNING, "recover failed");
55945592
}
55955593
CreateDatabaseOrExit(INTERNAL_DB);
5596-
if (!FLAGS_skip_grant_tables && db_table_info_[INTERNAL_DB].count(USER_INFO_NAME) == 0) {
5594+
if (db_table_info_[INTERNAL_DB].count(USER_INFO_NAME) == 0) {
55975595
auto temp = FLAGS_system_table_replica_num;
55985596
FLAGS_system_table_replica_num = tablets_.size();
55995597
CreateSystemTableOrExit(SystemTableType::kUser);

src/rpc/rpc_client.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ class RpcClient {
104104
if (use_sleep_policy_) {
105105
options.retry_policy = &sleep_retry_policy;
106106
}
107-
if (!FLAGS_skip_grant_tables) {
108-
options.auth = &client_authenticator_;
109-
}
107+
options.auth = &client_authenticator_;
110108

111109
if (channel_->Init(endpoint_.c_str(), "", &options) != 0) {
112110
return -1;

src/sdk/mini_cluster.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ class StandaloneEnv {
365365
});
366366
brpc::ServerOptions options;
367367
options.auth = ns_authenticator_;
368-
options.auth = ns_authenticator_;
369368
if (ns_.AddService(nameserver, brpc::SERVER_OWNS_SERVICE) != 0) {
370369
LOG(WARNING) << "fail to add ns";
371370
return false;

src/tablet/file_sender.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ bool FileSender::Init() {
6464
}
6565
channel_ = new brpc::Channel();
6666
brpc::ChannelOptions options;
67-
if (!FLAGS_skip_grant_tables) {
68-
options.auth = &client_authenticator_;
69-
}
67+
options.auth = &client_authenticator_;
7068
options.timeout_ms = FLAGS_request_timeout_ms;
7169
options.connect_timeout_ms = FLAGS_request_timeout_ms;
7270
options.max_retry = FLAGS_request_max_retry;

0 commit comments

Comments
 (0)