Skip to content

Commit 0f9cdb8

Browse files
committed
feat(server): place supervisor sessions by consistent hash and hand them off on shutdown
Signed-off-by: divesh <dgude@nvidia.com>
1 parent 8760396 commit 0f9cdb8

14 files changed

Lines changed: 1831 additions & 728 deletions

File tree

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ pub fn supervisor_pod(
275275
.iter()
276276
.map(|(name, value)| env_var(name, value)),
277277
);
278+
if let Some(server_name) = gateway_tls_server_name(grpc_endpoint) {
279+
environment.push(env_var(
280+
openshell_core::sandbox_env::GATEWAY_TLS_SERVER_NAME,
281+
&server_name,
282+
));
283+
}
278284
let mut volume_mounts = vec![
279285
volume_mount("bootstrap", "/.openshell/supervisor", true),
280286
volume_mount("sa-token", "/var/run/secrets/openshell", true),
@@ -659,6 +665,18 @@ fn control_labels(sandbox_id: &str, gateway_id: &str) -> BTreeMap<String, String
659665
labels
660666
}
661667

668+
/// The gateway may redirect the supervisor to a specific replica by pod
669+
/// address, which the server certificate does not name. Verifying every dial
670+
/// against the configured endpoint's host keeps those redirects valid.
671+
fn gateway_tls_server_name(grpc_endpoint: &str) -> Option<String> {
672+
let uri = grpc_endpoint.parse::<tonic::transport::Uri>().ok()?;
673+
if uri.scheme_str() != Some("https") {
674+
return None;
675+
}
676+
let host = uri.host()?.trim_start_matches('[').trim_end_matches(']');
677+
(!host.is_empty()).then(|| host.to_string())
678+
}
679+
662680
fn env_var(name: &str, value: &str) -> EnvVar {
663681
EnvVar {
664682
name: name.to_string(),
@@ -946,6 +964,29 @@ mod tests {
946964
assert!(!volumes.contains(&"client-tls".to_string()));
947965
}
948966

967+
#[test]
968+
fn supervisor_verifies_redirected_dials_against_the_configured_host() {
969+
let pod = supervisor_pod_with_client_tls(SupervisorClientTls::Disabled);
970+
let env = pod.spec.unwrap().containers[0].env.clone().unwrap();
971+
let server_name = env
972+
.iter()
973+
.find(|variable| variable.name == "OPENSHELL_GATEWAY_TLS_SERVER_NAME")
974+
.and_then(|variable| variable.value.as_deref());
975+
assert_eq!(server_name, Some("gateway"));
976+
977+
assert_eq!(
978+
gateway_tls_server_name("https://openshell.openshell.svc.cluster.local:8080")
979+
.as_deref(),
980+
Some("openshell.openshell.svc.cluster.local")
981+
);
982+
assert_eq!(
983+
gateway_tls_server_name("https://[fd00::1]:8080").as_deref(),
984+
Some("fd00::1")
985+
);
986+
assert_eq!(gateway_tls_server_name("http://gateway:8080"), None);
987+
assert_eq!(gateway_tls_server_name("not a uri"), None);
988+
}
989+
949990
#[test]
950991
fn owner_reference_does_not_require_finalizer_mutation_permission() {
951992
assert_eq!(owner().block_owner_deletion, Some(false));

0 commit comments

Comments
 (0)