From 964b35ae65803843bd1bc46755111312bbdff626 Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Thu, 8 Oct 2026 21:04:46 +0200 Subject: [PATCH] Backups reach a replicated store: pg_dump is given the cluster's authority with verify-full pgEnv passed sslmode=verify-full but dropped sslrootcert, so libpq looked for ~/.postgresql/root.crt and both backup and restore failed against the Patroni store. sslrootcert, sslcert and sslkey now go along as PGSSL*. Co-Authored-By: Claude Opus 5.5 (1M context) --- internal/cli/backup.go | 9 ++++++++- internal/cli/backup_test.go | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/cli/backup.go b/internal/cli/backup.go index 6a6eb39..a2f692b 100644 --- a/internal/cli/backup.go +++ b/internal/cli/backup.go @@ -249,7 +249,14 @@ func pgEnv(dsn string) ([]string, error) { set("PGPASSWORD", pw) } set("PGDATABASE", strings.TrimPrefix(u.Path, "/")) - set("PGSSLMODE", u.Query().Get("sslmode")) + // The TLS settings go with the mode: verify-full without the cluster's + // authority sent libpq looking for ~/.postgresql/root.crt, and the dump + // failed on every control plane whose store is replicated. + q := u.Query() + set("PGSSLMODE", q.Get("sslmode")) + set("PGSSLROOTCERT", q.Get("sslrootcert")) + set("PGSSLCERT", q.Get("sslcert")) + set("PGSSLKEY", q.Get("sslkey")) // A standby if there is one, else whichever answers — not the address's // read-write: a dump only reads, it need not load the primary, and one // that insists on the primary fails exactly while the cluster is failing diff --git a/internal/cli/backup_test.go b/internal/cli/backup_test.go index 73be1e7..e212849 100644 --- a/internal/cli/backup_test.go +++ b/internal/cli/backup_test.go @@ -238,3 +238,17 @@ func TestAStoreOfSeveralHostsIsGivenToPgDumpAsLibpqLists(t *testing.T) { t.Error("an empty host in the list was accepted") } } + +func TestPgDumpIsGivenTheClusterAuthorityAlongWithVerifyFull(t *testing.T) { + // Without it libpq looked for ~/.postgresql/root.crt and the dump failed. + env, err := pgEnv("postgres://llmgw:p@10.0.0.149:5432,10.0.0.150:5432/llmgw?sslmode=verify-full&sslrootcert=%2Fetc%2Fllmgw%2Fpki%2Fca.crt&target_session_attrs=read-write") + if err != nil { + t.Fatal(err) + } + got := strings.Join(env, " ") + for _, want := range []string{"PGSSLMODE=verify-full", "PGSSLROOTCERT=/etc/llmgw/pki/ca.crt"} { + if !strings.Contains(got, want) { + t.Errorf("%s is not in %s", want, got) + } + } +}