Repository navigation
feat(k8s): support the additional destination CA with shared supervisors #6080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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( | ||
|
|
@@ -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( | ||
|
|
@@ -4029,6 +4032,7 @@ impl KubernetesComputeDriver { | |
| provisioned.runtime_descriptor, | ||
| launch_authentication, | ||
| proxy_ca, | ||
| self.network_trust_bundle.as_ref(), | ||
| )?; | ||
| // The coordinator persists the launch material with the | ||
| // generation before it assigns the instance, so a restarted | ||
|
|
@@ -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) | ||
|
|
@@ -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; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 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
|
||
| 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. | ||
|
|
@@ -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(), | ||
|
|
@@ -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(), | ||
| }) | ||
| } | ||
|
|
@@ -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"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
crates/openshell-driver-kubernetes/src/driver.rs:4035stop_sandbox_innerand 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.