MySQL5.7-------proxy実現rols管理


1.背景
*ロールのコンセプト管理データベースへのアクセス権.ロール自体の設定によって、1つのロールはデータベース・ユーザー、またはデータベース・ユーザーのセットと見なすことができます.ロールは、データベース・オブジェクト(テーブルなど)と、これらのオブジェクトに付与された権限を他のロールに付与して、誰がどのオブジェクトにアクセスする権限を持っているかを制御できます.また、1つのロールのメンバー権限を他のロールに付与することもできます.これにより、メンバーロールがメンバー権限を付与されたロールの権限を使用することができます.
*MySQL 5.7は、「rols」のような役割管理機能を「proxy」エージェントで実現し始めました.
2.環境
   * MySQL Server
Server version: 5.7.18 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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 version();
+-----------+
| version() |
+-----------+
| 5.7.18    |
+-----------+
1 row in set (0.00 sec)

3.実現
*プロキシ・ユーザー・マッピングの有効化
mysql> SET @@global.check_proxy_users = ON;
Query OK, 0 rows affected (0.00 sec)


mysql> SET @@global.mysql_native_password_proxy_users = ON;
Query OK, 0 rows affected (0.00 sec)

*ロールユーザーの作成
mysql> create user 'rols_it'@'127.0.0.1';
Query OK, 0 rows affected (0.01 sec)

 
*一般ユーザーtomの作成
mysql> create user 'tom'@'127.0.0.1' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

*proxyでtomユーザーをロールに追加
mysql> grant proxy on 'rols_it'@'127.0.0.1' to 'tom'@'127.0.0.1';
Query OK, 0 rows affected (0.00 sec)

 
4.テスト
*テストデータベースitの作成
mysql> create database it;
Query OK, 1 row affected (0.00 sec)

*ロール(rols)にデータベースitの表示権限を追加
mysql> grant select ON it.* TO 'rols_it'@'127.0.0.1';
Query OK, 0 rows affected (0.00 sec)

*ロール権限の表示
mysql> show grants for 'rols_it'@'127.0.0.1';
+-------------------------------------------------+
| Grants for [email protected]                    |
+-------------------------------------------------+
| GRANT USAGE ON *.* TO 'rols_it'@'127.0.0.1'     |
| GRANT SELECT ON `it`.* TO 'rols_it'@'127.0.0.1' |
+-------------------------------------------------+
2 rows in set (0.01 sec)

*tomユーザー権限の表示
mysql> show grants for 'tom'@'127.0.0.1';
+-----------------------------------------------------------+
| Grants for [email protected]                                  |
+-----------------------------------------------------------+
| GRANT USAGE ON *.* TO 'tom'@'127.0.0.1'                   |
| GRANT PROXY ON 'rols_it'@'127.0.0.1' TO 'tom'@'127.0.0.1' |
+-----------------------------------------------------------+
2 rows in set (0.00 sec)

*tomユーザー登録によるMySQL接続
[root@MySQL mysql_data]# mysql -utom -p123456 -h127.0.0.1
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.18-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| it                 |
+--------------------+
2 rows in set (0.00 sec)

5.まとめ
需要駆動技術では、技術自体に優略の区別はなく、業務の区別しかない.