Giunsa Paggamit ang MySQL nga Wala’y Password (ug Mga Risgo sa Seguridad)

Giunsa Paggamit ang MySQL nga Wala’y Password (ug Mga Risgo sa Seguridad)

Giingon nila nga ang labing kaayo nga password mao ang usa nga dili nimo kinahanglan hinumdoman. Sa kaso sa MySQL, posible kini salamat sa plugin auth_socket ug ang bersyon niini para sa MariaDB - unix_socket.

Ang duha niini nga mga plugins dili na bag-o sa tanan; daghan ang gisulti bahin niini sa parehas nga blog, pananglitan sa artikulo bahin sa unsaon pag-usab sa mga password sa MySQL 5.7 gamit ang auth_socket plugin. Bisan pa, samtang nagtan-aw kung unsa ang bag-o sa MariaDB 10.4, nahibal-an nako nga ang unix_socket karon gi-install sa default ug usa sa mga pamaagi sa pag-authenticate ("usa sa", tungod kay sa MariaDB 10.4 labaw sa usa ka plugin ang magamit sa usa ka tiggamit alang sa pag-authenticate, nga gipasabut sa dokumento "Authentication" gikan sa MariaDB 10.04).

Sama sa akong giingon, dili kini balita, ug kung mag-install sa MySQL gamit ang .deb nga mga pakete nga gisuportahan sa Debian team, usa ka root user ang gihimo alang sa socket authentication. Tinuod kini alang sa MySQL ug 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>>

Uban sa Debian nga mga pakete alang sa MySQL, ang gamut nga tiggamit gipamatud-an sama sa mosunod:

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)

Ingon usab niini ang kaso sa .deb nga pakete alang sa 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)

Ang .deb packages gikan sa opisyal nga Percona repository nag-configure usab sa root user authentication ubos sa auth-socket ug para sa Percona Server. Maghatag kita ug usa ka pananglitan sa Percona Server alang sa MySQL 8.0.16-7 ug 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)

Busa unsa ang salamangka? Gisusi sa plugin nga ang user sa Linux motakdo sa user sa MySQL gamit ang SO_PEERCRED socket option aron mangolekta og impormasyon bahin sa user nga nagpadagan sa client program. Busa, ang plugin magamit lamang sa mga sistema nga nagsuporta sa SO_PEERCRED nga opsyon, sama sa Linux. Ang SO_PEERCRED nga opsyon sa socket nagtugot kanimo nga mahibal-an ang uid sa proseso nga nalangkit sa socket. Ug unya nakadawat na siya sa username nga nalambigit niini nga uid.

Ania ang usa ka pananglitan sa user nga "vagrant":

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

Tungod kay walay "vagrant" nga tiggamit sa MySQL, kami gihikawan sa pag-access. Himoon nato ang ingon nga tiggamit ug sulayan pag-usab:

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)

Nahitabo!

Aw, komosta ang usa ka dili-Debian nga pag-apod-apod diin wala kini gihatag nga default? Atong sulayan ang Percona Server alang sa MySQL 8 nga na-install sa 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

Bummer. Unsay kulang? Wala gikarga ang plugin:

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

Atong idugang ang usa ka plugin sa proseso:

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)

Karon naa na namo ang tanan nga among gikinahanglan. Atong sulayan pag-usab:

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)

Karon mahimo ka mag log in gamit ang username nga "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)

Ug kini mitrabaho pag-usab!

Pangutana: mahimo ba nga mag log in sa sistema sa ilawom sa parehas nga percona login, apan ingon usa ka lahi nga tiggamit?

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

Dili, dili kini molihok.

konklusyon

Ang MySQL kay flexible sa daghang aspeto, usa niini mao ang authentication method. Sama sa imong makita gikan sa kini nga post, ang pag-access mahimong makuha nga wala’y mga password, base sa mga tiggamit sa OS. Mahimo kini nga mapuslanon sa pipila nga mga senaryo, ug ang usa niini mao ang paglalin gikan sa RDS / Aurora ngadto sa regular nga MySQL gamit. IAM database authenticationaron makaangkon gihapon og access, apan walay mga password.

Source: www.habr.com

Idugang sa usa ka comment