Skip to content

Commit 311537f

Browse files
committed
Change the default authentication method to SCRAM-SHA-256
PostgreSQL has stored passwords as SCRAM-SHA-256 since PostgreSQL 14. PGO has stored passwords as SCRAM-SHA-256 since PostgreSQL 10. The "spec.authentication.rules" and "spec.config.parameters" fields allow users to downgrade to MD5 when necessary. Issue: PGO-2290 See: https://www.postgresql.org/docs/current/auth-password.html
1 parent 69ecfbe commit 311537f

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

internal/controller/postgrescluster/postgres.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ func (*Reconciler) generatePostgresHBA(spec *v1beta1.PostgresHBARule) *postgres.
5353
result.Origin(spec.Connection)
5454

5555
// 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.
56+
// use passwords generally. The "scram-sha-256" method is the preferred way
57+
// to do that.
5858
// - https://www.postgresql.org/docs/current/auth-password.html
5959
if spec.Method == "password" {
60-
result.Method("md5")
60+
result.Method("scram-sha-256")
6161
} else {
6262
result.Method(spec.Method)
6363
}

internal/controller/postgrescluster/postgres_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ 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
62+
// "password" input should be "scram-sha-256" output
6363
{
6464
rule: `{ connection: hostssl, method: password }`,
65-
expected: `"hostssl" all all all "md5"`,
65+
expected: `"hostssl" all all all "scram-sha-256"`,
6666
},
6767
} {
6868
var rule *v1beta1.PostgresHBARule

internal/postgres/hba.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func NewHBAs() HBAs {
2929
},
3030

3131
Default: []*HostBasedAuthentication{
32-
// Allow TLS connections to any database using passwords. The "md5"
33-
// authentication method automatically verifies passwords encrypted
34-
// using either MD5 or SCRAM-SHA-256.
32+
// Allow TLS connections to any database using passwords. Passwords are
33+
// hashed and stored using SCRAM-SHA-256 by default. Since PostgreSQL 10,
34+
// the "scram-sha-256" method is the preferred way to use those passwords.
3535
// - https://www.postgresql.org/docs/current/auth-password.html
36-
NewHBA().TLS().Method("md5"),
36+
NewHBA().TLS().Method("scram-sha-256"),
3737
},
3838
}
3939
}

internal/postgres/hba_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ hostssl "postgres" "_crunchyrepl" all "cert"
3636
host all "_crunchyrepl" all "reject"
3737
`))
3838
assert.Assert(t, matches(hba.Default, `
39-
hostssl all all all "md5"
39+
hostssl all all all "scram-sha-256"
4040
`))
4141
}
4242

0 commit comments

Comments
 (0)