Merge pull request #3261 from emqx/master
This commit is contained in:
commit
014e231378
|
@ -29,7 +29,7 @@ cluster.proto_dist = inet_tcp
|
||||||
## - mcast: IP Multicast
|
## - mcast: IP Multicast
|
||||||
## - dns: DNS A Record
|
## - dns: DNS A Record
|
||||||
## - etcd: etcd
|
## - etcd: etcd
|
||||||
## - k8s: Kubernates
|
## - k8s: Kubernetes
|
||||||
##
|
##
|
||||||
## Default: manual
|
## Default: manual
|
||||||
cluster.discovery = manual
|
cluster.discovery = manual
|
||||||
|
@ -141,9 +141,9 @@ cluster.autoclean = 5m
|
||||||
## cluster.etcd.ssl.cacertfile = {{ platform_etc_dir }}/certs/ca.pem
|
## cluster.etcd.ssl.cacertfile = {{ platform_etc_dir }}/certs/ca.pem
|
||||||
|
|
||||||
##--------------------------------------------------------------------
|
##--------------------------------------------------------------------
|
||||||
## Cluster using Kubernates
|
## Cluster using Kubernetes
|
||||||
|
|
||||||
## Kubernates API server list, seperated by ','.
|
## Kubernetes API server list, seperated by ','.
|
||||||
##
|
##
|
||||||
## Value: String
|
## Value: String
|
||||||
## cluster.k8s.apiserver = http://10.110.111.204:8080
|
## cluster.k8s.apiserver = http://10.110.111.204:8080
|
||||||
|
@ -168,7 +168,7 @@ cluster.autoclean = 5m
|
||||||
## Value: String
|
## Value: String
|
||||||
## cluster.k8s.suffix = pod.cluster.local
|
## cluster.k8s.suffix = pod.cluster.local
|
||||||
|
|
||||||
## Kubernates Namespace
|
## Kubernetes Namespace
|
||||||
##
|
##
|
||||||
## Value: String
|
## Value: String
|
||||||
## cluster.k8s.namespace = default
|
## cluster.k8s.namespace = default
|
||||||
|
@ -849,6 +849,11 @@ zone.internal.ignore_loop_deliver = false
|
||||||
## Value: true | false
|
## Value: true | false
|
||||||
zone.internal.strict_mode = false
|
zone.internal.strict_mode = false
|
||||||
|
|
||||||
|
## Allow the zone's clients to bypass authentication step
|
||||||
|
##
|
||||||
|
## Value: true | false
|
||||||
|
zone.internal.bypass_auth_plugins = true
|
||||||
|
|
||||||
##--------------------------------------------------------------------
|
##--------------------------------------------------------------------
|
||||||
## Listeners
|
## Listeners
|
||||||
##--------------------------------------------------------------------
|
##--------------------------------------------------------------------
|
||||||
|
|
|
@ -939,6 +939,12 @@ end}.
|
||||||
{datatype, {enum, [true, false]}}
|
{datatype, {enum, [true, false]}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
|
%% @doc Whether to bypass the authentication step
|
||||||
|
{mapping, "zone.$name.bypass_auth_plugins", "emqx.zones", [
|
||||||
|
{default, false},
|
||||||
|
{datatype, {enum, [true, false]}}
|
||||||
|
]}.
|
||||||
|
|
||||||
{translation, "emqx.zones", fun(Conf) ->
|
{translation, "emqx.zones", fun(Conf) ->
|
||||||
Mapping = fun("publish_limit", Val) ->
|
Mapping = fun("publish_limit", Val) ->
|
||||||
[L, D] = string:tokens(Val, ", "),
|
[L, D] = string:tokens(Val, ", "),
|
||||||
|
|
|
@ -34,11 +34,12 @@
|
||||||
|
|
||||||
-spec(authenticate(emqx_types:clientinfo()) -> {ok, result()} | {error, term()}).
|
-spec(authenticate(emqx_types:clientinfo()) -> {ok, result()} | {error, term()}).
|
||||||
authenticate(ClientInfo = #{zone := Zone}) ->
|
authenticate(ClientInfo = #{zone := Zone}) ->
|
||||||
case run_hooks('client.authenticate', [ClientInfo], default_auth_result(Zone)) of
|
AuthResult = default_auth_result(Zone),
|
||||||
Result = #{auth_result := success} ->
|
case emqx_zone:get_env(Zone, bypass_auth_plugins, false) of
|
||||||
{ok, Result};
|
true ->
|
||||||
Result ->
|
return_auth_result(AuthResult);
|
||||||
{error, maps:get(auth_result, Result, unknown_error)}
|
false ->
|
||||||
|
return_auth_result(run_hooks('client.authenticate', [ClientInfo], AuthResult))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @doc Check ACL
|
%% @doc Check ACL
|
||||||
|
@ -81,3 +82,8 @@ default_auth_result(Zone) ->
|
||||||
run_hooks(Name, Args, Acc) ->
|
run_hooks(Name, Args, Acc) ->
|
||||||
ok = emqx_metrics:inc(Name), emqx_hooks:run_fold(Name, Args, Acc).
|
ok = emqx_metrics:inc(Name), emqx_hooks:run_fold(Name, Args, Acc).
|
||||||
|
|
||||||
|
-compile({inline, [return_auth_result/1]}).
|
||||||
|
return_auth_result(Result = #{auth_result := success}) ->
|
||||||
|
{ok, Result};
|
||||||
|
return_auth_result(Result) ->
|
||||||
|
{error, maps:get(auth_result, Result, unknown_error)}.
|
||||||
|
|
|
@ -273,6 +273,8 @@ discard_session(ClientId) when is_binary(ClientId) ->
|
||||||
try
|
try
|
||||||
discard_session(ClientId, ChanPid)
|
discard_session(ClientId, ChanPid)
|
||||||
catch
|
catch
|
||||||
|
_:{noproc,_}:_Stk -> ok;
|
||||||
|
_:{{shutdown,_},_}:_Stk -> ok;
|
||||||
_:Error:_Stk ->
|
_:Error:_Stk ->
|
||||||
?LOG(error, "Failed to discard ~p: ~p", [ChanPid, Error])
|
?LOG(error, "Failed to discard ~p: ~p", [ChanPid, Error])
|
||||||
end
|
end
|
||||||
|
|
|
@ -103,7 +103,7 @@ safe_decode(Json, Opts) ->
|
||||||
, from_ejson/1
|
, from_ejson/1
|
||||||
]}).
|
]}).
|
||||||
|
|
||||||
to_ejson([[{_,_}]|_] = L) ->
|
to_ejson([[{_,_}|_]|_] = L) ->
|
||||||
[to_ejson(E) || E <- L];
|
[to_ejson(E) || E <- L];
|
||||||
to_ejson([{_, _}|_] = L) ->
|
to_ejson([{_, _}|_] = L) ->
|
||||||
lists:foldl(
|
lists:foldl(
|
||||||
|
|
|
@ -52,6 +52,20 @@ t_check_acl(_) ->
|
||||||
t_reload_acl(_) ->
|
t_reload_acl(_) ->
|
||||||
?assertEqual(ok, emqx_access_control:reload_acl()).
|
?assertEqual(ok, emqx_access_control:reload_acl()).
|
||||||
|
|
||||||
|
t_bypass_auth_plugins(_) ->
|
||||||
|
AuthFun = fun(#{zone := bypass_zone}, AuthRes) ->
|
||||||
|
{stop, AuthRes#{auth_result => password_error}};
|
||||||
|
(#{zone := _}, AuthRes) ->
|
||||||
|
{stop, AuthRes#{auth_result => success}}
|
||||||
|
end,
|
||||||
|
ClientInfo = clientinfo(),
|
||||||
|
emqx_zone:set_env(bypass_zone, allow_anonymous, true),
|
||||||
|
emqx_zone:set_env(zone, allow_anonymous, false),
|
||||||
|
emqx_zone:set_env(bypass_zone, bypass_auth_plugins, true),
|
||||||
|
emqx:hook('client.authenticate', AuthFun, []),
|
||||||
|
?assertMatch({ok, _}, emqx_access_control:authenticate(ClientInfo#{zone => bypass_zone})),
|
||||||
|
?assertMatch({ok, _}, emqx_access_control:authenticate(ClientInfo)).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Helper functions
|
%% Helper functions
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -68,6 +68,11 @@ t_decode_encode(_) ->
|
||||||
[{<<"foo">>, <<"bar">>}] = decode(encode({[{<<"foo">>, <<"bar">>}]})),
|
[{<<"foo">>, <<"bar">>}] = decode(encode({[{<<"foo">>, <<"bar">>}]})),
|
||||||
[{<<"foo">>, <<"bar">>}] = decode(encode([{<<"foo">>, <<"bar">>}])),
|
[{<<"foo">>, <<"bar">>}] = decode(encode([{<<"foo">>, <<"bar">>}])),
|
||||||
[[{<<"foo">>, <<"bar">>}]] = decode(encode([[{<<"foo">>, <<"bar">>}]])),
|
[[{<<"foo">>, <<"bar">>}]] = decode(encode([[{<<"foo">>, <<"bar">>}]])),
|
||||||
|
[[{<<"foo">>, <<"bar">>},
|
||||||
|
{<<"a">>, <<"b">>}],
|
||||||
|
[{<<"x">>, <<"y">>}]] = decode(encode([[{<<"foo">>, <<"bar">>},
|
||||||
|
{<<"a">>, <<"b">>}],
|
||||||
|
[{<<"x">>, <<"y">>}]])),
|
||||||
#{<<"foo">> := <<"bar">>} = decode(encode(#{<<"foo">> => <<"bar">>}), [return_maps]),
|
#{<<"foo">> := <<"bar">>} = decode(encode(#{<<"foo">> => <<"bar">>}), [return_maps]),
|
||||||
JsonText = <<"{\"bool\":true,\"int\":10,\"foo\":\"bar\"}">>,
|
JsonText = <<"{\"bool\":true,\"int\":10,\"foo\":\"bar\"}">>,
|
||||||
JsonMaps = #{<<"bool">> => true,
|
JsonMaps = #{<<"bool">> => true,
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
-module(emqx_logger_formatter_SUITE).
|
-module(emqx_logger_formatter_SUITE).
|
||||||
|
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
|
-compile(nowarn_export_all).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
|
Loading…
Reference in New Issue