|
@@ -425,7 +425,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 = #{zone := Zone}}) ->
|
|
|
|
|
|
|
+ Channel = #channel{clientinfo = ClientInfo}) ->
|
|
|
case emqx_packet:check(Packet) of
|
|
case emqx_packet:check(Packet) of
|
|
|
ok ->
|
|
ok ->
|
|
|
TopicFilters0 = parse_topic_filters(TopicFilters),
|
|
TopicFilters0 = parse_topic_filters(TopicFilters),
|
|
@@ -434,7 +434,7 @@ handle_in(Packet = ?SUBSCRIBE_PACKET(PacketId, Properties, TopicFilters),
|
|
|
HasAuthzDeny = lists:any(fun({_TopicFilter, ReasonCode}) ->
|
|
HasAuthzDeny = lists:any(fun({_TopicFilter, ReasonCode}) ->
|
|
|
ReasonCode =:= ?RC_NOT_AUTHORIZED
|
|
ReasonCode =:= ?RC_NOT_AUTHORIZED
|
|
|
end, TupleTopicFilters0),
|
|
end, TupleTopicFilters0),
|
|
|
- DenyAction = emqx_config:get_zone_conf(Zone, [authorization, deny_action]),
|
|
|
|
|
|
|
+ DenyAction = emqx:get_config([authorization, deny_action], ignore),
|
|
|
case DenyAction =:= disconnect andalso HasAuthzDeny of
|
|
case DenyAction =:= disconnect andalso HasAuthzDeny of
|
|
|
true -> handle_out(disconnect, ?RC_NOT_AUTHORIZED, Channel);
|
|
true -> handle_out(disconnect, ?RC_NOT_AUTHORIZED, Channel);
|
|
|
false ->
|
|
false ->
|
|
@@ -536,8 +536,7 @@ process_connect(AckProps, Channel = #channel{conninfo = ConnInfo,
|
|
|
%% Process Publish
|
|
%% Process Publish
|
|
|
%%--------------------------------------------------------------------
|
|
%%--------------------------------------------------------------------
|
|
|
|
|
|
|
|
-process_publish(Packet = ?PUBLISH_PACKET(QoS, Topic, PacketId),
|
|
|
|
|
- Channel = #channel{clientinfo = #{zone := Zone}}) ->
|
|
|
|
|
|
|
+process_publish(Packet = ?PUBLISH_PACKET(QoS, Topic, PacketId), Channel) ->
|
|
|
case pipeline([fun check_quota_exceeded/2,
|
|
case pipeline([fun check_quota_exceeded/2,
|
|
|
fun process_alias/2,
|
|
fun process_alias/2,
|
|
|
fun check_pub_alias/2,
|
|
fun check_pub_alias/2,
|
|
@@ -550,7 +549,7 @@ process_publish(Packet = ?PUBLISH_PACKET(QoS, Topic, PacketId),
|
|
|
{error, Rc = ?RC_NOT_AUTHORIZED, NChannel} ->
|
|
{error, Rc = ?RC_NOT_AUTHORIZED, 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(Rc)]),
|
|
[Topic, emqx_reason_codes:text(Rc)]),
|
|
|
- case emqx_config:get_zone_conf(Zone, [authorization, deny_action]) of
|
|
|
|
|
|
|
+ case emqx:get_config([authorization, deny_action], ignore) of
|
|
|
ignore ->
|
|
ignore ->
|
|
|
case QoS of
|
|
case QoS of
|
|
|
?QOS_0 -> {ok, NChannel};
|
|
?QOS_0 -> {ok, NChannel};
|
|
@@ -955,9 +954,8 @@ handle_call({takeover, 'end'}, Channel = #channel{session = Session,
|
|
|
AllPendings = lists:append(Delivers, Pendings),
|
|
AllPendings = lists:append(Delivers, Pendings),
|
|
|
disconnect_and_shutdown(takeovered, AllPendings, Channel);
|
|
disconnect_and_shutdown(takeovered, AllPendings, Channel);
|
|
|
|
|
|
|
|
-handle_call(list_authz_cache, #channel{clientinfo = #{zone := Zone}}
|
|
|
|
|
- = Channel) ->
|
|
|
|
|
- {reply, emqx_authz_cache:list_authz_cache(Zone), Channel};
|
|
|
|
|
|
|
+handle_call(list_authz_cache, Channel) ->
|
|
|
|
|
+ {reply, emqx_authz_cache:list_authz_cache(), Channel};
|
|
|
|
|
|
|
|
handle_call({quota, Policy}, Channel) ->
|
|
handle_call({quota, Policy}, Channel) ->
|
|
|
Zone = info(zone, Channel),
|
|
Zone = info(zone, Channel),
|
|
@@ -1420,8 +1418,7 @@ check_pub_alias(_Packet, _Channel) -> ok.
|
|
|
|
|
|
|
|
check_pub_authz(#mqtt_packet{variable = #mqtt_packet_publish{topic_name = Topic}},
|
|
check_pub_authz(#mqtt_packet{variable = #mqtt_packet_publish{topic_name = Topic}},
|
|
|
#channel{clientinfo = ClientInfo}) ->
|
|
#channel{clientinfo = ClientInfo}) ->
|
|
|
- case is_authz_enabled(ClientInfo) andalso
|
|
|
|
|
- emqx_access_control:authorize(ClientInfo, publish, Topic) of
|
|
|
|
|
|
|
+ case emqx_access_control:authorize(ClientInfo, publish, Topic) of
|
|
|
false -> ok;
|
|
false -> ok;
|
|
|
allow -> ok;
|
|
allow -> ok;
|
|
|
deny -> {error, ?RC_NOT_AUTHORIZED}
|
|
deny -> {error, ?RC_NOT_AUTHORIZED}
|
|
@@ -1454,8 +1451,7 @@ check_sub_authzs([], _Channel, Acc) ->
|
|
|
lists:reverse(Acc).
|
|
lists:reverse(Acc).
|
|
|
|
|
|
|
|
check_sub_authz(TopicFilter, #channel{clientinfo = ClientInfo}) ->
|
|
check_sub_authz(TopicFilter, #channel{clientinfo = ClientInfo}) ->
|
|
|
- case is_authz_enabled(ClientInfo) andalso
|
|
|
|
|
- emqx_access_control:authorize(ClientInfo, subscribe, TopicFilter) of
|
|
|
|
|
|
|
+ case emqx_access_control:authorize(ClientInfo, subscribe, TopicFilter) of
|
|
|
false -> allow;
|
|
false -> allow;
|
|
|
Result -> Result
|
|
Result -> Result
|
|
|
end.
|
|
end.
|
|
@@ -1621,11 +1617,6 @@ maybe_shutdown(Reason, Channel = #channel{conninfo = ConnInfo}) ->
|
|
|
_ -> shutdown(Reason, Channel)
|
|
_ -> shutdown(Reason, Channel)
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
-%%--------------------------------------------------------------------
|
|
|
|
|
-%% Is Authorization enabled?
|
|
|
|
|
-is_authz_enabled(#{zone := Zone, is_superuser := IsSuperuser}) ->
|
|
|
|
|
- (not IsSuperuser) andalso emqx_config:get_zone_conf(Zone, [authorization, enable]).
|
|
|
|
|
-
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
%%--------------------------------------------------------------------
|
|
|
%% Parse Topic Filters
|
|
%% Parse Topic Filters
|
|
|
|
|
|