Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MySQL 透過的暗号化とSSLを使ってみた

MySQL 透過的暗号化とSSLを使ってみた

Satoshi MITANI

July 23, 2018
Tweet

More Decks by Satoshi MITANI

Other Decks in Technology

Transcript

  1. 5-4ͬ͘͟Γ ઀ଓཁٻ ϧʔτ $"ূ໌ॻ αʔό ূ໌ॻ NZTRMHSKQ ΁઀ଓ͠Α͏ αʔό ূ໌ॻ

    αʔό αʔό؅ཧऀ NZTRMHSKQ ͷ؅ཧऀͰ͢Α ೝূہ9 ʢ$" ূ໌ॻ ൃߦਃ੥ ൿີ伴 ͔֬ʹɺ ৴པ͢Δ 9͔Β ൃߦ͞Εͨূ໌ॻ ͔ͭ NZTRMHSKQͷ΋ͷͩ ެ։伴 $PNNPO/BNF NZTRMHSKQ σδλϧॺ໊ νΣοΫ ڞ௨伴ɹަ׵ ҉߸௨৴ αʔό ূ໌ॻ
  2. 5-4ͬ͘͟Γ ઀ଓཁٻ ϧʔτ $"ূ໌ॻ αʔό ূ໌ॻ NZTRMHSKQ ΁઀ଓ͠Α͏ αʔό ূ໌ॻ

    αʔό αʔό؅ཧऀ NZTRMHSKQ ͷ؅ཧऀͰ͢Α ೝূہ9 ʢ$" ূ໌ॻ ൃߦਃ੥ ൿີ伴 ͔֬ʹɺ ৴པ͢Δ 9͔Β ൃߦ͞Εͨূ໌ॻ ͔ͭ NZTRMHSKQͷ΋ͷͩ ެ։伴 $PNNPO/BNF NZTRMHSKQ σδλϧॺ໊ νΣοΫ ڞ௨伴ɹަ׵ ҉߸௨৴ αʔό ূ໌ॻ
  3. 5-4ͬ͘͟Γ ઀ଓཁٻ ϧʔτ $"ূ໌ॻ αʔό ূ໌ॻ NZTRMHSKQ ΁઀ଓ͠Α͏ αʔό ূ໌ॻ

    αʔό αʔό؅ཧऀ NZTRMHSKQ ͷ؅ཧऀͰ͢Α ೝূہ9 ʢ$" ূ໌ॻ ൃߦਃ੥ ൿີ伴 ͔֬ʹɺ ৴པ͢Δ 9͔Β ൃߦ͞Εͨূ໌ॻ ͔ͭ NZTRMHSKQͷ΋ͷͩ ެ։伴 $PNNPO/BNF NZTRMHSKQ σδλϧॺ໊ νΣοΫ ڞ௨伴ɹަ׵ ҉߸௨৴ αʔό ূ໌ॻ
  4. 44-઀ଓͷಈ࡞ͷྫ # mysql -h db01.example.jp --ssl-ca=ca.pem --ssl-mode=VERIFY_CA -unativeuser -p mysql>

    \s -------------- mysql Ver 8.0.11 for Linux on x86_64 (MySQL Community Server - GPL) Connection id: 42 Current database: Current user: [email protected] SSL: Cipher in use is DHE-RSA-AES128-GCM-SHA256 Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 8.0.11 MySQL Community Server - GPL Protocol version: 10 Connection: db01.example.jp via TCP/IP Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8mb4 Conn. characterset: utf8mb4 TCP port: 3306 Uptime: 8 days 8 hours 33 min 53 sec
  5. TTMNPEFΦϓγϣϯ w > TTMNPEF ޮՌ %*4"#-&% 44-઀ଓΛར༻͠ͳ͍ 13&'&33&% %&'"6-5 44-઀ଓ͕࢖͑ͳ͚Ε͹ɺ

    ฏจ઀ଓΛར༻ 3&26*3&% 44-઀ଓͷΈΛར༻͢Δ ূ໌ॻ͸ݕূ͠ͳ͍ 7&3*':@$" 44-Λར༻͢Δ ৴པ͢Δೝূہ $" ͔Βൃߦ͞Εͨূ໌ॻ͔֬ೝ͢Δ 7&3*':@*%&/5*5: 44-Λར༻͢Δ ͞Βʹࢦఆͨ͠઀ଓઌͱূ໌ॻͷ$/͕Ұக͢Δ͔֬ೝ͢Δ ͔ͬ͠Γ νΣοΫ
  6. 44-઀ଓͷڧ੍ w αʔό·Δ͝ͱࢦఆ w Ϣʔβ୯ҐͰ઀ଓΛڧ੍ mysql> CREATE USER ‘appuser’@‘192.168.1.123’ REQUIRE

    SSL; mysql> GRANT SELECT ON important.secret TO ‘appuser’@‘192.168.1.123’; $ vi /etc/my.cnf [mysqld] require_secure_transport = on $ mysql -h db.example.jp --ssl-mode=DISABLED ERROR 3159 (HY000): Connections using insecure transport are prohibited 
 while —require_secure_transport=ON.
  7. 44-ϥΠϒϥϦͷมߋ w XPMG44- ZB44- ˠ0QFO44- w 5-4Wͷαϙʔτ w 4UBUJD-JOLͰ͸ͳ͘%ZOBNJD-JOLʹ w

    0QFO44-ʹ੬ऑੑ౳͕͋ͬͯ΋.Z42-ͷϦϦʔεΛ଴ͭඞཁ͕ͳ͍ &EJUJPO44-MJC WFS WFS $PNNVOJUZ &EJUJPO XPMG44- TUBUJDMJOL 0QFO44- EZOBNJDMJOL &OUFSQSJTF &EJUJPO 0QFO44- TUBUJDMJOL # MySQL 8.0 $ ldd `which mysqld` | grep ssl libssl.so.10 => /lib64/libssl.so.10 # MySQL 5.7 $ ldd `which mysqld` | grep ssl
  8. ࢼͨ݁͠Ռ $ openssl x509 -text -noout -in /var/lib/mysql/server-cert.pem | head

    -n 12 Certificate: Data: Version: 1 (0x0) Serial Number: db:86:48:69:9f:07:9b:7e Signature Algorithm: sha256WithRSAEncryption Issuer: CN=MySQL_Server_8.0.11_Auto_Generated_CA_Certificate Validity Not Before: Jul 7 04:43:14 2018 GMT Not After : Jul 4 04:43:14 2028 GMT Subject: C=JP, L=Default City, O=Default Company Ltd, CN=*.example.jp Subject Public Key Info: $ mysql -h db01.example.jp --ssl-mode=VERIFY_IDENTITY --ssl-ca=/var/lib/mysql/ca.pem ERROR 2026 (HY000): SSL connection error: SSL certificate validation failure $ mysql -h ¥*.example.jp —-ssl-mode=VERIFY_IDENTITY —ssl-ca=/var/lib/mysql/ca.pem mysql>