From 21347490f96e9b42acda7c359db672bec226663e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Cogolu=C3=A8gnes?= Date: Tue, 6 Jun 2023 11:08:02 +0200 Subject: [PATCH 1/2] Fix SASL external authentication in stream plugin --- .../src/rabbit_stream_reader.erl | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/deps/rabbitmq_stream/src/rabbit_stream_reader.erl b/deps/rabbitmq_stream/src/rabbit_stream_reader.erl index b163a48ee00a..923c25405b37 100644 --- a/deps/rabbitmq_stream/src/rabbit_stream_reader.erl +++ b/deps/rabbitmq_stream/src/rabbit_stream_reader.erl @@ -75,7 +75,7 @@ stream_leaders :: #{stream() => pid()}, stream_subscriptions :: #{stream() => [subscription_id()]}, credits :: atomics:atomics_ref(), - authentication_state :: atom(), + authentication_state :: any(), user :: undefined | #user{}, virtual_host :: undefined | binary(), connection_step :: @@ -1365,8 +1365,6 @@ handle_frame_pre_auth(Transport, ServerProperties}}), send(Transport, S, Frame), {Connection#stream_connection{client_properties = ClientProperties, - authentication_state = - peer_properties_exchanged, connection_step = peer_properties_exchanged}, State}; handle_frame_pre_auth(Transport, @@ -1431,10 +1429,8 @@ handle_frame_pre_auth(Transport, rabbit_core_metrics:auth_attempt_succeeded(Host, <<>>, stream), - {C1#stream_connection{authentication_state = - AuthState1, - connection_step = - authenticating}, + {C1#stream_connection{authentication_state = AuthState1, + connection_step = authenticating}, {sasl_authenticate, ?RESPONSE_SASL_CHALLENGE, Challenge}}; {ok, User = #user{username = Username}} -> @@ -1451,11 +1447,9 @@ handle_frame_pre_auth(Transport, [], C1, State), - {C1#stream_connection{authentication_state = - done, - user = User, - connection_step = - authenticated}, + {C1#stream_connection{user = User, + authentication_state = done, + connection_step = authenticated}, {sasl_authenticate, ?RESPONSE_CODE_OK, <<>>}}; not_allowed -> From 6c14d736abb66dd2db2d0740cdc7daa61d7f7e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Cogolu=C3=A8gnes?= Date: Tue, 6 Jun 2023 13:04:35 +0200 Subject: [PATCH 2/2] Polish authentication in stream reader --- deps/rabbitmq_stream/src/rabbit_stream_reader.erl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/deps/rabbitmq_stream/src/rabbit_stream_reader.erl b/deps/rabbitmq_stream/src/rabbit_stream_reader.erl index 923c25405b37..eb5e35c7b89a 100644 --- a/deps/rabbitmq_stream/src/rabbit_stream_reader.erl +++ b/deps/rabbitmq_stream/src/rabbit_stream_reader.erl @@ -64,6 +64,7 @@ %% client port peer_port, auth_mechanism, + authentication_state :: any(), connected_at :: integer(), helper_sup :: pid(), socket :: rabbit_net:socket(), @@ -75,7 +76,6 @@ stream_leaders :: #{stream() => pid()}, stream_subscriptions :: #{stream() => [subscription_id()]}, credits :: atomics:atomics_ref(), - authentication_state :: any(), user :: undefined | #user{}, virtual_host :: undefined | binary(), connection_step :: @@ -1426,9 +1426,6 @@ handle_frame_pre_auth(Transport, {C1#stream_connection{connection_step = failure}, {sasl_authenticate, ?RESPONSE_SASL_ERROR, <<>>}}; {challenge, Challenge, AuthState1} -> - rabbit_core_metrics:auth_attempt_succeeded(Host, - <<>>, - stream), {C1#stream_connection{authentication_state = AuthState1, connection_step = authenticating}, {sasl_authenticate, ?RESPONSE_SASL_CHALLENGE,