
Dicenu chì a megliu password hè quella chì ùn deve micca ricurdà. In u casu di MySQL, questu hè pussibule grazia à u plugin è a so versione per MariaDB - .
Tramindui sti plugins ùn sò micca novi in tuttu hè statu dettu assai di elli in questu bloggu, per esempiu in l'articulu circa . Tuttavia, mentre cercava ciò chì hè novu in MariaDB 10.4, aghju scupertu chì unix_socket hè avà stallatu per automaticamente è hè unu di i metudi di autentificazione ("unu di", perchè in MariaDB 10.4 più di un plugin hè dispunibule per un utilizatore per l'autentificazione, chì hè spiegatu in u documentu ).
Cum'è aghju dettu, questu ùn hè micca una nutizia, è quandu installate MySQL cù a squadra supportata Debian Per i pacchetti .deb, un utilizatore root hè creatu per l'autentificazione di socket. Questu vale sia per MySQL sia per MariaDB.
root@app:~# apt-cache show mysql-server-5.7 | grep -i maintainers
Original-Maintainer: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
Original-Maintainer: Debian MySQL Maintainers <<a href="mailto:pkg-mysql-maint@lists.alioth.debian.org">pkg-mysql-maint@lists.alioth.debian.org</a>>Cù sacchetti Debian Per MySQL, l'utilizatore root hè autenticatu cusì:
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)U listessu hè u casu cù u pacchettu .deb per 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)I pacchetti .deb da u repositoriu ufficiale di Percona cunfiguranu ancu l'autentificazione di l'utilizatori root sottu auth-socket è per Percona Server. Damu un esempiu cun и Ubuntu 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)Allora, chì hè a magia ? U plugin verifica chì l'utilizatore Linux currisponde à l'utilizatore MySQL aduprendu l'opzione di socket SO_PEERCRED per raccoglie informazioni nantu à l'utilizatore chì esegue u prugramma cliente. Dunque, u plugin pò esse adupratu solu nantu à i sistemi chì supportanu l'opzione SO_PEERCRED, cum'è LinuxL'opzione di socket SO_PEERCRED vi permette di determinà l'UID di u prucessu assuciatu à u socket. U prucessu ottiene tandu u nome d'utilizatore assuciatu à quellu UID.
Eccu un esempiu cù l'utilizatore "vagrant":
vagrant@mysql1:~$ whoami
vagrant
vagrant@mysql1:~$ mysql
ERROR 1698 (28000): Access denied for user 'vagrant'@'localhost'Siccomu ùn ci hè micca un utilizatore "vagrante" in MySQL, ci hè denegatu l'accessu. Creemu un tali utilizatore è pruvate di novu:
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)Accadutu!
Ebbè, chì ne dici di i non-Debian distribuzione induve questu ùn hè micca furnitu per difettu? Pruvemu Percona Server per MySQL 8, installatu annantu à 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 loadedBummer. Chì mancava ? Plugin micca caricatu:
mysql> pager grep socket
PAGER set to 'grep socket'
mysql> show plugins;
47 rows in set (0.00 sec)Aghjunghjemu un plugin à u prucessu:
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)Avà avemu tuttu ciò chì avemu bisognu. Pruvemu di novu:
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)Pudete avà login cù u nome d'utilizatore "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)È hà travagliatu di novu!
Quistione: serà pussibule di login in u sistema sottu u stessu login percona, ma cum'è un utilizatore sfarente?
[percona@ip-192-168-1-111 ~]$ logout
[root@ip-192-168-1-111 ~]# mysql -upercona
ERROR 1698 (28000): Access denied for user 'percona'@'localhost'No, ùn funziona micca.
cunchiusioni
MySQL hè abbastanza flexible in parechji aspetti, unu di i quali hè u metudu di autentificazione. Comu pudete vede da questu post, l'accessu pò esse acquistatu senza password, basatu annantu à l'utilizatori di u SO. Questu pò esse utile in certi scenarii, è unu d'elli hè quandu migrate da RDS / Aurora à MySQL regularmente utilizendu per sempre accede, ma senza password.
Source: www.habr.com
