Skip to content

Commit b4be754

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 c7bf02d commit b4be754

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

internal/controller/postgrescluster/postgres.go

+3-3
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

+2-2
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

+4-4
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

+1-1
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

testing/kuttl/e2e/password-change/04--secret.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
apiVersion: v1
23
kind: Secret
34
metadata:
@@ -7,3 +8,14 @@ stringData:
78
password: infopond
89
verifier: "md585eb8fa4f697b2ea949d3aba788e8631"
910
uri: ""
11+
---
12+
# Enable authenticating with MD5 passwords
13+
apiVersion: postgres-operator.crunchydata.com/v1beta1
14+
kind: PostgresCluster
15+
metadata:
16+
name: password-change
17+
spec:
18+
authentication:
19+
rules:
20+
- connection: hostssl
21+
method: md5

0 commit comments

Comments
 (0)