-
Notifications
You must be signed in to change notification settings - Fork 27
[DPE-6899] User->databases pg_hba rules #919
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
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Codecov ReportAttention: Patch coverage is
❌ Your patch status has failed because the patch coverage (30.55%) is below the target coverage (33.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #919 +/- ##
==========================================
- Coverage 74.65% 73.02% -1.64%
==========================================
Files 13 15 +2
Lines 3729 3870 +141
Branches 550 564 +14
==========================================
+ Hits 2784 2826 +42
- Misses 738 834 +96
- Partials 207 210 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…d db-admin relations Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…e-hba-rules Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
| ) | ||
| if cursor.fetchone() is None: | ||
| cursor.execute(""" | ||
| CREATE OR REPLACE FUNCTION update_pg_hba() |
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.
Function used to update the pg_hba file when PgBouncer creates or deletes an user.
…e-hba-rules Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…e-hba-rules Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…e-hba-rules Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…e-hba-rules Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…e-hba-rules Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…e-hba-rules Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…e-hba-rules Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
| if is_primary: | ||
| # Read contents from the pg_hba.conf file. | ||
| with open("/var/lib/postgresql/data/pgdata/pg_hba.conf") as file: | ||
| current_authorisation_rules = file.read() |
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.
Going forward, we should most probably just hash the file.
taurus-forever
left a comment
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.
Thank you!
… code when not a superuser Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Issue
Database access is not restricted through the
pg_hba.conffile.Solution
Retrieve the list that each user should have access to and rebuild the
pg_hba.conffile rules based on that list, while keeping access to all the databases for the system users and superusers.For the users created by this charm, some calls to the
update_configmethod were added to the client relations files (src/relations/db.pyandsrc/relations/postgresql_provider.py) to rebuild thepg_hba.conffile rules.For the users created by the PgBouncer charm, the PostgreSQL charm needs to gather that information in some way because the
data_interfacesdoesn't share it yet. For that, an event trigger is used. That should be removed after we improve the interface.An observer process (like the one we have in the VM charm) was created to update the list of users->databases in the replicas because the event trigger is fired only in the primary.
An integration test (
tests/integration/test_pg_hba.py) was created to validate users created by both this and an external charms (PgBouncer is simulated through creating users by using the Data Integration relation user).Still in progress (while you review the PR): fixing the failing integration tests and increasing coverage.
Checklist