Skip to content

Commit 4d44aa6

Browse files
michaelklishinmergify[bot]
authored andcommitted
Allow tagged (e.g. encrypted:...) values for more rabbitmq.conf` keys
When the support for tagged values in `rabbitmq.conf` was introduced, not all candidate keys were updated to include it. This PR updates a few more sensitive `rabbitmq.conf` keys to support `encrypted:...` values. References #11989. (cherry picked from commit e07cdf9) (cherry picked from commit 81fc0a8)
1 parent 6730797 commit 4d44aa6

11 files changed

Lines changed: 45 additions & 12 deletions

File tree

deps/rabbit/test/unit_config_value_encryption_SUITE.erl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ groups() ->
3030
decrypt_start_app_undefined,
3131
decrypt_start_app_wrong_passphrase,
3232
decrypt_config,
33+
decrypt_config_map,
3334
rabbitmqctl_encode
3435
]}
3536
].
@@ -105,6 +106,33 @@ do_decrypt_config(Algo = {C, H, I, P}) ->
105106
ok = application:unload(rabbit),
106107
ok.
107108

109+
decrypt_config_map(_Config) ->
110+
Hashes = rabbit_pbe:supported_hashes() -- ?SKIPPED_HASHES,
111+
Ciphers = rabbit_pbe:supported_ciphers() -- ?SKIPPED_CIPHERS,
112+
Iterations = [1, 100, 1000],
113+
_ = [begin
114+
PassPhrase = crypto:strong_rand_bytes(16),
115+
do_decrypt_config_map({C, H, I, PassPhrase})
116+
end || H <- Hashes, C <- Ciphers, I <- Iterations],
117+
ok.
118+
119+
%% Verifies that encrypted values nested inside maps are decrypted,
120+
%% as required by e.g. rabbitmq_management.oauth_resource_servers.
121+
do_decrypt_config_map({C, H, I, P} = Algo) ->
122+
case application:load(rabbit) of
123+
ok -> ok;
124+
{error, {already_loaded, rabbit}} -> ok
125+
end,
126+
Secret = <<"test_oauth_secret">>,
127+
{encrypted, EncSecret} = rabbit_pbe:encrypt_term(C, H, I, P, Secret),
128+
application:set_env(rabbit, test_map_decrypt,
129+
#{<<"server">> => [{oauth_client_secret, {encrypted, EncSecret}}]}),
130+
rabbit_prelaunch_conf:decrypt_config([rabbit], Algo),
131+
{ok, Decrypted} = application:get_env(rabbit, test_map_decrypt),
132+
Secret = proplists:get_value(oauth_client_secret, maps:get(<<"server">>, Decrypted)),
133+
application:unset_env(rabbit, test_map_decrypt),
134+
ok.
135+
108136
encrypt_value(Key, {C, H, I, P}) ->
109137
{ok, Value} = application:get_env(rabbit, Key),
110138
{encrypted, EncValue} = rabbit_pbe:encrypt_term(C, H, I, P, Value),

deps/rabbitmq_auth_backend_ldap/priv/schema/rabbitmq_auth_backend_ldap.schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ end}.
290290
[{datatype, {enum, [true, false]}}]}.
291291

292292
{mapping, "auth_ldap.ssl_options.password", "rabbitmq_auth_backend_ldap.ssl_options.password",
293-
[{datatype, string}]}.
293+
[{datatype, [tagged_binary, binary]}]}.
294294

295295
{mapping, "auth_ldap.ssl_options.psk_identity", "rabbitmq_auth_backend_ldap.ssl_options.psk_identity",
296296
[{datatype, string}]}.

deps/rabbitmq_management/priv/schema/rabbitmq_management.schema

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ end}.
466466
{mapping, "management.oauth_client_id", "rabbitmq_management.oauth_client_id",
467467
[{datatype, string}]}.
468468
{mapping, "management.oauth_client_secret", "rabbitmq_management.oauth_client_secret",
469-
[{datatype, string}]}.
469+
[{datatype, [tagged_binary, binary]}]}.
470470

471471
%% Configure OAuth2 authorization flow (defaults to code)
472472
{mapping, "management.oauth_response_type", "rabbitmq_management.oauth_response_type",
@@ -544,7 +544,7 @@ end}.
544544
{mapping,
545545
"management.oauth_resource_servers.$name.oauth_client_secret",
546546
"rabbitmq_management.oauth_resource_servers",
547-
[{datatype, string}]
547+
[{datatype, [tagged_binary, binary]}]
548548
}.
549549

550550
{mapping,

deps/rabbitmq_management/test/config_schema_SUITE_data/rabbitmq_management.snippets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@
674674
{oauth_enabled, true},
675675
{oauth_provider_url, "http://localhost:8080"},
676676
{oauth_client_id, "rabbitmq_client_code"},
677-
{oauth_client_secret, "rabbitmq_client_secret"},
677+
{oauth_client_secret, <<"rabbitmq_client_secret">>},
678678
{oauth_scopes, "openid profile rabbitmq.*"},
679679
{oauth_initiated_logon_type, idp_initiated},
680680
{oauth_token_endpoint_params, [

deps/rabbitmq_peer_discovery_aws/priv/schema/rabbitmq_peer_discovery_aws.schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end}.
5050
%% secret_key
5151

5252
{mapping, "cluster_formation.aws.secret_key", "rabbit.cluster_formation.peer_discovery_aws.aws_secret_key", [
53-
{datatype, string}
53+
{datatype, [tagged_string, string]}
5454
]}.
5555

5656
{translation, "rabbit.cluster_formation.peer_discovery_aws.aws_secret_key",

deps/rabbitmq_peer_discovery_consul/priv/schema/rabbitmq_peer_discovery_consul.schema

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ end}.
5353
%% ACL token
5454

5555
{mapping, "cluster_formation.consul.acl_token", "rabbit.cluster_formation.peer_discovery_consul.consul_acl_token", [
56-
{datatype, string}
56+
{datatype, [tagged_string, string]}
5757
]}.
5858

5959
{translation, "rabbit.cluster_formation.peer_discovery_consul.consul_acl_token",
@@ -416,7 +416,7 @@ end}.
416416
[{datatype, {enum, [true, false]}}]}.
417417

418418
{mapping, "cluster_formation.consul.ssl_options.password", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.password",
419-
[{datatype, string}]}.
419+
[{datatype, [tagged_binary, binary]}]}.
420420

421421
{mapping, "cluster_formation.consul.ssl_options.psk_identity", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.psk_identity",
422422
[{datatype, string}]}.

deps/rabbitmq_peer_discovery_etcd/priv/schema/rabbitmq_peer_discovery_etcd.schema

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fun(Conf) ->
152152
end}.
153153

154154
{mapping, "cluster_formation.etcd.password", "rabbit.cluster_formation.peer_discovery_etcd.etcd_password", [
155-
{datatype, string}
155+
{datatype, [tagged_binary, binary]}
156156
]}.
157157

158158
{translation, "rabbit.cluster_formation.peer_discovery_etcd.etcd_password",
@@ -226,7 +226,7 @@ end}.
226226
[{datatype, {enum, [true, false]}}]}.
227227

228228
{mapping, "cluster_formation.etcd.ssl_options.password", "rabbit.cluster_formation.peer_discovery_etcd.ssl_options.password",
229-
[{datatype, string}]}.
229+
[{datatype, [tagged_binary, binary]}]}.
230230

231231
{mapping, "cluster_formation.etcd.ssl_options.psk_identity", "rabbit.cluster_formation.peer_discovery_etcd.ssl_options.psk_identity",
232232
[{datatype, string}]}.

deps/rabbitmq_prelaunch/src/rabbit_prelaunch_conf.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ decrypt({encrypted, _} = EncValue,
528528
decrypt(EncValue, Algo);
529529
decrypt(List, Algo) when is_list(List) ->
530530
decrypt_list(List, Algo, []);
531+
decrypt(Map, Algo) when is_map(Map) ->
532+
maps:fold(fun(Key, Value, {AccMap, AccAlgo}) ->
533+
{NewValue, NewAlgo} = decrypt(Value, AccAlgo),
534+
{maps:put(Key, NewValue, AccMap), NewAlgo}
535+
end, {#{}, Algo}, Map);
531536
decrypt(Value, Algo) ->
532537
{Value, Algo}.
533538

deps/rabbitmq_stomp/priv/schema/rabbitmq_stomp.schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ end}.
189189
]}.
190190

191191
{mapping, "stomp.default_pass", "rabbitmq_stomp.default_user.passcode", [
192-
{datatype, string}
192+
{datatype, [tagged_binary, binary]}
193193
]}.
194194

195195
{mapping, "stomp.default_topic_exchange", "rabbitmq_stomp.default_topic_exchange", [

deps/rabbitmq_tracing/priv/schema/rabbitmq_tracing.schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
]}.
1515

1616
{mapping, "tracing.password", "rabbitmq_tracing.password", [
17-
{datatype, string}
17+
{datatype, [tagged_binary, binary]}
1818
]}.

0 commit comments

Comments
 (0)