libsql-server: enforce namespace authorization on gRPC replication RPCs - #28
Closed
bartzon wants to merge 1 commit into
Closed
libsql-server: enforce namespace authorization on gRPC replication RPCs#28bartzon wants to merge 1 commit into
bartzon wants to merge 1 commit into
Conversation
The replication path validated the JWT signature but discarded the returned Authenticated, so any valid token could replicate any namespace regardless of its ns claim. Check is_namespace_authorized against the served namespace and add a negative cross-namespace test.
Author
|
Closing in favor of router-layer enforcement. Per team direction (Rafał), we want to avoid further forking libsql — the namespace-claim check will live in retail-libsql-router (Shopify/libsql-infrastructure), which sees all public and internal traffic anyway. This branch is kept as a reference for the negative cross-namespace test shape. |
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.
Problem
The gRPC replication path in
libsql-servervalidated the JWT signature but never checked the token's namespace claim against the namespace being served:rpc/replication/auth.rscalledauth.authenticate(context)?and discarded the returnedAuthenticated.replication_log.rs(Hello/LogEntries/BatchLogEntries/Snapshot) then calledself.namespaces.with(...)directly, so nothing comparedp.ro.nsagainst the namespace being replicated.Consequence: any valid replication token — including one a legitimate client holds for its own namespace — could replicate any namespace by connecting to that namespace's host. This is the cross-namespace authorization gap behind shop/issues-retail#34480.
Fix
In
rpc/replication/auth.rs, use the returnedAuthenticatedand callis_namespace_authorized(&namespace), returningpermission_deniedon mismatch. All four replication RPCs flow throughauthenticate(), so this covers the whole path.is_namespace_authorizedonLegacy{ namespace: None }returnstrue, so legacy/no-namespace tokens (e.g. the CloudSync streamer) still replicate every namespace — no regression for existing server-side callers.Test
Adds
replicate_cross_namespace_deniedintests/embedded_replica/mod.rs:ns1-scoped token replicatesns1(control)ns1-scoped token replicatingns2is denied (the bug)Upstream's
replicate_authonly asserts token-present vs token-absent; this is the missing negative cross-namespace test.Verification
cargo check -p libsql-serverand--testspass clean.