direct_tls doesn't work with PostgreSQL 17+ because ALPN isn't set
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 76/100
Rechercherichtung
Beginne damit, die SSL-Kontexte zu lokalisieren, die asyncpg für direct_tls erstellt, sowie den Verbindungspfad, der die direkte SSL-Aushandlung verarbeitet. Reproduziere mit dem PostgreSQL-18-Docker-Befehl aus dem Issue und überprüfe anschließend, dass Verbindungen mit direct_tls mit dem Standardkontext funktionieren, und füge Abdeckung für das PostgreSQL-ALPN-Protokoll hinzu oder aktualisiere sie.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
- 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.
- Vorherrschende Sprache
- Python
- Sterne
- 8.1k
- Forks
- 469
- Ø Merge
- 4 T. 1 Std.
- Gemergte PRs (30 T.)
- 14
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus MagicStack/asyncpg
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
MagicStack/asyncpg#1342 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 56/100
MagicStack/asyncpg#1340 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 28/100
MagicStack/asyncpg#1337 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
MagicStack/asyncpg#1330 · 1 Kommentar ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 38/100
MagicStack/asyncpg#1322 ·
Alle Issues in MagicStack/asyncpg
Ähnliche Issues
-
agent-ready documentation needs-triage
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
documentation
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
-
instance instance add
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
searxng/searx-instances#939 · 1 Kommentar ·
-
area-deployment area-integrations triage:bot-seen
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 86/100