Skip to content

Commit

Permalink
Lock down the repmgr user (#222)
Browse files Browse the repository at this point in the history
* Lock down the repmgr user

* Add PGPASSFILE to timescale dockerfile
  • Loading branch information
davissp14 authored Mar 15, 2024
1 parent 396d2fd commit 41b6aba
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ COPY ./bin/* /fly/bin/
FROM wrouesnel/postgres_exporter:latest AS postgres_exporter
FROM postgres:${PG_VERSION}
ENV PGDATA=/data/postgresql
ENV PGPASSFILE=/data/.pgpass
ARG VERSION
ARG PG_MAJOR_VERSION
ARG POSTGIS_MAJOR=3
Expand Down
1 change: 1 addition & 0 deletions Dockerfile-timescaledb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ FROM wrouesnel/postgres_exporter:latest AS postgres_exporter

FROM postgres:${PG_VERSION}
ENV PGDATA=/data/postgresql
ENV PGPASSFILE=/data/.pgpass
ARG VERSION
ARG PG_MAJOR_VERSION
ARG POSTGIS_MAJOR=3
Expand Down
4 changes: 2 additions & 2 deletions internal/flypg/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,14 @@ func (c *PGConfig) setDefaultHBA() error {
Database: "replication",
User: c.repmgrUsername,
Address: "fdaa::/16",
Method: "trust",
Method: "md5",
},
{
Type: "host",
Database: fmt.Sprintf("replication,%s", c.repmgrDatabase),
User: c.repmgrUsername,
Address: "fdaa::/16",
Method: "trust",
Method: "md5",
},
{
Type: "host",
Expand Down
2 changes: 2 additions & 0 deletions internal/flypg/repmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (r *RepMgr) initialize() error {
if err := os.WriteFile(r.PasswordConfigPath, []byte(passStr), 0600); err != nil {
return fmt.Errorf("failed to write file %s: %s", r.PasswordConfigPath, err)
}

if err := utils.SetFileOwnership(r.PasswordConfigPath, "postgres"); err != nil {
return fmt.Errorf("failed to set file ownership: %s", err)
}
Expand Down Expand Up @@ -178,6 +179,7 @@ func (r *RepMgr) setDefaults() error {
"priority": 100,
"node_rejoin_timeout": 30,
"standby_reconnect_timeout": 30,
"passfile": fmt.Sprintf("'%s'", r.PasswordConfigPath),
}

if !r.eligiblePrimary() {
Expand Down

0 comments on commit 41b6aba

Please sign in to comment.