direct_tls doesn't work with PostgreSQL 17+ because ALPN isn't set
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
Hướng nghiên cứu
Trước tiên, hãy xác định các ngữ cảnh SSL mà asyncpg tạo cho direct_tls và đường dẫn kết nối xử lý quá trình thương lượng SSL trực tiếp. Tái hiện bằng lệnh Docker PostgreSQL 18 trong issue, sau đó xác minh rằng các kết nối với direct_tls hoạt động với ngữ cảnh mặc định và thêm hoặc cập nhật độ bao phủ cho giao thức ALPN của PostgreSQL.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- asyncpg version: 0.31.0 (also checked master)
- PostgreSQL version: 17.11 and 18.0
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: No, reproduced with a local PostgreSQL in Docker - Python version: 3.12
- Platform: Linux
- Do you use pgbouncer?: No
- Did you install asyncpg with pip?: Yes (via uv)
- If you built asyncpg locally, which version of Cython did you use?: N/A
- Can the issue be reproduced under both asyncio and
uvloop?: Only tried asyncio
When connecting with direct_tls=True, the connection gets dropped right away:
await asyncpg.connect(dsn, ssl="require", direct_tls=True)
# ConnectionDoesNotExistError: connection was closed in the middle of operation
The server log says why:
LOG: received direct SSL connection request without ALPN protocol negotiation extension
PostgreSQL 17 requires the postgresql ALPN protocol for direct SSL connections, and libpq always sends it. asyncpg doesn't set ALPN on the context it builds, so as far as I can tell direct_tls (and sslnegotiation=direct in the DSN) can't work against a stock PG 17+ server unless you pass your own context:
ctx = ssl.create_default_context()
ctx.set_alpn_protocols(["postgresql"])
await asyncpg.connect(dsn, ssl=ctx, direct_tls=True) # works
Repro with Docker:
docker run --rm -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:18 \
-c ssl=on \
-c ssl_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem \
-c ssl_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
I'll send a PR that sets postgresql ALPN on the contexts asyncpg creates.
- Ngôn ngữ chính
- Python
- Star
- 8.1k
- Fork
- 469
- Merge trung bình
- 4 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 14
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ó 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 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
MagicStack/asyncpg#1330 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
MagicStack/asyncpg#1322 ·
Tất cả issue của MagicStack/asyncpg
Issue tương tự
-
agent-ready documentation needs-triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Add https://search.jeremyh.xyz/ Đang mởinstance instance add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
searxng/searx-instances#939 · 1 bình luận ·
-
area-deployment area-integrations triage:bot-seen
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 86/100