googleapis / googleapis/google-cloud-python

google-auth: Thread safety race condition during 401 client certificate rotation in transports

Ouverte
#17,756 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
auth priority: p2 type: bug
Langage dominant
Python
Étoiles
5.4k
Forks
1.8k
Merge moyen
3 j 4 h
PR mergées (30 j)
122

Description

When handling `401 Unauthorized` responses, the HTTP transport interceptors in `google.auth.transport.requests` and `google.auth.transport.urllib3` attempt to auto-rotate expired mTLS client certificates by calling `configure_mtls_channel()`.

In multi-threaded environments, if multiple threads share an authorized session and hit a 401 concurrently, they will trigger the certificate rotation at the same time. Because there is no synchronization lock, this leads to race conditions. Multiple threads will redundantly read the updated certificates and concurrently mutate the underlying session's adapter mappings (`requests.Session.adapters`) or pool managers, which is not thread-safe and can cause runtime exceptions.

We should introduce a lock (e.g., using `threading.Lock`) around the `configure_mtls_channel` reconfiguration block inside the transport handlers to ensure that certificate rotation is performed serially.

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Start in google.auth.transport.requests and google.auth.transport.urllib3, focusing on the HTTP transport handlers that call configure_mtls_channel after a 401 response. Trace the shared-session and pool-manager reconfiguration paths, then verify that concurrent certificate rotations are serialized and no adapter or pool-manager mutation occurs simultaneously.

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

Évaluation

Stack technique
python
Domaine
networking, security
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
Calme
Clarté
Clairement spécifiée
Accessibilité débutants
72/100

Recevez les nouvelles issues par e-mail

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