Skip to content

Commit 71ab745

Browse files
committed
Feat[MQB]: Add authn plugin config and controller (#740)
Signed-off-by: Emelia Lei <[email protected]>
1 parent f175d40 commit 71ab745

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5055
-252
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
-DBDE_BUILD_TARGET_CPP17=ON \
6565
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/deps/srcs/bde-tools/BdeBuildSystem \
6666
-DCMAKE_INSTALL_LIBDIR=lib64
67-
cmake --build build/blazingmq --parallel 8 --target bmqbrkr bmqtool bmqstoragetool all.it
67+
cmake --build build/blazingmq --parallel 8 --target bmqbrkr bmqtool bmqstoragetool all.it bmqauthnpass bmqauthnfail
6868
6969
- name: Clean-up build directories before caching
7070
run: |

CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ if (NOT DEFINED INSTALL_TARGETS)
123123
set(BMQ_TARGET_E_BMQBRKR_NEEDED YES)
124124
set(BMQ_TARGET_TUTORIAL_NEEDED YES)
125125
set(BMQ_TARGET_PROMETHEUS_NEEDED NO)
126+
set(BMQ_TARGET_AUTHNPASS_NEEDED YES)
127+
set(BMQ_TARGET_AUTHNFAIL_NEEDED YES)
126128
else()
127129
bbproject_check_install_target("bmqbrkr" installBMQBRKR)
128130
bbproject_check_install_target("BMQBRKR_NIGHTLY" installNightly)
@@ -144,13 +146,17 @@ else()
144146
set(BMQ_TARGET_MQB_NEEDED NO)
145147
set(BMQ_TARGET_TUTORIAL_NEEDED NO)
146148
set(BMQ_TARGET_PROMETHEUS_NEEDED NO)
149+
set(BMQ_TARGET_AUTHNPASS_NEEDED NO)
150+
set(BMQ_TARGET_AUTHNFAIL_NEEDED NO)
147151

148152
bbproject_check_install_target("bmq" installBMQ)
149153
bbproject_check_install_target("mqb" installMQB)
150154
bbproject_check_install_target("bmqbrkrcfg" installBMQBRKRCFG)
151155
bbproject_check_install_target("bmqtool" installBMQTOOL)
152156
bbproject_check_install_target("bmqstoragetool" installBMQSTORAGETOOL)
153157
bbproject_check_install_target("prometheus" installPROMETHEUS)
158+
bbproject_check_install_target("authnpass" installAUTHNPASS)
159+
bbproject_check_install_target("authnfail" installAUTHNFAIL)
154160

155161
if (installBMQ)
156162
set(BMQ_TARGET_BMQ_NEEDED YES)
@@ -189,6 +195,18 @@ else()
189195
set(BMQ_TARGET_MQB_NEEDED YES)
190196
set(BMQ_TARGET_PROMETHEUS_NEEDED YES)
191197
endif()
198+
199+
if (installAUTHNPASS)
200+
set(BMQ_TARGET_BMQ_NEEDED YES)
201+
set(BMQ_TARGET_MQB_NEEDED YES)
202+
set(BMQ_TARGET_AUTHNPASS_NEEDED YES)
203+
endif()
204+
205+
if (installAUTHNFAIL)
206+
set(BMQ_TARGET_BMQ_NEEDED YES)
207+
set(BMQ_TARGET_MQB_NEEDED YES)
208+
set(BMQ_TARGET_AUTHNFAIL_NEEDED YES)
209+
endif()
192210
endif()
193211

194212
find_package(Git)
@@ -305,7 +323,7 @@ add_subdirectory( "src/integration-tests" )
305323
# PLUGINS
306324
# -----------------------------------------------------------------------------
307325

308-
# Install all the headers for mqb + bmq
326+
# Install all the headers for mqb + bmq
309327
install(TARGETS bmqbrkr_plugins
310328
EXPORT BmqbrkrPluginsTargets
311329
FILE_SET HEADERS

bin/build-darwin.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ CMAKE_OPTIONS=(\
109109

110110
PKG_CONFIG_PATH="${DIR_INSTALL}/lib/pkgconfig:${BREW_PKG_CONFIG_PATH}" \
111111
cmake -B "${DIR_BUILD}/blazingmq" -S "${DIR_ROOT}" "${CMAKE_OPTIONS[@]}"
112-
make -C "${DIR_BUILD}/blazingmq" -j 16
112+
cmake --build "${DIR_BUILD}/blazingmq" --parallel 16 --target bmqbrkr bmqtool all.it bmqauthnpass bmqauthnfail
113113

114114
echo broker is here: "${DIR_BUILD}/blazingmq/src/applications/bmqbrkr/bmqbrkr.tsk"
115115
echo to run the broker: "${DIR_BUILD}/blazingmq/src/applications/bmqbrkr/run"

docker/build_deps.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fetch_deps() {
4949
configure() {
5050
PATH="$PATH:$(realpath srcs/bde-tools/bin)"
5151
export PATH
52-
eval "$(bbs_build_env -u opt_64_cpp17)"
52+
eval "$(bbs_build_env -u opt_64_cpp17_pic)"
5353
}
5454

5555
build_bde() {
@@ -68,7 +68,7 @@ build_ntf() {
6868
--without-usage-examples \
6969
--without-applications \
7070
--without-warnings-as-errors \
71-
--ufid opt_64_cpp17
71+
--ufid opt_64_cpp17_pic
7272
make -j8
7373
make install
7474
popd

src/groups/mqb/group/mqb.mem

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mqba
2+
mqbauthn
23
mqbblp
34
mqbc
45
mqbcfg

src/groups/mqb/mqba/mqba_application.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <mqba_domainmanager.h>
2525
#include <mqba_initialconnectionhandler.h>
2626
#include <mqba_sessionnegotiator.h>
27+
#include <mqbauthn_authenticationcontroller.h>
2728
#include <mqbblp_clustercatalog.h>
2829
#include <mqbblp_relayqueueengine.h>
2930
#include <mqbcfg_brokerconfig.h>
@@ -166,6 +167,7 @@ Application::Application(bdlmt::EventScheduler* scheduler,
166167
, d_allocatorsStatContext_p(allocatorsStatContext)
167168
, d_pluginManager_mp()
168169
, d_statController_mp()
170+
, d_authenticationController_mp()
169171
, d_configProvider_mp()
170172
, d_dispatcher_mp()
171173
, d_transportManager_mp()
@@ -253,7 +255,8 @@ int Application::start(bsl::ostream& errorDescription)
253255
rc_DOMAINMANAGER = -8,
254256
rc_TRANSPORTMANAGER_LISTEN = -9,
255257
rc_ADMIN_POOL_START_FAILURE = -10,
256-
rc_PLUGINMANAGER = -11
258+
rc_PLUGINMANAGER = -11,
259+
rc_AUTHENTICATIONCONTROLLER = -12,
257260
};
258261

259262
int rc = rc_SUCCESS;
@@ -295,6 +298,17 @@ int Application::start(bsl::ostream& errorDescription)
295298
return (rc * 100) + rc_STATCONTROLLER; // RETURN
296299
}
297300

301+
// Start the AuthenticationController
302+
d_authenticationController_mp.load(
303+
new (*d_allocator_p) mqbauthn::AuthenticationController(
304+
d_pluginManager_mp.get(),
305+
d_allocators.get("AuthenticationController")),
306+
d_allocator_p);
307+
rc = d_authenticationController_mp->start(errorDescription);
308+
if (rc != 0) {
309+
return (rc * 100) + rc_AUTHENTICATIONCONTROLLER; // RETURN
310+
}
311+
298312
// Start the config provider
299313
d_configProvider_mp.load(new (*d_allocator_p) ConfigProvider(
300314
d_allocators.get("ConfigProvider")),
@@ -527,6 +541,7 @@ void Application::stop()
527541
STOP_OBJ(d_dispatcher_mp, "Dispatcher");
528542
STOP_OBJ(d_configProvider_mp, "ConfigProvider");
529543
STOP_OBJ(d_statController_mp, "StatController");
544+
STOP_OBJ(d_authenticationController_mp, "AuthenticationController");
530545
STOP_OBJ(d_pluginManager_mp, "PluginManager");
531546

532547
// and now DESTROY everything
@@ -536,6 +551,7 @@ void Application::stop()
536551
DESTROY_OBJ(d_dispatcher_mp, "Dispatcher");
537552
DESTROY_OBJ(d_configProvider_mp, "ConfigProvider");
538553
DESTROY_OBJ(d_statController_mp, "StatController");
554+
DESTROY_OBJ(d_authenticationController_mp, "AuthenticationController");
539555
DESTROY_OBJ(d_pluginManager_mp, "PluginManager");
540556

541557
BALL_LOG_INFO << "BMQbrkr stopped";

src/groups/mqb/mqba/mqba_application.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
// MQB
2929
#include <mqba_commandrouter.h>
30+
#include <mqbauthn_authenticationcontroller.h>
3031
#include <mqbcmd_messages.h>
3132
#include <mqbconfm_messages.h>
3233
#include <mqbi_cluster.h>
@@ -97,18 +98,20 @@ class Application {
9798

9899
private:
99100
// PRIVATE TYPES
100-
typedef bslma::ManagedPtr<mqbplug::PluginManager> PluginManagerMp;
101-
typedef bslma::ManagedPtr<mqbblp::ClusterCatalog> ClusterCatalogMp;
102-
typedef bslma::ManagedPtr<ConfigProvider> ConfigProviderMp;
103-
typedef bslma::ManagedPtr<Dispatcher> DispatcherMp;
104-
typedef bslma::ManagedPtr<DomainManager> DomainManagerMp;
105-
typedef bslma::ManagedPtr<mqbstat::StatController> StatControllerMp;
101+
typedef bslma::ManagedPtr<mqbplug::PluginManager> PluginManagerMp;
102+
typedef bslma::ManagedPtr<mqbblp::ClusterCatalog> ClusterCatalogMp;
103+
typedef bslma::ManagedPtr<ConfigProvider> ConfigProviderMp;
104+
typedef bslma::ManagedPtr<Dispatcher> DispatcherMp;
105+
typedef bslma::ManagedPtr<DomainManager> DomainManagerMp;
106+
typedef bslma::ManagedPtr<mqbstat::StatController> StatControllerMp;
107+
typedef bslma::ManagedPtr<mqbauthn::AuthenticationController>
108+
AuthenticationControllerMp;
106109
typedef bslma::ManagedPtr<mqbnet::TransportManager> TransportManagerMp;
107110
typedef bdlcc::SharedObjectPool<
108111
bdlbb::Blob,
109112
bdlcc::ObjectPoolFunctors::DefaultCreator,
110113
bdlcc::ObjectPoolFunctors::RemoveAll<bdlbb::Blob> >
111-
BlobSpPool;
114+
BlobSpPool;
112115
typedef bsl::vector<bsl::shared_ptr<mqbnet::Session> > Sessions;
113116

114117
// Data members
@@ -144,6 +147,9 @@ class Application {
144147
/// Statistics controller component.
145148
StatControllerMp d_statController_mp;
146149

150+
/// Authentication controller component.
151+
AuthenticationControllerMp d_authenticationController_mp;
152+
147153
ConfigProviderMp d_configProvider_mp;
148154

149155
DispatcherMp d_dispatcher_mp;

src/groups/mqb/mqba/package/mqba.dep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mqbauthn
12
mqbblp
23
mqbcmd
34
mqbnet
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// Copyright 2017-2023 Bloomberg Finance L.P.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
// mqbauthn_authenticationcontroller.cpp -*-C++-*-
17+
#include <mqbauthn_authenticationcontroller.h>
18+
19+
#include <mqbscm_version.h>
20+
// BMQ
21+
#include <bmqtsk_alarmlog.h>
22+
#include <bmqu_memoutstream.h>
23+
24+
// MQB
25+
#include <mqbcfg_brokerconfig.h>
26+
#include <mqbcfg_messages.h>
27+
#include <mqbplug_authenticator.h>
28+
#include <mqbplug_pluginfactory.h>
29+
30+
// BDE
31+
#include <bsl_string.h>
32+
#include <bsl_unordered_set.h>
33+
34+
namespace BloombergLP {
35+
namespace mqbauthn {
36+
37+
namespace {
38+
39+
typedef bsl::unordered_set<mqbplug::PluginFactory*> PluginFactories;
40+
41+
} // close unnamed namespace
42+
43+
// ------------------------------
44+
// class AuthenticationController
45+
// ------------------------------
46+
47+
AuthenticationController::AuthenticationController(
48+
mqbplug::PluginManager* pluginManager,
49+
bslma::Allocator* allocator)
50+
: d_pluginManager_p(pluginManager)
51+
, d_allocator_p(allocator)
52+
{
53+
}
54+
55+
int AuthenticationController::start(bsl::ostream& errorDescription)
56+
{
57+
enum RcEnum {
58+
// Enum for the various RC error categories
59+
rc_SUCCESS = 0,
60+
rc_DUPLICATE_MECHANISM = -1
61+
};
62+
63+
int rc = rc_SUCCESS;
64+
bmqu::MemOutStream errorStream(d_allocator_p);
65+
66+
// Assign fallback principal
67+
bdlb::NullableValue<bsl::string> fallbackPrincipal =
68+
mqbcfg::BrokerConfig::get().authentication().fallbackPrincipal();
69+
if (!fallbackPrincipal.isNull()) {
70+
d_principal = fallbackPrincipal.value();
71+
}
72+
73+
// Initialize Authenticators from plugins
74+
{
75+
PluginFactories pluginFactories(d_allocator_p);
76+
d_pluginManager_p->get(mqbplug::PluginType::e_AUTHENTICATOR,
77+
&pluginFactories);
78+
79+
for (PluginFactories::const_iterator factoryIt =
80+
pluginFactories.cbegin();
81+
factoryIt != pluginFactories.cend();
82+
++factoryIt) {
83+
mqbplug::AuthenticatorPluginFactory* factory =
84+
dynamic_cast<mqbplug::AuthenticatorPluginFactory*>(*factoryIt);
85+
AuthenticatorMp authenticator = factory->create(d_allocator_p);
86+
87+
// Check if there's an authenticator with duplicate mechanism
88+
AuthenticatorMap::const_iterator cit = d_authenticators.find(
89+
authenticator->mechanism());
90+
if (cit != d_authenticators.cend()) {
91+
errorDescription << "Attempting to create duplicate "
92+
"authenticator with mechanism '"
93+
<< authenticator->mechanism();
94+
return rc_DUPLICATE_MECHANISM;
95+
}
96+
97+
// Start the authenticator
98+
if (int status = authenticator->start(errorStream)) {
99+
BMQTSK_ALARMLOG_ALARM("#AUTHENTICATION")
100+
<< "Failed to start Authenticator '"
101+
<< authenticator->name() << "' [rc: " << status
102+
<< ", error: '" << errorStream.str() << "']"
103+
<< BMQTSK_ALARMLOG_END;
104+
errorStream.reset();
105+
continue; // CONTINUE
106+
}
107+
108+
// Add the authenticator into the collection
109+
d_authenticators.emplace(
110+
authenticator->mechanism(),
111+
bslmf::MovableRefUtil::move(authenticator));
112+
}
113+
}
114+
115+
return rc;
116+
}
117+
118+
void AuthenticationController::stop()
119+
{
120+
}
121+
122+
int AuthenticationController::authenticate(
123+
bsl::ostream& errorDescription,
124+
bsl::shared_ptr<mqbplug::AuthenticationResult>* result,
125+
bslstl::StringRef mechanism,
126+
const mqbplug::AuthenticationData& input)
127+
{
128+
enum RcEnum {
129+
// Enum for the various RC error categories
130+
rc_SUCCESS = 0,
131+
rc_AUTHENTICATION_FAILED = -1,
132+
rc_MECHANISM_NOT_SUPPORTED = -2
133+
};
134+
135+
int rc = rc_SUCCESS;
136+
bmqu::MemOutStream errorStream(d_allocator_p);
137+
138+
AuthenticatorMap::const_iterator cit = d_authenticators.find(mechanism);
139+
if (cit != d_authenticators.cend()) {
140+
const AuthenticatorMp& authenticator = cit->second;
141+
rc = authenticator->authenticate(errorStream, result, input);
142+
if (rc != rc_SUCCESS) {
143+
errorDescription << "AuthenticationController: failed to "
144+
"authenticate with mechanism '"
145+
<< mechanism << "'. (rc = " << rc
146+
<< "). Detailed error: " << errorStream.str();
147+
return (rc * 10 + rc_AUTHENTICATION_FAILED);
148+
}
149+
}
150+
else {
151+
errorDescription
152+
<< "AuthenticationController: authentication mechanism '"
153+
<< mechanism << "' not supported.";
154+
return (rc * 10 + rc_MECHANISM_NOT_SUPPORTED);
155+
}
156+
157+
return rc_SUCCESS;
158+
}
159+
160+
} // close package namespace
161+
} // close enterprise namespace

0 commit comments

Comments
 (0)