Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions internal/controller/postgrescluster/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func (*Reconciler) generatePostgresHBA(spec *v1beta1.PostgresHBARule) *postgres.
result.Origin(spec.Connection)

// 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.
// use passwords generally. The "scram-sha-256" method is the preferred way
// to do that.
// - https://www.postgresql.org/docs/current/auth-password.html
if spec.Method == "password" {
result.Method("md5")
result.Method("scram-sha-256")
} else {
result.Method(spec.Method)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/postgrescluster/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ 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
// "password" input should be "scram-sha-256" output
{
rule: `{ connection: hostssl, method: password }`,
expected: `"hostssl" all all all "md5"`,
expected: `"hostssl" all all all "scram-sha-256"`,
},
} {
var rule *v1beta1.PostgresHBARule
Expand Down
8 changes: 4 additions & 4 deletions internal/postgres/hba.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func NewHBAs() HBAs {
},

Default: []*HostBasedAuthentication{
// Allow TLS connections to any database using passwords. The "md5"
// authentication method automatically verifies passwords encrypted
// using either MD5 or SCRAM-SHA-256.
// Allow TLS connections to any database using passwords. Passwords are
// hashed and stored using SCRAM-SHA-256 by default. Since PostgreSQL 10,
// the "scram-sha-256" method is the preferred way to use those passwords.
// - https://www.postgresql.org/docs/current/auth-password.html
NewHBA().TLS().Method("md5"),
NewHBA().TLS().Method("scram-sha-256"),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/postgres/hba_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ hostssl "postgres" "_crunchyrepl" all "cert"
host all "_crunchyrepl" all "reject"
`))
assert.Assert(t, matches(hba.Default, `
hostssl all all all "md5"
hostssl all all all "scram-sha-256"
`))
}

Expand Down
12 changes: 12 additions & 0 deletions testing/kuttl/e2e/password-change/04--secret.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: v1
kind: Secret
metadata:
Expand All @@ -7,3 +8,14 @@ stringData:
password: infopond
verifier: "md585eb8fa4f697b2ea949d3aba788e8631"
uri: ""
---
# Enable authenticating with MD5 passwords
apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
name: password-change
spec:
authentication:
rules:
- connection: hostssl
method: md5