Skip to content

Commit d070d6c

Browse files
committed
feat(supervisor): add independent application listener and endpoints
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
1 parent af6604a commit d070d6c

39 files changed

Lines changed: 2659 additions & 182 deletions

File tree

‎.agents/skills/helm-dev-environment/SKILL.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,3 +611,14 @@ for dependencies still declared in `Chart.yaml`.
611611
| `deploy/kube/manifests/envoy-gateway-openshell.yaml` | GatewayClass and BackendTrafficPolicy for Envoy Gateway (`mise run helm:gateway:apply`) |
612612
| `tasks/scripts/helm-k3s-local.sh` | k3d cluster create/delete/start/stop/status |
613613
| `tasks/scripts/keycloak-k8s-setup.sh` | Keycloak deploy, realm import, and development TLS trust anchor |
614+
615+
## App listener fixture
616+
617+
The opt-in `deploy/helm/openshell/ci/values-app-listener.yaml` enables the
618+
supervisor listener at port 9443 without discovery or a proxy. Provision the
619+
operator TLS Secret and an ingress-client NetworkPolicy first. Follow
620+
`e2e/kubernetes/app-listener/README.md` for direct in-cluster verification,
621+
shared-member selection, and the HA follow-up checks. Keep the fixture disabled
622+
in default profiles. Shared supervisors expose app ports on their Pod IPs
623+
without a shared app Service. Select the member owning the sandbox; automatic
624+
owner selection belongs to the later discovery API.

‎Cargo.lock‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Driver-independent application listener configuration.
5+
6+
use serde::{Deserialize, Serialize};
7+
8+
/// Explicitly enabled application ingress. Deployment details such as TLS
9+
/// Secret names belong to the driver, not to this common configuration.
10+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
11+
#[serde(default, deny_unknown_fields)]
12+
pub struct AppListenerConfig {
13+
pub enabled: bool,
14+
pub port: u16,
15+
pub domain: String,
16+
}
17+
18+
impl Default for AppListenerConfig {
19+
fn default() -> Self {
20+
Self {
21+
enabled: false,
22+
port: 8443,
23+
domain: String::new(),
24+
}
25+
}
26+
}
27+
28+
impl AppListenerConfig {
29+
pub fn validate(&self) -> Result<(), String> {
30+
if !self.enabled {
31+
return Ok(());
32+
}
33+
if self.port < 1024 {
34+
return Err("supervisor.app_listener.port must be at least 1024".into());
35+
}
36+
if self.domain.len() > 253
37+
|| !self.domain.split('.').all(|label| {
38+
!label.is_empty()
39+
&& label.len() <= 63
40+
&& !label.starts_with('-')
41+
&& !label.ends_with('-')
42+
&& label
43+
.bytes()
44+
.all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'-')
45+
})
46+
{
47+
return Err("supervisor.app_listener.domain must be a lowercase DNS name".into());
48+
}
49+
Ok(())
50+
}
51+
}
52+
53+
#[cfg(test)]
54+
mod tests {
55+
use super::*;
56+
57+
#[test]
58+
fn only_explicit_enablement_requires_a_valid_endpoint() {
59+
assert!(!AppListenerConfig::default().enabled);
60+
assert!(AppListenerConfig::default().validate().is_ok());
61+
let mut config = AppListenerConfig {
62+
enabled: true,
63+
..Default::default()
64+
};
65+
assert!(config.validate().is_err());
66+
config.domain = "services.example.com".into();
67+
assert!(config.validate().is_ok());
68+
config.port = 0;
69+
assert!(config.validate().is_err());
70+
}
71+
}

‎crates/openshell-core/src/config.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ pub struct Config {
332332

333333
/// Browser-facing sandbox service routing configuration.
334334
pub service_routing: ServiceRoutingConfig,
335+
pub supervisor_app_listener: crate::app_listener::AppListenerConfig,
335336
}
336337

337338
/// Browser-facing sandbox service routing configuration.
@@ -1015,6 +1016,7 @@ impl Config {
10151016
grpc_rate_limit_requests: None,
10161017
grpc_rate_limit_window_secs: None,
10171018
service_routing: ServiceRoutingConfig::default(),
1019+
supervisor_app_listener: crate::app_listener::AppListenerConfig::default(),
10181020
}
10191021
}
10201022

‎crates/openshell-core/src/grpc_client.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,7 @@ pub struct CachedOpenShellClient {
18631863
/// Settings poll result returned by [`CachedOpenShellClient::poll_settings`].
18641864
#[derive(Clone, Debug)]
18651865
pub struct SettingsPollResult {
1866+
pub service_routes: Vec<crate::proto::SandboxServiceRoute>,
18661867
pub configuration_instance_id: String,
18671868
pub configuration_admitted: bool,
18681869
pub configuration_error: String,
@@ -1890,6 +1891,7 @@ pub struct SettingsPollResult {
18901891

18911892
fn settings_poll_result(inner: crate::proto::GetSandboxConfigResponse) -> SettingsPollResult {
18921893
SettingsPollResult {
1894+
service_routes: inner.service_routes,
18931895
configuration_instance_id: inner.configuration_instance_id,
18941896
configuration_admitted: inner.configuration_admitted,
18951897
configuration_error: inner.configuration_error,
@@ -1919,6 +1921,7 @@ fn settings_poll_result(inner: crate::proto::GetSandboxConfigResponse) -> Settin
19191921
impl From<crate::proto::SandboxConfigSnapshot> for SettingsPollResult {
19201922
fn from(snapshot: crate::proto::SandboxConfigSnapshot) -> Self {
19211923
settings_poll_result(crate::proto::GetSandboxConfigResponse {
1924+
service_routes: snapshot.service_routes,
19221925
policy: snapshot.policy,
19231926
version: snapshot.version,
19241927
policy_hash: snapshot.policy_hash,

‎crates/openshell-core/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! - Build version metadata
1111
1212
pub mod activity;
13+
pub mod app_listener;
1314
pub mod auth;
1415
pub mod config;
1516
pub mod container_paths;
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Reachable supervisor app endpoints. External ingress routes are owned by
5+
//! ingress integrations, not by this compute driver.
6+
7+
use crate::config::KubernetesAppListenerConfig;
8+
use k8s_openapi::api::core::v1::{
9+
ContainerPort, EnvVar, Pod, SecretVolumeSource, Volume, VolumeMount,
10+
};
11+
12+
const TLS_PATH: &str = "/etc/openshell/app-tls";
13+
14+
pub fn configure_supervisor_pod(mut pod: Pod, config: &KubernetesAppListenerConfig) -> Pod {
15+
if !config.common.enabled {
16+
return pod;
17+
}
18+
let spec = pod.spec.as_mut().expect("supervisor Pod spec");
19+
let container = spec
20+
.containers
21+
.iter_mut()
22+
.find(|c| c.name == "supervisor")
23+
.expect("supervisor container");
24+
let env = container.env.get_or_insert_default();
25+
for (name, value) in [
26+
("OPENSHELL_APP_LISTENER_ENABLED", "true".to_string()),
27+
(
28+
"OPENSHELL_APP_LISTEN_ADDRESS",
29+
format!("0.0.0.0:{}", config.common.port),
30+
),
31+
("OPENSHELL_APP_SERVICE_DOMAIN", config.common.domain.clone()),
32+
("OPENSHELL_APP_TLS_CERT", format!("{TLS_PATH}/tls.crt")),
33+
("OPENSHELL_APP_TLS_KEY", format!("{TLS_PATH}/tls.key")),
34+
] {
35+
env.push(EnvVar {
36+
name: name.into(),
37+
value: Some(value),
38+
..Default::default()
39+
});
40+
}
41+
container.ports.get_or_insert_default().push(ContainerPort {
42+
name: Some("app".into()),
43+
container_port: i32::from(config.common.port),
44+
protocol: Some("TCP".into()),
45+
..Default::default()
46+
});
47+
container
48+
.volume_mounts
49+
.get_or_insert_default()
50+
.push(VolumeMount {
51+
name: "app-tls".into(),
52+
mount_path: TLS_PATH.into(),
53+
read_only: Some(true),
54+
..Default::default()
55+
});
56+
spec.volumes.get_or_insert_default().push(Volume {
57+
name: "app-tls".into(),
58+
secret: Some(SecretVolumeSource {
59+
secret_name: Some(config.tls_secret_name.clone()),
60+
..Default::default()
61+
}),
62+
..Default::default()
63+
});
64+
pod
65+
}
66+
67+
#[cfg(test)]
68+
mod tests {
69+
use super::*;
70+
71+
#[test]
72+
fn disabled_listener_does_not_add_ports_or_private_key_mounts() {
73+
let pod = Pod {
74+
spec: Some(k8s_openapi::api::core::v1::PodSpec {
75+
containers: vec![k8s_openapi::api::core::v1::Container {
76+
name: "supervisor".into(),
77+
..Default::default()
78+
}],
79+
..Default::default()
80+
}),
81+
..Default::default()
82+
};
83+
let config = KubernetesAppListenerConfig {
84+
tls_secret_name: "app-tls".into(),
85+
..Default::default()
86+
};
87+
assert_eq!(configure_supervisor_pod(pod.clone(), &config), pod);
88+
}
89+
}

‎crates/openshell-driver-kubernetes/src/config.rs‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ impl FromStr for KubernetesControlConnection {
118118
#[derive(Debug, Clone, Serialize, Deserialize)]
119119
#[serde(default, deny_unknown_fields)]
120120
pub struct KubernetesSandboxRuntimeConfig {
121+
pub app_listener: KubernetesAppListenerConfig,
121122
/// TCP port of the Sandbox Protocol listener: the workload boundary for
122123
/// supervisor-initiated sandboxes, the supervisor for runtime-initiated ones.
123124
pub boundary_port: u16,
@@ -127,12 +128,32 @@ impl Default for KubernetesSandboxRuntimeConfig {
127128
fn default() -> Self {
128129
Self {
129130
boundary_port: 5500,
131+
app_listener: KubernetesAppListenerConfig::default(),
130132
}
131133
}
132134
}
133135

136+
/// Driver-owned TLS deployment inputs. Common listener settings
137+
/// are injected by the gateway so there is only one port/domain source.
138+
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
139+
#[serde(default, deny_unknown_fields)]
140+
pub struct KubernetesAppListenerConfig {
141+
pub tls_secret_name: String,
142+
#[serde(skip)]
143+
pub common: openshell_core::app_listener::AppListenerConfig,
144+
}
145+
134146
impl KubernetesSandboxRuntimeConfig {
135147
pub fn validate(&self) -> Result<(), String> {
148+
self.app_listener.common.validate()?;
149+
if self.app_listener.common.enabled {
150+
if !is_dns_subdomain(&self.app_listener.tls_secret_name) {
151+
return Err("sandbox_runtime.app_listener.tls_secret_name is required when the app listener is enabled".into());
152+
}
153+
if [self.boundary_port, 5501].contains(&self.app_listener.common.port) {
154+
return Err("supervisor.app_listener.port conflicts with a supervisor runtime or health port".into());
155+
}
156+
}
136157
if self.boundary_port < 1024 {
137158
return Err("sandbox_runtime.boundary_port must be at least 1024".to_string());
138159
}
@@ -557,6 +578,11 @@ impl KubernetesComputeConfig {
557578
"supervisor_topology=gateway requires shared_supervisor".to_string()
558579
})?;
559580
shared.validate()?;
581+
if self.sandbox_runtime.app_listener.common.enabled
582+
&& self.sandbox_runtime.app_listener.common.port == shared.runtime_port
583+
{
584+
return Err("supervisor.app_listener.port conflicts with shared_supervisor.runtime_port".into());
585+
}
560586
if self.provider_spiffe_enabled() {
561587
return Err("supervisor_topology=gateway does not support provider_spiffe_workload_api_socket_path; a shared supervisor has no per-sandbox workload identity".into());
562588
}
@@ -1118,6 +1144,25 @@ mod tests {
11181144
use super::*;
11191145
use std::collections::BTreeMap as HashMap;
11201146

1147+
#[test]
1148+
fn app_endpoint_configuration_has_one_port_source_and_explicit_enablement() {
1149+
let mut config = KubernetesSandboxRuntimeConfig::default();
1150+
config.app_listener.tls_secret_name = "app-tls".into();
1151+
assert!(!config.app_listener.common.enabled);
1152+
assert!(config.validate().is_ok());
1153+
config.app_listener.common = openshell_core::app_listener::AppListenerConfig {
1154+
enabled: true,
1155+
port: 9443,
1156+
domain: "services.example.com".into(),
1157+
};
1158+
assert!(config.validate().is_ok());
1159+
config.app_listener.common.port = config.boundary_port;
1160+
assert!(config.validate().is_err());
1161+
config.app_listener.common.port = 9443;
1162+
config.app_listener.tls_secret_name.clear();
1163+
assert!(config.validate().is_err());
1164+
}
1165+
11211166
#[test]
11221167
fn gateway_supervisor_topology_requires_its_connection_and_refuses_unsupported_inputs() {
11231168
let shared = || SharedSupervisorConfig {

0 commit comments

Comments
 (0)