Skip to content

Commit 37c2682

Browse files
author
Marek Młynarski
committed
BUG#36004507 Summarize/group Router accouts
This commit separates from "deprecatedAuthMethod", a new check "deprecatedRouterAuthMethod". In Upgrade Checker deprecatedAuthMethod will list all user accounts on MySQL Server that have deprecated authentication methods. If MySQL Router does not have a set user account (--account) it will generate one with default authentication method (if --account-create is not set to "never"). This lead to listing many mysql_router* users in deprecatedAuthMethod without a proper explenation why is this happening. From version 8.0.20 this can be fixed by AdminAPI, setuing up a dedicated user account. New check "deprecatedRouterAuthMethod" filters out those accounts in a seperate list, explains what they are, and points to documentation that can help fix it. Change-Id: I111380cec68e8867b56039698727a87175bfad73
1 parent 2cf45df commit 37c2682

File tree

4 files changed

+156
-1
lines changed

4 files changed

+156
-1
lines changed

modules/util/upgrade_check.cc

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,8 @@ class Deprecated_auth_method_check : public Sql_upgrade_check {
20812081
std::vector<std::string>{
20822082
"SELECT CONCAT(user, '@', host), plugin FROM "
20832083
"mysql.user WHERE plugin IN (" +
2084-
deprecated_auth_funcs::get_auth_list() + ");"},
2084+
deprecated_auth_funcs::get_auth_list() +
2085+
") AND user NOT LIKE 'mysql_router%';"},
20852086
Upgrade_issue::WARNING),
20862087
m_target_version(target_ver) {
20872088
m_advice =
@@ -2178,6 +2179,39 @@ bool UNUSED_VARIABLE(register_get_deprecated_default_auth_check) =
21782179
Upgrade_check::Target::SYSTEM_VARIABLES, "8.0.0", "8.1.0", "8.2.0");
21792180
}
21802181

2182+
std::unique_ptr<Sql_upgrade_check>
2183+
Sql_upgrade_check::get_deprecated_router_auth_method_check(
2184+
const Upgrade_check::Upgrade_info &info) {
2185+
return std::make_unique<Sql_upgrade_check>(
2186+
"deprecatedRouterAuthMethod",
2187+
"Check for deprecated or invalid authentication methods in use by MySQL "
2188+
"Router internal accounts.",
2189+
std::vector<std::string>{
2190+
"SELECT CONCAT(user, '@', host), ' - router user "
2191+
"with deprecated authentication method.' FROM "
2192+
"mysql.user WHERE plugin IN (" +
2193+
deprecated_auth_funcs::get_auth_list() +
2194+
") AND user LIKE 'mysql_router%';"},
2195+
info.target_version >= Version(8, 4, 0) ? Upgrade_issue::ERROR
2196+
: Upgrade_issue::WARNING,
2197+
"The following accounts are MySQL Router accounts that use a deprecated "
2198+
"authentication method.\n"
2199+
"Those accounts are automatically created at bootstrap time when the "
2200+
"Router is not instructed to use an existing account. Please upgrade "
2201+
"MySQL Router to the latest version to ensure deprecated authentication "
2202+
"methods are no longer used.\n"
2203+
"Since version 8.0.19 it's also possible to instruct MySQL Router to use "
2204+
"a dedicated account. That account can be created using the AdminAPI.");
2205+
}
2206+
2207+
namespace {
2208+
bool UNUSED_VARIABLE(register_get_deprecated_router_auth_method_check) =
2209+
Upgrade_check::register_check(
2210+
&Sql_upgrade_check::get_deprecated_router_auth_method_check,
2211+
Upgrade_check::Target::AUTHENTICATION_PLUGINS, "8.0.0", "8.1.0",
2212+
"8.2.0");
2213+
}
2214+
21812215
Upgrade_check_config::Upgrade_check_config(const Upgrade_check_options &options)
21822216
: m_output_format(options.output_format) {
21832217
m_upgrade_info.target_version = options.get_target_version();

modules/util/upgrade_check.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ class Sql_upgrade_check : public Upgrade_check {
227227
get_invalid_engine_foreign_key_check();
228228
static std::unique_ptr<Sql_upgrade_check> get_deprecated_auth_method_check(
229229
const Upgrade_check::Upgrade_info &info);
230+
static std::unique_ptr<Sql_upgrade_check>
231+
get_deprecated_router_auth_method_check(
232+
const Upgrade_check::Upgrade_info &info);
230233
static std::unique_ptr<Sql_upgrade_check> get_deprecated_default_auth_check(
231234
const Upgrade_check::Upgrade_info &info);
232235

res/upgrade_checker/upgrade_checker.msg

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,19 @@ https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html#mysql-nutshell-remov
458458

459459
* deprecatedDefaultAuth.docLink
460460

461+
* deprecatedRouterAuthMethod.title
462+
# Check for deprecated or invalid authentication methods in use by MySQL Router internal accounts.
463+
464+
* deprecatedRouterAuthMethod.description
465+
# Warning: The following accounts are MySQL Router accounts that use a deprecated authentication
466+
# method.\n
467+
# Those accounts are automatically created at bootstrap time when the Router is not instructed to
468+
# use an existing account. Please upgrade MySQL Router to the latest version to ensure deprecated
469+
# authentication methods are no longer used.\n
470+
# Since version 8.0.19 it's also possible to instruct MySQL Router to use a dedicated account. That
471+
# account can be created using the AdminAPI.
472+
473+
* deprecatedRouterAuthMethod.docLink
474+
https://dev.mysql.com/doc/mysql-shell/en/configuring-router-user.html\n
475+
https://dev.mysql.com/doc/mysql-router/en/mysqlrouter.html#option_mysqlrouter_account
476+

unittest/modules/upgrade_check_t.cc

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,108 @@ TEST_F(MySQL_upgrade_check_test, deprecated_auth_method_check_fido) {
21412141
ASSERT_NO_THROW(session->execute("drop schema if exists test;"));
21422142
}
21432143

2144+
namespace {
2145+
std::string local_usr(const std::string &user) { return user + "@localhost"; }
2146+
2147+
void drop_user(std::shared_ptr<mysqlshdk::db::ISession> session,
2148+
const std::string &user) {
2149+
ASSERT_NO_THROW(
2150+
session->execute("drop user if exists '" + user + "'@'localhost';"));
2151+
}
2152+
2153+
void add_user(std::shared_ptr<mysqlshdk::db::ISession> session,
2154+
const std::string &user, const std::string &plugin) {
2155+
ASSERT_NO_THROW(session->execute("create user '" + user +
2156+
"'@'localhost' identified with "
2157+
"'" +
2158+
plugin + "';"));
2159+
}
2160+
} // namespace
2161+
2162+
TEST_F(MySQL_upgrade_check_test, deprecated_router_auth_method_check) {
2163+
bool authentication_fido_installed = is_plugin_loaded("authentication_fido");
2164+
bool uninstall_authentication_fido = false;
2165+
if (!authentication_fido_installed) {
2166+
authentication_fido_installed = install_plugin("authentication_fido");
2167+
if (!authentication_fido_installed) {
2168+
SKIP_TEST(
2169+
"This test requires loaded authentication_fido MySQL Server plugin.");
2170+
} else {
2171+
uninstall_authentication_fido = true;
2172+
}
2173+
}
2174+
2175+
const std::string k_usr_sha = "user_sha_auth2";
2176+
const std::string k_usr_native = "usr_native_auth2";
2177+
const std::string k_usr_fido = "user_fido_auth2";
2178+
const std::string k_router_user1 = "mysql_router1_79mwl0xo1ep5";
2179+
const std::string k_router_user2 = "mysql_router335_cb43tc6945rz";
2180+
2181+
const std::string k_auth_sha = "sha256_password";
2182+
const std::string k_auth_native = "mysql_native_password";
2183+
const std::string k_auth_fido = "authentication_fido";
2184+
2185+
shcore::Scoped_callback cleanup([this, uninstall_authentication_fido,
2186+
&k_usr_sha, &k_usr_native, &k_usr_fido,
2187+
&k_router_user1, &k_router_user2]() {
2188+
drop_user(session, k_usr_sha);
2189+
drop_user(session, k_usr_native);
2190+
drop_user(session, k_usr_fido);
2191+
drop_user(session, k_router_user1);
2192+
drop_user(session, k_router_user2);
2193+
if (uninstall_authentication_fido) {
2194+
uninstall_plugin("authentication_fido");
2195+
}
2196+
});
2197+
2198+
PrepareTestDatabase("test");
2199+
2200+
Upgrade_check::Upgrade_info temp_info;
2201+
temp_info.target_version = Version(8, 4, 0);
2202+
auto check =
2203+
Sql_upgrade_check::get_deprecated_router_auth_method_check(temp_info);
2204+
2205+
EXPECT_ISSUES(check.get(), 0);
2206+
2207+
add_user(session, k_usr_sha, k_auth_sha);
2208+
add_user(session, k_usr_native, k_auth_native);
2209+
add_user(session, k_usr_fido, k_auth_fido);
2210+
2211+
EXPECT_ISSUES(check.get(), 0);
2212+
2213+
add_user(session, k_router_user1, k_auth_native);
2214+
add_user(session, k_router_user2, k_auth_sha);
2215+
2216+
EXPECT_ISSUES(check.get(), 2);
2217+
2218+
EXPECT_EQ(issues[0].schema, local_usr(k_router_user1));
2219+
EXPECT_EQ(issues[0].level, Upgrade_issue::Level::ERROR);
2220+
EXPECT_EQ(issues[0].description,
2221+
" - router user with deprecated authentication method.");
2222+
2223+
EXPECT_EQ(issues[1].schema, local_usr(k_router_user2));
2224+
EXPECT_EQ(issues[1].level, Upgrade_issue::Level::ERROR);
2225+
EXPECT_EQ(issues[1].description,
2226+
" - router user with deprecated authentication method.");
2227+
2228+
temp_info.target_version = Version(8, 2, 0);
2229+
check = Sql_upgrade_check::get_deprecated_router_auth_method_check(temp_info);
2230+
2231+
EXPECT_ISSUES(check.get(), 2);
2232+
2233+
EXPECT_EQ(issues[0].schema, local_usr(k_router_user1));
2234+
EXPECT_EQ(issues[0].level, Upgrade_issue::Level::WARNING);
2235+
EXPECT_EQ(issues[0].description,
2236+
" - router user with deprecated authentication method.");
2237+
2238+
EXPECT_EQ(issues[1].schema, local_usr(k_router_user2));
2239+
EXPECT_EQ(issues[1].level, Upgrade_issue::Level::WARNING);
2240+
EXPECT_EQ(issues[1].description,
2241+
" - router user with deprecated authentication method.");
2242+
2243+
ASSERT_NO_THROW(session->execute("drop schema if exists test;"));
2244+
}
2245+
21442246
namespace dep_def_auth_check {
21452247
void set_authentication_policy(std::shared_ptr<mysqlshdk::db::ISession> session,
21462248
const std::string &val) {

0 commit comments

Comments
 (0)