MXS-1167: Skip loading of users for internal services at startup
When MaxScale is being started and the users are loaded, the MySQL authenticator should not load the database users for internal services abstracted as servers. The loading of users at startup for internal services is avoided because the startup is done in a single thread context and the internal services have not yet been started. The delayed loading of users will cause the authentication to fail when the first client connect. This triggers the reloading of the users and the second attempt at authentication will succeed. All of this is hidden from the end user.
This commit is contained in:
parent
0b5d164855
commit
ab4c738c3c
@ -50,7 +50,7 @@
|
||||
FROM mysql.user AS u LEFT JOIN mysql.tables_priv AS t \
|
||||
ON (u.user = t.user AND u.host = t.host) %s"
|
||||
|
||||
static int get_users(SERV_LISTENER *listener);
|
||||
static int get_users(SERV_LISTENER *listener, bool skip_local);
|
||||
static MYSQL *gw_mysql_init(void);
|
||||
static int gw_mysql_set_timeouts(MYSQL* handle);
|
||||
static char *mysql_format_user_entry(void *data);
|
||||
@ -72,10 +72,10 @@ static char* get_new_users_query(const char *server_version, bool include_root)
|
||||
return rval;
|
||||
}
|
||||
|
||||
int replace_mysql_users(SERV_LISTENER *listener)
|
||||
int replace_mysql_users(SERV_LISTENER *listener, bool skip_local)
|
||||
{
|
||||
spinlock_acquire(&listener->lock);
|
||||
int i = get_users(listener);
|
||||
int i = get_users(listener, skip_local);
|
||||
spinlock_release(&listener->lock);
|
||||
return i;
|
||||
}
|
||||
@ -814,7 +814,7 @@ int get_users_from_server(MYSQL *con, SERVER_REF *server, SERVICE *service, SERV
|
||||
* @param users The users table into which to load the users
|
||||
* @return -1 on any error or the number of users inserted
|
||||
*/
|
||||
static int get_users(SERV_LISTENER *listener)
|
||||
static int get_users(SERV_LISTENER *listener, bool skip_local)
|
||||
{
|
||||
char *service_user = NULL;
|
||||
char *service_passwd = NULL;
|
||||
@ -841,6 +841,12 @@ static int get_users(SERV_LISTENER *listener)
|
||||
|
||||
for (server = service->dbref; !service->svc_do_shutdown && server; server = server->next)
|
||||
{
|
||||
if (skip_local && server_is_mxs_service(server->server))
|
||||
{
|
||||
total_users = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
MYSQL *con = gw_mysql_init();
|
||||
if (con)
|
||||
{
|
||||
|
@ -613,8 +613,11 @@ static int mysql_auth_load_users(SERV_LISTENER *port)
|
||||
return MXS_AUTH_LOADUSERS_FATAL;
|
||||
}
|
||||
|
||||
bool skip_local = false;
|
||||
|
||||
if (instance->handle == NULL)
|
||||
{
|
||||
skip_local = true;
|
||||
char path[PATH_MAX];
|
||||
get_database_path(port, path, sizeof(path));
|
||||
if (!open_instance_database(path, &instance->handle))
|
||||
@ -623,7 +626,7 @@ static int mysql_auth_load_users(SERV_LISTENER *port)
|
||||
}
|
||||
}
|
||||
|
||||
int loaded = replace_mysql_users(port);
|
||||
int loaded = replace_mysql_users(port, skip_local);
|
||||
|
||||
if (loaded < 0)
|
||||
{
|
||||
@ -641,7 +644,7 @@ static int mysql_auth_load_users(SERV_LISTENER *port)
|
||||
}
|
||||
}
|
||||
|
||||
if (loaded == 0)
|
||||
if (loaded == 0 && !skip_local)
|
||||
{
|
||||
MXS_WARNING("[%s]: failed to load any user information. Authentication"
|
||||
" will probably fail as a result.", service->name);
|
||||
|
@ -171,11 +171,12 @@ bool dbusers_save(sqlite3 *src, const char *filename);
|
||||
/**
|
||||
* Reload and replace the currently loaded database users
|
||||
*
|
||||
* @param service The current service
|
||||
* @param service The current service
|
||||
* @param skip_local Skip loading of users on local MaxScale services
|
||||
*
|
||||
* @return -1 on any error or the number of users inserted (0 means no users at all)
|
||||
*/
|
||||
int replace_mysql_users(SERV_LISTENER *listener);
|
||||
int replace_mysql_users(SERV_LISTENER *listener, bool skip_local);
|
||||
|
||||
/**
|
||||
* @brief Verify the user has access to the database
|
||||
|
Loading…
x
Reference in New Issue
Block a user