Add SNI test and fix hostname handling in nginx ssl handshake#154
Open
simbo1905 wants to merge 2 commits into
Open
Add SNI test and fix hostname handling in nginx ssl handshake#154simbo1905 wants to merge 2 commits into
simbo1905 wants to merge 2 commits into
Conversation
The nginx cosocket sslhandshake call hardcoded nil for server_name, so TLS SNI never advertised the target hostname to the server. Closes leafo#153
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In the nginx (
ngx.socket) code path, pgmoon performs its TLS handshake without sending the SNI (Server Name Indication) extension. Theserver_nameargument totcpsock:sslhandshakeis passed asnil:https://github.com/leafo/pgmoon/blob/master/pgmoon/init.moon#L1078
Managed PostgreSQL services that route connections by SNI cannot identify the target instance when the extension is absent, so they reject the connection during the handshake. libpq has sent SNI by default since PostgreSQL 14 (
sslsni), sopsqlconnects to the same endpoint while pgmoon does not.The fix is one line: pass the
hostpgmoon already holds as theserver_name.Working CI Proof On My Fork
The full suit with these two cherry-picked commits runs on my fork over at https://github.com/simbo1905/pgmoon/actions/runs/28831111428/job/85504998959#step:7:330
Environment
debian:trixie-slimlua-nginx-module, Debian package)Reproduction against a real SNI-routed service (Scaleway Serverless SQL)
This confirms the connection failure on a service that requires SNI. Following the Scaleway Serverless SQL quickstart, using the
scwCLI:1. Create a database:
The database ID forms part of the hostname (
{database-id}.pg.sdb.fr-par.scw.cloud), which is what the service routes on via SNI2. Generate credentials in the console (Connect, then Generate API key). The IAM key id and secret become the PostgreSQL user and password.
3. Put the connection details in
.env:PGHOST={database-id}.pg.sdb.fr-par.scw.cloud PGPORT=5432 PGDATABASE={database name} PGUSER={IAM key id} PGPASSWORD={IAM secret key}4. psql connects, because libpq sends SNI:
5. pgmoon 1.17.0 under nginx fails on the same endpoint
There is a complete demo of pgmoon with OpenResty implementing the GoThinkster API that has to manually patch around htis error at https://codeberg.org/simbo1905/realworld-openresty-lua/src/tag/2026-07-06_0825_main/app/db.lua#L33-L53 so to reproduce comment out those lines.
The error names the cause directly: no TLS Server Name Indication. Note that Serverless SQL scales to zero, so the first connection after idle can be slow or time out once before the instance wakes; retry if that happens.