Mar a chleachdas tu MySQL gun fhacal-faire (agus cunnartan tèarainteachd)

Mar a chleachdas tu MySQL gun fhacal-faire (agus cunnartan tèarainteachd)

Tha iad ag ràdh gur e am facal-faire as fheàrr fear nach fheum thu a chuimhneachadh. A thaobh MySQL, tha seo comasach le taing do plugan. socaid_ùghdarrais agus na dreachan aige airson MariaDB — unix_socaid.

Chan eil an dà plugin seo ùr idir, chaidh mòran a dheasbad mun deidhinn san aon bhlog seo, mar eisimpleir san artaigil mu dheidhinn Mar a dh’atharraicheas tu faclan-faire ann am MySQL 5.7 a’ cleachdadh am plugan auth_socketAch, fhad ’s a bha mi a’ sgrùdadh dè a tha ùr ann am MariaDB 10.4, fhuair mi a-mach gu bheil unix_socket air a stàladh gu bunaiteach a-nis agus gur e aon de na dòighean dearbhaidh a th’ ann ("aon de" oir ann am MariaDB 10.4, tha barrachd air aon plugan ri fhaighinn airson dearbhadh gach neach-cleachdaidh, mar a mhìnichear anns an sgrìobhainneachd. "Dearbhadh" bho MariaDB 10.04).

Mar a thuirt mi, chan e naidheachd a tha seo, agus nuair a stàlaicheas tu MySQL a’ cleachdadh an sgioba le taic Debian Airson pacaidean .deb, cruthaichear neach-cleachdaidh freumhach airson dearbhadh socaid. Tha seo a’ buntainn ri MySQL agus MariaDB le chèile.

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

Le pocannan Debian Airson MySQL, tha an neach-cleachdaidh freumhach air a dhearbhadh mar a leanas:

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)

Tha an aon rud fìor airson a’ phacaid .deb airson 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)

Bidh na pacaidean .deb bhon stòras oifigeil Percona cuideachd a’ rèiteachadh dearbhadh luchd-cleachdaidh freumhach airson auth-socket agus Frithealaiche Percona. Seo eisimpleir: Frithealaiche Percona airson MySQL 8.0.16-7 и 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)

Dè an draoidheachd a th’ ann, ma-thà? Bidh am plugan a’ dèanamh cinnteach gu bheil an neach-cleachdaidh Linux a’ maidseadh an neach-cleachdaidh MySQL le bhith a’ cleachdadh an roghainn socaid SO_PEERCRED gus fiosrachadh a chruinneachadh mun neach-cleachdaidh a tha a’ ruith prògram an neach-dèiligidh. Mar sin, chan urrainnear am plugan a chleachdadh ach air siostaman a tha a’ toirt taic don roghainn SO_PEERCRED, leithid LinuxLeigidh an roghainn socaid SO_PEERCRED leat UID a’ phròiseis co-cheangailte ris an t-socaid a dhearbhadh. An uairsin gheibh am pròiseas an t-ainm-cleachdaiche co-cheangailte ris an UID sin.

Gabhamaid eisimpleir leis an neach-cleachdaidh "vagrant":

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

Leis nach eil neach-cleachdaidh "falamh" aig MySQL, tha ruigsinneachd air a dhiĂšltadh. Cruthaichidh sinn fear agus feuchaidh sinn ris a-rithist:

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)

Thachair!

Uill, dè mu dheidhinn neo-Debian sgaoileadh far nach eil seo air a thoirt seachad gu bunaiteach? Feuchaidh sinn ri Percona Server airson MySQL 8, air a stàladh air 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

Duilich. Dè tha a dhÏth? Chan eil am plugan air a luchdachadh:

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

Cuiridh sinn plugan ris a’ phròiseas:

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)

A-nis tha a h-uile rud a dh’ fheumas sinn againn. Feuchaidh sinn ris a-rithist:

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)

A-nis faodaidh tu logadh a-steach leis an ainm-cleachdaiche “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)

Agus dh’obraich e a-rithist!

Ceist: Am bi e comasach logadh a-steach don t-siostam leis an aon ainm-cleachdaidh percona, ach mar neach-cleachdaidh eadar-dhealaichte?

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

Chan eil, cha obraich e.

co-dhĂšnadh

Tha MySQL gu math sùbailte ann an grunn dhòighean, agus is e aon dhiubh an dòigh dearbhaidh aige. Mar a tha an dreuchd seo a’ sealltainn, faodar ruigsinneachd a thoirt seachad às aonais faclan-faire, stèidhichte air luchd-cleachdaidh an t-siostaim obrachaidh. Faodaidh seo a bhith feumail ann an suidheachaidhean sònraichte, agus is e aon dhiubh sin nuair a thathar a’ gluasad bho RDS/Aurora gu MySQL àbhaisteach a’ cleachdadh Dearbhadh stòr-dàta IAMgus cothrom fhaighinn fhathast, ach às aonais faclan-faire.

Source: www.habr.com

Ceannaich aoigheachd earbsach airson làraich le dìon DDoS, frithealaichean VPS VDS 🔥 Ceannaich aoigheachd làrach-lìn earbsach le dìon DDoS, frithealaichean VPS VDS | ProHoster