feat: support HAProxy protocol for mgmt API
This commit is contained in:
parent
aeaf6ada2c
commit
2b407cf0fa
|
@ -90,6 +90,11 @@
|
||||||
{datatype, {enum, [true, false]}}
|
{datatype, {enum, [true, false]}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
|
{mapping, "management.listener.http.proxy_header", "emqx_management.listeners", [
|
||||||
|
{default, false},
|
||||||
|
{datatype, {enum, [true, false]}}
|
||||||
|
]}.
|
||||||
|
|
||||||
{mapping, "management.listener.https", "emqx_management.listeners", [
|
{mapping, "management.listener.https", "emqx_management.listeners", [
|
||||||
{datatype, [integer, ip]}
|
{datatype, [integer, ip]}
|
||||||
]}.
|
]}.
|
||||||
|
@ -186,6 +191,11 @@
|
||||||
{datatype, {enum, [true, false]}}
|
{datatype, {enum, [true, false]}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
|
{mapping, "management.listener.https.proxy_header", "emqx_management.listeners", [
|
||||||
|
{default, false},
|
||||||
|
{datatype, {enum, [true, false]}}
|
||||||
|
]}.
|
||||||
|
|
||||||
{translation, "emqx_management.application", fun(Conf) ->
|
{translation, "emqx_management.application", fun(Conf) ->
|
||||||
Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
|
Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
|
||||||
Opts = fun(Prefix) ->
|
Opts = fun(Prefix) ->
|
||||||
|
@ -202,7 +212,9 @@ end}.
|
||||||
Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
|
Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
|
||||||
Opts = fun(Prefix) ->
|
Opts = fun(Prefix) ->
|
||||||
Filter([{num_acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
|
Filter([{num_acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
|
||||||
{max_connections, cuttlefish:conf_get(Prefix ++ ".max_clients", Conf)}])
|
{max_connections, cuttlefish:conf_get(Prefix ++ ".max_clients", Conf)},
|
||||||
|
{proxy_header, cuttlefish:conf_get(Prefix ++ ".proxy_header", Conf)}
|
||||||
|
])
|
||||||
end,
|
end,
|
||||||
TcpOpts = fun(Prefix) ->
|
TcpOpts = fun(Prefix) ->
|
||||||
Filter([{backlog, cuttlefish:conf_get(Prefix ++ ".backlog", Conf, undefined)},
|
Filter([{backlog, cuttlefish:conf_get(Prefix ++ ".backlog", Conf, undefined)},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_management,
|
{application, emqx_management,
|
||||||
[{description, "EMQ X Management API and CLI"},
|
[{description, "EMQ X Management API and CLI"},
|
||||||
{vsn, "4.4.12"}, % strict semver, bump manually!
|
{vsn, "4.4.13"}, % strict semver, bump manually!
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, [emqx_management_sup]},
|
{registered, [emqx_management_sup]},
|
||||||
{applications, [kernel,stdlib,emqx_plugin_libs,minirest]},
|
{applications, [kernel,stdlib,emqx_plugin_libs,minirest]},
|
||||||
|
|
|
@ -52,12 +52,12 @@ stop_listeners() ->
|
||||||
start_listener({Proto, Port, Options}) when Proto == http ->
|
start_listener({Proto, Port, Options}) when Proto == http ->
|
||||||
Dispatch = [{"/status", emqx_mgmt_http, []},
|
Dispatch = [{"/status", emqx_mgmt_http, []},
|
||||||
{"/api/v4/[...]", minirest, http_handlers()}],
|
{"/api/v4/[...]", minirest, http_handlers()}],
|
||||||
minirest:start_http(listener_name(Proto), ranch_opts(Port, Options), Dispatch);
|
minirest:start_http(listener_name(Proto), ranch_opts(Port, Options), Dispatch, proto_opts(Options));
|
||||||
|
|
||||||
start_listener({Proto, Port, Options}) when Proto == https ->
|
start_listener({Proto, Port, Options}) when Proto == https ->
|
||||||
Dispatch = [{"/status", emqx_mgmt_http, []},
|
Dispatch = [{"/status", emqx_mgmt_http, []},
|
||||||
{"/api/v4/[...]", minirest, http_handlers()}],
|
{"/api/v4/[...]", minirest, http_handlers()}],
|
||||||
minirest:start_https(listener_name(Proto), ranch_opts(Port, Options), Dispatch).
|
minirest:start_https(listener_name(Proto), ranch_opts(Port, Options), Dispatch, proto_opts(Options)).
|
||||||
|
|
||||||
ranch_opts(Port, Options0) ->
|
ranch_opts(Port, Options0) ->
|
||||||
NumAcceptors = proplists:get_value(num_acceptors, Options0, 4),
|
NumAcceptors = proplists:get_value(num_acceptors, Options0, 4),
|
||||||
|
@ -68,6 +68,7 @@ ranch_opts(Port, Options0) ->
|
||||||
({inet6, false}, Acc) -> Acc;
|
({inet6, false}, Acc) -> Acc;
|
||||||
({ipv6_v6only, true}, Acc) -> [{ipv6_v6only, true} | Acc];
|
({ipv6_v6only, true}, Acc) -> [{ipv6_v6only, true} | Acc];
|
||||||
({ipv6_v6only, false}, Acc) -> Acc;
|
({ipv6_v6only, false}, Acc) -> Acc;
|
||||||
|
({proxy_header, _}, Acc) -> Acc;
|
||||||
({K, V}, Acc)->
|
({K, V}, Acc)->
|
||||||
[{K, V} | Acc]
|
[{K, V} | Acc]
|
||||||
end, [], Options0),
|
end, [], Options0),
|
||||||
|
@ -77,6 +78,9 @@ ranch_opts(Port, Options0) ->
|
||||||
socket_opts => [{port, Port} | Options]},
|
socket_opts => [{port, Port} | Options]},
|
||||||
Res.
|
Res.
|
||||||
|
|
||||||
|
proto_opts(Options) ->
|
||||||
|
maps:with([proxy_header], maps:from_list(Options)).
|
||||||
|
|
||||||
stop_listener({Proto, Port, _}) ->
|
stop_listener({Proto, Port, _}) ->
|
||||||
io:format("Stop http:management listener on ~s successfully.~n",[format(Port)]),
|
io:format("Stop http:management listener on ~s successfully.~n",[format(Port)]),
|
||||||
minirest:stop_http(listener_name(Proto)).
|
minirest:stop_http(listener_name(Proto)).
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
, {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.8.1.11"}}}
|
, {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.8.1.11"}}}
|
||||||
, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "3.0.1"}}}
|
, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "3.0.1"}}}
|
||||||
, {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.3.6"}}}
|
, {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.3.6"}}}
|
||||||
, {minirest, {git, "https://github.com/emqx/minirest", {tag, "0.3.10"}}}
|
, {minirest, {git, "https://github.com/emqx/minirest", {tag, "0.3.11"}}}
|
||||||
, {ecpool, {git, "https://github.com/emqx/ecpool", {tag, "0.5.2"}}}
|
, {ecpool, {git, "https://github.com/emqx/ecpool", {tag, "0.5.2"}}}
|
||||||
, {replayq, {git, "https://github.com/emqx/replayq", {tag, "0.3.4"}}}
|
, {replayq, {git, "https://github.com/emqx/replayq", {tag, "0.3.4"}}}
|
||||||
, {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {branch, "2.0.4"}}}
|
, {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {branch, "2.0.4"}}}
|
||||||
|
|
Loading…
Reference in New Issue