Share
Embed
Transcript
22 slides
-
Confidential Confidential 自己紹介 2 くぼ • DBREやってます • MySQL 8.0から仲良くなり始めました
• クラフトビールをよく飲みます • Xはこちら ◦ https://twitter.com/amamanam am -
Confidential Confidential 現場の効率化から経営改善まで一元管理できる クラウド型建設プロジェクト管理サービス 社 内 社 外 営業 / 監督 /
設計 事務 / 管理職 職人 / 業者 メーカー / 流通 案件管理 資料 工程表 写真 報告 チャット 黒板 図面 受発注 • • • 3 ANDPADとは -
Confidential Confidential 背景 6 • Aurora MySQLの認証プラグインを caching_sha2_password 認証へ移行中 •
Aurora V3.04(compatible MySQL8.0.28) ではまだmysql_native_passwordは使える • プロダクトの多さを見越して先に着手 -
Confidential Confidential caching_sha2_passwordの復習 7 • パスワードハッシュ方式(SHA-256)に基づいた認証 • 初回の接続時にSSL/TLSなどセキュアな通信経路を必要と する •
一度、接続が成功したらその認証情報をDBサーバが キャッシュし、2回目からはそのキャッシュを用いて認証 を行う • そのため2回目以降はセキュアな通信経路を必要としない -
Confidential Confidential caching_sha2_password移行で起きた事象 10 • Redashのcaching_sha2_password認証の 対応状況の調査 • ローカル環境は接続できるのに、staging 環境が接続できない現象に遭遇
• それぞれのDBクライアントのバージョン は同じ(mysqlclient 2.2.1 で非対応) なぜローカルで接続できる?? -
Confidential Confidential caching_sha2_password移行で起きた事象 11 ローカル環境 Staging環境 cachign_sha2_password接続 できる できない 環境
MySQL on Dockerコンテナ Aurora MySQL DBドライバ mysqlclient 2.2.1 mysqlclient 2.2.1 -
Confidential Confidential MariaDB Connector/Cのプラグインについて 13 • libmariadb3のパッケージに caching_sha2_passwordに関するプラグ インが存在することが分かった •
ただし、MariaDB Connector/Cのバー ジョン3.0.8以上の場合に存在する https://github.com/mariadb-corporation/mariadb-connector-c/blob/4 61a2c79ea63406065a6237bf1043a250099565d/plugins/auth/caching _sha2_pw.c -
Confidential Confidential MariaDB Connector/Cのプラグインについて 14 /* if no public key
file was specified or if we couldn't read the file, we ask server to send public key */ if (!filebuffer) { unsigned char request= REQUEST_PUBLIC_KEY; if (vio->write_packet(vio, &request, 1) || (packet_length=vio->read_packet(vio, &packet)) == -1) { mysql->methods->set_error(mysql, CR_AUTH_PLUGIN_ERR, "HY000", "Couldn't read RSA public key from server"); return CR_ERROR; } } • 実際にソースを見ると公開鍵のリクエスト している部分が見られた -
Confidential Confidential MariaDB Connector/Cのプラグインについて 15 • DBドライバ側で 公開鍵の受け渡しに対応 していなくても、MariaDB Connector/C
が自動的にやりとりし、初回のセキュアな 経路は確保できる libmariadb3のバージョンを上げれ ばstagingでも疎通できるはず -
Confidential Confidential caching_sha2_password移行で起きた事象 16 ローカル環境 Staging環境 cachign_sha2_password接続 できる できない 環境
MySQL on Dockerコンテナ Aurora MySQL DBドライバ mysqlclient 2.2.1 mysqlclient 2.2.1 クライアントライブラリ MariaDB Connector/C 3.08以上 MariaDB Connector/C 3.08未満 -
Confidential Confidential MariaDB Connector/Cのプラグインについて 17 RSA Encryption not supported -
caching_sha2_password plugin was built with GnuTLS support …と思ったが別のエラーが発生 -
Confidential Confidential MariaDB Connector/Cのプラグインについて 18 • MariaDB Connector/Cをビルドする際にcmakeのオプ ションでWITH_SSL=GNUTLSが指定されている場 合、エラーを常に返す
#if defined(HAVE_GNUTLS) mysql->methods->set_error(mysql, CR_AUTH_PLUGIN_ERR, "HY000", "RSA Encryption not supported - caching_sha2_password plugin was built with GnuTLS support"); return CR_ERROR; -
Confidential Confidential MariaDB Connector/Cのプラグインについて 19 • stagingのlibmariadb3はGnuTLSを指定してビルド していそうなことが判明 • ローカルで問題なく接続ができた理由はGnuTLSで
なくOpenSSLを使うようにビルドされていたため • Debian 12(bookworm)でのlibmariadb3は OpenSSLを使うようにビルドされているようで、 Debian 10(buster)はGnuTLSを使うようにビル ドされていた Redashのバージョンを上げて解決 -
Confidential Confidential caching_sha2_password移行で起きた事象 20 ローカル環境 Staging環境 cachign_sha2_password接続 できる できない 環境
MySQL on Dockerコンテナ Aurora MySQL DBドライバ mysqlclient 2.2.1 mysqlclient 2.2.1 クライアントライブラリ MariaDB Connector/C 3.08以上 MariaDB Connector/C 3.08以上 OS Debian 12(bookworm) Debian 10(buster) -
Confidential Confidential まとめ 21 • MariaDB Connector/C は caching_sha2_password 認証の初回接続
時のセキュアな通信経路確保を自動的に行 なってくれる • しかし、これには OpenSSLでビルドされ ている必要がある -
Confidential Confidential 参考 22 • Protecting MySQL Passwords With the
sha256_password Plugin • MySQL 8.0.4 : New Default Authentication Plugin : caching_sha2_password • Caching_sha2_password information