Skip to content

Commit d64603e

Browse files
author
Philip Hurst
committed
regenerate verifier only when user updates pgBouncer Secret password
1 parent 740400d commit d64603e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

internal/pgbouncer/reconcile.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/crunchydata/postgres-operator/internal/naming"
1818
"github.com/crunchydata/postgres-operator/internal/pki"
1919
"github.com/crunchydata/postgres-operator/internal/postgres"
20+
pwd "github.com/crunchydata/postgres-operator/internal/postgres/password"
2021
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
2122
)
2223

@@ -52,17 +53,25 @@ func Secret(ctx context.Context,
5253
var err error
5354
initialize.Map(&outSecret.Data)
5455

55-
// Use the existing password and verifier. Generate both when either is missing.
56+
// Use the existing password and verifier. Generate when one is missing.
5657
// NOTE(cbandy): We don't have a function to compare a plaintext password
5758
// to a SCRAM verifier.
5859
password := string(inSecret.Data[passwordSecretKey])
5960
verifier := string(inSecret.Data[verifierSecretKey])
6061

61-
if err == nil && (len(password) == 0 || len(verifier) == 0) {
62+
// If the password is empty, generate a new one.
63+
// The user may not have provided a SCRAM verifier.
64+
if err == nil && len(password) == 0 {
6265
password, verifier, err = generatePassword()
6366
err = errors.WithStack(err)
6467
}
6568

69+
// If the verifier is empty, generate a new one.
70+
if err == nil && len(verifier) == 0 {
71+
verifier, err = pwd.NewSCRAMPassword(password).Build()
72+
err = errors.WithStack(err)
73+
}
74+
6675
if err == nil {
6776
// Store the SCRAM verifier alongside the plaintext password so that
6877
// later reconciles don't generate it repeatedly.

0 commit comments

Comments
 (0)