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

Ouverte Adaptée aux débutants
#1,750 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 5 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
74/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
mysql, python

Piste de recherche

Commencez dans pyproject.toml, où pymysql>=1.1.1 est déclaré, et remplacez-le par pymysql[rsa]>=1.2.4 ; vérifiez aussi setup.py/setup.cfg si les métadonnées s’y trouvent. Ajoutez ensuite l’entrée des notes de version 2.3.7 expliquant que use_tls=False signifie pas de TLS depuis 2.3.6 et que les connexions MySQL 8 nécessitent désormais cryptography plus PyMySQL 1.2.4+. Reflétez le pin dans la recette conda-forge. Terminé lorsqu’une installation neuve sans cryptography se connecte à un conteneur mysql:8.0 avec use_tls=False et que la note est publiée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.
Langage dominant
Python
Étoiles
198
Forks
103
Merge moyen
5 j 1 h
PR mergées (30 j)
12

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de datajoint/datajoint-python

Toutes les issues de datajoint/datajoint-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.