Merge pull request #12334 from zmstone/0116-fix-authz-logging

0116 fix authz logging
This commit is contained in:
Zaiming (Stone) Shi 2024-01-16 16:33:15 +00:00 committed by GitHub
commit 1a02e8edba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -153,7 +153,7 @@ do_authorize(ClientInfo, Action, Topic) ->
case run_hooks('client.authorize', [ClientInfo, Action, Topic], Default) of
AuthzResult = #{result := Result} when Result == allow; Result == deny ->
From = maps:get(from, AuthzResult, unknown),
ok = log_result(ClientInfo, Topic, Action, From, NoMatch),
ok = log_result(ClientInfo, Topic, Action, From, Result),
emqx_hooks:run(
'client.check_authz_complete',
[ClientInfo, Action, Topic, Result, From]

View File

@ -48,12 +48,17 @@ is_list_report_acceptable(_) ->
enrich_report(ReportRaw, Meta) ->
%% clientid and peername always in emqx_conn's process metadata.
%% topic can be put in meta using ?SLOG/3, or put in msg's report by ?SLOG/2
%% topic and username can be put in meta using ?SLOG/3, or put in msg's report by ?SLOG/2
Topic =
case maps:get(topic, Meta, undefined) of
undefined -> maps:get(topic, ReportRaw, undefined);
Topic0 -> Topic0
end,
Username =
case maps:get(username, Meta, undefined) of
undefined -> maps:get(username, ReportRaw, undefined);
Username0 -> Username0
end,
ClientId = maps:get(clientid, Meta, undefined),
Peer = maps:get(peername, Meta, undefined),
MFA = emqx_utils:format_mfal(Meta),
@ -64,8 +69,9 @@ enrich_report(ReportRaw, Meta) ->
({_, undefined}, Acc) -> Acc;
(Item, Acc) -> [Item | Acc]
end,
maps:to_list(maps:without([topic, msg, clientid], ReportRaw)),
maps:to_list(maps:without([topic, msg, clientid, username], ReportRaw)),
[
{username, try_format_unicode(Username)},
{topic, try_format_unicode(Topic)},
{clientid, try_format_unicode(ClientId)},
{peername, Peer},