-
Notifications
You must be signed in to change notification settings - Fork 27
[DPE-6752] Implement predefined roles #837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ly removed database_owner role creation
…per database + increase upgrade test timeout
…tabase privileges for users
…ions created by db_owner
…mplement integration tests for predefined roles
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 16/edge #837 +/- ##
===========================================
- Coverage 71.03% 70.63% -0.40%
===========================================
Files 15 15
Lines 3870 3903 +33
Branches 571 572 +1
===========================================
+ Hits 2749 2757 +8
- Misses 938 959 +21
- Partials 183 187 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice implementation, Shayan!
cur_user := (SELECT current_user); | ||
EXECUTE 'SELECT current_database()' INTO db_name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity: does this work in replicas? I had some errors in the past where I tried to use INTO variable
in the replicas. I'm not sure if it was really related to the unit being a replica or another reason.
if "superuser" in roles: | ||
logger.warning("superuser privileges not allowed via extra-user-roles") | ||
roles.remove("superuser") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this break PgBouncer? I believe PgBouncer needs the SUPERUSER
role to grant the SUPERUSER
role to Landscape or another application when it connects to the PgBouncer legacy relation called db-admin
. I know that it might not apply to this charm version (PG 16), but we may need to handle this on PgBouncer side, to avoid it breaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PGB auth user also can't be created, since it needs access to user password hashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if in PG 16 only, we can translate SUPERUSER
extra-user-role to CREATEDB,CREATEROLE
in postgresql charm. if pgbouncer does not need superuser, it can continue to request superuser, and we can just provide it with what it needs in PG 16. we will also add support for pgbouncer
extra-user-role which pgbouncer can request once we build in support for sharing PG versions through data interfaces
"""Grant the specified priviliges on the provided database for the user.""" | ||
try: | ||
with self._connect_to_database() as connection, connection.cursor() as cursor: | ||
cursor.execute(SQL("GRANT {} ON DATABASE {} TO {};").format(Identifier(", ".join(privileges)), Identifier(database), Identifier(user))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PGB and create role users will need to be able to regrant at least connect privileges to created users.
Issue
We would like to introduce pre-defined roles with the introduction of postgres 16 track in our charm
These pre-defined roles not only will help users be more expressive of the
extra-user-roles
that they can request, but also serve as a means to start hardening the security in our charm. Furthermore, the changes proposed in this PR take a step in the direction of supporting creation of custom roles via data interfaces.Solution
Introduce the following instance level predefined roles:
Introduce, for every database created, the following roles:
Additionally, create a function
set_user_<database_name>_owner()
which can be used by<database_name>_admin
to escalate to<database_name>_owner
usingset_user
extensionAll resources created in a database will be owned by
<database_name>_owner
-> or reassigned to<database_name>_owner
when the provider relation is broken or when the first provider relation is formed (in the case that there is an existing database already)Backup users have much less privileges than previously (we do not grant all privileges to all databases to the
backup
user anymore)The following
extra-user-roles
still need to be maintained until we determine how to cleanly deprecate them:charmed_dml
with all privileges to all databases. additionally, will also havecreatedb
attribute enabled for created userThe
superuser
role is being deprecated (albeit, silently. there will be no errors thrown when requested, the charm will simply not comply)TODO
<database_name>_admin
to<database_name>_owner
upon login to ensure that all resources created by the user are correctly owned by the owner roleChecklist