Skip to content
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

k/server: Better handling of SCRAM parsing errors #12042

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions src/v/kafka/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,22 +372,38 @@ ss::future<response_ptr> sasl_authenticate_handler::handle(
log_request(ctx.header(), request);
vlog(klog.debug, "Received SASL_AUTHENTICATE {}", request);

auto result = co_await ctx.sasl()->authenticate(
std::move(request.data.auth_bytes));
if (likely(result)) {
sasl_authenticate_response_data data{
.error_code = error_code::none,
.error_message = std::nullopt,
.auth_bytes = std::move(result.value()),
};
co_return co_await ctx.respond(
sasl_authenticate_response(std::move(data)));
std::error_code ec;

try {
auto result = co_await ctx.sasl()->authenticate(
std::move(request.data.auth_bytes));
if (likely(result)) {
sasl_authenticate_response_data data{
.error_code = error_code::none,
.error_message = std::nullopt,
.auth_bytes = std::move(result.value()),
};
co_return co_await ctx.respond(
sasl_authenticate_response(std::move(data)));
}

ec = result.error();
} catch (security::scram_exception& e) {
vlog(
klog.warn,
"[{}:{}] Error processing SASL authentication request for {}: {}",
ctx.connection()->client_host(),
ctx.connection()->client_port(),
ctx.header().client_id.value_or(std::string_view("unset-client-id")),
e);

ec = make_error_code(security::errc::invalid_credentials);
}

sasl_authenticate_response_data data{
.error_code = error_code::sasl_authentication_failed,
.error_message = ssx::sformat(
"SASL authentication failed: {}", result.error().message()),
"SASL authentication failed: {}", ec.message()),
};
co_return co_await ctx.respond(sasl_authenticate_response(std::move(data)));
}
Expand Down
Loading