libsql-server: enforce namespace authorization on gRPC replication RPCs - #29
Closed
bartzon wants to merge 1 commit into
Closed
libsql-server: enforce namespace authorization on gRPC replication RPCs#29bartzon 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 — opened in error; will be resubmitted through the proper channel. |
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-servervalidates a JWT's signature but never checks itsnsclaim against the namespace being served:rpc/replication/auth.rscallsauth.authenticate(context)?and discards the returnedAuthenticated.Hello/LogEntries/BatchLogEntries/Snapshot) inreplication_log.rsthen callnamespaces.with(...)directly — nothing comparesp.ro.nsagainst the namespace being replicated.Empirically confirmed on staging: with a token scoped to namespace A, an embedded-replica client (
Builder::new_remote_replica+sync()— the same path a POS device uses) synced namespace B's entire database. HTTP paths are unaffected (they go throughwith_authenticated→is_namespace_authorized).Fix
In
rpc/replication/auth.rs, keep theAuthenticatedand callis_namespace_authorized(&namespace), returningpermission_deniedon mismatch. One change covers all four RPCs.is_namespace_authorizedonLegacy{ namespace: None }returnstrue, so no-namespace/legacy tokens (e.g. the CloudSync streamer) still replicate every namespace — no regression for server-side callers.Test
Adds
replicate_cross_namespace_denied(tests/embedded_replica/mod.rs): ns1-scoped token replicates ns1 (control), is denied on ns2 (the bug), and a both-namespaces token replicates both (control). Upstream'sreplicate_authonly asserts token-present vs token-absent; this is the missing negative cross-namespace test.Notes
cargo check -p libsql-serverand--testspass clean. The test run needs Linux/CI (libsql-server tests don't link on macOS/arm64).libsql-rs-v0.9.30-releaseis thelibsql-rs-v0.9.30+connection-initialization-patchtag materialized as a branch (PRs can't target tags).