Skip to content

Commit

Permalink
Handle non-existent namespace in authenticate_grpc
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Jastrzebski <[email protected]>
  • Loading branch information
haaawk committed Jan 11, 2024
1 parent b692016 commit 6ef845e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions libsql-server/src/rpc/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ impl ProxyService {
let namespace_jwt_key = self.namespaces.with(namespace, |ns| ns.jwt_key()).await;
let namespace_jwt_key = match namespace_jwt_key {
Ok(Ok(jwt_key)) => Ok(jwt_key),
Err(crate::error::Error::NamespaceDoesntExist(_)) => Ok(None),
Err(e) => Err(tonic::Status::internal(format!(
"Error fetching jwt key for a namespace: {}",
e
Expand Down
5 changes: 5 additions & 0 deletions libsql-server/src/rpc/replica_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ impl ReplicaProxyService {
authenticated.upgrade_grpc_request(req);
Ok(())
}
Err(crate::error::Error::NamespaceDoesntExist(_)) => {
let authenticated = self.auth.authenticate_grpc(req, false, None)?;
authenticated.upgrade_grpc_request(req);
Ok(())
}
Err(e) => Err(Status::internal(format!(
"Error fetching jwt key for a namespace: {}",
e
Expand Down
16 changes: 12 additions & 4 deletions libsql-server/src/rpc/replication_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,18 @@ impl ReplicationLogService {
}
Ok(())
}
Err(e) => Err(Status::internal(format!(
"Error fetching jwt key for a namespace: {}",
e
))),
Err(e) => match e.as_ref() {
crate::error::Error::NamespaceDoesntExist(_) => {
if let Some(auth) = &self.auth {
auth.authenticate_grpc(req, self.disable_namespaces, None)?;
}
Ok(())
}
_ => Err(Status::internal(format!(
"Error fetching jwt key for a namespace: {}",
e
))),
},
Ok(Err(e)) => Err(Status::internal(format!(
"Error fetching jwt key for a namespace: {}",
e
Expand Down

0 comments on commit 6ef845e

Please sign in to comment.