Merge pull request #13534 from JimMoen/feat-add-superuser-skip-authz
feat: add authz skipped trace for superuser
This commit is contained in:
commit
4065158be7
|
@ -477,9 +477,15 @@ authorize_deny(
|
||||||
sources()
|
sources()
|
||||||
) ->
|
) ->
|
||||||
authz_result().
|
authz_result().
|
||||||
authorize(Client, PubSub, Topic, _DefaultResult, Sources) ->
|
authorize(#{username := Username} = Client, PubSub, Topic, _DefaultResult, Sources) ->
|
||||||
case maps:get(is_superuser, Client, false) of
|
case maps:get(is_superuser, Client, false) of
|
||||||
true ->
|
true ->
|
||||||
|
?tp(authz_skipped, #{reason => client_is_superuser, action => PubSub}),
|
||||||
|
?TRACE("AUTHZ", "authorization_skipped_as_superuser", #{
|
||||||
|
username => Username,
|
||||||
|
topic => Topic,
|
||||||
|
action => emqx_access_control:format_action(PubSub)
|
||||||
|
}),
|
||||||
emqx_metrics:inc(?METRIC_SUPERUSER),
|
emqx_metrics:inc(?METRIC_SUPERUSER),
|
||||||
{stop, #{result => allow, from => superuser}};
|
{stop, #{result => allow, from => superuser}};
|
||||||
false ->
|
false ->
|
||||||
|
|
|
@ -674,5 +674,77 @@ t_publish_last_will_testament_banned_client_connecting(_Config) ->
|
||||||
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
t_sikpped_as_superuser(_Config) ->
|
||||||
|
ClientInfo = #{
|
||||||
|
clientid => <<"clientid">>,
|
||||||
|
username => <<"username">>,
|
||||||
|
peerhost => {127, 0, 0, 1},
|
||||||
|
zone => default,
|
||||||
|
listener => {tcp, default},
|
||||||
|
is_superuser => true
|
||||||
|
},
|
||||||
|
?check_trace(
|
||||||
|
begin
|
||||||
|
?assertEqual(
|
||||||
|
allow,
|
||||||
|
emqx_access_control:authorize(ClientInfo, ?AUTHZ_PUBLISH(?QOS_0), <<"p/t/0">>)
|
||||||
|
),
|
||||||
|
?assertEqual(
|
||||||
|
allow,
|
||||||
|
emqx_access_control:authorize(ClientInfo, ?AUTHZ_PUBLISH(?QOS_1), <<"p/t/1">>)
|
||||||
|
),
|
||||||
|
?assertEqual(
|
||||||
|
allow,
|
||||||
|
emqx_access_control:authorize(ClientInfo, ?AUTHZ_PUBLISH(?QOS_2), <<"p/t/2">>)
|
||||||
|
),
|
||||||
|
?assertEqual(
|
||||||
|
allow,
|
||||||
|
emqx_access_control:authorize(ClientInfo, ?AUTHZ_SUBSCRIBE(?QOS_0), <<"s/t/0">>)
|
||||||
|
),
|
||||||
|
?assertEqual(
|
||||||
|
allow,
|
||||||
|
emqx_access_control:authorize(ClientInfo, ?AUTHZ_SUBSCRIBE(?QOS_1), <<"s/t/1">>)
|
||||||
|
),
|
||||||
|
?assertEqual(
|
||||||
|
allow,
|
||||||
|
emqx_access_control:authorize(ClientInfo, ?AUTHZ_SUBSCRIBE(?QOS_2), <<"s/t/2">>)
|
||||||
|
)
|
||||||
|
end,
|
||||||
|
fun(Trace) ->
|
||||||
|
?assertMatch(
|
||||||
|
[
|
||||||
|
#{
|
||||||
|
reason := client_is_superuser,
|
||||||
|
action := #{qos := ?QOS_0, action_type := publish}
|
||||||
|
},
|
||||||
|
#{
|
||||||
|
reason := client_is_superuser,
|
||||||
|
action := #{qos := ?QOS_1, action_type := publish}
|
||||||
|
},
|
||||||
|
#{
|
||||||
|
reason := client_is_superuser,
|
||||||
|
action := #{qos := ?QOS_2, action_type := publish}
|
||||||
|
},
|
||||||
|
#{
|
||||||
|
reason := client_is_superuser,
|
||||||
|
action := #{qos := ?QOS_0, action_type := subscribe}
|
||||||
|
},
|
||||||
|
#{
|
||||||
|
reason := client_is_superuser,
|
||||||
|
action := #{qos := ?QOS_1, action_type := subscribe}
|
||||||
|
},
|
||||||
|
#{
|
||||||
|
reason := client_is_superuser,
|
||||||
|
action := #{qos := ?QOS_2, action_type := subscribe}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
?of_kind(authz_skipped, Trace)
|
||||||
|
),
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
),
|
||||||
|
|
||||||
|
ok = snabbkaffe:stop().
|
||||||
|
|
||||||
stop_apps(Apps) ->
|
stop_apps(Apps) ->
|
||||||
lists:foreach(fun application:stop/1, Apps).
|
lists:foreach(fun application:stop/1, Apps).
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add trace logging when superuser skipped authz check.
|
Loading…
Reference in New Issue