diff --git a/.github/workflows/build_slim_packages.yaml b/.github/workflows/build_slim_packages.yaml index d18aa18f3..2288e7f5f 100644 --- a/.github/workflows/build_slim_packages.yaml +++ b/.github/workflows/build_slim_packages.yaml @@ -181,7 +181,10 @@ jobs: pkg_name=$(find _packages/${EMQX_NAME} -mindepth 1 -maxdepth 1 -iname \*.zip) unzip -q $pkg_name gsed -i '/emqx_telemetry/d' ./emqx/data/loaded_plugins - ./emqx/bin/emqx start || cat emqx/log/erlang.log.1 + # test with a spaces in path + mv ./emqx "./emqx home/" + cd "./emqx home/" + ./bin/emqx start || cat log/erlang.log.1 ready='no' for i in {1..10}; do if curl -fs 127.0.0.1:18083 > /dev/null; then @@ -192,12 +195,13 @@ jobs: done if [ "$ready" != "yes" ]; then echo "Timed out waiting for emqx to be ready" - cat emqx/log/erlang.log.1 + cat log/erlang.log.1 exit 1 fi - ./emqx/bin/emqx_ctl status - ./emqx/bin/emqx stop - rm -rf emqx + ./bin/emqx_ctl status + ./bin/emqx stop + cd .. + rm -rf "emqx home" - uses: actions/upload-artifact@v2 with: name: macos diff --git a/CHANGES-4.3.md b/CHANGES-4.3.md index 21fecb336..52737724a 100644 --- a/CHANGES-4.3.md +++ b/CHANGES-4.3.md @@ -10,6 +10,10 @@ File format: - One list item per change topic Change log ends with a list of GitHub PRs +## v4.3.22 + +### Minor changes + ## v4.3.21 ### Enhancements @@ -23,13 +27,15 @@ File format: - TLS listener default buffer size to 4KB [#9007](https://github.com/emqx/emqx/pull/9007) Eliminate uncertainty that the buffer size is set by OS default. -- Fix delayed publish inaccurate caused by os time change. [#8908](https://github.com/emqx/emqx/pull/8908) - - Disable authorization for `api/v4/emqx_prometheus` endpoint. [8955](https://github.com/emqx/emqx/pull/8955) - Added a test to prevent a last will testament message to be published when a client is denied connection. [#8894](https://github.com/emqx/emqx/pull/8894) +### Bug fixes + +- Fix delayed publish inaccurate caused by os time change. [#8908](https://github.com/emqx/emqx/pull/8908) + ## v4.3.20 ### Bug fixes diff --git a/apps/emqx_auth_mnesia/test/emqx_acl_mnesia_SUITE.erl b/apps/emqx_auth_mnesia/test/emqx_acl_mnesia_SUITE.erl index 96e66d3c0..7fd18a62b 100644 --- a/apps/emqx_auth_mnesia/test/emqx_acl_mnesia_SUITE.erl +++ b/apps/emqx_auth_mnesia/test/emqx_acl_mnesia_SUITE.erl @@ -20,6 +20,7 @@ -compile(export_all). -include("emqx_auth_mnesia.hrl"). +-include_lib("emqx/include/emqx.hrl"). -include_lib("eunit/include/eunit.hrl"). -include_lib("common_test/include/ct.hrl"). -include_lib("snabbkaffe/include/snabbkaffe.hrl"). @@ -78,15 +79,37 @@ init_per_testcase_migration(_, Config) -> emqx_acl_mnesia_migrator:migrate_records(), Config. +init_per_testcase_other(t_last_will_testament_message_check_acl, Config) -> + OriginalACLNoMatch = application:get_env(emqx, acl_nomatch), + application:set_env(emqx, acl_nomatch, deny), + emqx_mod_acl_internal:unload([]), + %% deny all for this client + ClientID = <<"lwt_client">>, + ok = emqx_acl_mnesia_db:add_acl({clientid, ClientID}, <<"#">>, pubsub, deny), + [ {original_acl_nomatch, OriginalACLNoMatch} + , {clientid, ClientID} + | Config]; +init_per_testcase_other(_TestCase, Config) -> + Config. + init_per_testcase(Case, Config) -> PerTestInitializers = [ fun init_per_testcase_clean/2, fun init_per_testcase_migration/2, - fun init_per_testcase_emqx_hook/2 + fun init_per_testcase_emqx_hook/2, + fun init_per_testcase_other/2 ], lists:foldl(fun(Init, Conf) -> Init(Case, Conf) end, Config, PerTestInitializers). -end_per_testcase(_, Config) -> +end_per_testcase(t_last_will_testament_message_check_acl, Config) -> + emqx:unhook('client.check_acl', fun emqx_acl_mnesia:check_acl/5), + case ?config(original_acl_nomatch, Config) of + {ok, Original} -> application:set_env(emqx, acl_nomatch, Original); + _ -> ok + end, + emqx_mod_acl_internal:load([]), + ok; +end_per_testcase(_TestCase, Config) -> emqx:unhook('client.check_acl', fun emqx_acl_mnesia:check_acl/5), Config. @@ -465,6 +488,35 @@ t_rest_api(_Config) -> {ok, Res3} = request_http_rest_list(["$all"]), ?assertMatch([], get_http_data(Res3)). +%% asserts that we check ACL for the LWT topic before publishing the +%% LWT. +t_last_will_testament_message_check_acl(Config) -> + ClientID = ?config(clientid, Config), + {ok, C} = emqtt:start_link([ + {clientid, ClientID}, + {will_topic, <<"$SYS/lwt">>}, + {will_payload, <<"should not be published">>} + ]), + {ok, _} = emqtt:connect(C), + ok = emqx:subscribe(<<"$SYS/lwt">>), + unlink(C), + ok = snabbkaffe:start_trace(), + {true, {ok, _}} = + ?wait_async_action( + exit(C, kill), + #{?snk_kind := last_will_testament_publish_denied}, + 1_000 + ), + ok = snabbkaffe:stop(), + + receive + {deliver, <<"$SYS/lwt">>, #message{payload = <<"should not be published">>}} -> + error(lwt_should_not_be_published_to_forbidden_topic) + after 1_000 -> + ok + end, + + ok. create_conflicting_records() -> Records = [ diff --git a/apps/emqx_psk_file/include/emqx_psk_file.hrl b/apps/emqx_psk_file/include/emqx_psk_file.hrl new file mode 100644 index 000000000..fe8ed1f94 --- /dev/null +++ b/apps/emqx_psk_file/include/emqx_psk_file.hrl @@ -0,0 +1,25 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2022 EMQ Technologies Co., Ltd. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%%-------------------------------------------------------------------- + +-ifndef(EMQX_PSK_FILE). +-define(EMQX_PSK_FILE, true). + +-define(PSK_FILE_TAB, emqx_psk_file). + +-record(psk_entry, {psk_id :: binary(), + psk_str :: binary()}). + +-endif. diff --git a/apps/emqx_psk_file/src/emqx_psk_file.app.src b/apps/emqx_psk_file/src/emqx_psk_file.app.src index b8a6f08a0..ef18c8b69 100644 --- a/apps/emqx_psk_file/src/emqx_psk_file.app.src +++ b/apps/emqx_psk_file/src/emqx_psk_file.app.src @@ -1,6 +1,6 @@ {application, emqx_psk_file, [{description,"EMQX PSK Plugin from File"}, - {vsn, "4.3.0"}, % strict semver, bump manually! + {vsn, "4.3.1"}, % strict semver, bump manually! {modules,[]}, {registered,[emqx_psk_file_sup]}, {applications,[kernel,stdlib]}, diff --git a/apps/emqx_psk_file/src/emqx_psk_file.appup.src b/apps/emqx_psk_file/src/emqx_psk_file.appup.src new file mode 100644 index 000000000..c782000b5 --- /dev/null +++ b/apps/emqx_psk_file/src/emqx_psk_file.appup.src @@ -0,0 +1,10 @@ +%% -*- mode: erlang -*- +{VSN, + [{"4.3.0", + [{load_module,emqx_psk_file,brutal_purge,soft_purge,[]}, + {load_module,emqx_psk_file_sup,brutal_purge,soft_purge,[]}]} + ], + [{"4.3.0", + [{load_module,emqx_psk_file,brutal_purge,soft_purge,[]}, + {load_module,emqx_psk_file_sup,brutal_purge,soft_purge,[]}]} + ]}. diff --git a/apps/emqx_psk_file/src/emqx_psk_file.erl b/apps/emqx_psk_file/src/emqx_psk_file.erl index b4daee370..e252393c4 100644 --- a/apps/emqx_psk_file/src/emqx_psk_file.erl +++ b/apps/emqx_psk_file/src/emqx_psk_file.erl @@ -16,6 +16,7 @@ -module(emqx_psk_file). +-include("emqx_psk_file.hrl"). -include_lib("emqx/include/emqx.hrl"). -include_lib("emqx/include/logger.hrl"). @@ -26,15 +27,10 @@ %% Hooks functions -export([on_psk_lookup/2]). --define(TAB, ?MODULE). -define(LF, 10). --record(psk_entry, {psk_id :: binary(), - psk_str :: binary()}). - %% Called when the plugin application start load(Env) -> - _ = ets:new(?TAB, [set, named_table, {keypos, #psk_entry.psk_id}]), {ok, PskFile} = file:open(get_value(path, Env), [read, raw, binary, read_ahead]), preload_psks(PskFile, bin(get_value(delimiter, Env))), _ = file:close(PskFile), @@ -45,7 +41,7 @@ unload() -> emqx:unhook('tls_handshake.psk_lookup', fun ?MODULE:on_psk_lookup/2). on_psk_lookup(ClientPSKID, UserState) -> - case ets:lookup(?TAB, ClientPSKID) of + case ets:lookup(?PSK_FILE_TAB, ClientPSKID) of [#psk_entry{psk_str = PskStr}] -> {stop, PskStr}; [] -> @@ -57,7 +53,9 @@ preload_psks(FileHandler, Delimiter) -> {ok, Line} -> case binary:split(Line, Delimiter) of [Key, Rem] -> - ets:insert(?TAB, #psk_entry{psk_id = Key, psk_str = trim_lf(Rem)}), + ets:insert( + ?PSK_FILE_TAB, + #psk_entry{psk_id = Key, psk_str = trim_lf(Rem)}), preload_psks(FileHandler, Delimiter); [Line] -> ?LOG(warning, "[~p] - Invalid line: ~p, delimiter: ~p", [?MODULE, Line, Delimiter]) diff --git a/apps/emqx_psk_file/src/emqx_psk_file_sup.erl b/apps/emqx_psk_file/src/emqx_psk_file_sup.erl index 2e739519c..e643c000a 100644 --- a/apps/emqx_psk_file/src/emqx_psk_file_sup.erl +++ b/apps/emqx_psk_file/src/emqx_psk_file_sup.erl @@ -16,6 +16,8 @@ -module(emqx_psk_file_sup). +-include("emqx_psk_file.hrl"). + -behaviour(supervisor). %% API @@ -25,8 +27,11 @@ -export([init/1]). start_link() -> + _ = ets:new( + ?PSK_FILE_TAB, + [set, named_table, public, {keypos, #psk_entry.psk_id}] + ), supervisor:start_link({local, ?MODULE}, ?MODULE, []). init([]) -> {ok, { {one_for_one, 0, 1}, []} }. - diff --git a/apps/emqx_retainer/src/emqx_retainer.app.src b/apps/emqx_retainer/src/emqx_retainer.app.src index eb5613661..27baf5e88 100644 --- a/apps/emqx_retainer/src/emqx_retainer.app.src +++ b/apps/emqx_retainer/src/emqx_retainer.app.src @@ -1,6 +1,6 @@ {application, emqx_retainer, [{description, "EMQ X Retainer"}, - {vsn, "4.4.2"}, % strict semver, bump manually! + {vsn, "4.4.3"}, % strict semver, bump manually! {modules, []}, {registered, [emqx_retainer_sup]}, {applications, [kernel,stdlib]}, diff --git a/apps/emqx_retainer/src/emqx_retainer_sup.erl b/apps/emqx_retainer/src/emqx_retainer_sup.erl index 2028affb6..ca16a98bb 100644 --- a/apps/emqx_retainer/src/emqx_retainer_sup.erl +++ b/apps/emqx_retainer/src/emqx_retainer_sup.erl @@ -34,6 +34,23 @@ init([Env]) -> type => worker, modules => [emqx_retainer]} || not is_managed_by_modules()]}}. +-ifdef(EMQX_ENTERPRISE). + +is_managed_by_modules() -> + try + case supervisor:get_childspec(emqx_modules_sup, emqx_retainer) of + {ok, _} -> true; + _ -> false + end + catch + exit : {noproc, _} -> + false + end. + +-else. + is_managed_by_modules() -> %% always false for opensource edition false. + +-endif. diff --git a/apps/emqx_retainer/test/emqx_retainer_ct_helper.erl b/apps/emqx_retainer/test/emqx_retainer_ct_helper.erl index fd12a4e01..67f58ec26 100644 --- a/apps/emqx_retainer/test/emqx_retainer_ct_helper.erl +++ b/apps/emqx_retainer/test/emqx_retainer_ct_helper.erl @@ -20,7 +20,9 @@ -export([ensure_start/0, ensure_stop/0]). -ifdef(EMQX_ENTERPRISE). ensure_start() -> + %% for enterprise edition, retainer is started by modules application:stop(emqx_modules), + ensure_stop(), init_conf(), emqx_ct_helpers:start_apps([emqx_retainer]), ok. @@ -29,6 +31,7 @@ ensure_start() -> ensure_start() -> init_conf(), + ensure_stop(), emqx_ct_helpers:start_apps([emqx_retainer]), ok. diff --git a/bin/emqx b/bin/emqx index a27db494d..01f2802cf 100755 --- a/bin/emqx +++ b/bin/emqx @@ -523,6 +523,16 @@ case "$1" in ;; esac +if [ "$IS_BOOT_COMMAND" = 'no' ]; then + # for non-boot commands, inspect vm.