Skip to content

Commit fddc90e

Browse files
author
Jonathan S. Katz
committed
Provide guidance on manually setting passwords
This provides a method for how one can manually change the password of a Postgres user. Issue: [ch2724]
1 parent cc89fb6 commit fddc90e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/content/architecture/user-management.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,40 @@ Users and databases can be customized in the `spec.users` section of the custom
5353
- The special `postgres` user can be added as one of the custom users; however, the privileges of the users cannot be adjusted.
5454

5555
For specific examples for how to manage users, please see the [user and database management]({{< relref "tutorial/user-management.md" >}}) section of the [tutorial]({{< relref "tutorial/_index.md" >}}).
56+
57+
## Custom Passwords
58+
59+
There are cases where you may want to explicitly provide your own password for a Postgres user. PGO determines the password from an attribute in the user Secret called `verifier`. This contains a hashed copy of your password. When `verifier` changes, PGO will load the contents of the verifier into your Postgres cluster. This method allows for the secure transmission of the password into the Postgres database.
60+
61+
Postgres provides two methods for hashing password: SCRAM-SHA-256 and md5. The preferred (and as of PostgreSQL 14, default) method is to use SCRAM, which is also what PGO uses as a default.
62+
63+
You can still provide a plaintext password in the `password` field, but this merely for convenience: this makes it easier for your application to connect with an updated password.
64+
65+
### Example
66+
67+
For example, let's say we have a Postgres cluster named `hippo` and a Postgres user named `hippo`. The Secret then would be called `hippo-pguser-hippo`.
68+
69+
Let's say we want to set the password for `hippo` to be `datalake`. We would first need to create a SCRAM version of the password. You can find a script that [creates Postgres SCRAM-SHA-256](https://gist.github.com/jkatz/e0a1f52f66fa03b732945f6eb94d9c21) passwords [here](https://gist.github.com/jkatz/e0a1f52f66fa03b732945f6eb94d9c21).
70+
71+
Below is an example of a SCRAM verifier that may be generated for the password `datalake`, stored in two environmental variables:
72+
73+
```
74+
PASSWORD=datalake
75+
VERIFIER='SCRAM-SHA-256$4096:FAnSkUrL3jH6Bp17P5FTuQ==$BecLU0YXzBUwnTk3b3ghIZ7/zS2XvD8wX50Hz5JL0q4=:pxuEtozYTZpAc6wINV53sCr4Afxk8LLfor5MvkYp21s='
76+
```
77+
78+
To store these in a Kubernetes Secret, both values need to be base64 encoded. You can do so with the following example:
79+
80+
```
81+
PASSWORD=$(echo -n $PASSWORD | base64 | tr -d '\n')
82+
VERIFIER=$(echo -n $VERIFIER | base64 | tr -d '\n')
83+
```
84+
85+
Finally, you can update the Secret using `kubectl patch`. The below assumes that the Secret is stored in the `postgres-operator` namespace:
86+
87+
```
88+
kubectl patch secret -n postgres-operator hippo-pguser-hippo -p \
89+
"{\"data\":{\"password\":\"${PASSWORD}\",\"verifier\":\"${VERIFIER}\"}}"
90+
```
91+
92+
PGO will apply the updated password to Postgres, and you will be able to login with the password `datalake`.

0 commit comments

Comments
 (0)