Skip to content

Commit 1ea78ff

Browse files
committed
keeper: don't disable ssl for replication
Set sslmode to `prefer` so, if the user has enabled ssl/tls, it'll also be used for replication (and pg_rewind). Now it's not possible to force other options like verify-ca or verify-full since they requires more effort on the user side and need to be carefully tested.
1 parent 5df2426 commit 1ea78ff

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

cmd/keeper/cmd/keeper.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ func (p *PostgresKeeper) getSUConnParams(db, followedDB *cluster.DB) pg.ConnPara
220220
"port": followedDB.Status.Port,
221221
"application_name": common.StolonName(db.UID),
222222
"dbname": "postgres",
223-
"sslmode": "disable",
223+
// prefer ssl if available (already the default for postgres libpq but not for golang lib pq)
224+
"sslmode": "prefer",
224225
}
225226
if p.pgSUAuthMethod != "trust" {
226227
cp.Set("password", p.pgSUPassword)
@@ -234,7 +235,8 @@ func (p *PostgresKeeper) getReplConnParams(db, followedDB *cluster.DB) pg.ConnPa
234235
"host": followedDB.Status.ListenAddress,
235236
"port": followedDB.Status.Port,
236237
"application_name": common.StolonName(db.UID),
237-
"sslmode": "disable",
238+
// prefer ssl if available (already the default for postgres libpq but not for golang lib pq)
239+
"sslmode": "prefer",
238240
}
239241
if p.pgReplAuthMethod != "trust" {
240242
cp.Set("password", p.pgReplPassword)
@@ -244,11 +246,11 @@ func (p *PostgresKeeper) getReplConnParams(db, followedDB *cluster.DB) pg.ConnPa
244246

245247
func (p *PostgresKeeper) getLocalConnParams() pg.ConnParams {
246248
cp := pg.ConnParams{
247-
"user": p.pgSUUsername,
248-
"host": common.PgUnixSocketDirectories,
249-
"port": p.pgPort,
250-
"dbname": "postgres",
251-
"sslmode": "disable",
249+
"user": p.pgSUUsername,
250+
"host": common.PgUnixSocketDirectories,
251+
"port": p.pgPort,
252+
"dbname": "postgres",
253+
// no sslmode defined since it's not needed and supported over unix sockets
252254
}
253255
if p.pgSUAuthMethod != "trust" {
254256
cp.Set("password", p.pgSUPassword)
@@ -262,7 +264,7 @@ func (p *PostgresKeeper) getLocalReplConnParams() pg.ConnParams {
262264
"password": p.pgReplPassword,
263265
"host": common.PgUnixSocketDirectories,
264266
"port": p.pgPort,
265-
"sslmode": "disable",
267+
// no sslmode defined since it's not needed and supported over unix sockets
266268
}
267269
if p.pgReplAuthMethod != "trust" {
268270
cp.Set("password", p.pgReplPassword)

doc/ssl.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## PostgreSQL SSL/TLS setup
22

3-
SSL/TLS access to an HA postgres managed by stolon can be configured as usual (see the [official postgres doc](https://www.postgresql.org/docs/current/static/ssl-tcp.html)). The setup is done [defining the required pgParameters inside the cluster spec](postgres_parameters.md).
3+
SSL/TLS access to an HA postgres managed by stolon can be configured as usual (see the [official postgres doc](https://www.postgresql.org/docs/current/static/ssl-tcp.html)). The setup is done [defining the required pgParameters inside the cluster spec](postgres_parameters.md). If this is enabled also replication between instances will use tls (currently it'll use the default replication mode of "prefer").
44

55
If you want to enable client side full verification (`sslmode=verify-full` in the client connection string) you should configure the certificate CN to contain the FQDN or IP address that your client will use to connect to the stolon proxies. Depending on your architecture you'll have more than one stolon proxies behind a load balancer, a keepealived ip, a k8s service etc... So the certificate CN should be set to the hostname or ip that your client will connect to.
66

0 commit comments

Comments
 (0)