MySQL: with use_tls=False, 2.3.6 needs the cryptography package to log in to MySQL 8

オープン 初心者向け
#1,750 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 5 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
mysql, python

調査の方向性

pyproject.toml から始めます。ここで pymysql>=1.1.1 が宣言されているので、それを pymysql[rsa]>=1.2.4 に置き換えてください。メタデータがそこにある場合は setup.py/setup.cfg も確認してください。次に、use_tls=False は 2.3.6 以降 TLS なしを意味すること、MySQL 8 のログインには cryptography と PyMySQL 1.2.4+ が必要になったことを説明する 2.3.7 のリリースノート項目を追加します。conda-forge レシピの pin も合わせてください。cryptography なしの新規インストールが use_tls=False で mysql:8.0 コンテナに接続でき、そのノートが公開されたら完了です。

索引モデルが issue の本文から書いたものです。

説明

bug

Summary

Since 2.3.6, use_tls=False turns TLS off on MySQL; in 2.3.5 the connection still used TLS. Without TLS, PyMySQL needs the cryptography package to log in with MySQL 8's default authentication (caching_sha2_password) whenever the server has no cached login for the account. datajoint does not depend on cryptography, so after upgrading to 2.3.6 such a connection fails:

RuntimeError: 'cryptography' package is required for sha256_password or caching_sha2_password auth methods

The server caches a login after the account's first login over TLS or a local socket, so the error is intermittent in practice: it appears after a server restart, FLUSH PRIVILEGES, a password change, or for a new account.

Reproduction

A fresh mysql:8.0 container, use_tls = False, and a check of the session's cipher:

import datajoint as dj

dj.config["database.use_tls"] = False
conn = dj.conn(reset=True)
conn.query("SHOW SESSION STATUS LIKE 'Ssl_cipher'").fetchall()
DataJoint Ssl_cipher
2.3.5 TLS_AES_256_GCM_SHA384: TLS was used although use_tls=False
2.3.6 empty: no TLS, as configured

The test suite of https://github.com/datajoint/dj-png-codecs shows the effect. It sets use_tls = False against a fresh MySQL 8.0 container. With datajoint 2.3.5, all tests pass. With 2.3.6, the first connection raises the RuntimeError above (https://github.com/datajoint/dj-png-codecs/pull/9).

PostgreSQL connections are not affected.

Expected

use_tls=False keeps working after an upgrade, without a dependency the user has to discover from a PyMySQL error.

PyMySQL 1.2.1 to 1.2.3

With cryptography installed, the same login still fails on PyMySQL 1.2.1, 1.2.2 and 1.2.3:

AttributeError: 'NoneType' object has no attribute 'is_auth_switch_request'

In those releases, caching_sha2_password_auth (pymysql/_auth.py) sends the RSA-encrypted password but does not return the server's reply. PyMySQL 1.2.0 and 1.2.4 return it, and the login succeeds. The dj-png-codecs suite with datajoint 2.3.6 and cryptography passes on PyMySQL 1.1.2, 1.2.0 and 1.2.4, and fails on 1.2.1 to 1.2.3.

Proposed fix

  • Depend on pymysql[rsa]>=1.2.4 instead of pymysql>=1.1.1. The rsa extra installs cryptography, which PyMySQL documents as required for caching_sha2_password and sha256_password without TLS. The floor leaves out 1.2.1 to 1.2.3, and keeps the fix for CVE-2024-36039 that the current floor is for.
  • Say in the 2.3.7 release notes that use_tls=False disables TLS since 2.3.6, and that such connections to MySQL 8 need cryptography and PyMySQL 1.2.4 or later, which 2.3.7 installs.
  • Apply the same requirements in the conda-forge recipe.
主要言語
Python
スター
198
フォーク
103
平均マージ
5日 1時間
マージ済み PR(30日)
12

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

datajoint/datajoint-python のほかの issue

datajoint/datajoint-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。