Fix ownership and CRDT scoping by database#187
Merged
Conversation
Owner lookups previously keyed only on tenant_id, so a same-named collection in another database within the same tenant would incorrectly resolve to whichever owner happened to be recorded first. Thread database_id through permission checks, namespace authorization, and ownership DDL so ownership is correctly scoped per database.
CRDT constraint checkpoint filenames and tombstone lookups were keyed by tenant and collection only, so a collection with the same name in a different database within the same tenant could collide. Include the database id in checkpoint filenames and replace the crdt_constraints snapshot tuple with a named CrdtConstraintEntry struct carrying the database id alongside tenant, collection, version, and constraints.
farhan-syah
force-pushed
the
fix/drop-user-valid-owner-reassignment
branch
from
July 20, 2026 09:54
e4dffa0 to
cd6bd22
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.
Summary
Follow-up to the database-scoped ownership work already merged in
ed928f4f. That commit re-keyed the owners map to includedatabase_idbut did not update every reader, which left ownership authorization broken and the cluster test crate uncompilable. This restores both.Ownership authorization (435f3bb)
ed928f4fchanged the owners-map key to{object_type}:{database_id}:{tenant_id}:{object_name}, butPermissionStore::checkstill looked it up with the unqualifiedcollection_targetstring used for grants. The two shapes never match, sois_owneralways returned false and owners silently lost implicit permissions on their own objects, falling through to explicit grants only. This is reached in production viaauthorize_collection_requirement.check/check_functionnow take adatabase_id, andis_ownerbuilds the key withowner_keyrather than being handed a grant target. Owner keys and grant targets are documented as non-interchangeable so the two lookups don't get conflated again.Three further sites looked up database-scoped owner rows with a hardcoded database 0:
ALTER COLLECTION … OWNER TO— the owner check, theget_collection, and the single-node fallbackput_collection. For a collection outside the default database the fallback wrote the record into the wrong database.DROP INDEX— ignored thedatabase_idalready present in its own signature.SHOW PERMISSIONS ON <collection>— omitted the owner row outside the default database.New test
ownership_is_scoped_to_its_databasepins both directions: an owner is recognised in their own database, and not in another database holding a same-named collection.CRDT constraint snapshots (e4dffa0)
nodedb-cluster-testsdid not compile againsted928f4f— three tests still destructured tuples that commit had widened, so stage 2 could not build. Fixed, along with a stale checkpoint-filename assertion and doc comments still describing the pre-ed928f4fscheme. The filename scheme itself is unchanged here.TenantDataSnapshot::crdt_constraintsmoves from a 5-tuple to a namedCrdtConstraintEntrystruct. The tuple had crossed clippy'stype_complexitythreshold; a named type is the fix rather than an#[allow].Validation
Two-stage suite green: stage 1
11971/11971, stage 2310/310(one flaky,lease_renews_before_expiry, passed on retry). Clippy clean.Note: this branch is behind
mainand its runs did not include the CI commits merged since (c86abfe0,d990a85d,fe0e16cc). Stage 2 is worth re-running after mergingmain, asfe0e16cctouches the Calvin path.