Fix `acl_deny_action`
This commit is contained in:
parent
750b088922
commit
caed16f57b
|
@ -287,7 +287,7 @@ handle_in(?PUBCOMP_PACKET(PacketId, _ReasonCode), Channel = #channel{session = S
|
||||||
end;
|
end;
|
||||||
|
|
||||||
handle_in(Packet = ?SUBSCRIBE_PACKET(PacketId, Properties, TopicFilters),
|
handle_in(Packet = ?SUBSCRIBE_PACKET(PacketId, Properties, TopicFilters),
|
||||||
Channel = #channel{clientinfo = ClientInfo}) ->
|
Channel = #channel{clientinfo = ClientInfo = #{zone := Zone}}) ->
|
||||||
case emqx_packet:check(Packet) of
|
case emqx_packet:check(Packet) of
|
||||||
ok -> TopicFilters1 = parse_topic_filters(TopicFilters),
|
ok -> TopicFilters1 = parse_topic_filters(TopicFilters),
|
||||||
TopicFilters2 = enrich_subid(Properties, TopicFilters1),
|
TopicFilters2 = enrich_subid(Properties, TopicFilters1),
|
||||||
|
@ -296,7 +296,15 @@ handle_in(Packet = ?SUBSCRIBE_PACKET(PacketId, Properties, TopicFilters),
|
||||||
TopicFilters2
|
TopicFilters2
|
||||||
),
|
),
|
||||||
{ReasonCodes, NChannel} = process_subscribe(TopicFilters3, Channel),
|
{ReasonCodes, NChannel} = process_subscribe(TopicFilters3, Channel),
|
||||||
handle_out(suback, {PacketId, ReasonCodes}, NChannel);
|
case emqx_zone:get_env(Zone, acl_deny_action, ignore) =:= disconnect andalso
|
||||||
|
lists:any(fun(ReasonCode) ->
|
||||||
|
ReasonCode =:= ?RC_NOT_AUTHORIZED
|
||||||
|
end, ReasonCodes) of
|
||||||
|
true ->
|
||||||
|
handle_out(disconnect, ?RC_NOT_AUTHORIZED, NChannel);
|
||||||
|
false ->
|
||||||
|
handle_out(suback, {PacketId, ReasonCodes}, NChannel)
|
||||||
|
end;
|
||||||
{error, ReasonCode} ->
|
{error, ReasonCode} ->
|
||||||
handle_out(disconnect, ReasonCode, Channel)
|
handle_out(disconnect, ReasonCode, Channel)
|
||||||
end;
|
end;
|
||||||
|
@ -373,7 +381,8 @@ process_connect(ConnPkt = #mqtt_packet_connect{clean_start = CleanStart},
|
||||||
%% Process Publish
|
%% Process Publish
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
process_publish(Packet = ?PUBLISH_PACKET(_QoS, Topic, PacketId), Channel) ->
|
process_publish(Packet = ?PUBLISH_PACKET(QoS, Topic, PacketId),
|
||||||
|
Channel = #channel{clientinfo = #{zone := Zone}}) ->
|
||||||
case pipeline([fun process_alias/2,
|
case pipeline([fun process_alias/2,
|
||||||
fun check_pub_alias/2,
|
fun check_pub_alias/2,
|
||||||
fun check_pub_acl/2,
|
fun check_pub_acl/2,
|
||||||
|
@ -382,6 +391,19 @@ process_publish(Packet = ?PUBLISH_PACKET(_QoS, Topic, PacketId), Channel) ->
|
||||||
{ok, NPacket, NChannel} ->
|
{ok, NPacket, NChannel} ->
|
||||||
Msg = packet_to_message(NPacket, NChannel),
|
Msg = packet_to_message(NPacket, NChannel),
|
||||||
do_publish(PacketId, Msg, NChannel);
|
do_publish(PacketId, Msg, NChannel);
|
||||||
|
{error, ReasonCode, NChannel} when ReasonCode =:= ?RC_NOT_AUTHORIZED ->
|
||||||
|
?LOG(warning, "Cannot publish message to ~s due to ~s.",
|
||||||
|
[Topic, emqx_reason_codes:text(ReasonCode)]),
|
||||||
|
case emqx_zone:get_env(Zone, acl_deny_action, ignore) of
|
||||||
|
ignore ->
|
||||||
|
case QoS of
|
||||||
|
?QOS_0 -> {ok, NChannel};
|
||||||
|
_ ->
|
||||||
|
handle_out(puback, {PacketId, ReasonCode}, NChannel)
|
||||||
|
end;
|
||||||
|
disconnect ->
|
||||||
|
handle_out(disconnect, ReasonCode, NChannel)
|
||||||
|
end;
|
||||||
{error, ReasonCode, NChannel} ->
|
{error, ReasonCode, NChannel} ->
|
||||||
?LOG(warning, "Cannot publish message to ~s due to ~s.",
|
?LOG(warning, "Cannot publish message to ~s due to ~s.",
|
||||||
[Topic, emqx_reason_codes:text(ReasonCode)]),
|
[Topic, emqx_reason_codes:text(ReasonCode)]),
|
||||||
|
|
|
@ -478,8 +478,9 @@ format_variable(#mqtt_packet_publish{topic_name = TopicName,
|
||||||
packet_id = PacketId}) ->
|
packet_id = PacketId}) ->
|
||||||
io_lib:format("Topic=~s, PacketId=~p", [TopicName, PacketId]);
|
io_lib:format("Topic=~s, PacketId=~p", [TopicName, PacketId]);
|
||||||
|
|
||||||
format_variable(#mqtt_packet_puback{packet_id = PacketId}) ->
|
format_variable(#mqtt_packet_puback{packet_id = PacketId,
|
||||||
io_lib:format("PacketId=~p", [PacketId]);
|
reason_code = ReasonCode}) ->
|
||||||
|
io_lib:format("PacketId=~p, ReasonCode=~p", [PacketId, ReasonCode]);
|
||||||
|
|
||||||
format_variable(#mqtt_packet_subscribe{packet_id = PacketId,
|
format_variable(#mqtt_packet_subscribe{packet_id = PacketId,
|
||||||
topic_filters = TopicFilters}) ->
|
topic_filters = TopicFilters}) ->
|
||||||
|
|
Loading…
Reference in New Issue