Skip to content

Commit 48bee25

Browse files
Do not propagate password if not provided
This is relevant for ssl-based authentications
1 parent df783eb commit 48bee25

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

deps/rabbitmq_mqtt/src/rabbit_mqtt_processor.erl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,9 +1094,15 @@ check_vhost_alive(VHost) ->
10941094
end.
10951095

10961096
check_user_login(VHost, Username, Password, ClientId, PeerIp, ConnName) ->
1097-
AuthProps = [{vhost, VHost},
1098-
{client_id, ClientId},
1099-
{password, Password}],
1097+
AuthProps = case Password of
1098+
none ->
1099+
[{vhost, VHost},
1100+
{client_id, ClientId}];
1101+
_ ->
1102+
[{password, Password},
1103+
{vhost, VHost},
1104+
{client_id, ClientId}]
1105+
end,
11001106
case rabbit_access_control:check_user_login(Username, AuthProps) of
11011107
{ok, User = #user{username = Username1}} ->
11021108
notify_auth_result(user_authentication_success, Username1, ConnName),

deps/rabbitmq_mqtt/test/auth_SUITE.erl

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ sub_groups() ->
6666
ssl_user_vhost_parameter_mapping_success,
6767
ssl_user_vhost_parameter_mapping_not_allowed,
6868
ssl_user_vhost_parameter_mapping_vhost_does_not_exist,
69-
ssl_user_cert_vhost_mapping_takes_precedence_over_port_vhost_mapping
69+
ssl_user_cert_vhost_mapping_takes_precedence_over_port_vhost_mpping
7070
]},
7171
{ssl_user_with_invalid_client_id_in_cert_san_dns, [],
7272
[invalid_client_id_from_cert_san_dns
7373
]},
7474
{ssl_user_with_client_id_in_cert_san_dns, [],
75-
[client_id_from_cert_san_dns
75+
[client_id_from_cert_san_dns,
76+
ssl_user_password_not_propagated_if_not_provided
7677
]},
7778
{ssl_user_with_client_id_in_cert_san_dns_1, [],
7879
[client_id_from_cert_san_dns_1
@@ -81,7 +82,8 @@ sub_groups() ->
8182
[client_id_from_cert_san_email
8283
]},
8384
{ssl_user_with_client_id_in_cert_dn, [],
84-
[client_id_from_cert_dn
85+
[client_id_from_cert_dn,
86+
ssl_user_password_not_propagated_if_not_provided
8587
]},
8688
{no_ssl_user, [shuffle],
8789
[anonymous_auth_failure,
@@ -338,6 +340,7 @@ init_per_testcase(T, Config)
338340
when T =:= client_id_propagation;
339341
T =:= invalid_client_id_from_cert_san_dns;
340342
T =:= client_id_from_cert_san_dns;
343+
T =:= ssl_user_password_not_propagated_if_not_provided;
341344
T =:= client_id_from_cert_san_dns_1;
342345
T =:= client_id_from_cert_san_email;
343346
T =:= client_id_from_cert_dn ->
@@ -477,6 +480,7 @@ end_per_testcase(T, Config)
477480
when T =:= client_id_propagation;
478481
T =:= invalid_client_id_from_cert_san_dns;
479482
T =:= client_id_from_cert_san_dns;
483+
T =:= ssl_user_password_not_propagated_if_not_provided;
480484
T =:= client_id_from_cert_san_dns_1;
481485
T =:= client_id_from_cert_san_email;
482486
T =:= client_id_from_cert_dn ->
@@ -573,6 +577,7 @@ client_id_from_cert_san_email(Config) ->
573577
rabbit_auth_backend_mqtt_mock,
574578
get,
575579
[authentication]),
580+
ct:log("client_id_from_cert_dn. AuthProps: ~p", [AuthProps]),
576581
?assertEqual(ExpectedClientId, proplists:get_value(client_id, AuthProps)),
577582
ok = emqtt:disconnect(C).
578583

@@ -584,10 +589,22 @@ client_id_from_cert_dn(Config) ->
584589
[{authentication, AuthProps}] = rpc(Config, 0,
585590
rabbit_auth_backend_mqtt_mock,
586591
get,
587-
[authentication]),
592+
[authentication]),
588593
?assertEqual(ExpectedClientId, proplists:get_value(client_id, AuthProps)),
589594
ok = emqtt:disconnect(C).
590595

596+
ssl_user_password_not_propagated_if_not_provided(Config) ->
597+
ExpectedClientId = get_client_cert_subject(Config), % subject = distinguished_name
598+
MqttClientId = ExpectedClientId,
599+
{ok, C} = connect_ssl(MqttClientId, Config),
600+
{ok, _} = emqtt:connect(C),
601+
[{authentication, AuthProps}] = rpc(Config, 0,
602+
rabbit_auth_backend_mqtt_mock,
603+
get,
604+
[authentication]),
605+
?assertEqual(false, proplists:is_defined(password, AuthProps)),
606+
ok = emqtt:disconnect(C).
607+
591608
invalid_client_id_from_cert_san_dns(Config) ->
592609
MqttClientId = <<"other_client_id">>,
593610
{ok, C} = connect_ssl(MqttClientId, Config),

0 commit comments

Comments
 (0)