Repository navigation
Add read-only DB role for each tenant - #259
Draft
kiwitcms-bot wants to merge 1 commit into
Draft
kiwitcms-bot wants to merge 1 commit into
kiwitcms-bot wants to merge 1 commit into
Conversation
atodorov
marked this pull request as draft
October 6, 2026 15:21
kiwitcms-bot
force-pushed
the
read-only-database-role
branch
4 times, most recently
from
October 6, 2026 16:25
95c7478 to
498b0ca
Compare
kiwitcms-bot
changed the base branch from
master
to
read-only-database-role-model
October 6, 2026 16:25
kiwitcms-bot
force-pushed
the
read-only-database-role-model
branch
from
October 6, 2026 16:36
37782c8 to
7a681ff
Compare
CreateTenant.form_valid() creates the read-only DB role for the newly created tenant schema, after the tenant exists so we know its schema_name and paid_until. On recurring billing the role's `valid until` attribute is updated together with Tenant.paid_until.
kiwitcms-bot
force-pushed
the
read-only-database-role
branch
from
October 6, 2026 16:38
498b0ca to
5a27ec0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new
ReadOnlyDatabaseRolemodel and a helper that creates a real read-only PostgreSQL role for a tenant schema.Stacked on #260 (the model + migration + model tests). Review/merge that one first; this PR only contains the integration diff (2 files).
Fields:
name,created_at,valid_until,password.ReadOnlyDatabaseRole.create_for_schema(schema_name, valid_until):name=ro_for_<schema_name>(READ_ONLY_ROLE_PREFIXis a class attribute)password= random UUIDcreated_at= nowvalid_until= passed in (tenant.paid_until)It stores the model record and creates the DB role via raw SQL, escaping identifiers/values with psycopg's
sql.Identifier/sql.Literal. The role getsLOGIN+ENCRYPTED PASSWORD+VALID UNTIL,USAGEon the schema,SELECTon all its tables, andALTER DEFAULT PRIVILEGES ... GRANT SELECT ON TABLESfor future tables. No write privileges.This PR (integration)
CreateTenant.form_valid()creates the role after the tenant (and its schema) exists, soschema_nameandpaid_untilare known.Tenant.paid_untilcallsrole.update_valid_until(tenant.paid_until), updating both the model and the DB role in one transaction.tests/test_views_createview.py: creating a tenant createsro_for_<schema_name>.Follow-up (not in this PR)
Expose / propagate the role name + password to the customer in the subscription page, similar to how the Private Token is shown today.
black,flake8andpylint(10.00/10) are clean; tests pass. The existingtest_docker.pyfailures are unrelated (they need a real Quay.io token/network).