Skip to content

Commit e3795f2

Browse files
add sample for grant statement crd and update readme
1 parent 3625523 commit e3795f2

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ This guide provides an introduction to using the PostgreSQL Operator. It will he
1515
- You’ll need a Kubernetes cluster to run against. You can use [KIND](https://sigs.k8s.io/kind) to get a local cluster for testing, or run against a remote cluster.
1616
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).
1717
- A kubernetes secret that contains base64 encrypted PostgreSQL Database details `username`, `password`, `endpoint`, `port`, `database` and `role_password`
18-
> _Note:_
19-
> - You can use existing secret with database details and role password
20-
> - You can new secret with database details and role password
21-
> - You can also created two separate secret for database details and role password
2218

23-
- Create a secret that contains both the database details and the role password. You have the flexibility to choose your own name for the key representing the role password, as long as you reference it correctly in the Role CRD.
19+
> [!NOTE]
20+
> - You can use existing secret with database details and role password
21+
> - You can new secret with database details and role password
22+
> - You can also created two separate secret for database details and role password
23+
24+
> [!CAUTION]
25+
> - For granting permissions to a specific role, you should utilize either the Grant or GrantStatement Custom Resource Definition — but not both concurrently. Using both might lead to conflicts or unexpected behavior.
26+
> - For managing role permissions through the GrantStatement Custom Resource Definition on any database, ensure that no additional permissions are assigned outside the CRD manually. Any such additional permissions will be revoked when the CRD gets updated.
27+
> - Please note that you should not use any PostgreSQL GRANT query for a different database in a GrantStatement Custom Resource Definition that is specifically related to one database. If you do, the role cleanup process may not be successful.
28+
29+
- Create a secret that contains both the database details and the role password. You have the flexibility to choose your own name for the key representing the role password, as long as you reference it correctly in the Role CRD.
2430

2531
```bash
2632
kubectl create secret generic <secret_name> --from-literal=username=<postgresql_username> --from-literal=password=<postgresql_password> --from-literal=endpoint=<postgresql_endpoint> --from-literal=port=<postgresql_port> --from-literal=database=<postgresql_database> --from-literal=role_password=<postgresql_role_password>
@@ -75,6 +81,24 @@ spec:
7581
table: ALL
7682
```
7783

84+
#### Example GrantStatement CRD
85+
````yaml
86+
apiVersion: postgresql.facets.cloud/v1alpha1
87+
kind: GrantStatement
88+
metadata:
89+
name: test-grantstatement
90+
spec:
91+
roleRef:
92+
name: test-role
93+
namespace: default
94+
database: postgres
95+
statements:
96+
- 'GRANT CONNECT ON DATABASE postgres TO "test-role";'
97+
- 'GRANT USAGE ON SCHEMA public TO "test-role";'
98+
- 'GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "test-role";'
99+
- 'ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test-role";'
100+
````
101+
78102
For more examples, kindly check [here](examples)
79103

80104
### Running on the cluster

config/samples/postgresql_v1alpha1_grantstatement.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@ metadata:
99
app.kubernetes.io/created-by: postgresql-operator
1010
name: grantstatement-sample
1111
spec:
12-
# TODO(user): Add fields here
12+
roleRef:
13+
name: test-role
14+
namespace: default
15+
database: postgres
16+
statements:
17+
- 'GRANT CONNECT ON DATABASE postgres TO "test-role";'
18+
- 'GRANT USAGE ON SCHEMA public TO "test-role";'
19+
- 'GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "test-role";'
20+
- 'ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "test-role";'

docs/crd.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Package v1alpha1 contains API Schema definitions for the postgresql v1alpha1 API
1111
### Resource Types
1212
- [Grant](#grant)
1313
- [Role](#role)
14+
- [GrantStatement](#grantstatement)
1415

1516

1617

@@ -101,13 +102,40 @@ _Appears in:_
101102
| `privileges` _[RolePrivilege](#roleprivilege)_ | Privileges to be granted. |
102103

103104

105+
#### GrantStatement
106+
107+
108+
109+
GrantStatement is the Schema for the grantstatement API
110+
111+
112+
| Field | Description |
113+
| ------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------- |
114+
| `apiVersion` _string_ | `postgresql.facets.cloud/v1alpha1` |
115+
| `kind` _string_ | `GrantStatement` |
116+
| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. |
117+
| `spec` _[GrantStatementSpec](#rolespec)_ | |
118+
119+
#### GrantStatementSpec
120+
121+
GrantStatementSpec defines the desired state of GrantStatement
122+
123+
| Field | Description |
124+
| --------------------------------------------------- | ----------------------------------------------------------- |
125+
| `roleRef` _[ResourceReference](#resourcereference)_ | Defines the role reference to grant permissions |
126+
| `statements` _string array_ | Defines the list of grant queries to be executed for a role |
127+
| `database` _string_ | Defines the Database to execute grant queries for a role |
128+
129+
130+
104131
#### ResourceReference
105132

106133
The Database Connection details secret selector
107134

108135
_Appears in:_
109136
- [Role](#role)
110137
- [Grant](#Grant)
138+
- [GrantStatement](#GrantStatement)
111139

112140
| Field | Description |
113141
| ----------- | ---------------------------------------------------------------------------------------------------------------------- |

0 commit comments

Comments
 (0)