Skip to content

Commit 5e27d44

Browse files
committed
feat(kubernetes): support upstream proxies with shared supervisors
Carry operator proxy settings, credentials, and CA trust in each sandbox generation. Stage the material privately on the assigned supervisor and grant reads of the configured proxy Secret. Refs: #5879 Signed-off-by: Shiju <shiju@nvidia.com>
1 parent 38c4741 commit 5e27d44

20 files changed

Lines changed: 667 additions & 59 deletions

File tree

‎crates/openshell-driver-kubernetes/README.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,22 @@ fails closed.
266266
Shared supervisors receive final access tokens through their authenticated
267267
sessions. No SPIFFE socket is mounted in a shared supervisor or workload Pod.
268268

269-
The topology does not support upstream proxies.
269+
- **Upstream proxy.** The gateway snapshots the operator's proxy settings,
270+
credential Secret from the sandbox namespace, and CA bundle in the
271+
generation's private launch record. Pool members stage the material in the
272+
instance's private directory and use the same CONNECT path as dedicated
273+
supervisors. Recovery and handoff reuse the record. Restart the sandbox
274+
generation to pick up proxy changes. Upgrade the gateway and every pool
275+
member before enabling these settings. The Helm chart grants the gateway
276+
`get` on the configured credential Secret name in the sandbox namespace.
277+
270278
With a live replacement supervisor and a takeover-capable runtime, the gateway
271279
can move a paused sandbox generation to the replacement using a signed takeover
272280
grant. Recovery preserves workload processes and memory, but proxied connections
273281
and interactive sessions must reconnect. If recovery exceeds the configured
274282
deadline, the runtime terminates the workload. It cannot recover a lost workload
275283
Pod or node. See [supervisor recovery](../../docs/kubernetes/high-availability.mdx#recover-from-a-supervisor-failure).
284+
276285
Shared sandbox instances export no supervisor OTLP traces or OCSF events and do
277286
not relay agent traces; the driver warns at startup when the gateway configures
278287
any of them.

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,6 @@ impl KubernetesComputeConfig {
586586
Ok(())
587587
}
588588

589-
/// The shared supervisor serves only sandbox instances it can isolate: it
590-
/// holds no per-sandbox workload identity, upstream proxy credential, or
591-
/// proxy CA.
592589
pub fn validate_supervisor_topology(&self) -> Result<(), String> {
593590
match self.supervisor_topology {
594591
None => {
@@ -610,15 +607,6 @@ impl KubernetesComputeConfig {
610607
{
611608
return Err("supervisor.app_listener.port conflicts with shared_supervisor.runtime_port".into());
612609
}
613-
if self.https_proxy.is_some()
614-
|| self.proxy_auth_secret_name.is_some()
615-
|| self.proxy_ca_bundle.is_some()
616-
{
617-
return Err(
618-
"supervisor_topology=gateway does not support upstream proxy settings"
619-
.into(),
620-
);
621-
}
622610
Ok(())
623611
}
624612
}
@@ -1232,17 +1220,27 @@ mod tests {
12321220
.is_err()
12331221
);
12341222
}
1235-
// A shared supervisor holds no per-sandbox workload identity or proxy credential.
12361223
let with_proxy = KubernetesComputeConfig {
12371224
https_proxy: Some("http://proxy.example:3128".to_string()),
12381225
..gateway(Some(shared()))
12391226
};
1240-
assert!(with_proxy.validate_supervisor_topology().is_err());
1227+
assert!(with_proxy.validate_supervisor_topology().is_ok());
1228+
assert!(with_proxy.validate_upstream_proxy_config().is_ok());
1229+
let with_credentials = KubernetesComputeConfig {
1230+
proxy_auth_secret_name: Some("egress-auth".to_string()),
1231+
proxy_auth_secret_key: Some("credentials".to_string()),
1232+
proxy_auth_allow_insecure: Some(true),
1233+
..with_proxy
1234+
};
1235+
assert!(with_credentials.validate_supervisor_topology().is_ok());
1236+
assert!(with_credentials.validate_upstream_proxy_config().is_ok());
12411237
let with_proxy_ca = KubernetesComputeConfig {
1238+
https_proxy: Some("https://proxy.example:3130".to_string()),
12421239
proxy_ca_bundle: Some("/etc/proxy/ca.pem".to_string()),
12431240
..gateway(Some(shared()))
12441241
};
1245-
assert!(with_proxy_ca.validate_supervisor_topology().is_err());
1242+
assert!(with_proxy_ca.validate_supervisor_topology().is_ok());
1243+
assert!(with_proxy_ca.validate_upstream_proxy_config().is_ok());
12461244
let workspace = KubernetesComputeConfig {
12471245
supervisor_topology: Some(SupervisorTopology::Workspace),
12481246
..KubernetesComputeConfig::default()

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

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,6 +3518,65 @@ impl KubernetesComputeDriver {
35183518
})
35193519
}
35203520

3521+
/// Snapshot proxy credentials from the workload namespace into the same
3522+
/// private generation record as its route and trust, including on takeover.
3523+
async fn shared_upstream_proxy_launch(
3524+
&self,
3525+
namespace: &str,
3526+
ca_bundle: Option<Vec<u8>>,
3527+
) -> Result<Option<openshell_supervisor_control::UpstreamProxyLaunch>, KubernetesDriverError>
3528+
{
3529+
let Some(url) = &self.config.https_proxy else {
3530+
return Ok(None);
3531+
};
3532+
let credential = match (
3533+
self.config.proxy_auth_secret_name.as_deref(),
3534+
self.config.proxy_auth_secret_key.as_deref(),
3535+
) {
3536+
(None, None) => None,
3537+
(Some(name), Some(key)) => {
3538+
let secret = Api::<Secret>::namespaced(self.client.clone(), namespace)
3539+
.get(name)
3540+
.await
3541+
.map_err(KubernetesDriverError::from_kube)?;
3542+
let value = secret
3543+
.data
3544+
.and_then(|mut data| data.remove(key))
3545+
.ok_or_else(|| {
3546+
KubernetesDriverError::Precondition(
3547+
"proxy credential Secret is missing its configured key".to_string(),
3548+
)
3549+
})?;
3550+
Some(String::from_utf8(value.0).map_err(|_| {
3551+
KubernetesDriverError::Precondition(
3552+
"proxy credential Secret must contain UTF-8 user:pass".to_string(),
3553+
)
3554+
})?)
3555+
}
3556+
_ => {
3557+
return Err(KubernetesDriverError::Precondition(
3558+
"proxy_auth_secret_name and proxy_auth_secret_key must be set together".into(),
3559+
));
3560+
}
3561+
};
3562+
let proxy = openshell_supervisor_control::UpstreamProxyLaunch {
3563+
url: url.clone(),
3564+
no_proxy: self.config.no_proxy.clone(),
3565+
credential,
3566+
auth_allow_insecure: self.config.proxy_auth_allow_insecure.unwrap_or(false),
3567+
connect_by_hostname: self.config.proxy_connect_by_hostname.unwrap_or(false),
3568+
ca_bundle_pem: ca_bundle.map(String::from_utf8).transpose().map_err(|_| {
3569+
KubernetesDriverError::Precondition(
3570+
"proxy_ca_bundle must contain UTF-8 PEM".to_string(),
3571+
)
3572+
})?,
3573+
};
3574+
proxy
3575+
.validate()
3576+
.map_err(|error| KubernetesDriverError::Precondition(error.to_string()))?;
3577+
Ok(Some(proxy))
3578+
}
3579+
35213580
/// Create one generation's gated supervisor Pod and return its UID.
35223581
#[allow(clippy::too_many_arguments, clippy::similar_names)]
35233582
async fn create_sandbox_runtime_supervisor(
@@ -4015,6 +4074,9 @@ impl KubernetesComputeDriver {
40154074
.map_err(KubernetesDriverError::from_kube)?;
40164075
}
40174076
GenerationLaunchTarget::Shared { shared, route, .. } => {
4077+
let upstream_proxy = self
4078+
.shared_upstream_proxy_launch(namespace, staged.upstream_proxy_ca_bundle)
4079+
.await?;
40184080
self.create_generation_image_pull_secrets(
40194081
namespace,
40204082
names,
@@ -4029,6 +4091,7 @@ impl KubernetesComputeDriver {
40294091
provisioned.runtime_descriptor,
40304092
launch_authentication,
40314093
proxy_ca,
4094+
upstream_proxy,
40324095
)?;
40334096
// The coordinator persists the launch material with the
40344097
// generation before it assigns the instance, so a restarted
@@ -5889,6 +5952,7 @@ fn shared_instance_registration(
58895952
runtime_descriptor: openshell_sandbox_backend::boundary_protocol::SandboxRuntimeDescriptor,
58905953
launch_authentication: &openshell_core::jwt::SandboxLaunchAuthentication,
58915954
proxy_ca: crate::sandbox_runtime::ProxyCaMaterial,
5955+
upstream_proxy: Option<openshell_supervisor_control::UpstreamProxyLaunch>,
58925956
) -> Result<SandboxInstanceRegistration, KubernetesDriverError> {
58935957
Ok(SandboxInstanceRegistration {
58945958
route: route.to_string(),
@@ -5922,6 +5986,7 @@ fn shared_instance_registration(
59225986
certificate_pem: proxy_ca.certificate_pem,
59235987
private_key_pem: openshell_supervisor_control::SecretPem::new(proxy_ca.private_key_pem),
59245988
},
5989+
upstream_proxy,
59255990
trace_context: RegistrationTraceContext::current(),
59265991
})
59275992
}
@@ -9134,6 +9199,7 @@ fn spawn_namespace_file_watcher(
91349199
#[cfg(test)]
91359200
mod tests {
91369201
use super::*;
9202+
use k8s_openapi::ByteString;
91379203

91389204
/// Serve Pod GETs over one reusable HTTP/1 connection per client,
91399205
/// delaying a request for Pod `slow-<millis>` by that many milliseconds.
@@ -13587,6 +13653,90 @@ mod tests {
1358713653
(driver, steps, bodies)
1358813654
}
1358913655

13656+
#[tokio::test]
13657+
async fn shared_proxy_launch_snapshots_credentials_from_each_sandbox_namespace() {
13658+
let ca = generate_proxy_ca_material().unwrap().certificate_pem;
13659+
for (namespace, path) in [
13660+
(
13661+
"workspace-a",
13662+
"/api/v1/namespaces/workspace-a/secrets/egress-auth",
13663+
),
13664+
(
13665+
"workspace-b",
13666+
"/api/v1/namespaces/workspace-b/secrets/egress-auth",
13667+
),
13668+
] {
13669+
let credential = format!("{namespace}:private-password");
13670+
let secret = Secret {
13671+
data: Some(BTreeMap::from([(
13672+
"credentials".to_string(),
13673+
ByteString(credential.as_bytes().to_vec()),
13674+
)])),
13675+
..Secret::default()
13676+
};
13677+
let config = KubernetesComputeConfig {
13678+
https_proxy: Some("https://proxy.example:3130".to_string()),
13679+
proxy_auth_secret_name: Some("egress-auth".to_string()),
13680+
proxy_auth_secret_key: Some("credentials".to_string()),
13681+
..KubernetesComputeConfig::default()
13682+
};
13683+
let (driver, pending, _) = scripted_driver(
13684+
config,
13685+
vec![(
13686+
http::Method::GET,
13687+
path,
13688+
kube_test_response(http::StatusCode::OK, serde_json::to_value(secret).unwrap()),
13689+
)],
13690+
);
13691+
let proxy = driver
13692+
.shared_upstream_proxy_launch(namespace, Some(ca.as_bytes().to_vec()))
13693+
.await
13694+
.unwrap()
13695+
.unwrap();
13696+
assert_eq!(proxy.credential.as_deref(), Some(credential.as_str()));
13697+
assert_eq!(proxy.ca_bundle_pem.as_deref(), Some(ca.as_str()));
13698+
assert!(pending.lock().unwrap().is_empty());
13699+
}
13700+
}
13701+
13702+
#[tokio::test]
13703+
async fn shared_proxy_launch_refuses_missing_or_invalid_credentials() {
13704+
let path = "/api/v1/namespaces/workspace-a/secrets/egress-auth";
13705+
let invalid = [
13706+
None,
13707+
Some(vec![0xff]),
13708+
Some(b"private-password".to_vec()),
13709+
Some(vec![b'x'; 4097]),
13710+
];
13711+
for credential in invalid {
13712+
let secret = Secret {
13713+
data: credential
13714+
.map(|value| BTreeMap::from([("credentials".to_string(), ByteString(value))])),
13715+
..Secret::default()
13716+
};
13717+
let config = KubernetesComputeConfig {
13718+
https_proxy: Some("https://proxy.example:3130".to_string()),
13719+
proxy_auth_secret_name: Some("egress-auth".to_string()),
13720+
proxy_auth_secret_key: Some("credentials".to_string()),
13721+
..KubernetesComputeConfig::default()
13722+
};
13723+
let (driver, _, _) = scripted_driver(
13724+
config,
13725+
vec![(
13726+
http::Method::GET,
13727+
path,
13728+
kube_test_response(http::StatusCode::OK, serde_json::to_value(secret).unwrap()),
13729+
)],
13730+
);
13731+
let error = driver
13732+
.shared_upstream_proxy_launch("workspace-a", None)
13733+
.await
13734+
.unwrap_err()
13735+
.to_string();
13736+
assert!(!error.contains("private-password"), "{error}");
13737+
}
13738+
}
13739+
1359013740
fn pod_owner(name: &str, uid: &str) -> OwnerReference {
1359113741
OwnerReference {
1359213742
api_version: "v1".to_string(),

‎crates/openshell-supervisor-control/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ pub use pool_limits::{
5858
};
5959
pub use registration::{
6060
INSTANCE_REMOVAL_GRACE, MAX_LAUNCH_MATERIAL_BYTES, ProxyCaMaterial, RegistrationError,
61-
RegistrationTraceContext, SandboxInstanceRegistration, SecretPem,
61+
RegistrationTraceContext, SandboxInstanceRegistration, SecretPem, UpstreamProxyLaunch,
6262
};
6363
pub use status::{SandboxInstancePhaseReport, SandboxInstanceStatusReport};

0 commit comments

Comments
 (0)