dshimizu/blog

アルファ版

MySQLのバグレポート(bugs.mysql.com)にコメントしてみた

MySQL InnoDB Clusterの検証をしていて発生したエラーの事象の1つについてこちらに書きましたが、その事象がこのバグレポに記載されている内容と類似の事象のように思いました。 2017/9/5 以降コメントが途絶えていたので、初めてのOSSへの貢献として自分で確認できた内容をコメントしてみました。

概要

問題の概要としてはdba.checkInstanceConfiguration()dba.configurelocalinstance()を使った場合、コマンド実行権限のみ確認され、MySQLアカウントに必要な権限がチェックされない、というもののようです。

例えば、MySQL InnoDB Cluster 初期構築時、MySQL Shellから dba.configureLocalInstance()を実行しますが、その際に以下のようにInnoDB Cluster管理用のユーザを作成するかどうかを確認されます。

mysql-js> dba.configureLocalInstance('root@localhost:3306')
Please provide the password for 'root@localhost:3306':

Detecting the configuration file...
Found configuration file at standard location: /etc/mysql/mysql.conf.d/mysqld.cnf
Do you want to modify this file? [Y|n]:  [Y|n]: y
MySQL user 'root' cannot be verified to have access to other hosts in the network.

1) Create root@% with necessary grants
2) Create account with different name
3) Continue without creating account
4) Cancel
Please select an option [1]: 2
Please provide an account name (e.g: icroot@%) to have it created with the necessary
privileges or leave empty and press Enter to cancel.
Account Name: icroot
Password for new account:
Confirm password:
Validating instance...

The instance 'localhost:3306' is valid for Cluster usage
You can now use it in an InnoDB Cluster.

{
    "status": "ok"
}

ここでユーザを作成した場合、このユーザを使ってClusterを新規作成するコマンドを実行した際に以下のようなエラーが発生します。

mysql-js> cluster = dba.createCluster('ClusterDev');
A new InnoDB cluster will be created on instance 'icroot@192.168.10.65:3306'.

Warning: The instance configuration needs to be changed in order to
create an InnoDB cluster. To see which changes will be made, please
use the dba.checkInstanceConfiguration() function before confirming
to change the configuration.

Should the configuration be changed accordingly? [y|N]: y

Creating InnoDB cluster 'ClusterDev' on 'icroot@192.168.10.65:3306'...
Dba.createCluster: ERROR: 1 table(s) do not have a Primary Key or Primary Key Equivalent (non-null unique key).
ERROR: Error starting cluster: The operation could not continue due to the following requirements not being met:
Non-compatible tables found in database. (RuntimeError)

これは dba.configureLocalInstance() で作成されるユーザではInnoDB Clusterに対するオペレーションする権限が足りないためです。 必要な権限は以下リンクの User Privileges に記載されています(徐々に権限の内容が変わっている模様)。 MySQL :: MySQL 5.7 Reference Manual :: 20.2.5 Production Deployment of InnoDB Cluster

必要な権限

GRANT ALL PRIVILEGES ON mysql_innodb_cluster_metadata.* TO your_user@'%' WITH GRANT OPTION;
GRANT RELOAD, SHUTDOWN, PROCESS, FILE, SUPER, REPLICATION SLAVE, REPLICATION CLIENT, CREATE USER ON *.* TO your_user@'%' WITH GRANT OPTION;
GRANT SELECT, INSERT, UPDATE, DELETE ON `mysql`.* TO 'icroot'@'%' WITH GRANT OPTION;
GRANT SELECT ON `performance_schema`.* TO 'icroot'@'%' WITH GRANT OPTION;
GRANT SELECT ON *.* TO your_user@'%' WITH GRANT OPTION;

実際に付与される権限

GRANT ALL PRIVILEGES ON `mysql_innodb_cluster_metadata`.* TO 'icroot'@'%' WITH GRANT OPTION
GRANT RELOAD, SHUTDOWN, PROCESS, FILE, SUPER, REPLICATION SLAVE, REPLICATION CLIENT, CREATE USER ON *.* TO 'icroot'@'%' WITH GRANT OPTION
GRANT SELECT, INSERT, UPDATE, DELETE ON `mysql`.* TO 'icroot'@'%' WITH GRANT OPTION
GRANT SELECT ON `performance_schema`.* TO 'icroot'@'%' WITH GRANT OPTION

全テーブルに対するselect権限(GRANT SELECT ON . TO your_user@'%' WITH GRANT OPTION;)が付与されません。

MySQLのコードの修正をできれば最高なんでしょうけど残念ながらそれをするには能力不足なので、発生原因と暫定回避策について拙い英語で書いてみました。 ※当初はsys.*への参照権限があれば良いということがドキュメントに書かれていたと思うので(すが記憶が曖昧)以下のようにコメントしましたが、現状のドキュメントでは全DBの全テーブルにselect権限を付与する必要がある、となっています。

[19 Sep 2017 16:40] Daisuke Shimizu
I think that you probably need the following user accounts.

GRANT SELECT ON sys.* TO your_user@'%' WITH GRANT OPTION;

When using "dba.configureLocalInstance ()" to create InnoDB cluster administration account, I think that the InnoDB cluster administration account may not have privilege to "sys schema".

11/9にコメントがあり、次期バージョンのMySQL Shellの1.0.11とMySQLの8.0.4ではアカウントに必要な権限が付与されるように修正されるとのことでした。

[9 Nov 11:24] David Moss
Posted by developer:
 
Thank you for your feedback, this has been fixed in upcoming versions and the following was added to the 1.0.11  / 8.0.4 changelog:
When using the dba.checkInstanceConfiguration()  and dba.configurelocalinstance() commands, the account being used was not being checked if it had enough privileges to actually execute the command. The fix ensures that account has the required privileges before proceeding. This also required a change of the privileges given to clusterAdmin users.

まとめ

初めてMySQLのバグレポート(bugs.mysql.com)にコメントしてみたときのことを書きました。 全く大したことはやっていませんがバグ報告の議論に参加したと言うことでほーーーーーーーーんのちょっとだけOSSに貢献するということができた(つもりになれて)良かったです。いずれはコードで貢献できれば…とは思ってますが、とりあえず第一歩として前進できました。

参考