پاسورڊ کان سواءِ MySQL ڪيئن استعمال ڪجي (۽ سيڪيورٽي خطرا)

پاسورڊ کان سواءِ MySQL ڪيئن استعمال ڪجي (۽ سيڪيورٽي خطرا)

اهي چون ٿا ته بهترين پاسورڊ اهو آهي جيڪو توهان کي ياد رکڻ جي ضرورت ناهي. MySQL جي صورت ۾ اهو ممڪن آهي پلگ ان جي مهرباني auth_socket ۽ ان جو نسخو ماريا ڊي بي لاءِ - يونڪس_سڪوٽ.

اهي ٻئي پلگ ان بلڪل نوان نه آهن؛ انهن بابت گهڻو ڪجهه هن بلاگ ۾ چيو ويو آهي، مثال طور مضمون ۾ auth_socket پلگ ان استعمال ڪندي MySQL 5.7 ۾ پاسورڊ ڪيئن بدلجي. جڏهن ته، ماريا ڊي بي 10.4 ۾ نئون ڇا آهي، مون کي دريافت ڪيو ته هاڻي ڊفالٽ طور تي انسٽال ٿيل آهي unix_socket ۽ تصديق جي طريقن مان هڪ آهي ("هڪ مان"، ڇاڪاڻ ته ماريا ڊي بي 10.4 ۾ هڪ کان وڌيڪ پلگ ان هڪ صارف جي تصديق لاءِ موجود آهي، جيڪا دستاويز ۾ وضاحت ڪئي وئي آهي "تصديق" ماريا ڊي بي 10.04 کان).

جيئن مون چيو، اها خبر ناهي، ۽ جڏهن MySQL کي انسٽال ڪري رهيا آهيو .deb پيڪيجز استعمال ڪندي ڊيبين ٽيم پاران، هڪ روٽ صارف ٺاهي وئي آهي ساکٽ جي تصديق لاءِ. اهو صحيح آهي ٻنهي 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)

ساڳيو ئي معاملو آهي .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)

سرڪاري Percona مخزن مان .deb پيڪيجز پڻ روٽ صارف جي تصديق کي ترتيب ڏئي ٿو auth-socket ۽ Percona سرور لاءِ. اچو ته هڪ مثال سان ڏيو 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)

پوء جادو ڇا آهي؟ پلگ ان چيڪ ڪري ٿو ته لينڪس استعمال ڪندڙ MySQL استعمال ڪندڙ سان ملي ٿو SO_PEERCRED ساکٽ آپشن استعمال ڪندي صارف بابت معلومات گڏ ڪرڻ لاءِ ڪلائنٽ پروگرام هلائيندڙ. اهڙيء طرح، پلگ ان صرف سسٽم تي استعمال ڪري سگهجي ٿو جيڪي SO_PEERCRED اختيار کي سپورٽ ڪن ٿا، جهڙوڪ Linux. SO_PEERCRED ساکٽ آپشن توهان کي ساکٽ سان لاڳاپيل عمل جي uid کي ڳولڻ جي اجازت ڏئي ٿو. ۽ پوءِ هو اڳ ۾ ئي هن يوزر سان لاڳاپيل يوزر نالو وصول ڪري ٿو.

هتي استعمال ڪندڙ "vagrant" سان هڪ مثال آهي:

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)

ٿيو!

خير، هڪ غير ديبين جي تقسيم بابت ڇا آهي جتي اهو ڊفالٽ طرفان مهيا نه ڪيو ويو آهي؟ اچو ته ڪوشش ڪريون Percona سرور لاءِ MySQL 8 انسٽال ٿيل 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

ڌماڪو. ڇا غائب هو؟ پلگ ان لوڊ نه ٿيو:

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 ڪيترن ئي حصن ۾ ڪافي لچڪدار آهي، جن مان هڪ تصديق جو طريقو آهي. جئين توهان هن پوسٽ مان ڏسي سگهو ٿا، رسائي حاصل ڪري سگهجي ٿي بغير پاسورڊ جي، او ايس استعمال ڪندڙن جي بنياد تي. اهو ڪجهه خاص حالتن ۾ ڪارائتو ٿي سگهي ٿو، ۽ انهن مان هڪ آهي جڏهن RDS/Aurora کان باقاعده MySQL ڏانهن لڏپلاڻ ڪندي IAM ڊيٽابيس جي تصديقاڃا تائين رسائي حاصل ڪرڻ لاء، پر پاسورڊ کان سواء.

جو ذريعو: www.habr.com

تبصرو شامل ڪريو