Mokhoa oa ho sebelisa MySQL ntle le password (le Likotsi tsa Ts'ireletso)

Mokhoa oa ho sebelisa MySQL ntle le password (le Likotsi tsa Ts'ireletso)

Ba re password e molemo ka ho fetisisa ke eo u sa lokelang ho e hopola. Tabeng ea MySQL sena se ka khoneha ka lebaka la plugin Auth_socket le phetolelo ea eona bakeng sa MariaDB - unix_socket.

Ka bobeli li-plugins tsena ha li ncha ho hang, li 'nile tsa tšohloa haholo ka har'a blog ena, mohlala sehloohong se buang ka mokhoa oa ho fetola li-password ho MySQL 5.7 u sebelisa plugin ea auth_socket. Leha ho le joalo, ha ke ntse ke sheba se secha ho MariaDB 10.4, ke fumane hore unix_socket e se e kentsoe ka mokhoa oa kamehla 'me ke e' ngoe ea mekhoa ea ho netefatsa ("e 'ngoe ea", hobane ho MariaDB 10.4 ho na le plugin e fetang e le' ngoe e fumanehang ho mosebedisi a le mong bakeng sa netefatso, eo e hlalosoa tokomaneng "Tiiso" ho tsoa ho MariaDB 10.04).

Joalokaha ke boletse, sena ha se litaba, 'me ha u kenya MySQL u sebelisa liphutheloana tsa .deb tse tšehetsoeng ke sehlopha sa Debian, mosebelisi oa motso o bōptjoa bakeng sa ho netefatsa li-socket. Sena ke 'nete ho MySQL le MariaDB ka bobeli.

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

Ka liphutheloana tsa Debian bakeng sa MySQL, mosebelisi oa motso o netefalitsoe ka tsela e latelang:

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)

Ho joalo le ka sephutheloana sa .deb bakeng 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)

Liphutheloana tsa .deb tse tsoang polokelong ea semmuso ea Percona li boetse li lokisa netefatso ea basebelisi tlasa auth-socket le bakeng sa Server ea Percona. Ha re fane ka mohlala ka Percona Server bakeng sa MySQL 8.0.16-7 le 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)

Joale mohlolo ke ofe? Plugin e lekola hore na mosebelisi oa Linux o lumellana le mosebelisi oa MySQL a sebelisa khetho ea sokete ea SO_PEERCRED ho bokella lintlha ka mosebelisi ea tsamaisang lenaneo la moreki. Kahoo, plugin e ka sebelisoa feela lits'ebetsong tse tšehetsang khetho ea SO_PEERCRED, joalo ka Linux. Khetho ea socket ea SO_PEERCRED e u lumella ho fumana ts'ebetso e amanang le socket. Ebe joale o se a ntse a amohela lebitso la mosebelisi le amanang le uid ena.

Mona ke mohlala ka mosebelisi "vagrant":

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

Kaha ha ho na mosebelisi oa "vagrant" ho MySQL, re haneloa ho fihlella. Ha re theheng mosebelisi ea joalo 'me re leke hape:

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)

Ho etsahetse!

Ho thoe'ng ka kabo e seng ea Debian moo sena se sa fanoang ka boiketsetso? Ha re leke Percona Server bakeng sa MySQL 8 e kentsoeng ho 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. Ke eng e neng e haella? Plugin ha ea kengoa:

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

Ha re kenye plugin ts'ebetsong:

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)

Hona joale re na le tsohle tseo re li hlokang. Ha re leke hape:

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)

Joale o ka kena o sebelisa lebitso la mosebelisi "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)

Mme e ile ya sebetsa hape!

Potso: na ho tla khoneha ho kena tsamaisong tlas'a ho kena ka percona, empa e le mosebedisi ea fapaneng?

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

Che, e ke ke ea sebetsa.

fihlela qeto e

MySQL e fetoha habonolo likarolong tse 'maloa, e' ngoe ea tsona ke mokhoa oa ho netefatsa. Joalokaha u bona ho tsoa posong ena, phihlello e ka fumanoa ntle le li-password, ho ipapisitsoe le basebelisi ba OS. Sena se ka ba molemo maemong a itseng, 'me e' ngoe ea tsona ke ha u falla ho tloha RDS/Aurora ho ea ho MySQL e tloaelehileng u sebelisa. Netefatso ea database ea IAMho fumana phihlello, empa ntle le li-password.

Source: www.habr.com

Eketsa ka tlhaloso