Si të përdorni MySQL pa fjalëkalim (dhe rreziqe sigurie)

Si të përdorni MySQL pa fjalëkalim (dhe rreziqe sigurie)

Ata thonë se fjalëkalimi më i mirë është ai që nuk duhet ta mbani mend. Në rastin e MySQL kjo është e mundur falë shtojcës auth_socket dhe versioni i tij për MariaDB - unix_socket.

Të dyja këto shtojca nuk janë aspak të reja; është thënë shumë për to në të njëjtin blog, për shembull në artikullin rreth si të ndryshoni fjalëkalimet në MySQL 5.7 duke përdorur shtojcën auth_socket. Megjithatë, duke parë se çfarë ka të re në MariaDB 10.4, zbulova se unix_socket tani është instaluar si parazgjedhje dhe është një nga metodat e vërtetimit ("një nga", sepse në MariaDB 10.4 më shumë se një shtojcë është në dispozicion për një përdorues për vërtetim, e cila shpjegohet në dokument "Autentifikimi" nga MariaDB 10.04).

Siç thashë, ky nuk është lajm dhe kur instaloni MySQL duke përdorur paketat .deb të mbështetura nga ekipi Debian, krijohet një përdorues rrënjë për vërtetimin e socket-it. Kjo është e vërtetë si për MySQL ashtu edhe për 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>>

Me paketat Debian për MySQL, përdoruesi rrënjë vërtetohet si më poshtë:

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)

I njëjti është rasti me paketën .deb për 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)

Paketat .deb nga depoja zyrtare e Percona konfigurojnë gjithashtu vërtetimin e përdoruesit rrënjë nën auth-socket dhe për serverin Percona. Le të japim një shembull me Serveri Percona për MySQL 8.0.16-7 dhe 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)

Pra, cila është magjia? Shtojca kontrollon që përdoruesi i Linux përputhet me përdoruesin MySQL duke përdorur opsionin e folesë SO_PEERCRED për të mbledhur informacione rreth përdoruesit që drejton programin e klientit. Kështu, shtojca mund të përdoret vetëm në sistemet që mbështesin opsionin SO_PEERCRED, siç është Linux. Opsioni i folesë SO_PEERCRED ju lejon të zbuloni uid-in e procesit të lidhur me folenë. Dhe më pas ai tashmë merr emrin e përdoruesit të lidhur me këtë uid.

Ja një shembull me përdoruesin "vagrant":

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

Meqenëse nuk ka asnjë përdorues "vagrant" në MySQL, neve na është mohuar qasja. Le të krijojmë një përdorues të tillë dhe të provojmë përsëri:

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)

Ndodhi!

Epo, po në lidhje me një shpërndarje jo-Debian ku kjo nuk ofrohet si parazgjedhje? Le të provojmë Percona Server për MySQL 8 të instaluar në 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

Bumere. Çfarë mungonte? Shtojca nuk është ngarkuar:

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

Le të shtojmë një shtojcë në proces:

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)

Tani kemi gjithçka që na nevojitet. Le ta provojme perseri:

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)

Tani mund të identifikoheni duke përdorur emrin e përdoruesit "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)

Dhe funksionoi përsëri!

Pyetje: a do të jetë e mundur të hyni në sistem me të njëjtin hyrje percona, por si përdorues tjetër?

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

Jo, nuk do të funksionojë.

Prodhim

MySQL është mjaft fleksibël në disa aspekte, një prej të cilave është metoda e vërtetimit. Siç mund ta shihni nga ky postim, aksesi mund të fitohet pa fjalëkalime, bazuar në përdoruesit e OS. Kjo mund të jetë e dobishme në disa skenarë, dhe një prej tyre është kur migroni nga RDS/Aurora në MySQL të rregullt duke përdorur Autentifikimi i bazës së të dhënave IAMpër të fituar ende akses, por pa fjalëkalime.

Burimi: www.habr.com

Shto një koment