Skip to content

Commit aedf7e7

Browse files
committed
check auth for proxied replication requests
1 parent a7b546f commit aedf7e7

2 files changed

Lines changed: 31 additions & 18 deletions

File tree

libsql-server/src/lib.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ pub(crate) static BLOCKING_RT: Lazy<Runtime> = Lazy::new(|| {
129129
type Result<T, E = Error> = std::result::Result<T, E>;
130130
type StatsSender = mpsc::Sender<(NamespaceName, MetaStoreHandle, Weak<Stats>)>;
131131
type MakeReplicationSvc = Box<
132-
dyn FnOnce(
132+
dyn Fn(
133133
NamespaceStore,
134134
Option<Auth>,
135135
Option<IdleShutdownKicker>,
136136
bool,
137+
bool,
137138
) -> BoxReplicationService
138139
+ Send
139140
+ 'static,
@@ -620,17 +621,18 @@ where
620621

621622
let replication_service = make_replication_svc(
622623
namespace_store.clone(),
623-
None,
624+
Some(user_auth_strategy.clone()),
624625
idle_shutdown_kicker.clone(),
625626
false,
627+
true,
626628
);
627629

628630
task_manager.spawn_until_shutdown(run_rpc_server(
629631
proxy_service,
630632
config.acceptor,
631633
config.tls_config,
632634
idle_shutdown_kicker.clone(),
633-
replication_service,
635+
replication_service, // internal replicaton service
634636
));
635637
}
636638

@@ -658,12 +660,12 @@ where
658660
.await?;
659661
}
660662

661-
let replication_svc = ReplicationLogService::new(
663+
let replication_svc = make_replication_svc(
662664
namespace_store.clone(),
663-
idle_shutdown_kicker.clone(),
664665
Some(user_auth_strategy.clone()),
665-
self.disable_namespaces,
666+
idle_shutdown_kicker.clone(),
666667
true,
668+
false, // external replication service
667669
);
668670

669671
let proxy_svc = ProxyService::new(
@@ -936,9 +938,9 @@ where
936938
let make_replication_svc = Box::new({
937939
let registry = registry.clone();
938940
let disable_namespaces = self.disable_namespaces;
939-
move |store, user_auth, _, _| -> BoxReplicationService {
941+
move |store, user_auth, _, _, _| -> BoxReplicationService {
940942
Box::new(LibsqlReplicationService::new(
941-
registry,
943+
registry.clone(),
942944
store,
943945
user_auth,
944946
disable_namespaces,
@@ -1023,13 +1025,14 @@ where
10231025

10241026
let make_replication_svc = Box::new({
10251027
let disable_namespaces = self.disable_namespaces;
1026-
move |store, client_auth, idle_shutdown, collect_stats| -> BoxReplicationService {
1028+
move |store, client_auth, idle_shutdown, collect_stats, is_internal| -> BoxReplicationService {
10271029
Box::new(ReplicationLogService::new(
10281030
store,
10291031
idle_shutdown,
10301032
client_auth,
10311033
disable_namespaces,
10321034
collect_stats,
1035+
is_internal,
10331036
))
10341037
}
10351038
});
@@ -1055,13 +1058,14 @@ where
10551058

10561059
let make_replication_svc = Box::new({
10571060
let disable_namespaces = self.disable_namespaces;
1058-
move |store, client_auth, idle_shutdown, collect_stats| -> BoxReplicationService {
1061+
move |store, client_auth, idle_shutdown, collect_stats, is_internal| -> BoxReplicationService {
10591062
Box::new(ReplicationLogService::new(
10601063
store,
10611064
idle_shutdown,
10621065
client_auth,
10631066
disable_namespaces,
10641067
collect_stats,
1068+
is_internal,
10651069
))
10661070
}
10671071
});

libsql-server/src/rpc/replication/replication_log.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub struct ReplicationLogService {
3737
disable_namespaces: bool,
3838
session_token: Bytes,
3939
collect_stats: bool,
40+
// whether this is an internal service. If it is an internal service, auth is checked for
41+
// proxied requests
42+
service_internal: bool,
4043

4144
//deprecated:
4245
generation_id: Uuid,
@@ -52,6 +55,7 @@ impl ReplicationLogService {
5255
user_auth_strategy: Option<Auth>,
5356
disable_namespaces: bool,
5457
collect_stats: bool,
58+
service_internal: bool,
5559
) -> Self {
5660
let session_token = Uuid::new_v4().to_string().into();
5761
Self {
@@ -63,6 +67,7 @@ impl ReplicationLogService {
6367
collect_stats,
6468
generation_id: Uuid::new_v4(),
6569
replicas_with_hello: Default::default(),
70+
service_internal,
6671
}
6772
}
6873

@@ -71,14 +76,18 @@ impl ReplicationLogService {
7176
req: &tonic::Request<T>,
7277
namespace: NamespaceName,
7378
) -> Result<(), Status> {
74-
super::auth::authenticate(
75-
&self.namespaces,
76-
req,
77-
namespace,
78-
&self.user_auth_strategy,
79-
true,
80-
)
81-
.await
79+
if self.service_internal && req.metadata().get("libsql-proxied").is_some() || !self.service_internal {
80+
super::auth::authenticate(
81+
&self.namespaces,
82+
req,
83+
namespace,
84+
&self.user_auth_strategy,
85+
true,
86+
)
87+
.await
88+
} else {
89+
Ok(())
90+
}
8291
}
8392

8493
fn verify_session_token<R>(

0 commit comments

Comments
 (0)