Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@ Available task variants:
| `e2e:kubernetes:shared-supervisor` | One-member shared supervisor pool for the gateway's sandboxes (gateway TLS through the port-forward) |
| `e2e:kubernetes:shared-supervisor-ha` | Two-replica shared supervisor pool behind two gateway replicas on PostgreSQL: kills the member that owns a sandbox and checks the sandbox is adopted, not restarted; crashes and restarts gateways and checks each sandbox's session stays on its supervisor's gateway |
| `e2e:kubernetes:shared-supervisor-scaling` | One-member shared supervisor pool: scales it to two members and back with `helm upgrade`, checking sandboxes stay running and the removed member hands its sandboxes off |
| `e2e:kubernetes:additional-ca-shared` | Additional destination CA with a one-member shared supervisor pool: checks the bundle reaches sandboxes without a ConfigMap or mount, and that removing it applies after a gateway restart and sandbox stop/start |
| `e2e:kubernetes:tracing` | Deploys a Jaeger collector, exports gateway traces to it, and fails unless Jaeger receives gateway and Kubernetes compute-driver spans for a new sandbox. The only Kubernetes lane that exports traces |

Kubernetes e2e environment variables:
Expand All @@ -1020,6 +1021,7 @@ Kubernetes e2e environment variables:
| `OPENSHELL_E2E_KUBE_CONFORMANCE` | `0` skips the conformance suites that otherwise run before the lane's Rust tests |
| `OPENSHELL_E2E_KUBE_JAEGER` | `1` deploys a Jaeger collector, points gateway OTLP export at it, and sets `OPENSHELL_E2E_JAEGER_QUERY_URL` to its query API. Unset, the gateway exports no traces |
| `OPENSHELL_E2E_KUBE_TLS` | `1` reaches the gateway over mTLS through the port-forward; pair it with an overlay that keeps gateway TLS on, such as `ci/values-tls-port-forward.yaml` |
| `OPENSHELL_E2E_KUBE_SUPERVISOR_TOPOLOGY` | `gateway` tells the `additional_ca` test the release uses shared supervisors, such as with `ci/values-supervisor.yaml` |
| `OPENSHELL_E2E_KUBERNETES_FEATURES` | Cargo feature flags (default: `e2e,e2e-host-gateway,e2e-kubernetes`) |
| `IMAGE_TAG` | Gateway/supervisor image tag (default: `latest` for existing clusters) |
| `OPENSHELL_REGISTRY` | Image registry prefix (default: `ghcr.io/ai-openshell/openshell`) |
Expand Down
84 changes: 72 additions & 12 deletions crates/openshell-driver-kubernetes/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ const ANNOTATION_ADDITIONAL_CA_GENERATION: &str = "openshell.ai/additional-ca-ge
const ADDITIONAL_CA_CONFIG_MAP_PREFIX: &str = "openshell-additional-ca-";
const ADDITIONAL_CA_DATA_KEY: &str = "ca.crt";

/// A validated immutable `ConfigMap` generation selected for a supervisor Pod.
/// This contains only an object name and non-secret digest; PEM bytes remain in
/// the API object and are never copied into a workload template or Secret.
/// A validated immutable `ConfigMap` generation selected for a dedicated
/// supervisor Pod. This contains only an object name and non-secret digest;
/// PEM bytes remain in the API object and are never copied into a workload
/// template. Shared generations carry the public PEM in their launch material.
#[derive(Clone, Debug, PartialEq, Eq)]
struct NetworkAdditionalCaConfigMap {
name: String,
Expand Down Expand Up @@ -1165,17 +1166,20 @@ impl KubernetesComputeDriver {
config: KubernetesComputeConfig,
shutdown_rx: tokio::sync::watch::Receiver<bool>,
supervision: SharedSupervision,
network_trust_bundle: Option<NetworkSupervisorTrustBundle>,
supervisor_otlp_tls_bytes: usize,
) -> Result<Self, KubernetesDriverError> {
if config.shared_supervisor.is_none() {
return Err(KubernetesDriverError::Precondition(
"shared supervision was provided but the configuration does not place generations on the shared supervisor"
.to_string(),
));
}
// The gateway refuses the additional destination CA under the shared
// supervisor topology fail-closed, so no trust bundle reaches this
// constructor.
Self::build(config, shutdown_rx, Some(supervision), None).await
validate_shared_network_trust_bundle(
network_trust_bundle.as_ref(),
supervisor_otlp_tls_bytes,
)?;
Self::build(config, shutdown_rx, Some(supervision), network_trust_bundle).await
}

async fn build(
Expand Down Expand Up @@ -4002,8 +4006,7 @@ impl KubernetesComputeDriver {
.await?;
// A restarted generation must revalidate immediately before
// resuming the gated supervisor as well as before creating
// it. The shared topology never carries an additional CA:
// the gateway refuses that combination fail-closed.
// it.
self.ensure_network_additional_ca_config_map(namespace)
.await?;
pods.patch(
Expand All @@ -4029,6 +4032,7 @@ impl KubernetesComputeDriver {
provisioned.runtime_descriptor,
launch_authentication,
proxy_ca,
self.network_trust_bundle.as_ref(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gator-agent

Warning — GATOR-0b045b10-02 · Preserve destination trust when replaying a generation

Summary. If the gateway restarts during a shared sandbox's start after the launch Secret was saved but before the sandbox becomes ready, startup recovery can rebuild that same generation using the replacement gateway's CA bundle. A CA rollover or removal can therefore change destination trust for an already-registered generation without a new stop/start after rollover.

Fix. Preserve the persisted CA snapshot, including an unset bundle, when rebuilding the same generation. Use the current gateway snapshot for a new generation or an attempt that never persisted a snapshot.

Verify. Hold readiness after the start operation settles with CA A in the released generation's launch Secret. Restart the gateway with CA B and let startup recovery rebuild that same generation. Its replacement Secret should still carry CA A. A later start that allocates a new generation should carry CA B.

Agent context
  • Location: crates/openshell-driver-kubernetes/src/driver.rs:4035
  • Recovery can call stop_sandbox_inner and delete an incomplete generation's launch Secret before rebuilding it under the same generation ID. The PR reads current driver configuration when it builds the replacement registration. An explicit retry of the same settled start can also take this path.

)?;
// The coordinator persists the launch material with the
// generation before it assigns the instance, so a restarted
Expand Down Expand Up @@ -4370,9 +4374,12 @@ impl KubernetesComputeDriver {
// Validate the current gateway generation before touching a stopped
// sandbox's stale companion. This detects equal-generation
// delete/recreate tampering before a supervisor can be created or
// released, while running supervisors remain untouched.
self.ensure_network_additional_ca_config_map(&namespace)
.await?;
// released, while running supervisors remain untouched. Shared
// generations carry the bundle in their launch material instead.
if placement == SupervisorPlacement::Dedicated {
self.ensure_network_additional_ca_config_map(&namespace)
.await?;
}
let mut stale_generations = sandbox_runtime_generation(&object).as_slice().to_vec();
stale_generations.push(generation.as_str());
self.delete_sandbox_runtime_supervisor(sandbox_id, &namespace, &stale_generations)
Expand Down Expand Up @@ -5879,6 +5886,23 @@ struct SharedInstanceSecretRecord {
generation: String,
}

fn validate_shared_network_trust_bundle(
bundle: Option<&NetworkSupervisorTrustBundle>,
otlp_tls_bytes: usize,
) -> Result<(), KubernetesDriverError> {
let limit = openshell_supervisor_control::MAX_SHARED_TRUST_MATERIAL_BYTES;
let Some(bundle) = bundle else {
return Ok(());
};
let total = bundle.pem().len() + otlp_tls_bytes;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gator-agent

Warning — GATOR-0b045b10-01 · Budget the encoded shared-supervisor launch data

Summary. A Kubernetes operator using shared supervisors can configure a destination CA bundle and supervisor OTLP headers that pass gateway startup but push every new or restarted sandbox generation over the 256 KiB launch limit. Startup counts the raw CA and OTLP TLS bytes. The launch limit also counts the encoded headers and JSON overhead.

Fix. Keep the 192 KiB raw trust cap and the final per-generation guard. At startup, also budget the encoded CA and effective supervisor OTLP fields, with room for per-generation data. Name additional_ca_bundle and the applicable limit in the startup error.

Verify. With no OTLP TLS files, use a normalized CA bundle of roughly 185 KiB and valid headers of roughly 24 KiB for each of the traces, OCSF, and agent exports. Verify that startup rejects the fixture with the configuration error. The current startup accepts it, and registration serialization rejects the oversized launch. Also check the TLS-only case with a 90–96 KiB normalized destination CA and distinct traces and OCSF HTTPS CA files padded with blank lines to 64 KiB and 32 KiB. With no headers, the raw total is at most 192 KiB, but JSON escaping puts the registration over 256 KiB. Use a config fixture and a minimal registration without contacting a collector.

Agent context
  • Location: crates/openshell-driver-kubernetes/src/driver.rs:5897
  • This PR adds the CA to SandboxInstanceRegistration::to_assignment's existing size budget. It checks the final size before SharedSupervision::launch persists the Secret or assigns the generation.

if total > limit {
return Err(KubernetesDriverError::Precondition(format!(
"the network supervisor additional destination CA and supervisor OTLP TLS files total {total} bytes, more than the {limit}-byte limit with a shared supervisor topology"
)));
}
Ok(())
}

/// Launch material of one shared-supervisor sandbox instance, taken from the
/// generation's own Sandbox resource and gateway-issued credentials. The
/// coordinator validates, encodes, persists, and assigns it.
Expand All @@ -5889,7 +5913,17 @@ fn shared_instance_registration(
runtime_descriptor: openshell_sandbox_backend::boundary_protocol::SandboxRuntimeDescriptor,
launch_authentication: &openshell_core::jwt::SandboxLaunchAuthentication,
proxy_ca: crate::sandbox_runtime::ProxyCaMaterial,
network_trust_bundle: Option<&NetworkSupervisorTrustBundle>,
) -> Result<SandboxInstanceRegistration, KubernetesDriverError> {
let additional_ca_bundle = network_trust_bundle
.map(|bundle| {
String::from_utf8(bundle.pem().to_vec()).map_err(|_| {
KubernetesDriverError::Precondition(
"the network supervisor additional destination CA is not UTF-8 PEM".to_string(),
)
})
})
.transpose()?;
Ok(SandboxInstanceRegistration {
route: route.to_string(),
sandbox_id: sandbox_id.to_string(),
Expand Down Expand Up @@ -5922,6 +5956,7 @@ fn shared_instance_registration(
certificate_pem: proxy_ca.certificate_pem,
private_key_pem: openshell_supervisor_control::SecretPem::new(proxy_ca.private_key_pem),
},
additional_ca_bundle,
trace_context: RegistrationTraceContext::current(),
})
}
Expand Down Expand Up @@ -9608,6 +9643,31 @@ mod tests {
)
}

#[test]
fn shared_topology_bounds_the_additional_ca_bundle() {
let limit = openshell_supervisor_control::MAX_SHARED_TRUST_MATERIAL_BYTES;
let bundle_of = |len: usize| {
NetworkSupervisorTrustBundle::new(
vec![b'a'; len],
1,
"sha256:fixture",
PathBuf::from("/gateway-state/ca.crt"),
)
};

assert!(validate_shared_network_trust_bundle(None, 0).is_ok());
assert!(validate_shared_network_trust_bundle(None, limit + 1).is_ok());
assert!(validate_shared_network_trust_bundle(Some(&bundle_of(limit)), 0).is_ok());
assert!(matches!(
validate_shared_network_trust_bundle(Some(&bundle_of(limit + 1)), 0),
Err(KubernetesDriverError::Precondition(_))
));
assert!(matches!(
validate_shared_network_trust_bundle(Some(&bundle_of(limit - 10)), 11),
Err(KubernetesDriverError::Precondition(_))
));
}

#[test]
fn destination_trust_config_map_is_immutable_content_addressed_and_retained() {
let digest = "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
Expand Down
16 changes: 5 additions & 11 deletions crates/openshell-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,23 +269,17 @@ impl openshell_server::ComputeDriverFactory for KubernetesFactory {
config.supervisor_gateway_name = Some(context.gateway_name().to_string());
// With the gateway supervisor topology, the gateway owns the shared
// supervisor's assignments and token; the driver adapts them to
// Kubernetes objects. The experimental shared supervisor topology
// does not support the network supervisor additional destination CA;
// refuse the combination fail-closed rather than silently
// supervising generations without the operator's trust bundle.
// Kubernetes objects.
let network_trust = context.network_trust_bundle().cloned();
let driver = if config.shared_supervisor.is_some() {
if network_trust.is_some() {
return Err(openshell_core::Error::execution(
"the experimental shared supervisor topology does not support the \
network supervisor additional destination CA"
.to_string(),
));
}
openshell_driver_kubernetes::KubernetesComputeDriver::with_shared_supervision(
config,
context.shutdown_receiver(),
context.shared_supervision(),
network_trust,
context
.otlp_config()
.map_or(0, OtlpConfig::supervisor_tls_bytes),
)
.await
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/openshell-server/src/config_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl OtlpConfig {

/// Bytes of TLS files sent to supervisors, counting files shared by
/// several exports once.
fn supervisor_tls_bytes(&self) -> usize {
pub fn supervisor_tls_bytes(&self) -> usize {
crate::otel_tracing::supervisor_otlp_tls(Some(self))
.materials
.iter()
Expand Down
5 changes: 3 additions & 2 deletions crates/openshell-supervisor-control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ pub use pool_limits::{
MAX_POOL_INSTANCES_CEILING, PoolLimits, PoolLimitsError,
};
pub use registration::{
INSTANCE_REMOVAL_GRACE, MAX_LAUNCH_MATERIAL_BYTES, ProxyCaMaterial, RegistrationError,
RegistrationTraceContext, SandboxInstanceRegistration, SecretPem,
INSTANCE_REMOVAL_GRACE, MAX_LAUNCH_MATERIAL_BYTES, MAX_SHARED_TRUST_MATERIAL_BYTES,
ProxyCaMaterial, RegistrationError, RegistrationTraceContext, SandboxInstanceRegistration,
SecretPem,
};
pub use status::{SandboxInstancePhaseReport, SandboxInstanceStatusReport};
9 changes: 9 additions & 0 deletions crates/openshell-supervisor-control/src/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ use crate::proto::SandboxInstanceAssignment;

/// Largest launch material one assignment may carry.
pub const MAX_LAUNCH_MATERIAL_BYTES: usize = 256 * 1024;
/// Largest total of the additional CA bundle and supervisor OTLP TLS files
/// that shared launch material carries, leaving the rest of
/// [`MAX_LAUNCH_MATERIAL_BYTES`] to the launch credentials.
pub const MAX_SHARED_TRUST_MATERIAL_BYTES: usize = 192 * 1024;
/// Time a shared supervisor gives a withdrawn sandbox instance's workload to
/// stop before cancelling the instance.
pub const INSTANCE_REMOVAL_GRACE: Duration = Duration::from_secs(20);
Expand Down Expand Up @@ -117,6 +121,11 @@ pub struct SandboxInstanceRegistration {
#[serde(default)]
pub container_image: String,
pub proxy_ca: ProxyCaMaterial,
/// Operator destination CA bundle (PEM) the instance appends to its
/// sandbox trust bundle. Omitted when unset so supervisors that refuse it
/// still accept the material.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub additional_ca_bundle: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub trace_context: Option<RegistrationTraceContext>,
}
Expand Down
39 changes: 36 additions & 3 deletions crates/openshell-supervisor/src/shared_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@ impl SharedHost {
.as_bytes(),
)
.map_err(failure)?;
let additional_ca_bundle =
write_additional_ca_bundle(dir, registration.additional_ca_bundle.as_deref())
.map_err(failure)?;
let trust_dir = dir.join("trust");
crate::sandbox_instance_host::prepare_private_dir(&trust_dir).map_err(failure)?;
let ssh_socket = dir.join("ssh.sock");
Expand All @@ -892,11 +895,10 @@ impl SharedHost {
ssh_socket_path: Some(ssh_socket.to_string_lossy().into_owned()),
shared_ssh_socket: false,
// The Kubernetes driver refuses the gateway topology when an
// upstream proxy is configured,
// and it configures no extra CA for dedicated supervisors.
// upstream proxy is configured.
upstream_proxy_args:
openshell_supervisor_network::upstream_proxy::UpstreamProxyArgs::default(),
additional_ca_bundle: None,
additional_ca_bundle,
policy_dns_ipv6_egress: self.policy_dns_ipv6_egress,
nat64_prefixes: self.nat64_prefixes.clone(),
backend_descriptor: descriptor,
Expand Down Expand Up @@ -1030,6 +1032,17 @@ fn write_private_file(_path: &Path, _contents: &[u8]) -> Result<()> {
Err(miette::miette!("shared supervision requires a Unix host"))
}

/// Write the instance's additional CA bundle into `dir`, returning the path
/// the network supervisor reads it from.
fn write_additional_ca_bundle(dir: &Path, pem: Option<&str>) -> Result<Option<String>> {
let Some(pem) = pem else {
return Ok(None);
};
let path = dir.join("additional-ca.pem");
write_private_file(&path, pem.as_bytes())?;
Ok(Some(path.to_string_lossy().into_owned()))
}

/// How the host reaches the gateway's supervisor host service.
pub struct GatewayLink {
/// Gateway gRPC endpoint; must be `https`, since the supervisor token is
Expand Down Expand Up @@ -1748,6 +1761,26 @@ mod tests {
}
}

#[cfg(unix)]
#[test]
fn additional_ca_bundle_is_written_privately_only_when_present() {
use std::os::unix::fs::PermissionsExt as _;

let dir = tempfile::tempdir().unwrap();
assert_eq!(write_additional_ca_bundle(dir.path(), None).unwrap(), None);
assert!(!dir.path().join("additional-ca.pem").exists());

let pem = "-----BEGIN CERTIFICATE-----\nfixture\n-----END CERTIFICATE-----\n";
let path = write_additional_ca_bundle(dir.path(), Some(pem))
.unwrap()
.expect("a bundle yields a path");
assert_eq!(std::fs::read_to_string(&path).unwrap(), pem);
assert_eq!(
std::fs::metadata(&path).unwrap().permissions().mode() & 0o777,
0o600
);
}

/// A hosted instance whose stop path reports on `stopped`.
fn admit_supervising(host: &SharedHost, route: &str, stopped: tokio::sync::mpsc::Sender<()>) {
let bindings = crate::SandboxInstanceBindings {
Expand Down
3 changes: 3 additions & 0 deletions deploy/helm/openshell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ driver creates a separate managed ConfigMap in each target sandbox namespace
and mounts it only in the dedicated supervisor Pod at
`/etc/openshell/tls/additional/ca-bundle.pem`. That supervisor receives the
path through `--additional-ca-bundle` and folds the bundle into system roots.
With the shared supervisor topology, the driver creates no ConfigMap; each
sandbox generation's launch material carries the bundle to the shared
supervisor.
The configured roots augment default destination trust. They do not configure
the corporate proxy, OIDC, or gateway callback mTLS trust.

Expand Down
3 changes: 3 additions & 0 deletions deploy/helm/openshell/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ driver creates a separate managed ConfigMap in each target sandbox namespace
and mounts it only in the dedicated supervisor Pod at
`/etc/openshell/tls/additional/ca-bundle.pem`. That supervisor receives the
path through `--additional-ca-bundle` and folds the bundle into system roots.
With the shared supervisor topology, the driver creates no ConfigMap; each
sandbox generation's launch material carries the bundle to the shared
supervisor.
The configured roots augment default destination trust. They do not configure
the corporate proxy, OIDC, or gateway callback mTLS trust.

Expand Down
Loading
Loading