diff --git a/apps/emqx_auth/src/emqx_authz/emqx_authz.erl b/apps/emqx_auth/src/emqx_authz/emqx_authz.erl index 7ca9748a2..e76d52535 100644 --- a/apps/emqx_auth/src/emqx_authz/emqx_authz.erl +++ b/apps/emqx_auth/src/emqx_authz/emqx_authz.erl @@ -480,6 +480,7 @@ authorize_deny( authorize(#{username := Username} = Client, PubSub, Topic, _DefaultResult, Sources) -> case maps:get(is_superuser, Client, false) of true -> + ?tp(authz_skipped, #{reason => client_is_superuser, action => PubSub}), ?TRACE("AUTHZ", "authorization_skipped_as_superuser", #{ username => Username, topic => Topic, diff --git a/apps/emqx_auth/test/emqx_authz/emqx_authz_SUITE.erl b/apps/emqx_auth/test/emqx_authz/emqx_authz_SUITE.erl index 575eb4109..4745d7ec6 100644 --- a/apps/emqx_auth/test/emqx_authz/emqx_authz_SUITE.erl +++ b/apps/emqx_auth/test/emqx_authz/emqx_authz_SUITE.erl @@ -674,5 +674,77 @@ t_publish_last_will_testament_banned_client_connecting(_Config) -> 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) -> lists:foreach(fun application:stop/1, Apps).