Skip to content

Commit 6bfb690

Browse files
committed
Add SASL mechanism ANONYMOUS
* Add SASL mechansim ANONYMOUS * Require SASL security layer in AMQP 1.0
1 parent a373396 commit 6bfb690

File tree

14 files changed

+290
-264
lines changed

14 files changed

+290
-264
lines changed

deps/amqp10_client/test/system_SUITE.erl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ stop_amqp10_client_app(Config) ->
103103
%% -------------------------------------------------------------------
104104

105105
init_per_group(rabbitmq, Config0) ->
106-
Config = rabbit_ct_helpers:set_config(Config0,
107-
{sasl, {plain, <<"guest">>, <<"guest">>}}),
106+
Config = rabbit_ct_helpers:set_config(Config0, {sasl, anon}),
108107
Config1 = rabbit_ct_helpers:merge_app_env(Config,
109108
[{rabbit,
110109
[{max_message_size, 134217728}]}]),
@@ -115,7 +114,7 @@ init_per_group(rabbitmq_strict, Config0) ->
115114
{sasl, {plain, <<"guest">>, <<"guest">>}}),
116115
Config1 = rabbit_ct_helpers:merge_app_env(Config,
117116
[{rabbit,
118-
[{amqp1_0_default_user, none},
117+
[{anonymous_login_user, none},
119118
{max_message_size, 134217728}]}]),
120119
rabbit_ct_helpers:run_steps(Config1, rabbit_ct_broker_helpers:setup_steps());
121120

deps/rabbit/BUILD.bazel

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,15 @@ _APP_ENV = """[
5858
{default_user_tags, [administrator]},
5959
{default_vhost, <<"/">>},
6060
{default_permissions, [<<".*">>, <<".*">>, <<".*">>]},
61-
{amqp1_0_default_user, <<"guest">>},
62-
{amqp1_0_default_vhost, <<"/">>},
61+
{anonymous_login_user, <<"guest">>},
6362
{loopback_users, [<<"guest">>]},
6463
{password_hashing_module, rabbit_password_hashing_sha256},
6564
{server_properties, []},
6665
{collect_statistics, none},
6766
{collect_statistics_interval, 5000},
6867
{mnesia_table_loading_retry_timeout, 30000},
6968
{mnesia_table_loading_retry_limit, 10},
70-
{auth_mechanisms, ['PLAIN', 'AMQPLAIN']},
69+
{auth_mechanisms, ['PLAIN', 'AMQPLAIN', 'ANONYMOUS']},
7170
{auth_backends, [rabbit_auth_backend_internal]},
7271
{delegate_count, 16},
7372
{trace_vhosts, []},

deps/rabbit/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ define PROJECT_ENV
3838
{default_user_tags, [administrator]},
3939
{default_vhost, <<"/">>},
4040
{default_permissions, [<<".*">>, <<".*">>, <<".*">>]},
41-
{amqp1_0_default_user, <<"guest">>},
42-
{amqp1_0_default_vhost, <<"/">>},
41+
%% The identity to act as for anonymous logins.
42+
{anonymous_login_user, <<"guest">>},
4343
{loopback_users, [<<"guest">>]},
4444
{password_hashing_module, rabbit_password_hashing_sha256},
4545
{server_properties, []},
4646
{collect_statistics, none},
4747
{collect_statistics_interval, 5000},
4848
{mnesia_table_loading_retry_timeout, 30000},
4949
{mnesia_table_loading_retry_limit, 10},
50-
{auth_mechanisms, ['PLAIN', 'AMQPLAIN']},
50+
%% "The server mechanisms are ordered in decreasing level of preference."
51+
%% AMQP §5.3.3.1
52+
{auth_mechanisms, ['PLAIN', 'AMQPLAIN', 'ANONYMOUS']},
5153
{auth_backends, [rabbit_auth_backend_internal]},
5254
{delegate_count, 16},
5355
{trace_vhosts, []},

deps/rabbit/app.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def all_beam_files(name = "all_beam_files"):
5858
"src/rabbit_amqqueue_sup_sup.erl",
5959
"src/rabbit_auth_backend_internal.erl",
6060
"src/rabbit_auth_mechanism_amqplain.erl",
61+
"src/rabbit_auth_mechanism_anonymous.erl",
6162
"src/rabbit_auth_mechanism_cr_demo.erl",
6263
"src/rabbit_auth_mechanism_plain.erl",
6364
"src/rabbit_autoheal.erl",
@@ -313,6 +314,7 @@ def all_test_beam_files(name = "all_test_beam_files"):
313314
"src/rabbit_amqqueue_sup_sup.erl",
314315
"src/rabbit_auth_backend_internal.erl",
315316
"src/rabbit_auth_mechanism_amqplain.erl",
317+
"src/rabbit_auth_mechanism_anonymous.erl",
316318
"src/rabbit_auth_mechanism_cr_demo.erl",
317319
"src/rabbit_auth_mechanism_plain.erl",
318320
"src/rabbit_autoheal.erl",
@@ -586,6 +588,7 @@ def all_srcs(name = "all_srcs"):
586588
"src/rabbit_amqqueue_sup_sup.erl",
587589
"src/rabbit_auth_backend_internal.erl",
588590
"src/rabbit_auth_mechanism_amqplain.erl",
591+
"src/rabbit_auth_mechanism_anonymous.erl",
589592
"src/rabbit_auth_mechanism_cr_demo.erl",
590593
"src/rabbit_auth_mechanism_plain.erl",
591594
"src/rabbit_autoheal.erl",

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,12 @@ end}.
434434
%% ===========================================================================
435435

436436
%% Choose the available SASL mechanism(s) to expose.
437-
%% The two default (built in) mechanisms are 'PLAIN' and
438-
%% 'AMQPLAIN'. Additional mechanisms can be added via
439-
%% plugins.
437+
%% The three default (built in) mechanisms are 'PLAIN', 'AMQPLAIN' and 'ANONYMOUS'.
438+
%% Additional mechanisms can be added via plugins.
440439
%%
441440
%% See https://www.rabbitmq.com/authentication.html for more details.
442441
%%
443-
%% {auth_mechanisms, ['PLAIN', 'AMQPLAIN']},
442+
%% {auth_mechanisms, ['PLAIN', 'AMQPLAIN', 'ANONYMOUS']},
444443

445444
{mapping, "auth_mechanisms.$name", "rabbit.auth_mechanisms", [
446445
{datatype, atom}]}.
@@ -725,6 +724,21 @@ end}.
725724
end
726725
end}.
727726

727+
%% Connections that skip SASL layer or use SASL mechanism ANONYMOUS will use this identity.
728+
%% Setting this to a username will allow (anonymous) clients to connect and act as the
729+
%% given user without authenticating. For production environments, set this value to 'none'.
730+
{mapping, "anonymous_login_user", "rabbit.anonymous_login_user",
731+
[{datatype, [{enum, [none]}, string]}]}.
732+
733+
{translation, "rabbit.anonymous_login_user",
734+
fun(Conf) ->
735+
case cuttlefish:conf_get("anonymous_login_user", Conf) of
736+
none -> none;
737+
User -> list_to_binary(User)
738+
end
739+
end}.
740+
741+
728742
%%
729743
%% Default Policies
730744
%% ====================
@@ -2639,32 +2653,6 @@ end}.
26392653
end
26402654
}.
26412655

2642-
% ===============================
2643-
% AMQP 1.0
2644-
% ===============================
2645-
2646-
%% Connections that skip SASL layer or use SASL mechanism ANONYMOUS will connect as this account.
2647-
%% Setting this to a username will allow clients to connect without authenticating.
2648-
%% For production environments, set this value to 'none'.
2649-
{mapping, "amqp1_0.default_user", "rabbit.amqp1_0_default_user",
2650-
[{datatype, [{enum, [none]}, string]}]}.
2651-
2652-
{mapping, "amqp1_0.default_vhost", "rabbit.amqp1_0_default_vhost",
2653-
[{datatype, string}]}.
2654-
2655-
{translation, "rabbit.amqp1_0_default_user",
2656-
fun(Conf) ->
2657-
case cuttlefish:conf_get("amqp1_0.default_user", Conf) of
2658-
none -> none;
2659-
User -> list_to_binary(User)
2660-
end
2661-
end}.
2662-
2663-
{translation , "rabbit.amqp1_0_default_vhost",
2664-
fun(Conf) ->
2665-
list_to_binary(cuttlefish:conf_get("amqp1_0.default_vhost", Conf))
2666-
end}.
2667-
26682656
{mapping, "stream.replication.port_range.min", "osiris.port_range", [
26692657
{datatype, [integer]},
26702658
{validators, ["non_zero_positive_integer"]}

0 commit comments

Comments
 (0)