Skip to content

Commit c724036

Browse files
committed
feat(gateway): expose workspace service route discovery
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
1 parent 04a0ed7 commit c724036

20 files changed

Lines changed: 1781 additions & 424 deletions

‎crates/openshell-cli/tests/ensure_providers_integration.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ impl TestOpenShell {
8080

8181
#[tonic::async_trait]
8282
impl OpenShell for TestOpenShell {
83+
async fn get_service_route_snapshot(
84+
&self,
85+
_: tonic::Request<openshell_core::proto::GetServiceRouteSnapshotRequest>,
86+
) -> Result<Response<openshell_core::proto::GetServiceRouteSnapshotResponse>, Status> {
87+
Err(Status::unimplemented("unused"))
88+
}
89+
type WatchServiceRoutesStream = tokio_stream::wrappers::ReceiverStream<
90+
Result<openshell_core::proto::WatchServiceRoutesResponse, Status>,
91+
>;
92+
async fn watch_service_routes(
93+
&self,
94+
_: tonic::Request<openshell_core::proto::WatchServiceRoutesRequest>,
95+
) -> Result<Response<Self::WatchServiceRoutesStream>, Status> {
96+
Err(Status::unimplemented("unused"))
97+
}
8398
async fn peer_notify_config_update(
8499
&self,
85100
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,

‎crates/openshell-cli/tests/mtls_integration.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ struct TestOpenShell;
3232

3333
#[tonic::async_trait]
3434
impl OpenShell for TestOpenShell {
35+
async fn get_service_route_snapshot(
36+
&self,
37+
_: tonic::Request<openshell_core::proto::GetServiceRouteSnapshotRequest>,
38+
) -> Result<Response<openshell_core::proto::GetServiceRouteSnapshotResponse>, Status> {
39+
Err(Status::unimplemented("unused"))
40+
}
41+
type WatchServiceRoutesStream = tokio_stream::wrappers::ReceiverStream<
42+
Result<openshell_core::proto::WatchServiceRoutesResponse, Status>,
43+
>;
44+
async fn watch_service_routes(
45+
&self,
46+
_: tonic::Request<openshell_core::proto::WatchServiceRoutesRequest>,
47+
) -> Result<Response<Self::WatchServiceRoutesStream>, Status> {
48+
Err(Status::unimplemented("unused"))
49+
}
3550
async fn peer_notify_config_update(
3651
&self,
3752
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,

‎crates/openshell-cli/tests/provider_commands_integration.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@ impl TestOpenShell {
235235

236236
#[tonic::async_trait]
237237
impl OpenShell for TestOpenShell {
238+
async fn get_service_route_snapshot(
239+
&self,
240+
_: tonic::Request<openshell_core::proto::GetServiceRouteSnapshotRequest>,
241+
) -> Result<Response<openshell_core::proto::GetServiceRouteSnapshotResponse>, Status> {
242+
Err(Status::unimplemented("unused"))
243+
}
244+
type WatchServiceRoutesStream = tokio_stream::wrappers::ReceiverStream<
245+
Result<openshell_core::proto::WatchServiceRoutesResponse, Status>,
246+
>;
247+
async fn watch_service_routes(
248+
&self,
249+
_: tonic::Request<openshell_core::proto::WatchServiceRoutesRequest>,
250+
) -> Result<Response<Self::WatchServiceRoutesStream>, Status> {
251+
Err(Status::unimplemented("unused"))
252+
}
238253
async fn peer_notify_config_update(
239254
&self,
240255
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,

‎crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ struct TestOpenShell {
101101

102102
#[tonic::async_trait]
103103
impl OpenShell for TestOpenShell {
104+
async fn get_service_route_snapshot(
105+
&self,
106+
_: tonic::Request<openshell_core::proto::GetServiceRouteSnapshotRequest>,
107+
) -> Result<Response<openshell_core::proto::GetServiceRouteSnapshotResponse>, Status> {
108+
Err(Status::unimplemented("unused"))
109+
}
110+
type WatchServiceRoutesStream = tokio_stream::wrappers::ReceiverStream<
111+
Result<openshell_core::proto::WatchServiceRoutesResponse, Status>,
112+
>;
113+
async fn watch_service_routes(
114+
&self,
115+
_: tonic::Request<openshell_core::proto::WatchServiceRoutesRequest>,
116+
) -> Result<Response<Self::WatchServiceRoutesStream>, Status> {
117+
Err(Status::unimplemented("unused"))
118+
}
104119
async fn peer_notify_config_update(
105120
&self,
106121
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,

‎crates/openshell-cli/tests/sandbox_exec_streaming_integration.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ macro_rules! mock_gateway {
163163
) => {
164164
#[tonic::async_trait]
165165
impl OpenShell for MockGateway {
166+
async fn get_service_route_snapshot(&self, _: Request<openshell_core::proto::GetServiceRouteSnapshotRequest>) -> Result<Response<openshell_core::proto::GetServiceRouteSnapshotResponse>, Status> {
167+
Err(Status::unimplemented("unused"))
168+
}
169+
type WatchServiceRoutesStream = tokio_stream::wrappers::ReceiverStream<Result<openshell_core::proto::WatchServiceRoutesResponse, Status>>;
170+
async fn watch_service_routes(&self, _: Request<openshell_core::proto::WatchServiceRoutesRequest>) -> Result<Response<Self::WatchServiceRoutesStream>, Status> {
171+
Err(Status::unimplemented("unused"))
172+
}
166173
$(async fn $method(&self, _: Request<$request>) -> Result<Response<$response>, Status> {
167174
Err(Status::unimplemented("unused test RPC"))
168175
})*

‎crates/openshell-cli/tests/sandbox_name_fallback_integration.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ struct TestOpenShell {
4747

4848
#[tonic::async_trait]
4949
impl OpenShell for TestOpenShell {
50+
async fn get_service_route_snapshot(
51+
&self,
52+
_: tonic::Request<openshell_core::proto::GetServiceRouteSnapshotRequest>,
53+
) -> Result<Response<openshell_core::proto::GetServiceRouteSnapshotResponse>, Status> {
54+
Err(Status::unimplemented("unused"))
55+
}
56+
type WatchServiceRoutesStream = tokio_stream::wrappers::ReceiverStream<
57+
Result<openshell_core::proto::WatchServiceRoutesResponse, Status>,
58+
>;
59+
async fn watch_service_routes(
60+
&self,
61+
_: tonic::Request<openshell_core::proto::WatchServiceRoutesRequest>,
62+
) -> Result<Response<Self::WatchServiceRoutesStream>, Status> {
63+
Err(Status::unimplemented("unused"))
64+
}
5065
async fn peer_notify_config_update(
5166
&self,
5267
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,

‎crates/openshell-sdk/tests/client_mock.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,20 @@ fn workload_template_proto(name: &str, workspace: &str) -> proto::SandboxWorkloa
234234

235235
#[tonic::async_trait]
236236
impl OpenShell for TestOpenShell {
237+
async fn get_service_route_snapshot(
238+
&self,
239+
_: tonic::Request<proto::GetServiceRouteSnapshotRequest>,
240+
) -> Result<Response<proto::GetServiceRouteSnapshotResponse>, Status> {
241+
Err(Status::unimplemented("unused"))
242+
}
243+
type WatchServiceRoutesStream =
244+
tokio_stream::wrappers::ReceiverStream<Result<proto::WatchServiceRoutesResponse, Status>>;
245+
async fn watch_service_routes(
246+
&self,
247+
_: tonic::Request<proto::WatchServiceRoutesRequest>,
248+
) -> Result<Response<Self::WatchServiceRoutesStream>, Status> {
249+
Err(Status::unimplemented("unused"))
250+
}
237251
async fn peer_notify_config_update(
238252
&self,
239253
_request: tonic::Request<proto::PeerNotifyConfigUpdateRequest>,

‎crates/openshell-server/README.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,27 @@ change durable sandbox protobufs. Reads revalidate owner, configuration,
9797
generation, and expiry. Cleanup scans bounded pages and uses conditional deletes
9898
so concurrent renewals are preserved. Discovery consumers must not treat these
9999
records as application health or external ingress readiness.
100+
101+
## Workspace service discovery
102+
103+
`GetServiceRouteSnapshot` and `WatchServiceRoutes` expose accepted installations
104+
for one explicit active workspace. They require `sandbox:read` and workspace
105+
user access; omitted/all-workspaces selectors and sandbox principals are rejected.
106+
Dedicated discovery machine grants are separate work.
107+
108+
Each successful response replaces the complete view. Consumers preserve the
109+
returned hostname as TLS SNI and HTTP authority when dialing the supervisor
110+
endpoint, remove absent routes, and expire cached entries at `expires_at` even
111+
when discovery is unavailable. An error is not an empty replacement. The opaque
112+
snapshot revision includes lease renewals; `installation_version` remains stable
113+
across those renewals and changes when installation identity changes. These
114+
records establish neither application health nor ingress readiness.
115+
116+
Collection checks installation resource versions across two scans, retrying once
117+
if changed. This is a verified view, not a transaction across configuration and
118+
owner resources. Reads are bounded to 1,000 installation records, 4,096 routes,
119+
4 MiB, and ten seconds. Overflow, corruption, or storage failure returns an error.
120+
Watches refresh and reauthorize each second, use a one-message buffer, and end
121+
after one minute or a five-second blocked send. Each gateway process accepts at
122+
most 32 watches. Reconnect and relist on stream termination; revisions are opaque
123+
equality tokens, not resumable cursors or an ordering across gateway replicas.

‎crates/openshell-server/src/grpc/mod.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod supervisor_host;
1414
pub use sandbox::mint_persisted_authentication;
1515
mod service;
1616
pub mod service_advertisement;
17+
mod service_discovery;
1718
mod validation;
1819
pub mod workspace;
1920

@@ -497,6 +498,22 @@ impl OpenShell for OpenShellService {
497498
service::handle_list_services(&self.state, request).await
498499
}
499500

501+
async fn get_service_route_snapshot(
502+
&self,
503+
request: Request<openshell_core::proto::GetServiceRouteSnapshotRequest>,
504+
) -> Result<Response<openshell_core::proto::GetServiceRouteSnapshotResponse>, Status> {
505+
service_discovery::get_snapshot(&self.state, request).await
506+
}
507+
508+
type WatchServiceRoutesStream = service_discovery::RouteWatchStream;
509+
510+
async fn watch_service_routes(
511+
&self,
512+
request: Request<openshell_core::proto::WatchServiceRoutesRequest>,
513+
) -> Result<Response<Self::WatchServiceRoutesStream>, Status> {
514+
service_discovery::watch(&self.state, request).await
515+
}
516+
500517
async fn delete_service(
501518
&self,
502519
request: Request<DeleteServiceRequest>,

‎crates/openshell-server/src/grpc/service_advertisement.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ pub fn spawn_cleanup(state: Arc<ServerState>, mut shutdown: tokio::sync::watch::
391391
}
392392

393393
#[cfg(test)]
394-
mod tests {
394+
pub mod tests {
395395
use super::*;
396396

397397
fn route() -> SandboxServiceRoute {
@@ -530,6 +530,7 @@ mod tests {
530530
port: 9443,
531531
domain: "services.example.com".into(),
532532
};
533+
Arc::get_mut(&mut state).unwrap().admin_role = "openshell-admin".into();
533534
let sandbox = Sandbox {
534535
metadata: Some(ObjectMeta {
535536
id: "sandbox".into(),

0 commit comments

Comments
 (0)