`sslmode=prefere` surface misleading "no encryption" error when using a wrong password
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
まず、誤ったパスワードで SSL を要求する PostgreSQL サーバーに対して失敗を再現し、その後 _connect_addr/__connect_addr と connect_utils.py のリトライ処理を調査します。最初の認証失敗が保持されるか、リトライによってそれが誤解を招く "no encryption" エラーに置き換えられなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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?
- 主要言語
- Python
- スター
- 8.1k
- フォーク
- 469
- 平均マージ
- 2日 20時間
- マージ済み PR(30日)
- 9
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
MagicStack/asyncpg のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
MagicStack/asyncpg#1357 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
MagicStack/asyncpg#1354 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
MagicStack/asyncpg#1342 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 56/100
MagicStack/asyncpg#1340 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 28/100
MagicStack/asyncpg#1337 ·
MagicStack/asyncpg の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
canonical/paas-charm#368 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
tech debt
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
StevenBlack/hosts#3256 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
qualcomm/qai-appbuilder#275 ·