`sslmode=prefere` surface misleading "no encryption" error when using a wrong password
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia riproducendo il problema con un server PostgreSQL che richiede SSL usando una password errata, quindi esamina _connect_addr/__connect_addr e la gestione dei tentativi in connect_utils.py. Il lavoro è completato quando il primo errore di autenticazione viene preservato oppure il tentativo successivo non lo sostituisce più con l’errore fuorviante "no encryption".
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
When connecting with the default sslmode=prefere to a PostreSQL server that requires SSL (e.g. Amazon RDS with their default force_ssl=1), asyncpg reports:
asyncpg.exceptions.InvalidAuthorizationSpecificationError:
no pg_hba.conf entry for host "...", user "...", database "...", no encryption
The "no encryption" message points at an SSL/pg_hba.conf problem, when the actual issue is simply wrong credentials. This can send users on a lengthy debugging detour (so I heard).
Steps to reproduce
- Set up a PostgreSQL instance that requires SSL (e.g. Amazon RDS with
rds.force_ssl=1). - Attempt to connect with
sslmode=prefer(or rely on the default) using an incorrect password.
Expected: An error indicating password authentication failed (or at least something that points toward credentials). Actual: no pg_hba.conf entry ... no encryption
Analysis
(Disclaimer: First glance at the asyncpg code and no Python dev)
I believe what's happening is the following
The retry logic in _connect_addr / __connect_addr (connect_utils.py) does the following for sslmode=prefer:
- First attempt — connects with SSL. The TLS handshake succeeds, but authentication fails, raising
InvalidAuthorizationSpecificationError. The exact server message from this first attempt is never surfaced to the user. - The exception handler at the
except InvalidAuthorizationSpecificationErrorblock checksretry and params.sslmode == SSLMode.prefer and pr.is_ssl— allTrue— and raises_RetryConnectSignal. - Second attempt — connects without SSL. The server, which requires SSL, rejects the plaintext connection with the
pg_hba.conf/ "no encryption" error. This is the only error the user sees.
Is there a way to safely distinguish between both cases and do not attempt to retry when the first attempt fails because of a wrong password? Or otherwise: Can we preserve the error message and raise both?
- Lingua principale
- Python
- Stelle
- 8.1k
- Fork
- 469
- Merge medio
- 2g 20h
- PR unite (30g)
- 9
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MagicStack/asyncpg
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
MagicStack/asyncpg#1357 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
MagicStack/asyncpg#1354 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
MagicStack/asyncpg#1342 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
MagicStack/asyncpg#1340 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 28/100
MagicStack/asyncpg#1337 ·
Tutte le issue di MagicStack/asyncpg
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
canonical/paas-charm#368 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
tech debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
addition to tracking list Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
StevenBlack/hosts#3256 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
qualcomm/qai-appbuilder#275 ·