Skip to content

Commit 1e0ec11

Browse files
Merge pull request #5167 from rabbitmq/mergify/bp/v3.9.x/pr-5165
Add client-side TLS options support to Consul peer discovery (backport #5155) (backport #5165) (cherry picked from commit 61f2bca) Conflicts: deps/rabbitmq_peer_discovery_common/src/rabbit_peer_discovery_httpc.erl deps/rabbitmq_peer_discovery_consul/src/rabbit_peer_discovery_consul.erl
1 parent d8237d2 commit 1e0ec11

File tree

4 files changed

+267
-55
lines changed

4 files changed

+267
-55
lines changed

deps/rabbitmq_peer_discovery_common/src/rabbit_peer_discovery_httpc.erl

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
build_uri/5,
2020
build_path/1,
2121
delete/6,
22+
delete/7,
2223
get/5,
2324
get/7,
2425
post/6,
2526
post/8,
2627
put/6,
2728
put/7,
29+
put/8,
2830
maybe_configure_proxy/0,
2931
maybe_configure_inet6/0]).
3032

@@ -233,14 +235,38 @@ put(Scheme, Host, Port, Path, Args, Body) ->
233235
Headers :: list(),
234236
Body :: string() | binary() | tuple().
235237
put(Scheme, Host, Port, Path, Args, Headers, Body) ->
238+
put(Scheme, Host, Port, Path, Args, Headers, [], Body).
239+
240+
%% @spec put(Scheme, Host, Port, Path, Args, Headers, HttpOptions, Body) -> Result
241+
%% @where Scheme = string(),
242+
%% Host = string(),
243+
%% Port = integer(),
244+
%% Path = string(),
245+
%% Args = proplist(),
246+
%% Headers = proplist(),
247+
%% HttpOpts = proplist(),
248+
%% Body = string(),
249+
%% Result = {ok, mixed}|{error, Reason::string()}
250+
%% @doc Perform a HTTP PUT request
251+
%% @end
252+
%%
253+
-spec put(Scheme, Host, Port, Path, Args, Headers, HttpOpts, Body) -> {ok, string()} | {error, any()} when
254+
Scheme :: atom() | string(),
255+
Host :: string() | binary(),
256+
Port :: integer(),
257+
Path :: string() | binary(),
258+
Args :: list(),
259+
Headers :: list(),
260+
HttpOpts :: list(),
261+
Body :: string() | binary() | tuple().
262+
put(Scheme, Host, Port, Path, Args, Headers, HttpOpts, Body) ->
236263
URL = build_uri(Scheme, Host, Port, Path, Args),
237264
_ = rabbit_log:debug("PUT ~s [~p] [~p]", [URL, Headers, Body]),
238-
HttpOpts = ensure_timeout(),
239-
Response = httpc:request(put, {URL, Headers, ?CONTENT_URLENCODED, Body}, HttpOpts, []),
265+
HttpOpts1 = ensure_timeout(HttpOpts),
266+
Response = httpc:request(put, {URL, Headers, ?CONTENT_URLENCODED, Body}, HttpOpts1, []),
240267
_ = rabbit_log:debug("Response: [~p]", [Response]),
241268
parse_response(Response).
242269

243-
244270
%% @public
245271
%% @spec delete(Scheme, Host, Port, Path, Args, Body) -> Result
246272
%% @where Scheme = string(),
@@ -257,10 +283,29 @@ delete(Scheme, Host, Port, PathSegments, Args, Body) when is_list(PathSegments)
257283
Path = uri_string:recompose(#{path => lists:join("/", [rabbit_data_coercion:to_list(PS) || PS <- PathSegments])}),
258284
delete(Scheme, Host, Port, Path, Args, Body);
259285
delete(Scheme, Host, Port, Path, Args, Body) ->
286+
delete(Scheme, Host, Port, Path, Args, [], Body).
287+
288+
%% @public
289+
%% @spec delete(Scheme, Host, Port, Path, Args, Body) -> Result
290+
%% @where Scheme = string(),
291+
%% Host = string(),
292+
%% Port = integer(),
293+
%% Path = string(),
294+
%% Args = proplist(),
295+
%% HttpOpts = proplist(),
296+
%% Body = string(),
297+
%% Result = {ok, mixed}|{error, Reason::string()}
298+
%% @doc Perform a HTTP DELETE request
299+
%% @end
300+
%%
301+
delete(Scheme, Host, Port, PathSegments, Args, HttpOpts, Body) when is_list(PathSegments) ->
302+
Path = uri_string:recompose(#{path => lists:join("/", [rabbit_data_coercion:to_list(PS) || PS <- PathSegments])}),
303+
delete(Scheme, Host, Port, Path, Args, HttpOpts, Body);
304+
delete(Scheme, Host, Port, Path, Args, HttpOpts, Body) ->
260305
URL = build_uri(Scheme, Host, Port, Path, Args),
261306
_ = rabbit_log:debug("DELETE ~s [~p]", [URL, Body]),
262-
HttpOpts = ensure_timeout(),
263-
Response = httpc:request(delete, {URL, [], ?CONTENT_URLENCODED, Body}, HttpOpts, []),
307+
HttpOpts1 = ensure_timeout(HttpOpts),
308+
Response = httpc:request(delete, {URL, [], ?CONTENT_URLENCODED, Body}, HttpOpts1, []),
264309
_ = rabbit_log:debug("Response: [~p]", [Response]),
265310
parse_response(Response).
266311

deps/rabbitmq_peer_discovery_consul/priv/schema/rabbitmq_peer_discovery_consul.schema

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,119 @@ fun(Conf) ->
315315
Value -> Value
316316
end
317317
end}.
318+
319+
320+
%%
321+
%% TLS client options
322+
%%
323+
324+
{mapping, "cluster_formation.consul.ssl_options", "rabbit.cluster_formation.peer_discovery_consul.ssl_options", [
325+
{datatype, {enum, [none]}}
326+
]}.
327+
328+
{translation, "rabbit.cluster_formation.peer_discovery_consul.ssl_options",
329+
fun(Conf) ->
330+
case cuttlefish:conf_get("cluster_formation.consul.ssl_options", Conf, undefined) of
331+
none -> [];
332+
_ -> cuttlefish:invalid("Invalid cluster_formation.consul.ssl_options")
333+
end
334+
end}.
335+
336+
{mapping, "cluster_formation.consul.ssl_options.verify", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.verify", [
337+
{datatype, {enum, [verify_peer, verify_none]}}]}.
338+
339+
{mapping, "cluster_formation.consul.ssl_options.fail_if_no_peer_cert", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.fail_if_no_peer_cert", [
340+
{datatype, {enum, [true, false]}}]}.
341+
342+
{mapping, "cluster_formation.consul.ssl_options.cacertfile", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.cacertfile",
343+
[{datatype, string}, {validators, ["file_accessible"]}]}.
344+
345+
{mapping, "cluster_formation.consul.ssl_options.certfile", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.certfile",
346+
[{datatype, string}, {validators, ["file_accessible"]}]}.
347+
348+
{mapping, "cluster_formation.consul.ssl_options.cacerts.$name", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.cacerts",
349+
[{datatype, string}]}.
350+
351+
{translation, "rabbit.cluster_formation.peer_discovery_consul.ssl_options.cacerts",
352+
fun(Conf) ->
353+
Settings = cuttlefish_variable:filter_by_prefix("cluster_formation.consul.ssl_options.cacerts", Conf),
354+
[ list_to_binary(V) || {_, V} <- Settings ]
355+
end}.
356+
357+
{mapping, "cluster_formation.consul.ssl_options.cert", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.cert",
358+
[{datatype, string}]}.
359+
360+
{translation, "rabbit.cluster_formation.peer_discovery_consul.ssl_options.cert",
361+
fun(Conf) ->
362+
list_to_binary(cuttlefish:conf_get("cluster_formation.consul.ssl_options.cert", Conf))
363+
end}.
364+
365+
{mapping, "cluster_formation.consul.ssl_options.crl_check", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.crl_check",
366+
[{datatype, [{enum, [true, false, peer, best_effort]}]}]}.
367+
368+
{mapping, "cluster_formation.consul.ssl_options.depth", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.depth",
369+
[{datatype, integer}, {validators, ["byte"]}]}.
370+
371+
{mapping, "cluster_formation.consul.ssl_options.dh", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.dh",
372+
[{datatype, string}]}.
373+
374+
{translation, "rabbit.cluster_formation.peer_discovery_consul.ssl_options.dh",
375+
fun(Conf) ->
376+
list_to_binary(cuttlefish:conf_get("cluster_formation.consul.ssl_options.dh", Conf))
377+
end}.
378+
379+
{mapping, "cluster_formation.consul.ssl_options.dhfile", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.dhfile",
380+
[{datatype, string}, {validators, ["file_accessible"]}]}.
381+
382+
{mapping, "cluster_formation.consul.ssl_options.key.RSAPrivateKey", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.key",
383+
[{datatype, string}]}.
384+
385+
{mapping, "cluster_formation.consul.ssl_options.key.DSAPrivateKey", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.key",
386+
[{datatype, string}]}.
387+
388+
{mapping, "cluster_formation.consul.ssl_options.key.PrivateKeyInfo", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.key",
389+
[{datatype, string}]}.
390+
391+
{translation, "rabbit.cluster_formation.peer_discovery_consul.ssl_options.key",
392+
fun(Conf) ->
393+
case cuttlefish_variable:filter_by_prefix("cluster_formation.consul.ssl_options.key", Conf) of
394+
[{[_,_,Key], Val}|_] -> {list_to_atom(Key), list_to_binary(Val)};
395+
_ -> undefined
396+
end
397+
end}.
398+
399+
{mapping, "cluster_formation.consul.ssl_options.keyfile", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.keyfile",
400+
[{datatype, string}, {validators, ["file_accessible"]}]}.
401+
402+
{mapping, "cluster_formation.consul.ssl_options.log_alert", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.log_alert",
403+
[{datatype, {enum, [true, false]}}]}.
404+
405+
{mapping, "cluster_formation.consul.ssl_options.password", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.password",
406+
[{datatype, string}]}.
407+
408+
{mapping, "cluster_formation.consul.ssl_options.psk_identity", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.psk_identity",
409+
[{datatype, string}]}.
410+
411+
{mapping, "cluster_formation.consul.ssl_options.reuse_sessions", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.reuse_sessions",
412+
[{datatype, {enum, [true, false]}}]}.
413+
414+
{mapping, "cluster_formation.consul.ssl_options.secure_renegotiate", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.secure_renegotiate",
415+
[{datatype, {enum, [true, false]}}]}.
416+
417+
{mapping, "cluster_formation.consul.ssl_options.versions.$version", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.versions",
418+
[{datatype, atom}]}.
419+
420+
{translation, "rabbit.cluster_formation.peer_discovery_consul.ssl_options.versions",
421+
fun(Conf) ->
422+
Settings = cuttlefish_variable:filter_by_prefix("cluster_formation.consul.ssl_options.versions", Conf),
423+
[V || {_, V} <- Settings]
424+
end}.
425+
426+
{mapping, "cluster_formation.consul.ssl_options.ciphers.$cipher", "rabbit.cluster_formation.peer_discovery_consul.ssl_options.ciphers",
427+
[{datatype, string}]}.
428+
429+
{translation, "rabbit.cluster_formation.peer_discovery_consul.ssl_options.ciphers",
430+
fun(Conf) ->
431+
Settings = cuttlefish_variable:filter_by_prefix("cluster_formation.consul.ssl_options.ciphers", Conf),
432+
lists:reverse([V || {_, V} <- Settings])
433+
end}.

0 commit comments

Comments
 (0)