SSL = TLS
When was SSL added to PostgreSQL?
What version?
When was SSL added to PostgreSQL? — 2001
What version? — 7.1
+--------+ +--------+
| | | |
| | connect please? | |
| client |----------------------------->| server |
| | | |
| | ----> <---- | |
+--------+ I don't I don't +--------+
know you know you
postgresql.conf
#ssl = off
#ssl_ca_file = ''
#ssl_cert_file = 'server.crt'
#ssl_crl_file = ''
#ssl_crl_dir = ''
#ssl_key_file = 'server.key'
#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
#ssl_prefer_server_ciphers = on
#ssl_ecdh_curve = 'prime256v1'
#ssl_min_protocol_version = 'TLSv1.2'
#ssl_max_protocol_version = ''
#ssl_dh_params_file = ''
#ssl_passphrase_command = ''
#ssl_passphrase_command_supports_reload = off
libpq connection parameters
JDBC connection parameters (properties)
$ openssl version -d
OPENSSLDIR: "/opt/homebrew/etc/openssl@3"
${OPENSSLDIR}/openssl.cnf:
openssl_conf = openssl_init [openssl_init] ssl_conf = ssl_configuration [ssl_configuration] server = server_tls_config client = client_tls_config system_default = tls_system_default [server_tls_config] ... configuration for SSL/TLS servers ... [client_tls_config] ... configuration for SSL/TLS clients ... [tls_system_default] MinProtocol = TLSv1.2 CipherString = ...
see man config(5ssl), SSL_CONF_CMD(3ssl)
(probably less confusing to do it all inside PostgreSQL?)
pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
hostssl all all xxx yyy
hostssl replication all xxx yyy
libpq / JDBC
sslmode=require (*)
postgresql.conf
ssl_min_protocol_version = 'TLSv1.2'
(requires PostgreSQL 12)
libpq
ssl_min_protocol_version=TLSv1.2
(requires PostgreSQL 13)
openssl.cnf
MinProtocol=TLSv1.2
(requires OpenSSL 1.1.0)
ssl_ciphers = 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305'
Huh?!?
openssl.cnf
# TLS ≤1.2
CipherString = ...
# TLS 1.3
Ciphersuites = ...
sslmode=disablesslmode=allowsslmode=prefersslmode=requiresslmode=verify-casslmode=verify-fullremember that sslrootcert=system is now an option
for client authentication; useful for clients that you control, e.g., replication
pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
hostssl replication all xxx cert
or
# TYPE DATABASE USER ADDRESS METHOD
hostssl all all xxx yyy clientcert=verify-full
need CRL
≤397 days
probably not useful
libpq
gssencmode=disable
(GSS encryption preempts SSL)
libpq
require_auth=scram-sha-256
channel_binding=require
libpq
sslcertmode=require
ssl_dh_params_file = ...
ssl_ecdh_curve = ...
sslcompression(*) or similar
+--------+ +-----------+ +--------+
| | | | | |
| PG | | | | PG |
| client |-------------->| PgBouncer |-------------->| server |
| | SSL | | SSL | |
| | server | | client | |
+--------+ +-----------+ +--------+
pgbouncer.ini
;;; TLS settings for accepting clients
;client_tls_sslmode = disable
;client_tls_ca_file = system default
;client_tls_key_file =
;client_tls_cert_file =
;client_tls_ciphers = default
;client_tls_protocols = secure
;client_tls_dheparams = auto
;client_tls_ecdhcurve = auto
;;; TLS settings for connecting to backend databases
;server_tls_sslmode = prefer
;server_tls_ca_file = system default
;server_tls_key_file =
;server_tls_cert_file =
;server_tls_protocols = secure
;server_tls_ciphers = default
pgbouncer.ini
;;; TLS settings for accepting clients
;client_tls_sslmode = require
;client_tls_ca_file = your file
;client_tls_key_file = your file
;client_tls_cert_file = your file
;client_tls_ciphers = default
;client_tls_protocols = secure ; = tlsv1.2,tlsv1.3
;client_tls_dheparams = auto
;client_tls_ecdhcurve = auto
;;; TLS settings for connecting to backend databases
;server_tls_sslmode = verify-full
;server_tls_ca_file = your file
;server_tls_key_file =
;server_tls_cert_file =
;server_tls_protocols = secure ; = tlsv1.2,tlsv1.3
;server_tls_ciphers = default
sslnegotation=postgres (old)
C --> S: how about SSL? C <-- S: ok C --> S: start SSL, StartupMessage
sslnegotation=direct (new)
C --> S: start SSL, StartupMessage