環境
- Amazon Linux
手順
MySQL のインストール
yum install -y mysql-server
Chef のレシピ的には以下で...
package "mysql-server" do action :install end service "mysql_service" do case node["platform"] when "CentOS","RedHat","Fedora","amazon" service_name "mysqld" else service_name "mysql" end supports :status => true, :restart => true, :reload => true action [ :enable, :start ] end
MySQL 上の SSL 状態の確認
mysql> SHOW VARIABLES LIKE '%ssl%'; +---------------+----------+ | Variable_name | Value | +---------------+----------+ | have_openssl | DISABLED | | have_ssl | DISABLED | | ssl_ca | | | ssl_capath | | | ssl_cert | | | ssl_cipher | | | ssl_key | | +---------------+----------+ 7 rows in set (0.00 sec)
SSL を使う為の準備
- 注意点
- Common Name は CA と MySQL サーバーで分けること...
CA のキーを生成
mkdir /etc/mysql-ssl cd /etc/mysql-ssl openssl genrsa -out ca-key.pem 2048
CA の証明書を作成
openssl req -new -x509 -nodes -days 1000 -key ca-key.pem -out ca-cert.pem
MySQL サーバーの秘密鍵と CSR の作成
openssl req -newkey rsa:2048 -days 1000 -nodes -keyout server-key.pem -out server-req.pem
MySQL サーバーの証明書作成
openssl x509 -req -in server-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -out server-cert.pem -set_serial 01
my.cnf への設定し、MySQL の再起動を行う
[mysqld] ssl-ca=/etc/mysql-ssl/ca-cert.pem ssl-cert=/etc/mysql-ssl/server-cert.pem ssl-key=/etc/mysql-ssl/server-key.pem
/etc/init.d/mysqld restart
改めて MySQL 上の SSL 状態の確認
mysql> SHOW VARIABLES LIKE '%ssl%'; -------------- SHOW VARIABLES LIKE '%ssl%' -------------- +---------------+--------------------------------+ | Variable_name | Value | +---------------+--------------------------------+ | have_openssl | YES | | have_ssl | YES | | ssl_ca | /etc/mysql-ssl/ca-cert.pem | | ssl_capath | | | ssl_cert | /etc/mysql-ssl/server-cert.pem | | ssl_cipher | | | ssl_key | /etc/mysql-ssl/server-key.pem | +---------------+--------------------------------+ 7 rows in set (0.00 sec)
SSL でアクセスする為のユーザーを作る
GRANT ALL PRIVILEGES ON *.* TO ${your_user}@localhost IDENTIFIED BY '${your_pass}' REQUIRE SSL; FLUSH PRIVILEGES;
SSL 用ユーザーでアクセスする
- CA の証明書を指定して接続する
mysql -h localhost -u ${your_user} --ssl-ca=/etc/mysql-ssl/ca-cert.pem -p
show status like'Ssl_cipher';
-------------- SHOW STATUS LIKE 'Ssl_cipher' -------------- +---------------+--------------------+ | Variable_name | Value | +---------------+--------------------+ | Ssl_cipher | DHE-RSA-AES256-SHA | +---------------+--------------------+ 1 row in set (0.00 sec)