Skip to content

Commit 1aae34e

Browse files
committed
fix(discovery): separate and bound ingress discovery service
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
1 parent 8513511 commit 1aae34e

24 files changed

Lines changed: 1243 additions & 422 deletions

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,6 @@ 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-
}
9883
async fn peer_notify_config_update(
9984
&self,
10085
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,6 @@ 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-
}
5035
async fn peer_notify_config_update(
5136
&self,
5237
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,6 @@ 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-
}
253238
async fn peer_notify_config_update(
254239
&self,
255240
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,

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

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

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

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,7 @@ 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-
}
166+
173167
$(async fn $method(&self, _: Request<$request>) -> Result<Response<$response>, Status> {
174168
Err(Status::unimplemented("unused test RPC"))
175169
})*

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,6 @@ 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-
}
6550
async fn peer_notify_config_update(
6651
&self,
6752
_request: tonic::Request<openshell_core::proto::PeerNotifyConfigUpdateRequest>,

‎crates/openshell-sdk/src/client.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::auth::{BearerSlot, EdgeAuthInterceptor, bearer_metadata};
1212
use crate::config::{AuthConfig, ClientConfig};
1313
use crate::error::{Result, SdkError};
1414
use crate::pagination::{Page, Pager};
15-
use crate::raw::{AuthedGrpcClient, AuthedSandboxUpdatesClient};
15+
use crate::raw::{AuthedGrpcClient, AuthedSandboxUpdatesClient, AuthedServiceDiscoveryClient};
1616
use crate::refresh::{RefreshedToken, TokenSource};
1717
use crate::routing::OwnerCache;
1818
use crate::types::{
@@ -149,6 +149,23 @@ impl OpenShellClient {
149149
Ok(self.raw_sandbox_updates())
150150
}
151151

152+
/// Authenticated client for the separate ingress discovery service.
153+
/// Shares the channel and live auth slot; like [`Self::raw_grpc`], does not
154+
/// refresh or retry credentials by itself.
155+
pub fn raw_service_discovery(&self) -> AuthedServiceDiscoveryClient {
156+
proto::service_discovery_client::ServiceDiscoveryClient::with_interceptor(
157+
self.channel.clone(),
158+
self.interceptor.clone(),
159+
)
160+
}
161+
162+
/// Like [`Self::raw_service_discovery`], refreshing bearer credentials first.
163+
/// Reactive retry remains the raw caller's responsibility.
164+
pub async fn raw_service_discovery_fresh(&self) -> Result<AuthedServiceDiscoveryClient> {
165+
self.ensure_fresh().await?;
166+
Ok(self.raw_service_discovery())
167+
}
168+
152169
/// Force an OIDC refresh and write the new token into the live bearer
153170
/// slot, regardless of expiry. Returns `true` when a refresher is wired
154171
/// and a fresh token was minted, `false` for static auth. Use after a

‎crates/openshell-sdk/src/raw.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
pub use openshell_core::proto;
2222
pub use openshell_core::proto::open_shell_client::OpenShellClient as GrpcClient;
2323
pub use openshell_core::proto::sandbox_updates_client::SandboxUpdatesClient;
24+
pub use openshell_core::proto::service_discovery_client::ServiceDiscoveryClient;
2425
pub use openshell_core::proto::{
2526
CreateSandboxRequest, CreateSandboxTemplateRequest, CreateWorkspaceRequest,
2627
DeleteSandboxRequest, DeleteSandboxTemplateRequest, DeleteWorkspaceRequest, ExecSandboxRequest,
@@ -53,3 +54,11 @@ pub type AuthedSandboxUpdatesClient = SandboxUpdatesClient<
5354
crate::EdgeAuthInterceptor,
5455
>,
5556
>;
57+
58+
/// Application ingress discovery using the SDK transport and live auth slot.
59+
pub type AuthedServiceDiscoveryClient = ServiceDiscoveryClient<
60+
tonic::service::interceptor::InterceptedService<
61+
tonic::transport::Channel,
62+
crate::EdgeAuthInterceptor,
63+
>,
64+
>;

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

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

246246
#[tonic::async_trait]
247247
impl OpenShell for TestOpenShell {
248-
async fn get_service_route_snapshot(
249-
&self,
250-
_: tonic::Request<proto::GetServiceRouteSnapshotRequest>,
251-
) -> Result<Response<proto::GetServiceRouteSnapshotResponse>, Status> {
252-
Err(Status::unimplemented("unused"))
253-
}
254-
type WatchServiceRoutesStream =
255-
tokio_stream::wrappers::ReceiverStream<Result<proto::WatchServiceRoutesResponse, Status>>;
256-
async fn watch_service_routes(
257-
&self,
258-
_: tonic::Request<proto::WatchServiceRoutesRequest>,
259-
) -> Result<Response<Self::WatchServiceRoutesStream>, Status> {
260-
Err(Status::unimplemented("unused"))
261-
}
262248
async fn peer_notify_config_update(
263249
&self,
264250
_request: tonic::Request<proto::PeerNotifyConfigUpdateRequest>,
@@ -1209,6 +1195,35 @@ impl SandboxUpdates for TestOpenShell {
12091195
}
12101196
}
12111197

1198+
#[tonic::async_trait]
1199+
impl proto::service_discovery_server::ServiceDiscovery for TestOpenShell {
1200+
async fn get_service_route_snapshot(
1201+
&self,
1202+
request: tonic::Request<proto::GetServiceRouteSnapshotRequest>,
1203+
) -> Result<Response<proto::GetServiceRouteSnapshotResponse>, Status> {
1204+
if let Some(expected) = &self.state.require_bearer
1205+
&& request
1206+
.metadata()
1207+
.get("authorization")
1208+
.and_then(|v| v.to_str().ok())
1209+
!= Some(expected.as_str())
1210+
{
1211+
return Err(Status::unauthenticated("invalid or missing bearer token"));
1212+
}
1213+
Ok(Response::new(proto::GetServiceRouteSnapshotResponse {
1214+
snapshot: Some(proto::ServiceRouteSnapshot::default()),
1215+
}))
1216+
}
1217+
type WatchServiceRoutesStream =
1218+
tokio_stream::wrappers::ReceiverStream<Result<proto::WatchServiceRoutesResponse, Status>>;
1219+
async fn watch_service_routes(
1220+
&self,
1221+
_: tonic::Request<proto::WatchServiceRoutesRequest>,
1222+
) -> Result<Response<Self::WatchServiceRoutesStream>, Status> {
1223+
Err(Status::unimplemented("unused"))
1224+
}
1225+
}
1226+
12121227
/// Spin up the mock gateway, return its endpoint URL.
12131228
async fn start_mock(state: Arc<MockState>) -> String {
12141229
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
@@ -1218,11 +1233,15 @@ async fn start_mock(state: Arc<MockState>) -> String {
12181233
let updates = SandboxUpdatesServer::new(TestOpenShell {
12191234
state: state.clone(),
12201235
});
1236+
let discovery = proto::service_discovery_server::ServiceDiscoveryServer::new(TestOpenShell {
1237+
state: state.clone(),
1238+
});
12211239
let svc = OpenShellServer::new(TestOpenShell { state });
12221240
tokio::spawn(async move {
12231241
let _ = tonic::transport::Server::builder()
12241242
.add_service(svc)
12251243
.add_service(updates)
1244+
.add_service(discovery)
12261245
.serve_with_incoming(stream)
12271246
.await;
12281247
});
@@ -2471,6 +2490,58 @@ async fn raw_sandbox_updates_shares_transport_and_live_auth_slot() {
24712490
assert_eq!(*state.last_update.lock().await, Some(request));
24722491
}
24732492

2493+
#[tokio::test]
2494+
async fn raw_discovery_shares_transport_and_refreshes_the_live_auth_slot() {
2495+
let state = Arc::new(MockState {
2496+
require_bearer: Some("Bearer fresh-token".into()),
2497+
..Default::default()
2498+
});
2499+
let endpoint = start_mock(state).await;
2500+
let calls = Arc::new(AtomicU32::new(0));
2501+
let mut config = ClientConfig::new(&endpoint);
2502+
config.auth = Some(AuthConfig::Oidc {
2503+
token: "stale-token".into(),
2504+
expires_at: Some(
2505+
std::time::SystemTime::now()
2506+
.duration_since(std::time::UNIX_EPOCH)
2507+
.unwrap()
2508+
.as_secs()
2509+
+ 5,
2510+
),
2511+
refresh: Some(Arc::new(OneShotRefresher {
2512+
calls: calls.clone(),
2513+
})),
2514+
});
2515+
let client = OpenShellClient::connect(config).await.unwrap();
2516+
let mut discovery = client.raw_service_discovery();
2517+
let request = proto::GetServiceRouteSnapshotRequest {
2518+
workspace_scope: Some(proto::workspace_selector("team")),
2519+
};
2520+
assert_eq!(
2521+
discovery
2522+
.get_service_route_snapshot(request.clone())
2523+
.await
2524+
.unwrap_err()
2525+
.code(),
2526+
tonic::Code::Unauthenticated
2527+
);
2528+
assert_eq!(calls.load(Ordering::SeqCst), 0);
2529+
client
2530+
.raw_service_discovery_fresh()
2531+
.await
2532+
.unwrap()
2533+
.get_service_route_snapshot(request.clone())
2534+
.await
2535+
.unwrap();
2536+
assert_eq!(calls.load(Ordering::SeqCst), 1);
2537+
discovery.get_service_route_snapshot(request).await.unwrap();
2538+
client
2539+
.raw_grpc()
2540+
.health(proto::HealthRequest {})
2541+
.await
2542+
.unwrap();
2543+
}
2544+
24742545
#[tokio::test]
24752546
async fn watch_logs_forwards_logs_and_warnings() {
24762547
let state = Arc::new(MockState {

‎crates/openshell-server/README.md‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ Both discovery RPCs require `supervisor_app_listener.enabled = true`. When the
302302
listener is disabled, they return `FAILED_PRECONDITION` without collecting routes
303303
or starting a watch.
304304

305-
`GetServiceRouteSnapshot` and `WatchServiceRoutes` expose accepted installations
305+
`openshell.v1.ServiceDiscovery.GetServiceRouteSnapshot` and `WatchServiceRoutes` expose accepted installations
306306
for one explicit active workspace. They require `sandbox:read` and workspace
307307
user access; omitted/all-workspaces selectors and sandbox principals are rejected.
308308
Dedicated discovery machine grants are separate work.
@@ -315,11 +315,18 @@ snapshot revision includes lease renewals; `installation_version` remains stable
315315
across those renewals and changes when installation identity changes. These
316316
records establish neither application health nor ingress readiness.
317317

318-
Collection checks installation resource versions across two scans, retrying once
319-
if changed. This is a verified view, not a transaction across configuration and
320-
owner resources. Reads are bounded to 1,000 installation records, 4,096 routes,
321-
4 MiB, and ten seconds. Overflow, corruption, or storage failure returns an error.
322-
Watches refresh and reauthorize each second, use a one-message buffer, and end
323-
after one minute or a five-second blocked send. Each gateway process accepts at
324-
most 32 watches. Reconnect and relist on stream termination; revisions are opaque
318+
Collection validates each installation once; lease renewals during a scan do not
319+
invalidate the view. This is not a cross-resource transaction. Reads are bounded
320+
to 1,000 records, 4,096 routes, 4 MiB, and ten seconds. A per-workspace cache shares
321+
one collection for a one-second refresh interval, retains at most 16 workspaces,
322+
and never returns expired routes. At most four collections and 16 unary snapshot
323+
requests run concurrently per gateway. Unary admission permits four requests per
324+
principal and eight per workspace. Overflow returns `RESOURCE_EXHAUSTED`; storage
325+
failure or timeout returns `UNAVAILABLE`; malformed records return `INTERNAL`.
326+
Watches recheck bearer authentication and workspace authorization each second,
327+
use a one-message buffer, and end after one minute or a five-second blocked send.
328+
Each gateway allows 32 watches, at most four per principal and 16 per workspace.
329+
Cache reuse adds at most one refresh interval to collection freshness; consumers
330+
must independently honor the advertised lease expiry.
331+
Reconnect and relist on stream termination; revisions are opaque
325332
equality tokens, not resumable cursors or an ordering across gateway replicas.

0 commit comments

Comments
 (0)