`sslmode=prefere` surface misleading "no encryption" error when using a wrong password
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện lỗi khi kết nối đến một máy chủ PostgreSQL yêu cầu SSL với mật khẩu không đúng, sau đó kiểm tra _connect_addr/__connect_addr và cách xử lý việc thử lại trong connect_utils.py. Được coi là hoàn tất khi lỗi xác thực đầu tiên được giữ nguyên hoặc lần thử lại không còn thay thế nó bằng lỗi gây hiểu nhầm "no encryption".
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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?
- Ngôn ngữ chính
- Python
- Star
- 8.1k
- Fork
- 469
- Merge trung bình
- 2 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 9
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MagicStack/asyncpg
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
MagicStack/asyncpg#1357 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
MagicStack/asyncpg#1354 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
MagicStack/asyncpg#1342 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 56/100
MagicStack/asyncpg#1340 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 28/100
MagicStack/asyncpg#1337 ·
Tất cả issue của MagicStack/asyncpg
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
canonical/paas-charm#368 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
tech debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
addition to tracking list Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
StevenBlack/hosts#3256 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
qualcomm/qai-appbuilder#275 ·