๋น„๋ฐ€๋ฒˆํ˜ธ(๋ฐ ๋ณด์•ˆ ์œ„ํ—˜) ์—†์ด MySQL์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

๋น„๋ฐ€๋ฒˆํ˜ธ(๋ฐ ๋ณด์•ˆ ์œ„ํ—˜) ์—†์ด MySQL์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•

๊ฐ€์žฅ ์ข‹์€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ๊ธฐ์–ตํ•  ํ•„์š”๊ฐ€ ์—†๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. MySQL์˜ ๊ฒฝ์šฐ ํ”Œ๋Ÿฌ๊ทธ์ธ ๋•๋ถ„์— ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์ธ์ฆ ์†Œ์ผ“ MariaDB ๋ฒ„์ „ - ์œ ๋‹‰์Šค ์†Œ์ผ“.

์ด ๋‘ ํ”Œ๋Ÿฌ๊ทธ์ธ์€ ๋ชจ๋‘ ์ „ํ˜€ ์ƒˆ๋กœ์šด ๊ฒƒ์ด ์•„๋‹™๋‹ˆ๋‹ค. ๋™์ผํ•œ ๋ธ”๋กœ๊ทธ์—์„œ ์ด์— ๋Œ€ํ•ด ๋งŽ์€ ์ด์•ผ๊ธฐ๊ฐ€ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. auth_socket ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉํ•˜์—ฌ MySQL 5.7์—์„œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ•. ๊ทธ๋Ÿฌ๋‚˜ MariaDB 10.4์˜ ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์กฐ์‚ฌํ•˜๋Š” ๋™์•ˆ unix_socket์ด ์ด์ œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์„ค์น˜๋˜๊ณ  ์ธ์ฆ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜("์ค‘ ํ•˜๋‚˜")๋ผ๋Š” ์‚ฌ์‹ค์„ ๋ฐœ๊ฒฌํ–ˆ์Šต๋‹ˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด MariaDB 10.4์—์„œ๋Š” ํ•œ ์‚ฌ์šฉ์ž๊ฐ€ ์ธ์ฆ์„ ์œ„ํ•ด ๋‘˜ ์ด์ƒ์˜ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋ฌธ์„œ์— ์„ค๋ช…๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค MariaDB 10.04์˜ "์ธ์ฆ").

๋‚ด๊ฐ€ ๋งํ–ˆ๋“ฏ์ด ์ด๊ฒƒ์€ ๋‰ด์Šค๊ฐ€ ์•„๋‹ˆ๋ฉฐ Debian ํŒ€์—์„œ ์ง€์›ํ•˜๋Š” .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์šฉ 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 Server์— ๋Œ€ํ•œ ๋ฃจํŠธ ์‚ฌ์šฉ์ž ์ธ์ฆ์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. MySQL 8.0.16-7์šฉ Percona ์„œ๋ฒ„ ๋ฐ ์šฐ๋ถ„ํˆฌ 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" ์‚ฌ์šฉ์ž์˜ ์˜ˆ์ž…๋‹ˆ๋‹ค.

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 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 ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ธ์ฆ๊ณ„์†ํ•ด์„œ ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์—†์Šต๋‹ˆ๋‹ค.

์ถœ์ฒ˜ : habr.com

์ฝ”๋ฉ˜ํŠธ๋ฅผ ์ถ”๊ฐ€