Merge pull request #12349 from zmstone/0118-fix-authz-cache-excludes-type

0118 fix authz cache excludes type
This commit is contained in:
Zaiming (Stone) Shi 2024-01-18 10:32:38 +00:00 committed by GitHub
commit 6b462a9100
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 13 additions and 5 deletions

View File

@ -135,6 +135,7 @@ is_username_defined(_) -> false.
check_authorization_cache(ClientInfo, Action, Topic) ->
case emqx_authz_cache:get_authz_cache(Action, Topic) of
not_found ->
inc_authz_metrics(cache_miss),
AuthzResult = do_authorize(ClientInfo, Action, Topic),
emqx_authz_cache:put_authz_cache(Action, Topic, AuthzResult),
AuthzResult;
@ -219,7 +220,9 @@ inc_authz_metrics(allow) ->
inc_authz_metrics(deny) ->
emqx_metrics:inc('authorization.deny');
inc_authz_metrics(cache_hit) ->
emqx_metrics:inc('authorization.cache_hit').
emqx_metrics:inc('authorization.cache_hit');
inc_authz_metrics(cache_miss) ->
emqx_metrics:inc('authorization.cache_miss').
inc_authn_metrics(error) ->
emqx_metrics:inc('authentication.failure');

View File

@ -56,7 +56,7 @@ drain_k() -> {?MODULE, drain_timestamp}.
-spec is_enabled(emqx_types:topic()) -> boolean().
is_enabled(Topic) ->
case emqx:get_config([authorization, cache]) of
#{enable := true, excludes := Filters} ->
#{enable := true, excludes := Filters} when Filters =/= [] ->
not is_excluded(Topic, Filters);
#{enable := IsEnabled} ->
IsEnabled

View File

@ -258,7 +258,8 @@
-define(STASTS_ACL_METRICS, [
{counter, 'authorization.allow'},
{counter, 'authorization.deny'},
{counter, 'authorization.cache_hit'}
{counter, 'authorization.cache_hit'},
{counter, 'authorization.cache_miss'}
]).
%% Statistic metrics for auth checking
@ -702,6 +703,7 @@ reserved_idx('session.terminated') -> 224;
reserved_idx('authorization.allow') -> 300;
reserved_idx('authorization.deny') -> 301;
reserved_idx('authorization.cache_hit') -> 302;
reserved_idx('authorization.cache_miss') -> 303;
reserved_idx('authentication.success') -> 310;
reserved_idx('authentication.success.anonymous') -> 311;
reserved_idx('authentication.failure') -> 312;

View File

@ -468,7 +468,7 @@ fields(authz_cache) ->
}
)},
{excludes,
sc(hoconsc:array(string()), #{
sc(hoconsc:array(binary()), #{
default => [],
desc => ?DESC(fields_authz_cache_excludes)
})}

View File

@ -2,7 +2,7 @@
{application, emqx_prometheus, [
{description, "Prometheus for EMQX"},
% strict semver, bump manually!
{vsn, "5.0.18"},
{vsn, "5.0.19"},
{modules, []},
{registered, [emqx_prometheus_sup]},
{applications, [kernel, stdlib, prometheus, emqx, emqx_management]},

View File

@ -486,6 +486,8 @@ emqx_collect(emqx_authorization_deny, Stats) ->
counter_metric(?C('authorization.deny', Stats));
emqx_collect(emqx_authorization_cache_hit, Stats) ->
counter_metric(?C('authorization.cache_hit', Stats));
emqx_collect(emqx_authorization_cache_miss, Stats) ->
counter_metric(?C('authorization.cache_miss', Stats));
emqx_collect(emqx_authorization_superuser, Stats) ->
counter_metric(?C('authorization.superuser', Stats));
emqx_collect(emqx_authorization_nomatch, Stats) ->
@ -591,6 +593,7 @@ emqx_metrics_acl() ->
emqx_authorization_allow,
emqx_authorization_deny,
emqx_authorization_cache_hit,
emqx_authorization_cache_miss,
emqx_authorization_superuser,
emqx_authorization_nomatch,
emqx_authorization_matched_allow,