Wrap TLS options password into a function in more places
A follow-up to #13958 #13999. Pair: @dcorbacho.
This commit is contained in:
parent
f7a238a8f4
commit
e9fc656241
|
@ -39,18 +39,7 @@
|
||||||
|
|
||||||
-spec wrap_password_opt(tls_opts()) -> tls_opts().
|
-spec wrap_password_opt(tls_opts()) -> tls_opts().
|
||||||
wrap_password_opt(Opts0) ->
|
wrap_password_opt(Opts0) ->
|
||||||
case proplists:get_value(password, Opts0) of
|
rabbit_ssl_options:wrap_password_opt(Opts0).
|
||||||
undefined ->
|
|
||||||
Opts0;
|
|
||||||
Fun when is_function(Fun) ->
|
|
||||||
Opts0;
|
|
||||||
Password ->
|
|
||||||
%% A password can be a value or a function returning that value.
|
|
||||||
%% See the key_pem_password/0 type in https://github.com/erlang/otp/pull/5843/files.
|
|
||||||
NewOpts = proplists:delete(password, Opts0),
|
|
||||||
Fun = fun() -> Password end,
|
|
||||||
[{password, Fun} | NewOpts]
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec cipher_suites(cipher_suites_mode()) -> ssl:ciphers().
|
-spec cipher_suites(cipher_suites_mode()) -> ssl:ciphers().
|
||||||
cipher_suites(Mode) ->
|
cipher_suites(Mode) ->
|
||||||
|
|
|
@ -33,7 +33,7 @@ wrap_tls_opts_with_binary_password(_Config) ->
|
||||||
{password, Bin}
|
{password, Bin}
|
||||||
],
|
],
|
||||||
|
|
||||||
Opts = rabbit_ssl:wrap_password_opt(Opts0),
|
Opts = rabbit_ssl_options:wrap_password_opt(Opts0),
|
||||||
M = maps:from_list(Opts),
|
M = maps:from_list(Opts),
|
||||||
|
|
||||||
?assertEqual(Path, maps:get(keyfile, M)),
|
?assertEqual(Path, maps:get(keyfile, M)),
|
||||||
|
@ -53,7 +53,7 @@ wrap_tls_opts_with_function_password(_Config) ->
|
||||||
{password, Fun}
|
{password, Fun}
|
||||||
],
|
],
|
||||||
|
|
||||||
Opts = rabbit_ssl:wrap_password_opt(Opts0),
|
Opts = rabbit_ssl_options:wrap_password_opt(Opts0),
|
||||||
M = maps:from_list(Opts),
|
M = maps:from_list(Opts),
|
||||||
|
|
||||||
?assertEqual(Path, maps:get(keyfile, M)),
|
?assertEqual(Path, maps:get(keyfile, M)),
|
||||||
|
|
|
@ -7,15 +7,34 @@
|
||||||
|
|
||||||
-module(rabbit_ssl_options).
|
-module(rabbit_ssl_options).
|
||||||
|
|
||||||
-export([fix/1]).
|
-export([
|
||||||
-export([fix_client/1]).
|
fix/1,
|
||||||
|
fix_client/1,
|
||||||
|
wrap_password_opt/1
|
||||||
|
]).
|
||||||
|
|
||||||
-define(BAD_SSL_PROTOCOL_VERSIONS, [
|
-define(BAD_SSL_PROTOCOL_VERSIONS, [
|
||||||
%% POODLE
|
%% POODLE
|
||||||
sslv3
|
sslv3
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
-type tls_opts() :: [ssl:tls_server_option()] | [ssl:tls_client_option()].
|
||||||
|
|
||||||
|
-spec wrap_password_opt(tls_opts()) -> tls_opts().
|
||||||
|
wrap_password_opt(Opts0) ->
|
||||||
|
case proplists:get_value(password, Opts0) of
|
||||||
|
undefined ->
|
||||||
|
Opts0;
|
||||||
|
Fun when is_function(Fun) ->
|
||||||
|
Opts0;
|
||||||
|
Password ->
|
||||||
|
%% A password can be a value or a function returning that value.
|
||||||
|
%% See the key_pem_password/0 type in https://github.com/erlang/otp/pull/5843/files.
|
||||||
|
NewOpts = proplists:delete(password, Opts0),
|
||||||
|
Fun = fun() -> Password end,
|
||||||
|
[{password, Fun} | NewOpts]
|
||||||
|
end.
|
||||||
|
|
||||||
-spec fix(rabbit_types:infos()) -> rabbit_types:infos().
|
-spec fix(rabbit_types:infos()) -> rabbit_types:infos().
|
||||||
|
|
||||||
fix(Config) ->
|
fix(Config) ->
|
||||||
|
|
|
@ -128,16 +128,17 @@ get_legacy_listener() ->
|
||||||
get_tls_listener() ->
|
get_tls_listener() ->
|
||||||
{ok, Listener0} = application:get_env(rabbitmq_management, ssl_config),
|
{ok, Listener0} = application:get_env(rabbitmq_management, ssl_config),
|
||||||
{ok, Listener1} = ensure_port(tls, Listener0),
|
{ok, Listener1} = ensure_port(tls, Listener0),
|
||||||
|
Listener2 = rabbit_ssl:wrap_password_opt(Listener1),
|
||||||
Port = proplists:get_value(port, Listener1),
|
Port = proplists:get_value(port, Listener1),
|
||||||
case proplists:get_value(cowboy_opts, Listener0) of
|
case proplists:get_value(cowboy_opts, Listener0) of
|
||||||
undefined ->
|
undefined ->
|
||||||
[
|
[
|
||||||
{port, Port},
|
{port, Port},
|
||||||
{ssl, true},
|
{ssl, true},
|
||||||
{ssl_opts, Listener0}
|
{ssl_opts, Listener2}
|
||||||
];
|
];
|
||||||
CowboyOpts ->
|
CowboyOpts ->
|
||||||
WithoutCowboyOpts = lists:keydelete(cowboy_opts, 1, Listener0),
|
WithoutCowboyOpts = lists:keydelete(cowboy_opts, 1, Listener2),
|
||||||
[
|
[
|
||||||
{port, Port},
|
{port, Port},
|
||||||
{ssl, true},
|
{ssl, true},
|
||||||
|
|
|
@ -34,7 +34,16 @@ init(_) ->
|
||||||
-spec start_configured_listener() -> ok.
|
-spec start_configured_listener() -> ok.
|
||||||
start_configured_listener() ->
|
start_configured_listener() ->
|
||||||
TCPListenerConf = get_env(tcp_config, []),
|
TCPListenerConf = get_env(tcp_config, []),
|
||||||
TLSListenerConf = get_env(ssl_config, []),
|
TLSListenerConf0 = get_env(ssl_config, []),
|
||||||
|
TLSListenerConf =
|
||||||
|
case proplists:get_value(ssl_opts, TLSListenerConf0, undef) of
|
||||||
|
undef ->
|
||||||
|
TLSListenerConf0;
|
||||||
|
Opts0 ->
|
||||||
|
Opts = rabbit_ssl:wrap_password_opt(Opts0),
|
||||||
|
Tmp = proplists:delete(ssl_opts, TLSListenerConf0),
|
||||||
|
[{ssl_opts, Opts} | Tmp]
|
||||||
|
end,
|
||||||
|
|
||||||
case {TCPListenerConf, TLSListenerConf} of
|
case {TCPListenerConf, TLSListenerConf} of
|
||||||
%% nothing is configured
|
%% nothing is configured
|
||||||
|
@ -64,10 +73,11 @@ start_configured_tcp_listener(Conf) ->
|
||||||
start_configured_tls_listener(Conf) ->
|
start_configured_tls_listener(Conf) ->
|
||||||
case Conf of
|
case Conf of
|
||||||
[] -> ok;
|
[] -> ok;
|
||||||
SSLCon ->
|
TLSConf ->
|
||||||
SSLListener0 = [{ssl, true} | SSLCon],
|
TLSListener0 = [{ssl, true} | TLSConf],
|
||||||
SSLListener1 = maybe_disable_sendfile(SSLListener0),
|
TLSListener1 = maybe_disable_sendfile(TLSListener0),
|
||||||
start_listener(SSLListener1)
|
TLSListener2 = rabbit_ssl:wrap_password_opt(TLSListener1),
|
||||||
|
start_listener(TLSListener2)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
maybe_disable_sendfile(Listener) ->
|
maybe_disable_sendfile(Listener) ->
|
||||||
|
|
|
@ -27,7 +27,8 @@ ensure_listener(Listener) ->
|
||||||
undefined ->
|
undefined ->
|
||||||
{error, {no_port_given, Listener}};
|
{error, {no_port_given, Listener}};
|
||||||
_ ->
|
_ ->
|
||||||
{Transport, TransportOpts, ProtoOpts} = preprocess_config(Listener),
|
{Transport, TransportOpts0, ProtoOpts} = preprocess_config(Listener),
|
||||||
|
TransportOpts = rabbit_ssl_options:wrap_password_opt(TransportOpts0),
|
||||||
ProtoOptsMap = maps:from_list(ProtoOpts),
|
ProtoOptsMap = maps:from_list(ProtoOpts),
|
||||||
StreamHandlers = stream_handlers_config(ProtoOpts),
|
StreamHandlers = stream_handlers_config(ProtoOpts),
|
||||||
rabbit_log:debug("Starting HTTP[S] listener with transport ~ts", [Transport]),
|
rabbit_log:debug("Starting HTTP[S] listener with transport ~ts", [Transport]),
|
||||||
|
@ -86,9 +87,10 @@ auto_ssl(Options) ->
|
||||||
fix_ssl([{ssl_opts, SSLOpts} | Options]).
|
fix_ssl([{ssl_opts, SSLOpts} | Options]).
|
||||||
|
|
||||||
fix_ssl(Options) ->
|
fix_ssl(Options) ->
|
||||||
SSLOpts = proplists:get_value(ssl_opts, Options),
|
TLSOpts0 = proplists:get_value(ssl_opts, Options),
|
||||||
|
TLSOpts = rabbit_ssl_options:wrap_password_opt(TLSOpts0),
|
||||||
{ranch_ssl,
|
{ranch_ssl,
|
||||||
transport_config(Options ++ rabbit_networking:fix_ssl_options(SSLOpts)),
|
transport_config(Options ++ rabbit_networking:fix_ssl_options(TLSOpts)),
|
||||||
protocol_config(Options)}.
|
protocol_config(Options)}.
|
||||||
|
|
||||||
transport_config(Options0) ->
|
transport_config(Options0) ->
|
||||||
|
|
Loading…
Reference in New Issue