Skip to content

Commit 085ae08

Browse files
[DPE-7792] Update predefined roles docs (#1054)
* Update roles.md * Update database-level roles in SQL query results * Add charmed_dba, charmed_admin and charmed_databases_owner to SQL query result * Add CREATEDB to custom word list Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Add note about roles that cannot be requested through relation --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]>
1 parent 3f989d0 commit 085ae08

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

docs/.custom_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cjk
2828
codebase
2929
config
3030
configs
31+
CREATEDB
3132
cryptographically
3233
CSR
3334
CSRs

docs/explanation/roles.md

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
There are several definitions of roles in Charmed PostgreSQL:
44
* Predefined PostgreSQL roles
5-
* Instance level DB/relation-specific roles
5+
* Instance-level DB/relation-specific roles
66
* LDAP-specific roles
77
* Extra user roles relation flag
88

@@ -35,13 +35,17 @@ test123=> SELECT * FROM pg_roles;
3535

3636
## Charmed PostgreSQL 16 roles
3737

38-
Charmed PostgreSQL 16 introduces the following instance level predefined roles:
38+
Charmed PostgreSQL 16 introduces the following instance-level predefined roles:
3939

4040
* `charmed_stats` (inherit from pg_monitor)
41-
* `charmed_read` (inherit from pg_read_all_data)
42-
* `charmed_dml` (inherit from pg_write_all_data)
43-
* `charmed_backup` (inherit from pg_checkpoint)
41+
* `charmed_read` (inherit from pg_read_all_data and `charmed_stats`)
42+
* `charmed_dml` (inherit from pg_write_all_data and `charmed_read`)
43+
* `charmed_backup` (inherit from pg_checkpoint and `charmed_stats`)
4444
* `charmed_dba` (allowed to escalate to any other user, including the superuser `operator`)
45+
* `charmed_admin` (inherit from `charmed_dml` and allowed to escalate to the database-specific `charmed_<database-name>_owner` role, which is explained later in this document)
46+
* `charmed_databases_owner` (allowed to create databases; it can be requested through the CREATEDB extra user role)
47+
48+
Currently, `charmed_backup` and `charmed_dba` cannot be requested through the relation as extra user roles.
4549

4650
```text
4751
test123=> SELECT * FROM pg_roles;
@@ -52,25 +56,30 @@ test123=> SELECT * FROM pg_roles;
5256
charmed_read | f | t | f | f | f | f | -1 | ******** | | f | | 16388
5357
charmed_dml | f | t | f | f | f | f | -1 | ******** | | f | | 16390
5458
charmed_backup | f | t | f | f | f | f | -1 | ******** | | f | | 16392
59+
charmed_dba | f | t | f | f | f | f | -1 | ******** | | f | | 16393
60+
charmed_admin | f | t | f | f | f | f | -1 | ******** | | f | | 16394
61+
charmed_databases_owner | f | t | f | t | t | f | -1 | ******** | | f | | 16395
5562
...
5663
```
5764

5865
Charmed PostgreSQL 16 also introduces catalogue/database level roles, with permissions tied to each database that's created. Example for a database named `test`:
5966

6067
```text
61-
test123=> SELECT * FROM pg_roles where rolname like 'test_%';;
62-
rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolbypassrls | rolconfig | oid
63-
----------------------------+----------+------------+---------------+-------------+-------------+----------------+--------------+-------------+---------------+--------------+-----------+-------
64-
test_owner | f | t | f | f | f | f | -1 | ******** | | f | | 16479
65-
test_admin | f | f | f | f | f | f | -1 | ******** | | f | | 16480
68+
test123=> SELECT * FROM pg_roles WHERE rolname LIKE 'charmed_test_%';
69+
rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolbypassrls | rolconfig | oid
70+
--------------------+----------+------------+---------------+-------------+-------------+----------------+--------------+-------------+---------------+--------------+-----------+-------
71+
charmed_test_owner | f | t | f | f | f | f | -1 | ******** | | f | | 16396
72+
charmed_test_admin | f | f | f | f | f | f | -1 | ******** | | f | | 16397
73+
charmed_test_dml | f | t | f | f | f | f | -1 | ******** | | f | | 16398
6674
```
6775

68-
The `*_admin` role is assigned to each relation user (explained in the next section) with access to the specific database. When that user connects to the database, it's auto-escalated to the `*_owner` user, which will own every object inside the database, simplifying the permissions to perform operations on those objects when a new user requests access to that same database.
76+
The `charmed_<database-name>_admin` role is assigned to each relation user (explained in the next section) with access to the specific database. When that user connects to the database, it's auto-escalated to the `charmed_<database-name>_owner` user, which will own every object inside the database, simplifying the permissions to perform operations on those objects when a new user requests access to that same database.
6977

70-
<!--TODO: are the next two sections also relevant for 16?-->
71-
### Relation specific roles
78+
There is also a `charmed_<database-name>_dml` role that is assigned to each relation user to still allow them to read and write to the database objects even if the mechanism to auto-escalate the relation user to the `charmed_<database-name>_owner` role doesn't work.
7279

73-
For each application/relation the dedicated user is been created (with matching role and all all resources ownership). The resources ownership is being updated on each re-relation for new users/roles regeneration. Example of simple application relation to PostgreSQL and creating table:
80+
### Relation-specific roles
81+
82+
For each application/relation, the dedicated user has been created:
7483

7584
```text
7685
postgres=# SELECT * FROM pg_roles;
@@ -85,17 +94,9 @@ postgres=# SELECT * FROM pg_user;
8594
----------------------------+----------+-------------+----------+---------+--------------+----------+----------+-----------
8695
...
8796
relation_id_12 | 16416 | t | f | f | f | ******** | |
88-
...
89-
90-
mydb=# \d+
91-
List of relations
92-
Schema | Name | Type | Owner | ...
93-
--------+---------+-------+----------------+ ...
94-
public | mytable | table | relation_id_12 | ...
95-
9697
```
9798

98-
When the same application is being related through PgBouncer, the extra users/roles created following the same logic as above:
99+
When the same application is being related through PgBouncer, the extra users/roles are created following the same logic as above:
99100

100101
```text
101102
postgres=# SELECT * FROM pg_roles;
@@ -114,19 +115,12 @@ postgres=# SELECT * FROM pg_user;
114115
relation-14 | 16403 | f | t | f | f | ******** | |
115116
pgbouncer_auth_relation_14 | 16410 | f | t | f | f | ******** | |
116117
relation_id_13 | 16417 | t | f | f | f | ******** | |
117-
...
118-
119-
mydb=# \d+
120-
List of relations
121-
Schema | Name | Type | Owner | ...
122-
--------+---------+-------+----------------+ ...
123-
public | mytable | table | relation_id_13 | ...
124118
```
125119

126-
In this case there several records created to:
120+
In this case, there are several records created to:
127121
* `relation_id_13` - for relation between Application and PgBouncer
128122
* `relation-14` - for relation between PgBouncer and PostgreSQL
129-
* `pgbouncer_auth_relation_14` - to authenticate end-users which connects PgBouncer
123+
* `pgbouncer_auth_relation_14` - to authenticate end-users, which connects PgBouncer
130124

131125
### Charmed PostgreSQL LDAP roles
132126

0 commit comments

Comments
 (0)