Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
cbandy committed Mar 6, 2025
commit 69ecfbef0596ef7cde0e9eb12bfdc2bc9ce878b5
11 changes: 10 additions & 1 deletion internal/controller/postgrescluster/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ func (*Reconciler) generatePostgresHBA(spec *v1beta1.PostgresHBARule) *postgres.

result := postgres.NewHBA()
result.Origin(spec.Connection)
result.Method(spec.Method)

// The "password" method is not recommended. More likely, the user wants to
// use passwords generally. The most compatible method for that is "md5"
// which accepts a password in the format in which it is hashed in the database.
// - https://www.postgresql.org/docs/current/auth-password.html
if spec.Method == "password" {
result.Method("md5")
} else {
result.Method(spec.Method)
}

if len(spec.Databases) > 0 {
result.Databases(spec.Databases[0], spec.Databases[1:]...)
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/postgrescluster/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func TestGeneratePostgresHBA(t *testing.T) {
rule: `{ connection: hostssl, method: md5, options: { clientcert: verify-ca } }`,
expected: `"hostssl" all all all "md5" "clientcert"="verify-ca"`,
},
// "password" input should be "md5" output
{
rule: `{ connection: hostssl, method: password }`,
expected: `"hostssl" all all all "md5"`,
},
} {
var rule *v1beta1.PostgresHBARule
require.UnmarshalInto(t, &rule, tt.rule)
Expand Down