Skip to content

Commit 69ecfbe

Browse files
committed
Send the "password" method to Postgres as "md5" instead
The differences between "password," "md5," and "scram-sha-256" are not interesting to Postgres novices. This allows one to say "password" in the API and have secure authentication using usernames and passwords. The PGO default "password_encryption" has always been "scram-sha-256". Issue: PGO-2263
1 parent c5d279f commit 69ecfbe

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

internal/controller/postgrescluster/postgres.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ func (*Reconciler) generatePostgresHBA(spec *v1beta1.PostgresHBARule) *postgres.
5151

5252
result := postgres.NewHBA()
5353
result.Origin(spec.Connection)
54-
result.Method(spec.Method)
54+
55+
// The "password" method is not recommended. More likely, the user wants to
56+
// use passwords generally. The most compatible method for that is "md5"
57+
// which accepts a password in the format in which it is hashed in the database.
58+
// - https://www.postgresql.org/docs/current/auth-password.html
59+
if spec.Method == "password" {
60+
result.Method("md5")
61+
} else {
62+
result.Method(spec.Method)
63+
}
5564

5665
if len(spec.Databases) > 0 {
5766
result.Databases(spec.Databases[0], spec.Databases[1:]...)

internal/controller/postgrescluster/postgres_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ func TestGeneratePostgresHBA(t *testing.T) {
5959
rule: `{ connection: hostssl, method: md5, options: { clientcert: verify-ca } }`,
6060
expected: `"hostssl" all all all "md5" "clientcert"="verify-ca"`,
6161
},
62+
// "password" input should be "md5" output
63+
{
64+
rule: `{ connection: hostssl, method: password }`,
65+
expected: `"hostssl" all all all "md5"`,
66+
},
6267
} {
6368
var rule *v1beta1.PostgresHBARule
6469
require.UnmarshalInto(t, &rule, tt.rule)

0 commit comments

Comments
 (0)