fix(authz): ensure acl.conf path template rendered

This commit is contained in:
Zaiming (Stone) Shi 2023-05-02 09:04:35 +02:00
parent a3b1664c06
commit c825102bed
2 changed files with 11 additions and 4 deletions

View File

@ -205,7 +205,7 @@ sources(get, _) ->
}, },
AccIn AccIn
) -> ) ->
case file:read_file(Path) of case emqx_authz_file:read_file(Path) of
{ok, Rules} -> {ok, Rules} ->
lists:append(AccIn, [ lists:append(AccIn, [
#{ #{
@ -242,7 +242,7 @@ source(get, #{bindings := #{type := Type}}) ->
Type, Type,
fun fun
(#{<<"type">> := <<"file">>, <<"enable">> := Enable, <<"path">> := Path}) -> (#{<<"type">> := <<"file">>, <<"enable">> := Enable, <<"path">> := Path}) ->
case file:read_file(Path) of case emqx_authz_file:read_file(Path) of
{ok, Rules} -> {ok, Rules} ->
{200, #{ {200, #{
type => file, type => file,

View File

@ -32,14 +32,15 @@
create/1, create/1,
update/1, update/1,
destroy/1, destroy/1,
authorize/4 authorize/4,
read_file/1
]). ]).
description() -> description() ->
"AuthZ with static rules". "AuthZ with static rules".
create(#{path := Path0} = Source) -> create(#{path := Path0} = Source) ->
Path = emqx_schema:naive_env_interpolation(Path0), Path = filename(Path0),
Rules = Rules =
case file:consult(Path) of case file:consult(Path) of
{ok, Terms} -> {ok, Terms} ->
@ -64,3 +65,9 @@ destroy(_Source) -> ok.
authorize(Client, PubSub, Topic, #{annotations := #{rules := Rules}}) -> authorize(Client, PubSub, Topic, #{annotations := #{rules := Rules}}) ->
emqx_authz_rule:matches(Client, PubSub, Topic, Rules). emqx_authz_rule:matches(Client, PubSub, Topic, Rules).
read_file(Path) ->
file:read_file(filename(Path)).
filename(PathMaybeTemplate) ->
emqx_schema:naive_env_interpolation(PathMaybeTemplate).