పాస్‌వర్డ్ లేకుండా MySQLని ఎలా ఉపయోగించాలి (మరియు భద్రతా ప్రమాదాలు)

పాస్‌వర్డ్ లేకుండా MySQLని ఎలా ఉపయోగించాలి (మరియు భద్రతా ప్రమాదాలు)

మీరు గుర్తుంచుకోవాల్సిన అవసరం లేని పాస్‌వర్డ్ ఉత్తమమైనదని వారు అంటున్నారు. MySQL విషయంలో ఇది ప్లగ్‌ఇన్‌ వల్ల సాధ్యమవుతుంది auth_socket మరియు MariaDB కోసం దాని వెర్షన్ - unix_socket.

ఈ రెండు ప్లగిన్‌లు కొత్తవి కావు; వాటి గురించి ఇదే బ్లాగ్‌లో చాలా చెప్పబడింది, ఉదాహరణకు దీని గురించి వ్యాసంలో auth_socket ప్లగిన్‌ని ఉపయోగించి MySQL 5.7లో పాస్‌వర్డ్‌లను ఎలా మార్చాలి. అయినప్పటికీ, MariaDB 10.4లో కొత్తవి ఏమి ఉన్నాయో పరిశీలిస్తున్నప్పుడు, unix_socket ఇప్పుడు డిఫాల్ట్‌గా ఇన్‌స్టాల్ చేయబడిందని మరియు ప్రామాణీకరణ పద్ధతుల్లో ఒకటి అని నేను కనుగొన్నాను (“ఒకటి”, ఎందుకంటే MariaDB 10.4లో ప్రమాణీకరణ కోసం ఒక వినియోగదారుకు ఒకటి కంటే ఎక్కువ ప్లగిన్ అందుబాటులో ఉంది, ఇది పత్రంలో వివరించబడింది MariaDB 10.04 నుండి "ప్రామాణీకరణ").

నేను చెప్పినట్లుగా, ఇది వార్త కాదు మరియు డెబియన్ బృందంచే మద్దతిచ్చే .deb ప్యాకేజీలను ఉపయోగించి MySQLని ఇన్‌స్టాల్ చేస్తున్నప్పుడు, సాకెట్ ప్రమాణీకరణ కోసం రూట్ వినియోగదారు సృష్టించబడతారు. ఇది MySQL మరియు 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>>

MySQL కోసం డెబియన్ ప్యాకేజీలతో, రూట్ వినియోగదారు ఈ క్రింది విధంగా ప్రమాణీకరించబడతారు:

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 కోసం .deb ప్యాకేజీ విషయంలో కూడా అలాగే ఉంటుంది:

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)

అధికారిక పెర్కోనా రిపోజిటరీ నుండి .deb ప్యాకేజీలు కూడా auth-socket క్రింద మరియు Percona సర్వర్ కోసం రూట్ వినియోగదారు ప్రమాణీకరణను కాన్ఫిగర్ చేస్తాయి. తో ఒక ఉదాహరణ ఇద్దాం MySQL 8.0.16-7 కోసం పెర్కోనా సర్వర్ మరియు ఉబుంటు 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)

ఇంతకీ మంత్రం ఏమిటి? క్లయింట్ ప్రోగ్రామ్‌ను నడుపుతున్న వినియోగదారు గురించి సమాచారాన్ని సేకరించడానికి SO_PEERCRED సాకెట్ ఎంపికను ఉపయోగించి Linux వినియోగదారు MySQL వినియోగదారుతో సరిపోలినట్లు ప్లగ్ఇన్ తనిఖీ చేస్తుంది. అందువలన, ప్లగ్ఇన్ Linux వంటి SO_PEERCRED ఎంపికకు మద్దతు ఇచ్చే సిస్టమ్‌లలో మాత్రమే ఉపయోగించబడుతుంది. SO_PEERCRED సాకెట్ ఎంపిక సాకెట్‌తో అనుబంధించబడిన ప్రక్రియ యొక్క uidని కనుగొనడానికి మిమ్మల్ని అనుమతిస్తుంది. ఆపై అతను ఇప్పటికే ఈ uidతో అనుబంధించబడిన వినియోగదారు పేరును అందుకున్నాడు.

వినియోగదారు "వాగ్రాంట్"తో ఇక్కడ ఒక ఉదాహరణ ఉంది:

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

MySQLలో "వాగ్రాంట్" యూజర్ లేనందున, మాకు యాక్సెస్ నిరాకరించబడింది. అటువంటి వినియోగదారుని సృష్టించి, మళ్లీ ప్రయత్నిద్దాం:

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)

జరిగింది!

సరే, ఇది డిఫాల్ట్‌గా అందించబడని డెబియన్-యేతర పంపిణీ గురించి ఏమిటి? CentOS 8లో ఇన్‌స్టాల్ చేయబడిన MySQL 7 కోసం Percona సర్వర్‌ని ప్రయత్నిద్దాం:

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

బమ్మర్. ఏమి లేదు? ప్లగిన్ లోడ్ కాలేదు:

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

ప్రక్రియకు ప్లగిన్‌ని జోడిద్దాం:

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)

ఇప్పుడు మనకు కావాల్సినవన్నీ ఉన్నాయి. మళ్లీ ప్రయత్నిద్దాం:

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)

మీరు ఇప్పుడు "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)

మరియు అది మళ్లీ పని చేసింది!

ప్రశ్న: అదే పెర్కోనా లాగిన్ కింద సిస్టమ్‌కి లాగిన్ చేయడం సాధ్యమవుతుందా, కానీ వేరే వినియోగదారుగా?

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

లేదు, అది పని చేయదు.

తీర్మానం

MySQL అనేక అంశాలలో చాలా సరళంగా ఉంటుంది, వాటిలో ఒకటి ప్రమాణీకరణ పద్ధతి. మీరు ఈ పోస్ట్ నుండి చూడగలిగినట్లుగా, OS వినియోగదారుల ఆధారంగా పాస్‌వర్డ్‌లు లేకుండా యాక్సెస్ పొందవచ్చు. ఇది కొన్ని సందర్భాలలో ఉపయోగకరంగా ఉంటుంది మరియు RDS/Aurora నుండి సాధారణ MySQLకి మైగ్రేట్ చేస్తున్నప్పుడు వాటిలో ఒకటి IAM డేటాబేస్ ప్రమాణీకరణఇప్పటికీ యాక్సెస్ పొందడానికి, కానీ పాస్‌వర్డ్‌లు లేకుండా.

మూలం: www.habr.com

ఒక వ్యాఖ్యను జోడించండి