Skip to content

Commit 0a6faf8

Browse files
committed
Add docs about dbusers
Signed-off-by: Nikolai Rodionov <allanger@badhouseplants.net>
1 parent 332ff41 commit 0a6faf8

2 files changed

Lines changed: 119 additions & 4 deletions

File tree

docs/database.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ my-database-creds 4 4m46s
4949

5050
The Secret should contain credentials to connect to the database generated by operator.
5151

52-
For postgres,
52+
For **PostgreSQL**:
5353
```YAML
5454
apiVersion: v1
5555
kind: Secret
@@ -67,7 +67,7 @@ data:
6767
CONNECTION_STRING: << base64 encoded database connection string >>
6868
```
6969

70-
For mysql,
70+
For **MySQL**:
7171
```YAML
7272
apiVersion: v1
7373
kind: Secret
@@ -162,10 +162,16 @@ spec:
162162
163163
## Generic additional options
164164
165+
### Deletion Protection
166+
165167
For production databases you might want to set `.spec.deletionProtected` to `true`. With this setting, db-operator will not remove the database from the server, if a Kubernetes resource is deleted.
166168
169+
### Credentials Templates
170+
167171
DB operator is capable of generating custom connections strings using the information it has about a database, [here](templates.md) you can read more about templates.
168172
173+
### Extra Grants
174+
169175
It is possible to apply extra grants to databases, when it's enabled on the db-instance level.
170176
To enable it, one must set `.spec.allowExtraGrants` to `true` on an instance.
171177
@@ -188,6 +194,25 @@ spec:
188194

189195
Now the `database-admin` should have enough permissions for reading data from this database. If access needs to be revoked or changed to `readWrite`, it should be enough to remove the entry from the spec or modify it.
190196

197+
### Extra Labels and Annotations
198+
199+
With `credentials.metadata.extraLabels` and `credentials.metadata.extraAnnotations` you can add custom metadata to the **Secret** that stores the generated user credentials. These values are merged with the metadata created by the operator. Keys defined in `extraLabels` or `extraAnnotations` overwrite existing values with the same key.
200+
201+
Example:
202+
203+
```yaml
204+
spec:
205+
credentials:
206+
metadata:
207+
extraLabels:
208+
environment: development
209+
extraAnnotations:
210+
reflector.v1.k8s.emberstack.com/reflection-allowed: "true"
211+
reflector.v1.k8s.emberstack.com/reflection-auto-enabled: "true"
212+
reflector.v1.k8s.emberstack.com/reflection-auto-namespaces: target-namespace
213+
```
214+
215+
This metadata can be used by external controllers that watch annotations or require specific labels to enable Secret synchronization or reflection across namespaces.
191216
192217
## Additional PostgreSQL options
193218
@@ -231,14 +256,17 @@ Then DB Operator will connect to an existing database and set up a user for it.
231256

232257
Experimental features are added via annotations, the following features are available for `Databases`
233258

234-
---
259+
### RDS IAM Impersonate
260+
235261
This annotation should be used, when a DbUser is not allowed to log in with password, should be used on the RDS instances, when the SSO is used for authentication.
236262

237263
For more info see this issue: https://github.com/db-operator/db-operator/issues/125
238264
```yaml
239265
kinda.rocks/rds-iam-impersonate: "true"
240266
```
241-
---
267+
268+
### Force Database Deletion
269+
242270
Delete a postgres database with present connections, might be useful when pgbouncer is used
243271

244272
```yaml

docs/dbuser.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,88 @@
11
# DbUser
2+
3+
**DbUsers** can be used to manage users on a database server.
4+
5+
When you create a `Database`, db-operator will create a main user, that full access to the created database. You should use this user for you workloads.
6+
If you happen to need more users on your database, you can use `DbUser` Custom Resource
7+
8+
## How to create DbUsers
9+
10+
Let's have a look at the manifest:
11+
```
12+
apiVersion: kinda.rocks/v1beta1
13+
kind: DbUser
14+
metadata:
15+
name: mysql-readwrite
16+
namespace: default
17+
spec:
18+
secretName: mysql-readwrite-secret
19+
accessType: readWrite
20+
databaseRef: mysql-db
21+
```
22+
23+
### Secret Name
24+
25+
The `.secretName` we have already seen in the **Databases**, and here it's used almost in the same way. The only difference is that dbuser controller will reuse the **ConfigMap** that was created by the database controller, and will only create a **Secret**.
26+
27+
28+
### Access Types
29+
30+
`DbUser` supports two access types:
31+
32+
- readWrite (SELECT, INSERT, UPDATE, DELETE)
33+
- readOnly (SELECT)
34+
35+
### Database Reference
36+
37+
**DbUsers** are always attached to **Databases**. Once you have a **Database** that is ready, you can create a **DbUser** to grant additional access to it. Another important thing to consider, is that **DbUser** is a namespace resource, and it must live in the same namespace as a **Database**
38+
39+
### Credentials Templates
40+
41+
You can also use [templates](templates.md) to generate connection strings for users, but since it's reusing the database **ConfigMaps**, you are only allowed to write templated values to **Secrets**, so the `.secret` in the template should always be `true`
42+
43+
### Extra Labels and Annotations
44+
45+
With `credentials.metadata.extraLabels` and `credentials.metadata.extraAnnotations` you can add custom metadata to the **Secret** that stores the generated user credentials. These values are merged with the metadata created by the operator. Keys defined in `extraLabels` or `extraAnnotations` overwrite existing values with the same key.
46+
47+
Example:
48+
49+
```yaml
50+
spec:
51+
credentials:
52+
metadata:
53+
extraLabels:
54+
environment: development
55+
extraAnnotations:
56+
reflector.v1.k8s.emberstack.com/reflection-allowed: "true"
57+
reflector.v1.k8s.emberstack.com/reflection-auto-enabled: "true"
58+
reflector.v1.k8s.emberstack.com/reflection-auto-namespaces: target-namespace
59+
```
60+
61+
This metadata can be used by external controllers that watch annotations or require specific labels to enable Secret synchronization or reflection across namespaces.
62+
63+
## Experimental features
64+
65+
Experimental features are added via annotations, the following features are available for `DbUsers`
66+
67+
### Grant To Admin on Delete
68+
69+
On instances where the admin is not a super user, it might not be able to drop owned by user, so we need to grant the user to the admin.
70+
71+
But it's not possible on the AWS instances with the `rds_iam` roles, because then admins are not able to log in with a password anymore and the db-operator will not be able to do anything on databases.
72+
73+
That's where this workaround might be used. It will only grant the role to the admin when a user is being removed.
74+
```yaml
75+
kinda.rocks/grant-to-admin-on-delete: "true"
76+
```
77+
78+
### Allow Existing User
79+
80+
By default the operator is trying to make sure, that the user that it's trying to maintain is also created by it. Because otherwise it would be possible to make operator believe that a **Database** user that is created by the database controller should become a **readOnly** one.
81+
82+
So if a user already exists on a server, when a **CR** is created, operator will not try to manage it.
83+
84+
If you need the operator to be able to managed existing users, you need to set the following annotation:
85+
86+
```yaml
87+
kinda.rocks/allow-existing-user: "true"
88+
```

0 commit comments

Comments
 (0)