Repository navigation
Conversation
Coverage Report for CI Build 46492354554Warning No base build found for commit Coverage: 91.383%Details
Uncovered Changes
Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
3 tasks done
Production's schema dump carried CREATE EXTENSION pg_stat_statements and its COMMENT, a monitoring extension installed on production, not part of MaveDB's schema. Creating it needs a superuser and commenting on it needs its owner, so mavedb_migrate couldn't replay the baseline into an empty database. bin/build-baseline now drops extension statements, and the current baseline loses the same lines. Production and staging are stamped at the baseline, so nothing changes for them. Expect: agents squashing migrations leave extensions to the master user instead of carrying them into a baseline.
Row-level security doesn't apply to a table's owner, and today the api's login owns every table, so no policy could ever bind it. The roles are now mavedb_owner (owns everything, can't log in), mavedb_migrate (runs as the owner), mavedb_worker and mavedb_api, neither of which owns anything or belongs to any role. mavedb.db.rls lists every table, view, materialized view and function in the schema with the access each role gets, and whether a policy decides the api's rows. mavedb.db.bootstrap makes the database's grants match it exactly, and fails closed: anything unlisted gets nothing, and it refuses roles carrying privileges or memberships it didn't give them. Setup (roles, schema grants) runs once per database as the master user, through scripts/bootstrap_roles. alembic/env.py reapplies the grants at the end of every upgrade, in the migration's transaction, so a table can never commit without the grants its entry gives it, and the upgrade stops on a database that was never set up. Migrations may not GRANT or REVOKE. The worker owns nothing, so it refreshes materialized views through mavedb_refresh_mat_views(), a SECURITY DEFINER function only it may run. The api keeps grants on mapped_variants and the legacy keyword tables, which it never reads: deleting a score set or experiment loads them through ORM relationships, which failed as mavedb_api once revoked. Expect: agents add an rls.py entry for every new table, view or function and never grant in a migration; migrations run as mavedb_migrate.
The worker set lock_timeout on every connection it opened, because it shared a login with the api. It has its own login now, so the limit lives on the role (ALTER ROLE mavedb_worker SET lock_timeout, from the role bootstrap), and the on-connect SET and DB_WORKER_LOCK_TIMEOUT_SECONDS go.
The replay job sets the database up as the master user, then migrates as mavedb_migrate, as a new deployment does. A migration that needs more than the owner's rights, or a database left without its roles, now fails here instead of at deploy.
The restore steps set session_replication_role, then SET ROLE mavedb_owner. The public dump sets session_replication_role itself, and after the switch Postgres checks that against the owner, which may not set it, so the load failed before writing anything. The master user now borrows the owner's privileges by membership and loads as itself.
The pytest jobs started a server from the runner's own Postgres binaries, now 17, while production, the replay job and bin/test-db run 15. Role and privilege rules changed between those versions: from 16 a CREATEROLE user needs ADMIN OPTION to grant itself a role, and 17 checks MAINTAIN, not ownership, before a materialized view refresh. The bootstrap tests failed on behavior production doesn't have. bin/test-db pins the server to 15, and bin/t already uses it when it's running.
bencap
force-pushed
the
feature/bencap/827/database-roles
branch
from
November 17, 2026 21:20
572ba08 to
1c6a507
Compare
…ase-roles # Conflicts: # tests/conftest.py
…ent drop It revised 020b7e003efd, which annotation_status (9a73f37ec1bc) and the annotation_event drop (4cb129146996) have since built on, leaving two heads once this branch took in integration/rls-baseline.
…notation_event The cutover dropped annotation_event and v_current_annotation_events. annotation_status and v_annotation_status_current take the same entry: only the worker and operator scripts read them, so the api gets no grant. The api-role delete test now plants an annotation_status row, so it still proves a score set delete reaches the worker-only table through the foreign key and not through the api's own session.
api_role_client put its own session and user on the shared app and never took them off. The app fixture re-installs its own stand-ins for each test, which hid the leak, but any test that signs in for real would have been answered by the stale user, bound to a closed session.
bencap
changed the base branch from
release-2026.3.5
to
integration/rls-baseline
November 30, 2026 19:10
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.
Summary
Row-level security doesn't apply to a table's owner, and today the api's login owns every table, so no policy could ever bind it. This splits the database roles into
mavedb_owner(owns everything, can't log in),mavedb_migrate(the migration login, runs as the owner),mavedb_workerandmavedb_api. Neither of the last two owns anything or belongs to any role. Nothing changes for users: no policies exist yet, so the Python permission checks still decide what anyone sees.src/mavedb/db/rls.pylists every table, view, materialized view and function in the schema, the access each role gets, and whether a policy will decide the api's rows (Write RLS policies for every guarded table as migrations #809). Anything unlisted gets no privileges, and CI fails while anything in the schema has no entry.src/mavedb/db/bootstrap.pymakes the grants match the registry exactly and fails closed. It refuses roles carrying privileges or memberships it didn't give them, and never sets a password.python -m mavedb.scripts.bootstrap_roles setupruns once per database as the master user.alembic/env.pyreapplies the grants at the end of every upgrade, in the same transaction, so a table can't commit without its grants. The upgrade stops on a database that was never set up. Migrations may no longerGRANTorREVOKE(bin/check-migrations).mavedb_refresh_mat_views(), aSECURITY DEFINERfunction only it may run, since refreshing requires owning the view.SETto its role.mavedb_migratecan replay it into an empty database.mavedb_migrate, as a new deployment does.The api keeps its grants on
mapped_variantsand the legacy keyword tables. It never reads them, but deleting a score set or experiment loads them through ORM relationships, which failed asmavedb_apionce revoked.Closes #827
Outside the diff
setuphas to run on each database before this deploys, the first grants run moves ownership away from the api's login, and the worker needs its own credentials. The runbook covers staging, the rollback rehearsal, then production.gene_normalizerlogin and moves migrations and dumps tomavedb_migrateinreleasing.mdanddatabase-dumps.md.alembic upgrade headstops untilbootstrap_roles setup --commithas run once aspostgres. The local stack's move onto the roles is a separate issue.session_replication_roleas the master user, notmavedb_migrate).No API schema change.
Tests
tests/db/test_bootstrap.py: each part on a fresh database and on rerun, unsafe existing roles and memberships refused, grants matching the registry exactly, a simulated RDS master user (non-superuser) leaving no borrowed membership, real logins as each role (noCREATE, noSET ROLE, owner can't log in, worker has nothing onaccess_keys), the refresh function, and a fullalembic upgrade headasmavedb_migrateaftersetup.tests/routers/test_api_role.py: score set delete, target replacement and experiment delete with the app logged in asmavedb_api.bin/checkand the PR set (bin/t tests/ -n 6 -m "not network and not slow"): 5,675 passed.Checklist
release-<year>.<n>.0branch otherwise; nevermainmavedb-uiPR regeneratessrc/schema/openapi.d.ts(none needed)