-
Notifications
You must be signed in to change notification settings - Fork 154
Feat[MQB]: Add authn plugin #990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have some comments.
The most important ones are regarding breaking changes in plugins API (bslstl::StringRef
-> bsl::string_view
)
I cannot build everything on Solaris/Linux due to these issues
|
||
/// Return the name of the plugin. | ||
virtual bslstl::StringRef name() const = 0; | ||
virtual bsl::string_view name() const = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change.
All other plugins still use bslstl::StringRef
and cannot inherit from bsl::string_view
one
Even if we update them, we will lose compatibility with older versions of the plugins. It might result in strange crashes due to incompatible API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To deal with this, I propose to
- Keep the original
bslstl::StringRef
declaration - Add a new one virtual
virtual bsl::string_view name() const { return static_cast<bslstl::StringRef>(name()); }
With the default implementation, it will be compatible with older plugins.
We are free to gradually addbsl::string_view
implementation in plugins and eventually removebslstl::StringRef
one.
Alternatively we can revert this change to remove possible risks
@hallfox what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in another PR #993
|
||
// Start the authenticator | ||
if (int status = authenticator->start(errorStream)) { | ||
BMQTSK_ALARMLOG_ALARM("#AUTHENTICATION") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Authn Controller makes decision to print an alarm, should it also print it on other failures in this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean if we should ALARM on other errors in this function? I'm actually not fully sure what are the scenarios where we trigger an ALARM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can move forward with this for now, can discuss the alarms separately.
c9d3350
to
2a104a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a few ideas about logs
4964518
to
66ee90a
Compare
bsl::string anonMechanism = bsl::string(AnonAuthenticator::k_MECHANISM, | ||
d_allocator_p); | ||
|
||
if (d_authenticators.find(anonMechanism) != d_authenticators.cend()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bsl::string anonMechanism = bsl::string(AnonAuthenticator::k_MECHANISM, | |
d_allocator_p); | |
if (d_authenticators.find(anonMechanism) != d_authenticators.cend()) { | |
if (d_authenticators.find(AnonAuthenticator::k_MECHANISM) != d_authenticators.cend()) { |
Possible to avoid constructing tmp string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would cause a compiler error since bsl::unordered_map<bsl::string, AuthenticatorMp>
doesn't accept bsl::string_view
as the parameter to find
.
// If no authenticators are configured, use AnonAuthenticator for | ||
// anonymous pass authentication | ||
if (d_authenticators.empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If no authenticators are configured, use AnonAuthenticator for | |
// anonymous pass authentication | |
if (d_authenticators.empty()) { | |
if (!d_authenticators.empty()) { | |
// Have authenticators, nothing to do | |
return 0; | |
} | |
// If no authenticators are configured, use AnonAuthenticator for | |
// anonymous pass authentication |
Not strictly necessary to do, but I would make an early return here to reduce indentation of the following code.
Your original option is also good: it only has 1 return, not 2.
If the body of if-then
has more lines or if there are even more layers of indentation, early return looks better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How it might help the reader.
Consider the following code:
void foo(bool flag) {
if (flag) {
// 200 lines here
}
// nothing in the end
}
If a reader sees if
like this, they must scroll down 200 lines to see the end of this function just to know if there is any more processing if flag == false
.
Compared to this:
void foo(bool flag) {
if (!flag) return;
// 200 lines here
}
The reader knows that after the first line (with early return) there are no instructions for flag == false
Another case:
void foo(bool flag) {
if (flag) {
// 100 lines here
}
if (somethingElse()) {
// 100 lines here
}
// nothing in the end
}
In this case, it is not even enough to scroll down 200 lines, the reader has to notice the end of the current if
structure and start of another structure not related to flag
. This might be solved by folding structures in IDE, however, these are extra mouse clicks
if (!d_isStarted) { | ||
return; // RETURN | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BALL_LOG_INFO << "Stopping AuthenticationController"; | |
If we log starting, we might log stopping as well
errorDescription | ||
<< "AuthenticationController: authentication mechanism '" | ||
<< normMech << "' not supported."; | ||
return (rc * 10 + rc_MECHANISM_NOT_SUPPORTED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rc == e_SUCCESS
here, might simplify:
return (rc * 10 + rc_MECHANISM_NOT_SUPPORTED); | |
return rc_MECHANISM_NOT_SUPPORTED; |
We already have functions where we mix const * rc + enum
with just rc
or enum
, this for example:
return rc * 100 + |
int rc = rc_SUCCESS; | ||
bmqu::MemOutStream errorStream(d_allocator_p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int rc = rc_SUCCESS; | |
bmqu::MemOutStream errorStream(d_allocator_p); |
Possible to move closer to authenticate
below.
This is a "minimal scope" principle for definition of variables.
Minimal scope means that a reader has to keep in mind less variables at a point of time, making reading the code easier. Also, sometimes (rarely) defining variables in the least scope possible prevents others from misusing these variables later
<< "authenticating with mechanism '" << normMech << "'" | ||
<< " (authenticator: '" << authenticator->name() | ||
<< "')"; | ||
rc = authenticator->authenticate(errorStream, result, input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rc = authenticator->authenticate(errorStream, result, input); | |
bmqu::MemOutStream errorStream(d_allocator_p); | |
const int rc = authenticator->authenticate(errorStream, result, input); |
IT failure is unrelated |
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
Signed-off-by: Emelia Lei <[email protected]>
99d77af
to
4266111
Compare
Signed-off-by: Emelia Lei <[email protected]>
This PR includes:
mqbplug
mqbcfg
mqbauthn
package that controls the plugin and includes built-in plugins