Skip to content

Commit 790c453

Browse files
Merge pull request #1465 from rabbitmq/rabbitmq-server-story-153435857-37x
Internal authN backend: make it impossible to successfully log in with a blank password (for 3.7.x)
2 parents e47387c + e091696 commit 790c453

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

src/rabbit_auth_backend_internal.erl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ hashing_module_for_user(#internal_user{
9898
hashing_algorithm = ModOrUndefined}) ->
9999
rabbit_password:hashing_mod(ModOrUndefined).
100100

101+
-define(BLANK_PASSWORD_REJECTION_MESSAGE,
102+
"user '~s' attempted to log in with a blank password, which is prohibited by the internal authN backend. "
103+
"To use TLS/x509 certificate-based authentication, see the rabbitmq_auth_mechanism_ssl plugin and configure the client to use the EXTERNAL authentication mechanism. "
104+
"Alternatively change the password for the user to be non-blank.").
105+
101106
%% For cases when we do not have a set of credentials,
102107
%% namely when x509 (TLS) certificates are used. This should only be
103108
%% possible when the EXTERNAL authentication mechanism is used, see
@@ -108,6 +113,12 @@ user_login_authentication(Username, []) ->
108113
%% performs initial validation.
109114
user_login_authentication(Username, AuthProps) ->
110115
case lists:keyfind(password, 1, AuthProps) of
116+
{password, <<"">>} ->
117+
{refused, ?BLANK_PASSWORD_REJECTION_MESSAGE,
118+
[Username]};
119+
{password, ""} ->
120+
{refused, ?BLANK_PASSWORD_REJECTION_MESSAGE,
121+
[Username]};
111122
{password, Cleartext} ->
112123
internal_check_user_login(
113124
Username,

test/unit_inbroker_parallel_SUITE.erl

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-include_lib("common_test/include/ct.hrl").
2020
-include_lib("kernel/include/file.hrl").
2121
-include_lib("amqp_client/include/amqp_client.hrl").
22+
-include_lib("eunit/include/eunit.hrl").
2223

2324
-compile(export_all).
2425

@@ -49,6 +50,10 @@ groups() ->
4950
password_hashing,
5051
change_password
5152
]},
53+
{auth_backend_internal, [parallel], [
54+
login_with_credentials_but_no_password,
55+
login_of_passwordless_user
56+
]},
5257
set_disk_free_limit_command,
5358
set_vm_memory_high_watermark_command,
5459
topic_matching,
@@ -517,6 +522,58 @@ change_password1(_Config) ->
517522
UserName, [{password, Password}]),
518523
passed.
519524

525+
526+
%% -------------------------------------------------------------------
527+
%% rabbit_auth_backend_internal
528+
%% -------------------------------------------------------------------
529+
530+
login_with_credentials_but_no_password(Config) ->
531+
passed = rabbit_ct_broker_helpers:rpc(Config, 0,
532+
?MODULE, login_with_credentials_but_no_password1, [Config]).
533+
534+
login_with_credentials_but_no_password1(_Config) ->
535+
Username = <<"login_with_credentials_but_no_password-user">>,
536+
Password = <<"login_with_credentials_but_no_password-password">>,
537+
ok = rabbit_auth_backend_internal:add_user(Username, Password, <<"acting-user">>),
538+
539+
try
540+
rabbit_auth_backend_internal:user_login_authentication(Username,
541+
[{key, <<"value">>}]),
542+
?assert(false)
543+
catch exit:{unknown_auth_props, Username, [{key, <<"value">>}]} ->
544+
ok
545+
end,
546+
547+
ok = rabbit_auth_backend_internal:delete_user(Username, <<"acting-user">>),
548+
549+
passed.
550+
551+
%% passwordless users are not supposed to be used with
552+
%% this backend (and PLAIN authentication mechanism in general)
553+
login_of_passwordless_user(Config) ->
554+
passed = rabbit_ct_broker_helpers:rpc(Config, 0,
555+
?MODULE, login_of_passwordless_user1, [Config]).
556+
557+
login_of_passwordless_user1(_Config) ->
558+
Username = <<"login_of_passwordless_user-user">>,
559+
Password = <<"">>,
560+
ok = rabbit_auth_backend_internal:add_user(Username, Password, <<"acting-user">>),
561+
562+
?assertMatch(
563+
{refused, _Message, [Username]},
564+
rabbit_auth_backend_internal:user_login_authentication(Username,
565+
[{password, <<"">>}])),
566+
567+
?assertMatch(
568+
{refused, _Format, [Username]},
569+
rabbit_auth_backend_internal:user_login_authentication(Username,
570+
[{password, ""}])),
571+
572+
ok = rabbit_auth_backend_internal:delete_user(Username, <<"acting-user">>),
573+
574+
passed.
575+
576+
520577
%% -------------------------------------------------------------------
521578
%% rabbitmqctl.
522579
%% -------------------------------------------------------------------
@@ -1220,4 +1277,4 @@ expand_options(As, Bs) ->
12201277
flush() ->
12211278
receive _ -> flush()
12221279
after 10 -> ok
1223-
end.
1280+
end.

0 commit comments

Comments
 (0)