MySQL-i Parolsuz Necə İstifadə Etmək olar (və Təhlükəsizlik Riskləri)

MySQL-i Parolsuz Necə İstifadə Etmək olar (və Təhlükəsizlik Riskləri)

Deyirlər ki, ən yaxşı parol yadda saxlamaq məcburiyyətində olmayan paroldur. MySQL vəziyyətində bu, plagin sayəsində mümkündür auth_socket və onun MariaDB üçün versiyası - unix_socket.

Bu plaginlərin hər ikisi heç də yeni deyil; onlar haqqında eyni bloqda, məsələn, haqqında məqalədə çox şey deyilib. auth_socket plaginindən istifadə edərək MySQL 5.7-də parolları necə dəyişdirmək olar. Bununla belə, MariaDB 10.4-də yenilikləri araşdırarkən aşkar etdim ki, unix_socket indi defolt olaraq quraşdırılıb və autentifikasiya üsullarından biridir (“bir”, çünki MariaDB 10.4-də autentifikasiya üçün bir istifadəçi üçün birdən çox plagin mövcuddur. sənəddə izah olunur MariaDB-dən "Autentifikasiya" 10.04).

Dediyim kimi, bu xəbər deyil və Debian komandası tərəfindən dəstəklənən .deb paketlərindən istifadə edərək MySQL-i quraşdırarkən, soket autentifikasiyası üçün kök istifadəçi yaradılır. Bu həm MySQL, həm də MariaDB üçün doğrudur.

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>>

MySQL üçün Debian paketləri ilə kök istifadəçi aşağıdakı kimi autentifikasiya olunur:

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)

MariaDB üçün .deb paketi ilə eyni vəziyyətdir:

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)

Rəsmi Percona repozitoriyasından olan .deb paketləri həmçinin auth-socket altında və Percona Server üçün kök istifadəçi autentifikasiyasını konfiqurasiya edir. ilə bir misal verək MySQL 8.0.16-7 üçün Percona Server və 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)

Beləliklə, sehr nədir? Plugin müştəri proqramını işlədən istifadəçi haqqında məlumat toplamaq üçün SO_PEERCRED yuva seçimindən istifadə edərək Linux istifadəçisinin MySQL istifadəçisi ilə uyğunluğunu yoxlayır. Beləliklə, plagin yalnız Linux kimi SO_PEERCRED seçimini dəstəkləyən sistemlərdə istifadə edilə bilər. SO_PEERCRED yuva seçimi sizə rozetka ilə əlaqəli prosesin uid-ini tapmağa imkan verir. Və sonra o, artıq bu uid ilə əlaqəli istifadəçi adını alır.

"Vagrant" istifadəçisi ilə bir nümunə:

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

MySQL-də "vaqrant" istifadəçi olmadığı üçün bizə giriş qadağan edilir. Gəlin belə bir istifadəçi yaradaq və yenidən cəhd edək:

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)

baş verdi!

Yaxşı, bunun standart olaraq təmin edilmədiyi qeyri-Debian paylanması haqqında nə demək olar? CentOS 8-də quraşdırılmış MySQL 7 üçün Percona Serveri sınayaq:

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. Nə çatmırdı? Plugin yüklənməyib:

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

Prosesə plagin əlavə edək:

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)

İndi bizə lazım olan hər şey var. Yenidən cəhd edək:

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)

İndi “percona” istifadəçi adı ilə daxil ola bilərsiniz.

[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)

Və yenidən işlədi!

Sual: sistemə eyni percona girişi ilə, lakin fərqli istifadəçi kimi daxil olmaq mümkün olacaqmı?

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

Xeyr, işə yaramayacaq.

Buraxılış

MySQL bir neçə aspektdə kifayət qədər çevikdir, onlardan biri autentifikasiya üsuludur. Bu yazıdan göründüyü kimi, OS istifadəçilərinə əsaslanaraq, giriş parol olmadan əldə edilə bilər. Bu, müəyyən ssenarilərdə faydalı ola bilər və onlardan biri RDS/Aurora-dan adi MySQL-ə keçid zamanıdır. IAM verilənlər bazası autentifikasiyasıhələ də giriş əldə etmək, lakin parollar olmadan.

Mənbə: www.habr.com

Добавить комментарий