Skip to content

Commit 35c8f6f

Browse files
committed
fix(gateway): gate service discovery on the app listener
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
1 parent e3ed8ba commit 35c8f6f

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
@@ -298,6 +298,10 @@ records as application health or external ingress readiness.
298298

299299
## Workspace service discovery
300300

301+
Both discovery RPCs require `supervisor_app_listener.enabled = true`. When the
302+
listener is disabled, they return `FAILED_PRECONDITION` without collecting routes
303+
or starting a watch.
304+
301305
`GetServiceRouteSnapshot` and `WatchServiceRoutes` expose accepted installations
302306
for one explicit active workspace. They require `sandbox:read` and workspace
303307
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
@@ -2002,6 +2002,10 @@ allow for pool membership failure detection before the last serving lease expire
20022002
Storage errors prevent lease renewal. Discovery expiry and serving expiry are
20032003
separate from external ingress readiness.
20042004

2005+
Both discovery RPCs require `supervisor_app_listener.enabled = true`. When the
2006+
listener is disabled, they return `FAILED_PRECONDITION` without collecting routes
2007+
or starting a watch.
2008+
20052009
Discovery clients can call `GetServiceRouteSnapshot` or `WatchServiceRoutes` with
20062010
one explicit workspace selector, `sandbox:read`, and workspace user access. Each
20072011
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
@@ -1734,6 +1734,8 @@ readiness; ambiguous shared ownership must not publish an address.
17341734

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

0 commit comments

Comments
 (0)