Skip to content

Commit 41b6aba

Browse files
authored
Lock down the repmgr user (#222)
* Lock down the repmgr user * Add PGPASSFILE to timescale dockerfile
1 parent 396d2fd commit 41b6aba

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ COPY ./bin/* /fly/bin/
1919
FROM wrouesnel/postgres_exporter:latest AS postgres_exporter
2020
FROM postgres:${PG_VERSION}
2121
ENV PGDATA=/data/postgresql
22+
ENV PGPASSFILE=/data/.pgpass
2223
ARG VERSION
2324
ARG PG_MAJOR_VERSION
2425
ARG POSTGIS_MAJOR=3

Dockerfile-timescaledb

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ FROM wrouesnel/postgres_exporter:latest AS postgres_exporter
2020

2121
FROM postgres:${PG_VERSION}
2222
ENV PGDATA=/data/postgresql
23+
ENV PGPASSFILE=/data/.pgpass
2324
ARG VERSION
2425
ARG PG_MAJOR_VERSION
2526
ARG POSTGIS_MAJOR=3

internal/flypg/pg.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,14 @@ func (c *PGConfig) setDefaultHBA() error {
471471
Database: "replication",
472472
User: c.repmgrUsername,
473473
Address: "fdaa::/16",
474-
Method: "trust",
474+
Method: "md5",
475475
},
476476
{
477477
Type: "host",
478478
Database: fmt.Sprintf("replication,%s", c.repmgrDatabase),
479479
User: c.repmgrUsername,
480480
Address: "fdaa::/16",
481-
Method: "trust",
481+
Method: "md5",
482482
},
483483
{
484484
Type: "host",

internal/flypg/repmgr.go

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func (r *RepMgr) initialize() error {
124124
if err := os.WriteFile(r.PasswordConfigPath, []byte(passStr), 0600); err != nil {
125125
return fmt.Errorf("failed to write file %s: %s", r.PasswordConfigPath, err)
126126
}
127+
127128
if err := utils.SetFileOwnership(r.PasswordConfigPath, "postgres"); err != nil {
128129
return fmt.Errorf("failed to set file ownership: %s", err)
129130
}
@@ -178,6 +179,7 @@ func (r *RepMgr) setDefaults() error {
178179
"priority": 100,
179180
"node_rejoin_timeout": 30,
180181
"standby_reconnect_timeout": 30,
182+
"passfile": fmt.Sprintf("'%s'", r.PasswordConfigPath),
181183
}
182184

183185
if !r.eligiblePrimary() {

0 commit comments

Comments
 (0)