ื›ื™ืฆื“ ืœื”ืฉืชืžืฉ ื‘-MySQL ืœืœื ืกื™ืกืžื” (ื•ืกื™ื›ื•ื ื™ ืื‘ื˜ื—ื”)

ื›ื™ืฆื“ ืœื”ืฉืชืžืฉ ื‘-MySQL ืœืœื ืกื™ืกืžื” (ื•ืกื™ื›ื•ื ื™ ืื‘ื˜ื—ื”)

ื”ื ืื•ืžืจื™ื ืฉื”ืกื™ืกืžื” ื”ื˜ื•ื‘ื” ื‘ื™ื•ืชืจ ื”ื™ื ื–ื• ืฉืื™ื ืš ืฆืจื™ืš ืœื–ื›ื•ืจ. ื‘ืžืงืจื” ืฉืœ MySQL ื–ื” ืืคืฉืจื™ ื”ื•ื“ื•ืช ืœืคืœืื’ื™ืŸ auth_socket ื•ื”ื’ืจืกื” ืฉืœื• ืขื‘ื•ืจ MariaDB - unix_socket.

ืฉื ื™ ื”ืชื•ืกืคื™ื ื”ืœืœื• ืื™ื ื ื—ื“ืฉื™ื ื›ืœืœ; ื”ืจื‘ื” ื ืืžืจ ืขืœื™ื”ื ื‘ืื•ืชื• ื‘ืœื•ื’, ืœืžืฉืœ ื‘ืžืืžืจ ืขืœ ื›ื™ืฆื“ ืœืฉื ื•ืช ืกื™ืกืžืื•ืช ื‘-MySQL 5.7 ื‘ืืžืฆืขื•ืช ืชื•ืกืฃ auth_socket. ืขื ื–ืืช, ื‘ื–ืžืŸ ืฉื‘ื“ืงืชื™ ืžื” ื—ื“ืฉ ื‘-MariaDB 10.4, ื’ื™ืœื™ืชื™ ืฉ-unix_socket ืžื•ืชืงืŸ ื›ืขืช ื›ื‘ืจื™ืจืช ืžื—ื“ืœ ื•ื”ื™ื ืื—ืช ืžืฉื™ื˜ื•ืช ื”ืื™ืžื•ืช ("ืื—ืช ืžื”ืŸ", ืžื›ื™ื•ื•ืŸ ืฉื‘-MariaDB 10.4 ื™ื•ืชืจ ืžืชื•ืกืฃ ืื—ื“ ื–ืžื™ืŸ ืœืžืฉืชืžืฉ ืื—ื“ ืœืื™ืžื•ืช, ืืฉืจ ืžื•ืกื‘ืจ ื‘ืžืกืžืš "ืื™ืžื•ืช" ืž-MariaDB 10.04).

ื›ืคื™ ืฉืืžืจืชื™, ื–ื” ืœื ื—ื“ืฉื•ืช, ื•ื›ืืฉืจ ืžืชืงื™ื ื™ื ืืช MySQL ื‘ืืžืฆืขื•ืช ื—ื‘ื™ืœื•ืช ื”-.deb ื”ื ืชืžื›ื•ืช ืขืœ ื™ื“ื™ ืฆื•ื•ืช ื“ื‘ื™ืืŸ, ื ื•ืฆืจ ืžืฉืชืžืฉ ืฉื•ืจืฉ ืœืื™ืžื•ืช socket. ื–ื” ื ื›ื•ืŸ ื’ื ืขื‘ื•ืจ MySQL ื•ื’ื ืขื‘ื•ืจ MariaDB.

root@app:~# apt-cache show mysql-server-5.7 | grep -i maintainers
Original-Maintainer: Debian MySQL Maintainers <[email protected]>
Original-Maintainer: Debian MySQL Maintainers <<a href="mailto:[email protected]">[email protected]</a>>

ืขื ื—ื‘ื™ืœื•ืช Debian ืขื‘ื•ืจ MySQL, ืžืฉืชืžืฉ ื”ืฉื•ืจืฉ ืžืื•ืžืช ื‘ืื•ืคืŸ ื”ื‘ื:

root@app:~# whoami
root=
root@app:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.27-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> select user, host, plugin, authentication_string from mysql.user where user = 'root';
+------+-----------+-------------+-----------------------+
| user | host      | plugin | authentication_string |
+------+-----------+-------------+-----------------------+
| root | localhost | auth_socket |                       |
+------+-----------+-------------+-----------------------+
1 row in set (0.01 sec)

ืื•ืชื• ื”ื“ื‘ืจ ืขื ื—ื‘ื™ืœืช ื”-.deb ืขื‘ื•ืจ MariaDB:

10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

MariaDB [(none)]> show grants;
+------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                      |
+------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED VIA unix_socket WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION                                  |
+------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

ื—ื‘ื™ืœื•ืช ื”-.deb ืžื”ืžืื’ืจ ื”ืจืฉืžื™ ืฉืœ Percona ืžื’ื“ื™ืจื™ื ื’ื ืื™ืžื•ืช ืžืฉืชืžืฉ ืฉื•ืจืฉ ืชื—ืช aut-socket ื•ืขื‘ื•ืจ Percona Server. ื‘ื•ืื• ื ื™ืชืŸ ื“ื•ื’ืžื” ืขื ืฉืจืช Percona ืขื‘ื•ืจ MySQL 8.0.16-7 ื•ืื•ื‘ื•ื ื˜ื• 16.04:

root@app:~# whoami
root
root@app:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 9
Server version: 8.0.16-7 Percona Server (GPL), Release '7', Revision '613e312'

Copyright (c) 2009-2019 Percona LLC and/or its affiliates
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> select user, host, plugin, authentication_string from mysql.user where user ='root';
+------+-----------+-------------+-----------------------+
| user | host      | plugin | authentication_string |
+------+-----------+-------------+-----------------------+
| root | localhost | auth_socket |                       |
+------+-----------+-------------+-----------------------+
1 row in set (0.00 sec)

ืื– ืžื” ื”ืงืกื? ื”ืชื•ืกืฃ ื‘ื•ื“ืง ืฉืžืฉืชืžืฉ ื”ืœื™ื ื•ืงืก ืžืชืื™ื ืœืžืฉืชืžืฉ MySQL ื‘ืืžืฆืขื•ืช ืืคืฉืจื•ืช ื”ืฉืงืข SO_PEERCRED ื›ื“ื™ ืœืืกื•ืฃ ืžื™ื“ืข ืขืœ ื”ืžืฉืชืžืฉ ื”ืžืจื™ืฅ ืืช ืชื•ื›ื ื™ืช ื”ืœืงื•ื—. ืœืคื™ื›ืš, ื ื™ืชืŸ ืœื”ืฉืชืžืฉ ื‘ืชื•ืกืฃ ืจืง ื‘ืžืขืจื›ื•ืช ื”ืชื•ืžื›ื•ืช ื‘ืืคืฉืจื•ืช SO_PEERCRED, ื›ืžื• ืœื™ื ื•ืงืก. ืืคืฉืจื•ืช ื”ืฉืงืข SO_PEERCRED ืžืืคืฉืจืช ืœืš ืœื’ืœื•ืช ืืช ื”-uid ืฉืœ ื”ืชื”ืœื™ืš ื”ืžืฉื•ื™ืš ืœืฉืงืข. ื•ืื– ื”ื•ื ื›ื‘ืจ ืžืงื‘ืœ ืืช ืฉื ื”ืžืฉืชืžืฉ ื”ืžืฉื•ื™ืš ืœ-uid ื”ื–ื”.

ื”ื ื” ื“ื•ื’ืžื” ืขื ื”ืžืฉืชืžืฉ "ื ื•ื“ื“":

vagrant@mysql1:~$ whoami
vagrant
vagrant@mysql1:~$ mysql
ERROR 1698 (28000): Access denied for user 'vagrant'@'localhost'

ืžื›ื™ื•ื•ืŸ ืฉืื™ืŸ ืžืฉืชืžืฉ "ื ื•ื“ื“" ื‘-MySQL, ื ืžื ืขืช ื’ื™ืฉื”. ื‘ื•ืื• ื ื™ืฆื•ืจ ืžืฉืชืžืฉ ื›ื–ื” ื•ื ื ืกื” ืฉื•ื‘:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'vagrant'@'localhost' IDENTIFIED VIA unix_socket;
Query OK, 0 rows affected (0.00 sec)

vagrant@mysql1:~$ mysql
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 45
Server version: 10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> show grants;
+---------------------------------------------------------------------------------+
| Grants for vagrant@localhost                                                    |
+---------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'vagrant'@'localhost' IDENTIFIED VIA unix_socket |
+---------------------------------------------------------------------------------+
1 row in set (0.00 sec)

ืงืจื”!

ื•ื‘ื›ืŸ, ืžื” ืœื’ื‘ื™ ื”ืคืฆื” ืฉืื™ื ื” ื“ื‘ื™ืืŸ ืฉื‘ื” ื–ื” ืœื ืžืกื•ืคืง ื›ื‘ืจื™ืจืช ืžื—ื“ืœ? ื‘ื•ืื• ื ื ืกื” ืืช Percona Server ืขื‘ื•ืจ MySQL 8 ื”ืžื•ืชืงืŸ ื‘- CentOS 7:

mysql> show variables like '%version%comment';
+-----------------+---------------------------------------------------+
| Variable_name   | Value                                   |
+-----------------+---------------------------------------------------+
| version_comment | Percona Server (GPL), Release 7, Revision 613e312 |
+-----------------+---------------------------------------------------+
1 row in set (0.01 sec)

mysql> CREATE USER 'percona'@'localhost' IDENTIFIED WITH auth_socket;
ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded

ื‘ืืกื”. ืžื” ื”ื™ื” ื—ืกืจ? ื”ืคืœืื’ื™ืŸ ืœื ื ื˜ืขืŸ:

mysql> pager grep socket
PAGER set to 'grep socket'
mysql> show plugins;
47 rows in set (0.00 sec)

ื‘ื•ืื• ื ื•ืกื™ืฃ ืชื•ืกืฃ ืœืชื”ืœื™ืš:

mysql> nopager
PAGER set to stdout
mysql> INSTALL PLUGIN auth_socket SONAME 'auth_socket.so';
Query OK, 0 rows affected (0.00 sec)

mysql> pager grep socket; show plugins;
PAGER set to 'grep socket'
| auth_socket                     | ACTIVE | AUTHENTICATION | auth_socket.so | GPL     |
48 rows in set (0.00 sec)

ืขื›ืฉื™ื• ื™ืฉ ืœื ื• ืืช ื›ืœ ืžื” ืฉืื ื—ื ื• ืฆืจื™ื›ื™ื. ื‘ื•ื ื ื ืกื” ืฉื•ื‘:

mysql> CREATE USER 'percona'@'localhost' IDENTIFIED WITH auth_socket;
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'percona'@'localhost';
Query OK, 0 rows affected (0.01 sec)

ื›ืขืช ืชื•ื›ืœ ืœื”ืชื—ื‘ืจ ื‘ืืžืฆืขื•ืช ืฉื ื”ืžืฉืชืžืฉ "percona".

[percona@ip-192-168-1-111 ~]$ whoami
percona
[percona@ip-192-168-1-111 ~]$ mysql -upercona
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 19
Server version: 8.0.16-7 Percona Server (GPL), Release 7, Revision 613e312

Copyright (c) 2009-2019 Percona LLC and/or its affiliates
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> select user, host, plugin, authentication_string from mysql.user where user ='percona';
+---------+-----------+-------------+-----------------------+
| user    | host   | plugin   | authentication_string |
+---------+-----------+-------------+-----------------------+
| percona | localhost | auth_socket |                       |
+---------+-----------+-------------+-----------------------+
1 row in set (0.00 sec)

ื•ื–ื” ืขื‘ื“ ืฉื•ื‘!

ืฉืืœื”: ื”ืื ื ื™ืชืŸ ื™ื”ื™ื” ืœื”ื™ื›ื ืก ืœืžืขืจื›ืช ื‘ืื•ืชื• ื”ืชื—ื‘ืจื•ืช ืฉืœ percona, ืืš ื›ืžืฉืชืžืฉ ืื—ืจ?

[percona@ip-192-168-1-111 ~]$ logout
[root@ip-192-168-1-111 ~]# mysql -upercona
ERROR 1698 (28000): Access denied for user 'percona'@'localhost'

ืœื, ื–ื” ืœื ื™ืขื‘ื•ื“.

ืคืœื˜

MySQL ื“ื™ ื’ืžื™ืฉ ื‘ื›ืžื” ื”ื™ื‘ื˜ื™ื, ืื—ื“ ืžื”ื ื”ื•ื ืฉื™ื˜ืช ื”ืื™ืžื•ืช. ื›ืคื™ ืฉื ื™ืชืŸ ืœืจืื•ืช ืžืคื•ืกื˜ ื–ื”, ื ื™ืชืŸ ืœืงื‘ืœ ื’ื™ืฉื” ืœืœื ืกื™ืกืžืื•ืช, ื‘ื”ืชื‘ืกืก ืขืœ ืžืฉืชืžืฉื™ ืžืขืจื›ืช ื”ื”ืคืขืœื”. ื–ื” ื™ื›ื•ืœ ืœื”ื™ื•ืช ืฉื™ืžื•ืฉื™ ื‘ืชืจื—ื™ืฉื™ื ืžืกื•ื™ืžื™ื, ื•ืื—ื“ ืžื”ื ื”ื•ื ื‘ืขืช ื”ื’ื™ืจื” ืž-RDS/Aurora ืœ-MySQL ืจื’ื™ืœ ื‘ืืžืฆืขื•ืช ืื™ืžื•ืช ืžืกื“ ื ืชื•ื ื™ื ืฉืœ IAMืขื“ื™ื™ืŸ ืœืงื‘ืœ ื’ื™ืฉื”, ืืš ืœืœื ืกื™ืกืžืื•ืช.

ืžืงื•ืจ: www.habr.com

ื”ื•ืกืคืช ืชื’ื•ื‘ื”