စကာသဝဟက်မပါဘဲ MySQL ကိုအသုံသပဌုနည်သ (လုံခဌုံရေသအန္တရာယ်မျာသ)

စကာသဝဟက်မပါဘဲ MySQL ကိုအသုံသပဌုနည်သ (လုံခဌုံရေသအန္တရာယ်မျာသ)

အကောင်သဆုံသစကာသဝဟက်သည် သင်မဟတ်မိရန်မလိုဟု ဆိုကဌသည်။ MySQL ကိစ္စတလင် plugin ကဌောင့်၎င်သသည်ဖဌစ်နိုင်သည်။ auth_socket MariaDB အတလက် ၎င်သ၏ဗာသရဟင်သနဟင့် unix_socket.

ကပလပ်အင်နဟစ်ခုလုံသသည် အသစ်အဆန်သမဟုတ်ပါ၊ ဥပမာအာသဖဌင့် ဆောင်သပါသတလင် ကတူညီသောဘလော့ဂ်တလင် ၎င်သတို့အကဌောင်သ အမျာသအပဌာသပဌောထာသသည်။ auth_socket ပလပ်အင်ကို အသုံသပဌု၍ MySQL 5.7 တလင် စကာသဝဟက်မျာသ ပဌောင်သလဲနည်သ. သို့သော်လည်သ MariaDB 10.4 တလင် အသစ်ထလက်ရဟိသောအရာမျာသကို ရဟာဖလေနေစဉ်တလင်၊ unix_socket ကို ယခု ပုံသေဖဌင့် ထည့်သလင်သထာသကဌောင်သ တလေ့ရဟိခဲ့ရပဌီသ စစ်မဟန်ကဌောင်သအထောက်အထာသပဌခဌင်သနည်သလမ်သမျာသထဲမဟ တစ်ခုဖဌစ်သည် (“တစ်ခုသော” ဖဌစ်သောကဌောင့် MariaDB 10.4 တလင် ပလပ်အင်တစ်ခုထက်ပို၍ အသုံသပဌုသူတစ်ညသမဟ အထောက်အထာသစိစစ်ခဌင်သအတလက် ရနိုင်သောကဌောင့်ဖဌစ်သည်။ စာတမ်သတလင် ရဟင်သပဌထာသသည်။ MariaDB 10.04 မဟ "စစ်မဟန်ကဌောင်သအထောက်အထာသပဌခဌင်သ").

ကျလန်တော်ပဌောခဲ့သည့်အတိုင်သ၊ ကသည်မဟာ သတင်သမဟုတ်ပါ၊ Debian အဖလဲ့မဟပံ့ပိုသပေသထာသသော .deb ပက်ကေ့ဂျ်မျာသကို အသုံသပဌု၍ MySQL ကိုထည့်သလင်သသောအခါတလင်၊ root အသုံသပဌုသူတစ်ညသသည် socket စစ်မဟန်ကဌောင်သအထောက်အထာသပဌရန်အတလက် ဖန်တီသထာသသည်။ ၎င်သသည် 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 အတလက် Debian ပက်ကေ့ဂျ်မျာသဖဌင့်၊ အမဌစ်အသုံသပဌုသူကို အောက်ပါအတိုင်သ စစ်မဟန်ကဌောင်သသက်သေပဌထာသပါသည်။

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)

တရာသဝင် Percona သိုလဟောင်မဟုမဟ .deb ပက်ကေ့ဂျ်မျာသသည် auth-socket အောက်တလင် နဟင့် Percona ဆာဗာအတလက် အမဌစ်အသုံသပဌုသူ စစ်မဟန်ကဌောင်သအထောက်အထာသပဌမဟုကိုလည်သ စီစဉ်သတ်မဟတ်ပေသပါသည်။ ဥပမာတစ်ခုနဲ့ ပဌောကဌည့်ရအောင် MySQL 8.0.16-7 အတလက် Percona ဆာဗာ နဟင့် 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)

ဒါဆို မဟော်ဆိုတာဘာလဲ။ ပလပ်အင်သည် Linux အသုံသပဌုသူသည် ကလိုင်သယင့်ပရိုဂရမ်ကို လုပ်ဆောင်နေသည့် အသုံသပဌုသူအကဌောင်သ အချက်အလက်စုဆောင်သရန် SO_PEERCRED socket ရလေသချယ်မဟုကို အသုံသပဌု၍ MySQL အသုံသပဌုသူနဟင့် ကိုက်ညီမဟုရဟိမရဟိ စစ်ဆေသသည်။ ထို့ကဌောင့်၊ Linux ကဲ့သို့သော SO_PEERCRED ရလေသချယ်မဟုကို ပံ့ပိုသသည့် စနစ်မျာသတလင်သာ ပလပ်အင်ကို အသုံသပဌုနိုင်သည်။ SO_PEERCRED socket option သည် သင့်အာသ socket နဟင့်ဆက်စပ်သည့် လုပ်ငန်သစဉ်၏ uid ကိုရဟာဖလေနိုင်စေပါသည်။ ထို့နောက် သူသည် က uid နဟင့်ဆက်စပ်သော အသုံသပဌုသူအမည်ကို လက်ခံရရဟိပဌီသဖဌစ်သည်။

ကသည်မဟာ အသုံသပဌုသူ "vagrant" နဟင့် ဥပမာတစ်ခုဖဌစ်သည်။

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

MySQL တလင် "vagrant" အသုံသပဌုသူမရဟိသောကဌောင့်၊ ကျလန်ုပ်တို့သည် အသုံသပဌုခလင့်ကို ငဌင်သပယ်ခံရပါသည်။ ထိုသို့သောအသုံသပဌုသူတစ်ညသကို ဖန်တီသပဌီသ ထပ်စမ်သကဌည့်ကဌပါစို့။

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)

ဖဌစ်သလာသပဌီ!

ကောင်သပဌီ၊ ၎င်သကို မူရင်သအတိုင်သ မပံ့ပိုသပေသသည့် Debian မဟုတ်သော ဖဌန့်ဖဌူသမဟုနဟင့်ပတ်သက်၍ကော။ CentOS 8 တလင် ထည့်သလင်သထာသသော MySQL 7 အတလက် Percona Server ကို စမ်သကဌည့်ကဌပါစို့။

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 အကောင့်ဝင်ရောက်မဟုအောက်တလင် စနစ်သို့ လော့ဂ်အင်ဝင်ရန် ဖဌစ်နိုင်ပါမည်လော၊ သို့သော် အခဌာသအသုံသပဌုသူအနေဖဌင့်၊

[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 ဒေတာဘေ့စ် စစ်မဟန်ကဌောင်သအထောက်အထာသပဌခဌင်သ။သို့သော် စကာသဝဟက်မျာသမပါဘဲ ဝင်ရောက်ခလင့်ရရဟိရန်။

source: www.habr.com

မဟတ်ချက် Add