mirror of
https://github.com/MariaDB/server.git
synced 2025-07-20 10:24:14 +03:00
MDEV-12484 Enable unix socket authentication by default
Change the default authentication for root@localhost to IDENTIFIED VIA mysql_native_password USING 'invalid' OR unix_socket which provides secure passwordless login, while still allowing SET PASSWORD to work as expected. Also create a second all-privilege account for the user that owns datadir (and thus has full access to the data anyway). Compile unix_socket plugin statically into the server.
This commit is contained in:
@ -98,17 +98,20 @@ ELSEIF(RPM)
|
|||||||
SET(CHECKMODULE /usr/bin/checkmodule CACHE STRING "")
|
SET(CHECKMODULE /usr/bin/checkmodule CACHE STRING "")
|
||||||
SET(SEMODULE_PACKAGE /usr/bin/semodule_package CACHE STRING "")
|
SET(SEMODULE_PACKAGE /usr/bin/semodule_package CACHE STRING "")
|
||||||
SET(WITH_LIBARCHIVE ON CACHE STRING "")
|
SET(WITH_LIBARCHIVE ON CACHE STRING "")
|
||||||
|
SET(PLUGIN_AUTH_SOCKET YES)
|
||||||
ELSEIF(DEB)
|
ELSEIF(DEB)
|
||||||
SET(WITH_SSL system CACHE STRING "")
|
SET(WITH_SSL system CACHE STRING "")
|
||||||
SET(WITH_ZLIB system CACHE STRING "")
|
SET(WITH_ZLIB system CACHE STRING "")
|
||||||
SET(WITH_LIBWRAP ON)
|
SET(WITH_LIBWRAP ON)
|
||||||
SET(HAVE_EMBEDDED_PRIVILEGE_CONTROL ON)
|
SET(HAVE_EMBEDDED_PRIVILEGE_CONTROL ON)
|
||||||
SET(WITH_LIBARCHIVE ON CACHE STRING "")
|
SET(WITH_LIBARCHIVE ON CACHE STRING "")
|
||||||
|
SET(PLUGIN_AUTH_SOCKET YES)
|
||||||
ELSE()
|
ELSE()
|
||||||
SET(WITH_SSL bundled CACHE STRING "")
|
SET(WITH_SSL bundled CACHE STRING "")
|
||||||
SET(WITH_ZLIB bundled CACHE STRING "")
|
SET(WITH_ZLIB bundled CACHE STRING "")
|
||||||
SET(WITH_JEMALLOC static CACHE STRING "")
|
SET(WITH_JEMALLOC static CACHE STRING "")
|
||||||
SET(WITH_LIBARCHIVE STATIC CACHE STRING "")
|
SET(WITH_LIBARCHIVE STATIC CACHE STRING "")
|
||||||
|
SET(PLUGIN_AUTH_SOCKET STATIC)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
IF(NOT COMPILATION_COMMENT)
|
IF(NOT COMPILATION_COMMENT)
|
||||||
|
@ -8,6 +8,6 @@ flush privileges;
|
|||||||
connect(localhost,USER,,test,MASTER_PORT,MASTER_SOCKET);
|
connect(localhost,USER,,test,MASTER_PORT,MASTER_SOCKET);
|
||||||
ERROR 28000: Access denied for user 'USER'@'localhost'
|
ERROR 28000: Access denied for user 'USER'@'localhost'
|
||||||
ERROR 28000: Access denied for user 'USER'@'localhost'
|
ERROR 28000: Access denied for user 'USER'@'localhost'
|
||||||
update mysql.global_priv set priv=json_remove(priv, '$.plugin');
|
update mysql.global_priv set priv=json_compact(json_remove(priv, '$.plugin'));
|
||||||
flush privileges;
|
flush privileges;
|
||||||
uninstall plugin unix_socket;
|
uninstall plugin unix_socket;
|
||||||
|
@ -36,7 +36,7 @@ connect (fail,localhost,$USER);
|
|||||||
--error ER_ACCESS_DENIED_NO_PASSWORD_ERROR
|
--error ER_ACCESS_DENIED_NO_PASSWORD_ERROR
|
||||||
change_user $USER;
|
change_user $USER;
|
||||||
|
|
||||||
update mysql.global_priv set priv=json_remove(priv, '$.plugin');
|
update mysql.global_priv set priv=json_compact(json_remove(priv, '$.plugin'));
|
||||||
flush privileges;
|
flush privileges;
|
||||||
uninstall plugin unix_socket;
|
uninstall plugin unix_socket;
|
||||||
|
|
||||||
|
@ -63,6 +63,6 @@ test
|
|||||||
Phase 7/7: Running 'FLUSH PRIVILEGES'
|
Phase 7/7: Running 'FLUSH PRIVILEGES'
|
||||||
OK
|
OK
|
||||||
connect con1,localhost,root,foo,,,;
|
connect con1,localhost,root,foo,,,;
|
||||||
update mysql.global_priv set priv=json_remove(priv, '$.plugin', '$.authentication_string');
|
update mysql.global_priv set priv=json_compact(json_remove(priv, '$.plugin', '$.authentication_string'));
|
||||||
flush privileges;
|
flush privileges;
|
||||||
set global event_scheduler=OFF;
|
set global event_scheduler=OFF;
|
||||||
|
@ -17,7 +17,7 @@ update mysql.global_priv set priv=json_set(priv, '$.plugin', 'mysql_native_passw
|
|||||||
|
|
||||||
connect(con1,localhost,root,foo,,,);
|
connect(con1,localhost,root,foo,,,);
|
||||||
|
|
||||||
update mysql.global_priv set priv=json_remove(priv, '$.plugin', '$.authentication_string');
|
update mysql.global_priv set priv=json_compact(json_remove(priv, '$.plugin', '$.authentication_string'));
|
||||||
flush privileges;
|
flush privileges;
|
||||||
# Load event table
|
# Load event table
|
||||||
set global event_scheduler=OFF;
|
set global event_scheduler=OFF;
|
||||||
|
@ -78,4 +78,4 @@ drop role role3;
|
|||||||
drop role role2;
|
drop role role2;
|
||||||
drop role role1;
|
drop role role1;
|
||||||
drop user foo;
|
drop user foo;
|
||||||
update mysql.global_priv set priv=json_remove(priv, '$.default_role');
|
update mysql.global_priv set priv=json_compact(json_remove(priv, '$.default_role'));
|
||||||
|
@ -59,4 +59,4 @@ drop role role3;
|
|||||||
drop role role2;
|
drop role role2;
|
||||||
drop role role1;
|
drop role role1;
|
||||||
drop user foo;
|
drop user foo;
|
||||||
update mysql.global_priv set priv=json_remove(priv, '$.default_role');
|
update mysql.global_priv set priv=json_compact(json_remove(priv, '$.default_role'));
|
||||||
|
@ -37,8 +37,8 @@ force=0
|
|||||||
in_rpm=0
|
in_rpm=0
|
||||||
ip_only=0
|
ip_only=0
|
||||||
cross_bootstrap=0
|
cross_bootstrap=0
|
||||||
auth_root_authentication_method=normal
|
auth_root_authentication_method=socket
|
||||||
auth_root_socket_user='root'
|
auth_root_socket_user=""
|
||||||
skip_test_db=0
|
skip_test_db=0
|
||||||
|
|
||||||
usage()
|
usage()
|
||||||
@ -46,17 +46,17 @@ usage()
|
|||||||
cat <<EOF
|
cat <<EOF
|
||||||
Usage: $0 [OPTIONS]
|
Usage: $0 [OPTIONS]
|
||||||
--auth-root-authentication-method=normal|socket
|
--auth-root-authentication-method=normal|socket
|
||||||
Chooses the authentication method for the created initial
|
Chooses the authentication method for the created
|
||||||
root user. The default is 'normal' to creates a root user
|
initial root user. The historical behavior is 'normal'
|
||||||
that can login without password, which can be insecure.
|
to creates a root user that can login without password,
|
||||||
The alternative 'socket' allows only the system root user
|
which can be insecure. The default behavior 'socket'
|
||||||
to login as MariaDB root; this requires the unix socket
|
sets an invalid root password but allows the system root
|
||||||
authentication plugin.
|
user to login as MariaDB root without a password.
|
||||||
--auth-root-socket-user=user
|
--auth-root-socket-user=user
|
||||||
Used with --auth-root-authentication-method=socket. It
|
Used with --auth-root-authentication-method=socket. It
|
||||||
specifies the name of the MariaDB root account, as well
|
specifies the name of the second MariaDB root account,
|
||||||
as of the system account allowed to access it. Defaults
|
as well as of the system account allowed to access it.
|
||||||
to 'root'.
|
Defaults to the value of --user.
|
||||||
--basedir=path The path to the MariaDB installation directory.
|
--basedir=path The path to the MariaDB installation directory.
|
||||||
--builddir=path If using --srcdir with out-of-directory builds, you
|
--builddir=path If using --srcdir with out-of-directory builds, you
|
||||||
will need to set this to the location of the build
|
will need to set this to the location of the build
|
||||||
@ -505,6 +505,11 @@ cat_sql()
|
|||||||
{
|
{
|
||||||
echo "use mysql;"
|
echo "use mysql;"
|
||||||
|
|
||||||
|
# Use $auth_root_socket_user if explicitly specified.
|
||||||
|
# Otherwise use the owner of datadir - ${user:-$USER}
|
||||||
|
# Use 'root' as a fallback
|
||||||
|
auth_root_socket_user=${auth_root_socket_user:-${user:-${USER:-root}}}
|
||||||
|
|
||||||
case "$auth_root_authentication_method" in
|
case "$auth_root_authentication_method" in
|
||||||
normal)
|
normal)
|
||||||
echo "SET @auth_root_socket=NULL;"
|
echo "SET @auth_root_socket=NULL;"
|
||||||
|
@ -25,7 +25,9 @@
|
|||||||
-- add escape character in front of wildcard character to convert "_" or "%" to
|
-- add escape character in front of wildcard character to convert "_" or "%" to
|
||||||
-- a plain character
|
-- a plain character
|
||||||
SELECT LOWER( REPLACE((SELECT REPLACE(@@hostname,'_','\_')),'%','\%') )INTO @current_hostname;
|
SELECT LOWER( REPLACE((SELECT REPLACE(@@hostname,'_','\_')),'%','\%') )INTO @current_hostname;
|
||||||
SELECT json_object('access',cast(-1 as unsigned)) INTO @all_privileges;
|
SELECT '{"access":18446744073709551615}' INTO @all_privileges;
|
||||||
|
SELECT '{"access":18446744073709551615,"plugin":"mysql_native_password","authentication_string":"invalid","auth_or":[{},{"plugin":"unix_socket"}]}' into @all_with_auth;
|
||||||
|
|
||||||
|
|
||||||
-- Fill "global_priv" table with default users allowing root access
|
-- Fill "global_priv" table with default users allowing root access
|
||||||
-- from local machine if "global_priv" table didn't exist before
|
-- from local machine if "global_priv" table didn't exist before
|
||||||
@ -37,7 +39,8 @@ REPLACE INTO tmp_user_nopasswd SELECT @current_hostname,'root',@all_privileges F
|
|||||||
REPLACE INTO tmp_user_nopasswd VALUES ('127.0.0.1','root',@all_privileges);
|
REPLACE INTO tmp_user_nopasswd VALUES ('127.0.0.1','root',@all_privileges);
|
||||||
REPLACE INTO tmp_user_nopasswd VALUES ('::1','root',@all_privileges);
|
REPLACE INTO tmp_user_nopasswd VALUES ('::1','root',@all_privileges);
|
||||||
-- More secure root account using unix socket auth.
|
-- More secure root account using unix socket auth.
|
||||||
INSERT INTO tmp_user_socket VALUES ('localhost',IFNULL(@auth_root_socket, 'root'),json_set(@all_privileges, '$.plugin', 'unix_socket'));
|
INSERT INTO tmp_user_socket VALUES ('localhost', 'root',@all_with_auth);
|
||||||
|
REPLACE INTO tmp_user_socket VALUES ('localhost',IFNULL(@auth_root_socket, 'root'),@all_with_auth);
|
||||||
IF @auth_root_socket is not null THEN
|
IF @auth_root_socket is not null THEN
|
||||||
IF not exists(select 1 from information_schema.plugins where plugin_name='unix_socket') THEN
|
IF not exists(select 1 from information_schema.plugins where plugin_name='unix_socket') THEN
|
||||||
INSTALL SONAME 'auth_socket'; END IF; END IF;
|
INSTALL SONAME 'auth_socket'; END IF; END IF;
|
||||||
|
Reference in New Issue
Block a user