1
0
Fork 0
mirror of https://github.com/glebarez/pgssl.git synced 2025-12-31 03:46:22 +00:00
No description
Find a file
2023-08-24 19:34:59 +03:00
.github Create dependabot.yml 2023-02-24 00:56:21 +07:00
go.mod Bump github.com/jackc/pgproto3/v2 from 2.2.0 to 2.3.2 2023-04-17 19:12:29 +03:00
go.sum Bump github.com/jackc/pgproto3/v2 from 2.2.0 to 2.3.2 2023-04-17 19:12:29 +03:00
LICENSE Create LICENSE 2022-01-31 13:31:23 +03:00
main.go feat: pgssl password with env var 2023-08-24 19:34:59 +03:00
pgssl.drawio.png readme 2022-01-31 00:27:59 +03:00
pgssl.go feat: add optional connection password 2023-08-24 17:00:21 +03:00
pipe.go ssl 2022-01-30 21:11:44 +03:00
readme.md feat: pgssl password with env var 2023-08-24 19:34:59 +03:00

pgSSL

pgSSL is a proxy for PostgreSQL that wraps plain TCP connections (sslmode=disable) into SSL and provides (optional) client certificate to the backend PostgreSQL server. This way it allows SSL encryption and certificate-based authentication for plain-text PostgreSQL clients.

Motivation

PostgreSQL listens to both plain and SSL connections on a single port, therefore it has its own handshake that precedes the usual SSL/TLS handshake. For this reason it's not possible to wrap plain connections into SSL with usual proxies like nginx, envoy, istio, HAproxy. Though pgbouncer can be used for such task, the purpose of pgbouncer is to load-balance and pool the connections, so for a simple SSL-wrap it seems to be overkill. pgSSL wraps connections with regard to PostgreSQL-specific SSL handshake.

How it works

sequenceDiagram
    client->>pgSSL: TCP connect (plain)
    pgSSL-->>PostgreSQL: SSLRequest
    PostgreSQL-->>pgSSL: S(OK)
    pgSSL-->>PostgreSQL: SSL Handshake
    PostgreSQL-->>pgSSL: SSL Handshake complete
    loop
    client->>pgSSL: plain query
    activate pgSSL
    pgSSL-->>PostgreSQL: encrypted query
    deactivate pgSSL
    PostgreSQL-->>pgSSL: encrypted result
    activate pgSSL
    pgSSL->>client: plain result
    deactivate pgSSL
    end

Installation

go install github.com/glebarez/pgssl

Usage examples

  • pgssl -p postgres-server:5432 -l :15432 -k client.key -c client.crt
  • pgssl -p postgres-server:5432 -l :15432
  • PGSSL_PASSWORD=changeme pgssl -p postgres-server:5432 -l :15432