pg.ddx.io pgbouncer/pgbouncer GitHub issues and pull requests
help / color / mirror / Atom feed[pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
17+ messages / 4 participants
[nested] [flat]
* [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-09-03 19:17 "dpittner (@dpittner)" <noreply+dpittner@github.com>
0 siblings, 0 replies; 17+ messages in thread
From: dpittner (@dpittner) @ 2026-09-03 19:17 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
What: attempt in addressing the remaining part of https://github.com/pgbouncer/pgbouncer/issues/1203 as per https://github.com/pgbouncer/pgbouncer/issues/1203#issuecomment-3182650069 and adding support for upstream tlsdirect
inline patch 1: doc/config.md, etc/pgbouncer.ini, include/bouncer.h and 6 more (+278/-6 lines) download inline-1.patch
diff --git a/doc/config.md b/doc/config.md
index 1cb43dd1b8bb..9f71fc5e228c 100644
--- a/doc/config.md
+++ b/doc/config.md
@@ -1003,6 +1003,23 @@ verify-full
according to `server_tls_ca_file`. Server host name must match
certificate information.
+### server_tls_direct
+
+If set to 1, PgBouncer initiates a TLS handshake immediately upon TCP connect,
+without sending the PostgreSQL `SSLRequest` message first. Use this when
+connecting to PostgreSQL 17+ servers or proxies that expect a direct TLS
+connection rather than the standard SSL-negotiation protocol (e.g. a
+TLS-terminating load balancer or stunnel).
+
+Certificate verification behaviour is controlled by `server_tls_sslmode` as
+normal: `require`, `verify-ca`, and `verify-full` all work correctly with
+`server_tls_direct = 1`.
+
+Setting `server_tls_direct = 1` together with `server_tls_sslmode = disable`
+is an error.
+
+Default: 0
+
### server_tls_ca_file
Root certificate file to validate PostgreSQL server certificates.
diff --git a/etc/pgbouncer.ini b/etc/pgbouncer.ini
index 0e50c757955a..033120f5bc89 100644
--- a/etc/pgbouncer.ini
+++ b/etc/pgbouncer.ini
@@ -110,6 +110,9 @@ listen_port = 6432
;; disable, allow, prefer, require, verify-ca, verify-full
;server_tls_sslmode = prefer
+;; If set to 1, initiates a TLS handshake immediately upon TCP connect
+;server_tls_direct = 1
+
;; Path to that contains trusted CA certs
;server_tls_ca_file = <system default>
diff --git a/include/bouncer.h b/include/bouncer.h
index 88ea46eb35cf..772934c3efe6 100644
--- a/include/bouncer.h
+++ b/include/bouncer.h
@@ -923,6 +923,7 @@ extern char *cf_client_tls_dheparams;
extern char *cf_client_tls_ecdhecurve;
extern int cf_server_tls_sslmode;
+extern int cf_server_tls_direct;
extern char *cf_server_tls_protocols;
extern char *cf_server_tls_ca_file;
extern char *cf_server_tls_cert_file;
diff --git a/include/sbuf.h b/include/sbuf.h
index fede6f537285..563a1bc1178b 100644
--- a/include/sbuf.h
+++ b/include/sbuf.h
@@ -115,10 +115,17 @@ extern int client_accept_sslmode;
* Same as client_accept_sslmode, but for server connections.
*/
extern int server_connect_sslmode;
+/*
+ * Mirrors cf_server_tls_direct after a successful sbuf_tls_setup().
+ * When non-zero, server connections skip the SSLRequest negotiation and
+ * initiate a direct TLS handshake immediately after TCP connect.
+ */
+extern int server_connect_tls_direct;
bool sbuf_tls_setup(void);
bool sbuf_tls_accept(SBuf *sbuf) _MUSTCHECK;
bool sbuf_tls_connect(SBuf *sbuf, const char *hostname) _MUSTCHECK;
+bool sbuf_tls_connect_direct(SBuf *sbuf, const char *hostname) _MUSTCHECK;
bool sbuf_pause(SBuf *sbuf) _MUSTCHECK;
void sbuf_continue(SBuf *sbuf);
diff --git a/lib/usual/tls/tls_client.c b/lib/usual/tls/tls_client.c
index 111b3b02c82b..967dc2ae18d0 100644
--- a/lib/usual/tls/tls_client.c
+++ b/lib/usual/tls/tls_client.c
@@ -183,6 +183,24 @@ int tls_connect_fds(struct tls *ctx, int fd_read, int fd_write,
goto err;
}
+ /*
+ * Advertise the "postgresql" ALPN protocol. This is required for
+ * PostgreSQL 17+ direct TLS connections (RFC 7301) and is harmless
+ * for STARTTLS connections where PostgreSQL ignores ALPN.
+ * Mirrors PG_ALPN_PROTOCOL_VECTOR in tls_server.c.
+ */
+ {
+ static const unsigned char alpn_protos[] = {
+ 10, 'p', 'o', 's', 't', 'g', 'r', 'e', 's', 'q', 'l'
+ };
+ if (SSL_CTX_set_alpn_protos(ctx->ssl_ctx,
+ alpn_protos,
+ sizeof(alpn_protos)) != 0) {
+ tls_set_errorx(ctx, "failed to set ALPN protocols");
+ goto err;
+ }
+ }
+
if (tls_configure_ssl(ctx) != 0)
goto err;
if (tls_configure_keypair(ctx, ctx->ssl_ctx, ctx->config->keypair, 0) != 0)
diff --git a/src/main.c b/src/main.c
index 7840212e9915..6a8e01a7945b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -195,6 +195,7 @@ char *cf_client_tls_dheparams;
char *cf_client_tls_ecdhecurve;
int cf_server_tls_sslmode;
+int cf_server_tls_direct; /* bool: skip SSLRequest, do direct TLS handshake */
char *cf_server_tls_protocols;
char *cf_server_tls_ca_file;
char *cf_server_tls_cert_file;
@@ -333,6 +334,7 @@ static const struct CfKey bouncer_params [] = {
CF_ABS("server_tls_ca_file", CF_STR, cf_server_tls_ca_file, 0, ""),
CF_ABS("server_tls_cert_file", CF_STR, cf_server_tls_cert_file, 0, ""),
CF_ABS("server_tls_ciphers", CF_STR, cf_server_tls_ciphers, 0, "default"),
+ CF_ABS("server_tls_direct", CF_INT, cf_server_tls_direct, 0, "0"),
CF_ABS("server_tls_key_file", CF_STR, cf_server_tls_key_file, 0, ""),
CF_ABS("server_tls_protocols", CF_STR, cf_server_tls_protocols, 0, "secure"),
CF_ABS("server_tls_sslmode", CF_LOOKUP(sslmode_map), cf_server_tls_sslmode, 0, "prefer"),
diff --git a/src/sbuf.c b/src/sbuf.c
index c90b6e71c73a..d6de49ee964a 100644
--- a/src/sbuf.c
+++ b/src/sbuf.c
@@ -1072,6 +1072,12 @@ static void sbuf_connect_cb(evutil_socket_t sock, short flags, void *arg)
goto failed;
if (!sbuf_call_proto(sbuf, SBUF_EV_CONNECT_OK))
return;
+ /*
+ * If the proto handler already registered an event (e.g. a
+ * direct-TLS handshake callback), don't overwrite it.
+ */
+ if (sbuf->wait_type != W_NONE)
+ return;
if (!sbuf_wait_for_data(sbuf))
goto failed;
return;
@@ -1145,6 +1151,7 @@ static struct tls_config *client_accept_conf;
int client_accept_sslmode;
static struct tls_config *server_connect_conf;
int server_connect_sslmode;
+int server_connect_tls_direct;
/*
* TLS setup
@@ -1246,6 +1253,9 @@ static bool tls_change_requires_reconnect(struct tls_config *new_server_connect_
if (server_connect_sslmode != cf_server_tls_sslmode) {
log_noise("new server_tls_sslmode detected");
return true;
+ } else if (server_connect_tls_direct != cf_server_tls_direct) {
+ log_noise("new server_tls_direct detected");
+ return true;
} else if (server_connect_conf == NULL) {
log_noise("no existing server tls config detected");
return true;
@@ -1296,6 +1306,11 @@ bool sbuf_tls_setup(void)
if (err)
fatal("tls_init failed");
+ if (cf_server_tls_direct && cf_server_tls_sslmode == SSLMODE_DISABLED) {
+ log_error("server_tls_direct requires server_tls_sslmode to not be 'disable'");
+ return false;
+ }
+
if (cf_server_tls_sslmode != SSLMODE_DISABLED) {
new_server_connect_conf = tls_config_new();
if (!new_server_connect_conf) {
@@ -1360,6 +1375,7 @@ bool sbuf_tls_setup(void)
client_accept_sslmode = cf_client_tls_sslmode;
server_connect_conf = new_server_connect_conf;
server_connect_sslmode = cf_server_tls_sslmode;
+ server_connect_tls_direct = cf_server_tls_direct;
return true;
failed:
usual_tls_free(new_client_accept_base);
@@ -1433,12 +1449,24 @@ bool sbuf_tls_connect(SBuf *sbuf, const char *hostname)
struct tls *ctls;
int err;
- if (!sbuf_pause(sbuf))
- return false;
-
- if (cf_server_tls_sslmode != SSLMODE_VERIFY_FULL)
- hostname = NULL;
+ /*
+ * Pause the current read event if one is registered. When called from
+ * the STARTTLS path (handle_sslchar) the socket is in W_RECV.
+ */
+ if (sbuf->wait_type == W_RECV) {
+ if (!sbuf_pause(sbuf))
+ return false;
+ }
+ /*
+ * Always pass the hostname to tls_connect_fds() so it is set as SNI in
+ * the ClientHello. SNI is needed for server-side backend routing
+ * (e.g. cloud VPE endpoints) regardless of whether we verify the
+ * server's certificate name. Certificate name verification is already
+ * controlled independently by tls_config_insecure_noverifyname() in
+ * sbuf_tls_setup(), so nulling the hostname here only breaks SNI without
+ * making connections any less strict.
+ */
ctls = tls_client();
if (!ctls)
return false;
@@ -1463,6 +1491,27 @@ bool sbuf_tls_connect(SBuf *sbuf, const char *hostname)
return true;
}
+/*
+ * Set up TLS for a direct-TLS server connection (no SSLRequest round-trip)
+ * and immediately start the handshake. Called from handle_connect() at
+ * SBUF_EV_CONNECT_OK time, when wait_type is W_NONE.
+ */
+bool sbuf_tls_connect_direct(SBuf *sbuf, const char *hostname)
+{
+ if (!sbuf_tls_connect(sbuf, hostname))
+ return false;
+
+ /*
+ * Kick the TLS handshake right away. handle_tls_handshake() will
+ * either complete synchronously (TLS_WANT_POLLIN / TLS_WANT_POLLOUT
+ * registers a one-shot callback) or fire SBUF_EV_TLS_READY when done.
+ * We must NOT call sbuf_continue() here — that would attempt recv()
+ * before the handshake completes and see EOF from PG.
+ */
+ sbuf->pkt_action = SBUF_TLS_IN_HANDSHAKE;
+ return handle_tls_handshake(sbuf);
+}
+
/*
* TLS IO ops.
*/
@@ -1602,6 +1651,7 @@ static void sbuf_possible_direct_tls_startup_cb(evutil_socket_t fd, short flags,
int client_accept_sslmode = SSLMODE_DISABLED;
int server_connect_sslmode = SSLMODE_DISABLED;
+int server_connect_tls_direct;
bool sbuf_tls_setup(void)
{
@@ -1615,6 +1665,10 @@ bool sbuf_tls_connect(SBuf *sbuf, const char *hostname)
{
return false;
}
+bool sbuf_tls_connect_direct(SBuf *sbuf, const char *hostname)
+{
+ return false;
+}
void sbuf_cleanup(void)
{
diff --git a/src/server.c b/src/server.c
index 5abbc985d937..92f94a93c3a2 100644
--- a/src/server.c
+++ b/src/server.c
@@ -723,7 +723,15 @@ static bool handle_connect(PgSocket *server)
disconnect_server(server, false, "peer server was not necessary anymore, because client cancel connection was already closed");
} else {
/* proceed with login */
- if (server_connect_sslmode > SSLMODE_DISABLED && !is_unix) {
+ if (server_connect_tls_direct && !is_unix) {
+ slog_noise(server, "P: direct TLS");
+ /*
+ * Start TLS handshake immediately — no SSLRequest round-trip.
+ * On completion SBUF_EV_TLS_READY fires and send_startup_message()
+ * is called, same as the STARTTLS path.
+ */
+ res = sbuf_tls_connect_direct(&server->sbuf, server->host);
+ } else if (server_connect_sslmode > SSLMODE_DISABLED && !is_unix) {
slog_noise(server, "P: SSL request");
res = send_sslreq_packet(server);
if (res)
diff --git a/test/test_ssl.py b/test/test_ssl.py
index 6d70706eb22d..021240859e15 100644
--- a/test/test_ssl.py
+++ b/test/test_ssl.py
@@ -513,3 +513,165 @@ def test_system_error_propagation(bouncer_tls, cert_dir):
# since it is expected.
except psycopg.errors.ConfigFileError as e:
assert "RELOAD failed" in str(e)
+
+
+# ---------------------------------------------------------------------------
+# server_tls_direct tests
+# ---------------------------------------------------------------------------
+
+
+@pytest.mark.skipif(
+ "not DIRECT_TLS_SUPPORT", reason="Direct TLS requires PG 17+ with TLS support"
+)
+def test_server_tls_direct_basic(pg, bouncer_tls, cert_dir):
+ """Bouncer connects to PG using direct TLS (no SSLRequest round-trip)."""
+ root = cert_dir / "TestCA1" / "ca.crt"
+
+ # Enable SSL on PG, allow only SSL connections (reject plain TCP)
+ pg.configure("ssl=on")
+ pg.configure(f"ssl_ca_file='{root}'")
+ pg.ssl_access("all", "trust")
+ pg.nossl_access("all", "reject")
+ pg.reload()
+
+ bouncer_tls.write_ini(f"server_tls_sslmode = require")
+ bouncer_tls.write_ini(f"server_tls_ca_file = {root}")
+ bouncer_tls.write_ini("server_tls_direct = 1")
+ bouncer_tls.admin("reload")
+
+ with bouncer_tls.log_contains(r"SSL established"):
+ bouncer_tls.test()
+
+
+@pytest.mark.skipif(
+ "not DIRECT_TLS_SUPPORT", reason="Direct TLS requires PG 17+ with TLS support"
+)
+def test_server_tls_direct_verify_full(pg, bouncer_tls, cert_dir):
+ """Direct TLS works with verify-full — cert validation is orthogonal to transport."""
+ root = cert_dir / "TestCA1" / "ca.crt"
+
+ # Enable SSL on PG, allow only SSL connections (reject plain TCP)
+ pg.configure("ssl=on")
+ pg.configure(f"ssl_ca_file='{root}'")
+ pg.ssl_access("all", "trust")
+ pg.nossl_access("all", "reject")
+ pg.reload()
+
+ bouncer_tls.write_ini(f"server_tls_sslmode = verify-full")
+ bouncer_tls.write_ini(f"server_tls_ca_file = {root}")
+ bouncer_tls.write_ini("server_tls_direct = 1")
+ bouncer_tls.admin("reload")
+
+ with bouncer_tls.log_contains(r"SSL established"):
+ bouncer_tls.test()
+
+
+@pytest.mark.skipif(
+ "not DIRECT_TLS_SUPPORT", reason="Direct TLS requires PG 17+ with TLS support"
+)
+def test_server_tls_direct_plain_server_fails(pg, bouncer_tls, cert_dir):
+ """Direct TLS against a plain-TCP server fails — no fallback to unencrypted."""
+ bouncer_tls.write_ini("server_tls_sslmode = require")
+ bouncer_tls.write_ini("server_tls_direct = 1")
+ bouncer_tls.admin("reload")
+
+ # PostgreSQL with ssl=off speaks plain TCP; the direct TLS handshake will fail
+ pg.configure("ssl=off")
+ pg.restart()
+
+ with pytest.raises(psycopg.OperationalError):
+ bouncer_tls.test(connect_timeout=4)
+
+
+def test_server_tls_direct_disabled_sslmode_rejected(bouncer_tls):
+ """server_tls_direct=1 combined with sslmode=disable must be rejected at reload."""
+ bouncer_tls.write_ini("server_tls_sslmode = disable")
+ bouncer_tls.write_ini("server_tls_direct = 1")
+
+ with bouncer_tls.log_contains(
+ r"server_tls_direct requires server_tls_sslmode to not be 'disable'"
+ ):
+ try:
+ bouncer_tls.admin("RELOAD")
+ except psycopg.errors.ConfigFileError:
+ pass
+
+
+@pytest.mark.skipif(
+ "not DIRECT_TLS_SUPPORT", reason="Direct TLS requires PG 17+ with TLS support"
+)
+def test_server_tls_direct_reconnect_on_flag_change(bouncer_tls, pg, cert_dir):
+ """Changing server_tls_direct triggers pool reconnect (marks connections dirty)."""
+ root = cert_dir / "TestCA1" / "ca.crt"
+ bouncer_tls.default_db = "pTxnPool"
+
+ # Start with STARTTLS (server_tls_direct=0), SSL required
+ pg.configure("ssl=on")
+ pg.configure(f"ssl_ca_file='{root}'")
+ pg.ssl_access("all", "trust")
+ pg.reload()
+
+ bouncer_tls.write_ini(f"server_tls_sslmode = require")
+ bouncer_tls.write_ini(f"server_tls_ca_file = {root}")
+ bouncer_tls.write_ini("server_tls_direct = 0")
+ bouncer_tls.admin("reload")
+
+ with bouncer_tls.cur() as cur:
+ assert pg.connection_count(dbname="p0") == 1
+ # Switch to direct TLS — should mark the STARTTLS connection as dirty
+ bouncer_tls.write_ini("server_tls_direct = 1")
+
+ with bouncer_tls.log_contains(
+ r"pTxnPool.*database configuration changed|pTxnPool.*obsolete connection"
+ ):
+ bouncer_tls.admin("RELOAD")
+ cur.execute("SELECT 1")
+
+
+@pytest.mark.skipif(
+ "not DIRECT_TLS_SUPPORT", reason="Direct TLS requires PG 17+ with TLS support"
+)
+def test_server_tls_direct_alpn_negotiated(pg, bouncer_tls, cert_dir):
+ """ALPN 'postgresql' is negotiated — PG 17 rejects connections without it."""
+ root = cert_dir / "TestCA1" / "ca.crt"
+
+ # Enable SSL on PG, allow only SSL connections (reject plain TCP)
+ pg.configure("ssl=on")
+ pg.configure(f"ssl_ca_file='{root}'")
+ pg.ssl_access("all", "trust")
+ pg.nossl_access("all", "reject")
+ pg.reload()
+
+ bouncer_tls.write_ini(f"server_tls_sslmode = require")
+ bouncer_tls.write_ini(f"server_tls_ca_file = {root}")
+ bouncer_tls.write_ini("server_tls_direct = 1")
+ bouncer_tls.admin("reload")
+
+ # If ALPN negotiation failed PG 17+ would have rejected the connection outright;
+ # a successful query through pg_stat_ssl confirms TLS + ALPN both worked.
+ result = bouncer_tls.sql("SELECT ssl FROM pg_stat_ssl WHERE pid = pg_backend_pid()")
+ assert result and result[0][0] is True
+
+
+@pytest.mark.skipif(
+ "not DIRECT_TLS_SUPPORT", reason="Direct TLS requires PG 17+ with TLS support"
+)
+def test_server_tls_direct_sni_sent_for_non_verify_full(pg, bouncer_tls, cert_dir):
+ """SNI is sent in the ClientHello even when sslmode is not verify-full."""
+ root = cert_dir / "TestCA1" / "ca.crt"
+
+ pg.configure("ssl=on")
+ pg.configure(f"ssl_ca_file='{root}'")
+ pg.ssl_access("all", "trust")
+ pg.nossl_access("all", "reject")
+ pg.reload()
+
+ bouncer_tls.write_ini("server_tls_sslmode = verify-ca")
+ bouncer_tls.write_ini(f"server_tls_ca_file = {root}")
+ bouncer_tls.write_ini("server_tls_direct = 1")
+ bouncer_tls.admin("reload")
+
+ # A successful query proves the handshake completed — which requires SNI
+ # because the server only accepts hostssl connections.
+ with bouncer_tls.log_contains(r"SSL established"):
+ bouncer_tls.test()
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-09-03 21:19 "dubee (@dubee)" <noreply+dubee@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: dubee (@dubee) @ 2026-09-03 21:19 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
Thanks for working on this, direct TLS is exactly what I need for IBM Cloud VPE Postgres endpoints, which currently require an stunnel sidecar.
I hit one issue: the connection fails with tlsv1 alert no application protocol unless server_tls_sslmode is verify-full.
The cause is in sbuf_tls_connect(), src/sbuf.c:1461-1462:
if (cf_server_tls_sslmode != SSLMODE_VERIFY_FULL)
hostname = NULL;
The hostname passed from handle_connect() is correct, but this drops it before it reaches tls_connect_fds(), which is what sets SNI. That was harmless for STARTTLS, but with direct TLS the handshake is the first thing on the wire, so SNI is how the endpoint selects the backend. Without it the connection is rejected.
Removing those two lines fixes it, and doesn't weaken verification — setup_tls() already calls tls_config_insecure_noverifyname() for the modes below verify-full.
Confirmed with openssl s_client -alpn postgresql: succeeds with -servername, reproduces the alert with -noservername.
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-09-04 15:52 "dpittner (@dpittner)" <noreply+dpittner@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: dpittner (@dpittner) @ 2026-09-04 15:52 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
Thanks, I've added the fix you suggested and included a testcase to ensure we're covering.
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-09-24 16:25 "victorrelkins-design (@victorrelkins-design)" <noreply+victorrelkins-design@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: victorrelkins-design (@victorrelkins-design) @ 2026-09-24 16:25 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
Tracking Issue
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-09-29 13:17 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-09-29 13:17 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
(on lib/usual/tls/tls_client.c:196)
`tls_handshake_client()` accepts connections without checking the server's ALPN selection. PostgreSQL [requires ALPN for direct TLS](https://www.postgresql.org/docs/17/protocol-flow.html#PROTOCOL-FLOW-SSL) to prevent protocol confusion.
For direct TLS, check the selection after the handshake, just like [libpq does](https://github.com/postgres/postgres/blob/REL_17_0/src/interfaces/libpq/fe-secure-openssl.c#L1496-L1...). Reject a missing selection or a protocol other than `postgresql` before PgBouncer sends StartupMessage. We should also add a test that asserts rejection before StartupMessage when the TLS endpoint doesn't select an ALPN protocol.
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584 (changes requested): feat: add support for upstream TLSDirect
@ 2026-09-29 13:19 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-09-29 13:19 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
Use libpq's implementation as the reference here. I can propose the test if anything about my feedback is unclear. just lmk
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-10-02 04:37 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-10-02 04:37 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
(on src/server.c:717)
```suggestion
if (server_connect_tls_direct && !is_unix && !pool->db->peer_id) {
slog_noise(server, "P: direct TLS");
res = sbuf_tls_connect_direct(&server->sbuf, server->host);
if (!res)
disconnect_server(server, false, "startup pkt failed");
return res && server->state != SV_JUSTFREE;
}
if (!statlist_empty(&pool->waiting_cancel_req_list)) {
```
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-10-02 04:38 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-10-02 04:38 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
(on src/server.c:734)
```suggestion
if (server_connect_sslmode > SSLMODE_DISABLED && !is_unix) {
```
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-10-02 04:40 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-10-02 04:40 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
(on src/server.c:945)
```suggestion
if (server_connect_tls_direct && !statlist_empty(&server->pool->waiting_cancel_req_list)) {
forward_cancel_request(server);
break;
}
res = send_startup_message(server);
```
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584 (changes requested): feat: add support for upstream TLSDirect
@ 2026-10-02 04:41 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-10-02 04:41 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
For normal pools, TCP cancellations must use direct TLS when enabled. In this PR, a TLS-only backend can accept queries but reject cancellations. Peer forwarding doesn't need to change.
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-10-03 19:57 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-10-03 19:57 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
(on src/sbuf.c:1658)
```suggestion
if (cf_server_tls_direct) {
log_error("server_tls_direct requires TLS support");
return false;
}
return true;
```
When pgbouncer is compiled without TLS support, sbuf_tls_setup() returns true so plaintext operation works. A guard here makes setup reject an explicit request for unsupported direct TLS...
`server_tls_direct=1` should be rejected and not silently ignored IMHO. This suggestion needs a call from @eulerto or @JelteF, I think.
pgbouncer silently ignores unused TLS settings in no-TLS builds, for instance even `server_tls_sslmode=require` making this is a bit of a design question. I could be totally off the mark.
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-10-04 03:34 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-10-04 03:34 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
(on test/test_ssl.py:675)
I don't believe this is a correct inference. A successful query does prove the handshake completed, naturally. I am not so certain that this however implies that SNI was sent since SNI is not really required by the server.
I can't really see a great way to assert this server-side.
In order for this test to prove that direct SNI is sent it might help to use of a stub or stand-in server and assert the hostname is sent properly.
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-10-04 03:35 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-10-04 03:35 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
(on test/test_ssl.py:675)
If you can red this test by disabling SNI in PgBouncer, I could be mistaken. I'd expect it to stay green, since hostssl only requires TLS and PostgreSQL doesn't check the requested SNI hostname.
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-10-04 15:56 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-10-04 15:56 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
(on lib/usual/tls/tls_client.c:189)
```suggestion
* for SSLRequest-based connections, where ALPN may be omitted
* but is checked when offered.
```
Minor wording tweak.
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-11-07 20:35 "dpittner (@dpittner)" <noreply+dpittner@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: dpittner (@dpittner) @ 2026-11-07 20:35 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
Thanks @cosgroveb! I hope I was able to address all the comments you had, let me know if things look fine from your perspective right now, or if you'd suggest some further tweaks.
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584 (approved): feat: add support for upstream TLSDirect
@ 2026-11-09 04:18 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-11-09 04:18 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
All my previous feedback is addressed and lgtm. One minor test question inline.
^ permalink raw [nested|flat] 17+ messages in thread
* Re: [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect
@ 2026-11-09 04:20 "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
15 siblings, 0 replies; 17+ messages in thread
From: cosgroveb (@cosgroveb) @ 2026-11-09 04:20 UTC (permalink / raw)
To: pgbouncer/pgbouncer <noreply+pgbouncer-pgbouncer@github.com>
(on test/test_ssl.py:763)
Smells racey. Does this assertion also duplicate the one on line 768?
^ permalink raw [nested|flat] 17+ messages in thread
end of thread, other threads:[~2026-11-09 04:20 UTC | newest]
Thread overview: 17+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-03 19:17 [pgbouncer/pgbouncer] PR #1584: feat: add support for upstream TLSDirect "dpittner (@dpittner)" <noreply+dpittner@github.com>
2026-09-03 21:19 ` "dubee (@dubee)" <noreply+dubee@github.com>
2026-09-04 15:52 ` "dpittner (@dpittner)" <noreply+dpittner@github.com>
2026-09-24 16:25 ` "victorrelkins-design (@victorrelkins-design)" <noreply+victorrelkins-design@github.com>
2026-09-29 13:17 ` "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-09-29 13:19 ` Re: [pgbouncer/pgbouncer] PR #1584 (changes requested): feat: add support for upstream TLSDirect "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-10-02 04:37 ` "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-10-02 04:38 ` "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-10-02 04:40 ` "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-10-02 04:41 ` Re: [pgbouncer/pgbouncer] PR #1584 (changes requested): feat: add support for upstream TLSDirect "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-10-03 19:57 ` "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-10-04 03:34 ` "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-10-04 03:35 ` "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-10-04 15:56 ` "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-11-07 20:35 ` "dpittner (@dpittner)" <noreply+dpittner@github.com>
2026-11-09 04:18 ` Re: [pgbouncer/pgbouncer] PR #1584 (approved): feat: add support for upstream TLSDirect "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
2026-11-09 04:20 ` "cosgroveb (@cosgroveb)" <noreply+cosgroveb@github.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox