-
Notifications
You must be signed in to change notification settings - Fork 707
Add support for PLAIN authn for Shadow Linking #28708
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -981,8 +981,8 @@ errc frontend::validator::validate_connection_config( | |||||
| } | ||||||
|
|
||||||
| if ( | ||||||
| c.mechanism != "SCRAM-SHA-256" | ||||||
| && c.mechanism != "SCRAM-SHA-512") { | ||||||
| c.mechanism != "SCRAM-SHA-256" && c.mechanism != "SCRAM-SHA-512" | ||||||
| && c.mechanism != "PLAIN") { | ||||||
| vlog( | ||||||
| cluster::clusterlog.warn, | ||||||
| "Unsupported SCRAM mechanism: {}", | ||||||
|
||||||
| "Unsupported SCRAM mechanism: {}", | |
| "Unsupported authentication mechanism: {}", |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |||||||||||||||||||||
| #include "net/connection.h" | ||||||||||||||||||||||
| #include "random/generators.h" | ||||||||||||||||||||||
| #include "security/oidc_authenticator.h" | ||||||||||||||||||||||
| #include "security/plain_authenticator.h" | ||||||||||||||||||||||
| #include "security/scram_authenticator.h" | ||||||||||||||||||||||
| #include "thirdparty/c-ares/ares.h" | ||||||||||||||||||||||
| #include "utils/backoff_policy.h" | ||||||||||||||||||||||
|
|
@@ -320,7 +321,8 @@ ss::future<> remote_broker::do_authenticate() { | |||||||||||||||||||||
| if ( | ||||||||||||||||||||||
| mechanism != security::scram_sha256_authenticator::name | ||||||||||||||||||||||
| && mechanism != security::scram_sha512_authenticator::name | ||||||||||||||||||||||
| && mechanism != security::oidc::sasl_authenticator::name) { | ||||||||||||||||||||||
| && mechanism != security::oidc::sasl_authenticator::name | ||||||||||||||||||||||
| && mechanism != security::plain_authenticator::name) { | ||||||||||||||||||||||
| throw broker_error{ | ||||||||||||||||||||||
| _node_id, | ||||||||||||||||||||||
| error_code::sasl_authentication_failed, | ||||||||||||||||||||||
|
|
@@ -348,11 +350,17 @@ ss::future<> remote_broker::do_authenticate() { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (mechanism == security::scram_sha256_authenticator::name) { | ||||||||||||||||||||||
| co_await do_authenticate_scram256(username, password); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| } else if (mechanism == security::scram_sha512_authenticator::name) { | ||||||||||||||||||||||
| co_await do_authenticate_scram512(username, password); | ||||||||||||||||||||||
| } else if (mechanism == security::oidc::sasl_authenticator::name) { | ||||||||||||||||||||||
| co_await do_authenticate_oauthbearer(password); | ||||||||||||||||||||||
| } else if (mechanism == security::plain_authenticator::name) { | ||||||||||||||||||||||
| co_await do_authenticate_plain(username, password); | ||||||||||||||||||||||
michael-redpanda marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| throw broker_error{ | ||||||||||||||||||||||
| _node_id, | ||||||||||||||||||||||
| error_code::sasl_authentication_failed, | ||||||||||||||||||||||
| fmt_with_ctx(ssx::sformat, "Unknown mechanism: {}", mechanism)}; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
353
to
364
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -520,6 +528,27 @@ ss::future<> remote_broker::do_authenticate_oauthbearer(ss::sstring token) { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ss::future<> remote_broker::do_authenticate_plain( | ||||||||||||||||||||||
| ss::sstring username, ss::sstring password) { | ||||||||||||||||||||||
| sasl_authenticate_request req; | ||||||||||||||||||||||
| std::string bytes; | ||||||||||||||||||||||
| // 2 - number of null characters in the PLAIN auth message | ||||||||||||||||||||||
| bytes.reserve(2 + username.size() + password.size()); | ||||||||||||||||||||||
| bytes.push_back('\0'); | ||||||||||||||||||||||
| bytes.append(username.cbegin(), username.cend()); | ||||||||||||||||||||||
| bytes.push_back('\0'); | ||||||||||||||||||||||
| bytes.append(password.cbegin(), password.cend()); | ||||||||||||||||||||||
| req.data.auth_bytes = bytes::from_string(std::move(bytes)); | ||||||||||||||||||||||
|
Comment on lines
+534
to
+541
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick:
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I tried this but I think the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You, my bad, you'll need: auto bytes = fmt::format("\0{}\0{}", username, password);
req.data.auth_bytes = bytes::from_string(std::string_view{bytes.begin(), bytes.end()});
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That unfortunately won't work either...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should work if the format string is a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should work if the format string is a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide an example of what you mean please |
||||||||||||||||||||||
| auto res = co_await do_dispatch( | ||||||||||||||||||||||
| std::move(req), get_sasl_authenticate_request_version()); | ||||||||||||||||||||||
| if (res.data.errored()) { | ||||||||||||||||||||||
| throw broker_error{ | ||||||||||||||||||||||
| _node_id, | ||||||||||||||||||||||
| res.data.error_code, | ||||||||||||||||||||||
| res.data.error_message.value_or("<no error message>")}; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| namespace { | ||||||||||||||||||||||
| template<typename ReqT> | ||||||||||||||||||||||
| api_version get_auth_request_version( | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ using proto::admin::authentication_configuration; | |||||
| using proto::admin::consumer_offset_sync_options; | ||||||
| using proto::admin::create_shadow_link_request; | ||||||
| using proto::admin::name_filter; | ||||||
| using proto::admin::plain_config; | ||||||
| using proto::admin::schema_registry_sync_options; | ||||||
| using proto::admin::schema_registry_sync_options_shadow_schema_registry_topic; | ||||||
| using proto::admin::scram_config; | ||||||
|
|
@@ -407,6 +408,19 @@ create_authn_settings(const authentication_configuration& authn_config) { | |||||
| scram_mechanism_to_string(scram.get_scram_mechanism())}; | ||||||
| return creds; | ||||||
| }, | ||||||
| [](const plain_config& plain) | ||||||
| -> cluster_link::model::connection_config::authn_variant { | ||||||
| if (plain.get_username().empty() || plain.get_password().empty()) { | ||||||
| throw std::invalid_argument( | ||||||
| "When setting PLAIN configuration, must provide username and " | ||||||
| "password"); | ||||||
| } | ||||||
| cluster_link::model::scram_credentials creds; | ||||||
BenPope marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| creds.username = plain.get_username(); | ||||||
| creds.password = plain.get_password(); | ||||||
| creds.mechanism = "PLAIN"; | ||||||
| return creds; | ||||||
| }, | ||||||
| [](std::monostate) | ||||||
| -> cluster_link::model::connection_config::authn_variant { | ||||||
| throw std::invalid_argument( | ||||||
|
|
@@ -524,26 +538,38 @@ authentication_configuration create_authentication_configuration( | |||||
| authn, | ||||||
| [](const cluster_link::model::scram_credentials& scram) | ||||||
| -> authentication_configuration { | ||||||
| scram_config scram_proto; | ||||||
| scram_proto.set_username(ss::sstring{scram.username}); | ||||||
| scram_proto.set_password_set(true); | ||||||
| scram_proto.set_password_set_at( | ||||||
| absl::FromChrono( | ||||||
| model::to_time_point(scram.password_last_updated))); | ||||||
| scram_proto.set_scram_mechanism( | ||||||
| proto::admin::scram_mechanism::unspecified); | ||||||
| if (scram.mechanism == "SCRAM-SHA-256") { | ||||||
| scram_proto.set_scram_mechanism( | ||||||
| proto::admin::scram_mechanism::scram_sha_256); | ||||||
| } else if (scram.mechanism == "SCRAM-SHA-512") { | ||||||
| scram_proto.set_scram_mechanism( | ||||||
| proto::admin::scram_mechanism::scram_sha_512); | ||||||
| authentication_configuration authn; | ||||||
| if (scram.mechanism == "PLAIN") { | ||||||
| plain_config plain_proto; | ||||||
| plain_proto.set_username(ss::sstring{scram.username}); | ||||||
| plain_proto.set_password_set(true); | ||||||
| plain_proto.set_password_set_at( | ||||||
| absl::FromChrono( | ||||||
| model::to_time_point(scram.password_last_updated))); | ||||||
| authn.set_plain_configuration(std::move(plain_proto)); | ||||||
| } else { | ||||||
| throw std::invalid_argument( | ||||||
| ssx::sformat("Unknown SCRAM mechanism: {}", scram.mechanism)); | ||||||
| scram_config scram_proto; | ||||||
| scram_proto.set_username(ss::sstring{scram.username}); | ||||||
| scram_proto.set_password_set(true); | ||||||
| scram_proto.set_password_set_at( | ||||||
| absl::FromChrono( | ||||||
| model::to_time_point(scram.password_last_updated))); | ||||||
| scram_proto.set_scram_mechanism( | ||||||
| proto::admin::scram_mechanism::unspecified); | ||||||
| if (scram.mechanism == "SCRAM-SHA-256") { | ||||||
| scram_proto.set_scram_mechanism( | ||||||
| proto::admin::scram_mechanism::scram_sha_256); | ||||||
| } else if (scram.mechanism == "SCRAM-SHA-512") { | ||||||
| scram_proto.set_scram_mechanism( | ||||||
| proto::admin::scram_mechanism::scram_sha_512); | ||||||
| } else { | ||||||
| throw std::invalid_argument( | ||||||
| ssx::sformat( | ||||||
| "Unknown SCRAM mechanism: {}", scram.mechanism)); | ||||||
|
||||||
| "Unknown SCRAM mechanism: {}", scram.mechanism)); | |
| "Unknown authentication mechanism: {}", scram.mechanism)); |
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 we're gonna do that, it can go in another else on the outer scope. It's unreachable, though.
Uh oh!
There was an error while loading. Please reload this page.