Postgres SSL Termination with Traefik #684
Replies: 2 comments 1 reply
|
Thanks for this, Graeme. @josep-tecnativa can you please check this and comment which were the problems you faced when doing something similar? |
|
Hi @gdgellatly , Just for context: in the doodba-copier-template (our project scaffold), when you choose to expose PostgreSQL externally, the template automatically generates Traefik rules that are very similar to the ones you described. For example: This part works fine, and the logic is basically the same: TCP router, HostSNI, TLS termination, and forwarding to the internal Postgres port. The issue we’ve found, however, is that while this setup works well with some clients (notably ODBC), several other PostgreSQL drivers fail to connect properly through Traefik’s TCP+SNI routing. That’s essentially the main limitation we’ve hit when trying to rely on this configuration. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Preamble:
Objective:
Traefik Setup
In a dynamic config file add the following (and ensure it gets loaded).
Define your entrypoint and expose the port in your docker-compose.yml (only showing needed config, obviously there is more)
Database Compose file
Connection
When we connect, Traefik will detect the Postgres STARTTLS prototol, terminate the connection and forward it the HostSNI contained in the header via regular TCP. You may need to set
sslmode=requirein your connection string and should be considered best practice.psql "host=pg.example.com dbname=postgres user=postgres sslmode=require"If successful you should see something like
With VSCode Postgres Explorer
From Windows Machine on Excel using ODBC Data Source
This is almost correct but with v17 of the pgodbc driver
{PostgreSQL Unicode}is the driver. Once you click OK, the next screen asks for user and password plus connection information. In connection information you addsslmode=requireAll reactions