Skip to content

Commit 9a4abc9

Browse files
committed
fix(gateway): gate service discovery on the app listener
Signed-off-by: Taylor Mutch <[email protected]>
1 parent 57eb165 commit 9a4abc9

4 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎crates/openshell-server/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ records as application health or external ingress readiness.
264264

265265
## Workspace service discovery
266266

267+
Both discovery RPCs require `supervisor_app_listener.enabled = true`. When the
268+
listener is disabled, they return `FAILED_PRECONDITION` without collecting routes
269+
or starting a watch.
270+
267271
`GetServiceRouteSnapshot` and `WatchServiceRoutes` expose accepted installations
268272
for one explicit active workspace. They require `sandbox:read` and workspace
269273
user access; omitted/all-workspaces selectors and sandbox principals are rejected.

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,21 @@ async fn authorize(
5757
Ok(())
5858
}
5959

60+
fn require_enabled(state: &ServerState) -> Result<(), Status> {
61+
if !state.config.supervisor_app_listener.enabled {
62+
return Err(Status::failed_precondition(
63+
"service discovery requires the supervisor app listener to be enabled",
64+
));
65+
}
66+
Ok(())
67+
}
68+
6069
pub async fn get_snapshot(
6170
state: &Arc<ServerState>,
6271
request: Request<GetServiceRouteSnapshotRequest>,
6372
) -> Result<Response<GetServiceRouteSnapshotResponse>, Status> {
6473
let principal = super::extract_principal(&request)?;
74+
require_enabled(state)?;
6575
let workspace = selected_workspace_name(request.get_ref().workspace_scope.as_ref())?;
6676
authorize(state, &principal, workspace).await?;
6777
Ok(Response::new(GetServiceRouteSnapshotResponse {
@@ -74,6 +84,7 @@ pub async fn watch(
7484
request: Request<WatchServiceRoutesRequest>,
7585
) -> Result<Response<RouteWatchStream>, Status> {
7686
let principal = super::extract_principal(&request)?;
87+
require_enabled(state)?;
7788
let workspace =
7889
selected_workspace_name(request.get_ref().workspace_scope.as_ref())?.to_string();
7990
authorize(state, &principal, &workspace).await?;
@@ -300,6 +311,38 @@ mod tests {
300311
}
301312
}
302313

314+
#[tokio::test]
315+
async fn disabled_listener_rejects_discovery_without_allocating_a_watch() {
316+
let (mut state, owner, report) = installed_fixture().await;
317+
// Persist a route first: disabling must reject discovery even with stored evidence.
318+
accept(&state, &owner, &report, current_time_ms() + 10_000)
319+
.await
320+
.unwrap();
321+
Arc::get_mut(&mut state)
322+
.unwrap()
323+
.config
324+
.supervisor_app_listener
325+
.enabled = false;
326+
let permits = state.discovery_watches.available_permits();
327+
let error = get_snapshot(&state, authed_request(request()))
328+
.await
329+
.unwrap_err();
330+
assert_eq!(error.code(), tonic::Code::FailedPrecondition);
331+
assert!(error.message().contains("app listener"));
332+
let error = watch(
333+
&state,
334+
authed_request(WatchServiceRoutesRequest {
335+
workspace_scope: request().workspace_scope,
336+
..Default::default()
337+
}),
338+
)
339+
.await
340+
.unwrap_err();
341+
assert_eq!(error.code(), tonic::Code::FailedPrecondition);
342+
assert!(error.message().contains("app listener"));
343+
assert_eq!(state.discovery_watches.available_permits(), permits);
344+
}
345+
303346
#[tokio::test]
304347
async fn snapshot_is_shared_between_gateway_states_and_rejects_expired_or_replaced_owners() {
305348
let (state, owner, report) = installed_fixture().await;

‎docs/how-it-works/gateways/configuration.mdx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,10 @@ allow for pool membership failure detection before the last serving lease expire
19521952
Storage errors prevent lease renewal. Discovery expiry and serving expiry are
19531953
separate from external ingress readiness.
19541954

1955+
Both discovery RPCs require `supervisor_app_listener.enabled = true`. When the
1956+
listener is disabled, they return `FAILED_PRECONDITION` without collecting routes
1957+
or starting a watch.
1958+
19551959
Discovery clients can call `GetServiceRouteSnapshot` or `WatchServiceRoutes` with
19561960
one explicit workspace selector, `sandbox:read`, and workspace user access. Each
19571961
response replaces the workspace route view and includes the hostname, supervisor

‎skills/debug-openshell-cluster/SKILL.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,8 @@ readiness; ambiguous shared ownership must not publish an address.
17031703

17041704
For discovery troubleshooting, request `GetServiceRouteSnapshot` for an explicit
17051705
active workspace using an identity with `sandbox:read` and workspace user access.
1706+
Both discovery RPCs return `FAILED_PRECONDITION` when
1707+
`supervisor_app_listener.enabled` is false; enable the listener before discovering routes.
17061708
`WatchServiceRoutes` rechecks access every second and ends after one minute;
17071709
clients must reconnect/relist. Compare installation versions separately from
17081710
snapshot revisions: lease renewal changes expiry and the snapshot revision while

0 commit comments

Comments
 (0)