diff --git a/crates/openshell-driver-vm/README.md b/crates/openshell-driver-vm/README.md index ff2ed322e2..45c20588c5 100644 --- a/crates/openshell-driver-vm/README.md +++ b/crates/openshell-driver-vm/README.md @@ -181,13 +181,72 @@ Select the VM driver with `--compute-driver vm`, `OPENSHELL_COMPUTE_DRIVER=vm`, | `proxy_auth_allow_insecure` | unset | Required with `proxy_auth_file` against an `http://` proxy: acknowledges that Basic auth is cleartext on the connection to the proxy. | | `proxy_connect_by_hostname` | unset | Send hostnames rather than validated IPs in CONNECT. Last resort for proxies whose ACLs reject IP CONNECT targets. | | `proxy_ca_bundle` | unset | Gateway-host PEM CA bundle trusted for the corporate proxy and TLS-intercepted server certificates. The driver validates it and stages it at a fixed non-secret guest path in the protected overlay. Requires `https_proxy`. | -| `provider_spiffe_workload_api_tcp_endpoint` | unset | Explicit guest-reachable `tcp:IP:port` SPIFFE Workload API listener for provider token exchange. It requires `provider_spiffe_allow_guest_tcp = true`; a host UNIX socket is never silently exposed to a VM guest. | +| `provider_spiffe_workload_api_socket` | unset | Absolute path of a SPIFFE Workload API Unix socket on the driver host. Each host supervisor receives the path in its environment. The socket and its credentials never enter a VM. See [Provider workload identity](#provider-workload-identity). | +| `provider_spiffe_workload_api_tcp_endpoint`, `provider_spiffe_allow_guest_tcp` | unset | Legacy guest TCP settings. They have no effect: the host supervisor never used them. The driver still validates the pair, so an endpoint requires `provider_spiffe_allow_guest_tcp = true`, and logs a warning when an endpoint is set. | | `enable_bind_mounts` | `false` | Allow per-sandbox `driver_config.vm.mounts` host directory shares (libkrun virtiofs only). The driver writes a `tag\ttarget\tmode` manifest to `/.openshell/mounts.manifest` in the overlay, and guest init mounts each share after `/sandbox` ownership fixups. Rejected while resource admission is enabled. | The proxy settings are operator-owned and deployment-level: they are not accepted through `template.driver_config.vm`, and the driver passes them only to native host control. Every present-but-invalid value is fatal at gateway or sandbox startup rather than degrading to a direct dial. See [`openshell-gateway --help`](../openshell-server/src/cli.rs) for the gateway process flag surface. +## Provider workload identity + +Set `provider_spiffe_workload_api_socket` in the driver table, or +`OPENSHELL_VM_PROVIDER_SPIFFE_WORKLOAD_API_SOCKET`, to give host supervisors a +SPIFFE Workload API socket for provider token grants. Each host supervisor +receives the path in `OPENSHELL_PROVIDER_SPIFFE_WORKLOAD_API_SOCKET`. The guest +receives nothing. + +The driver advertises the `openshell.compute.provider-workload-identity` +capability when all of these hold: + +- The gateway selected the mode in `Configure`, or the driver runs standalone. +- The socket is configured. +- The host supervisor reaches the gateway over HTTPS, or over HTTP on a + numeric loopback address. +- The host supervisor's `provider-workload-identity-probe ` command + reports that it sees the socket. + +The driver runs these checks on each `GetCapabilities` call, with the +supervisor binary that it launches. If a check fails, the driver logs the +reason and omits the capability. The driver checks the embedded supervisor +against its SHA-256 before every use. An `OPENSHELL_VM_SUPERVISOR_BIN` override +is not pinned, so the probe describes the file at that path at the time of the +call. + +A launch bundle in this mode carries the sandbox's stable SPIFFE ID and a +launch ID, which is the stable ID followed by `/launch/`. +`CreateSandbox` and `StartSandbox` check both against the sandbox and +generation of the request, and reject the request before any state changes if +they do not match. The supervisor reads the IDs from its launch bundle. + +The launch ID changes exactly when the gateway issues a new runtime generation. +Without this mode, the driver refuses `StartSandbox` for a running VM when the +request carries another generation. In this mode, `StartSandbox` for a running +VM compares the launch ID in the request with the one in the saved bundle: + +- If the request names another launch, the driver stops the VM launcher and its + host supervisor, then starts both with the new bundle and the existing + overlay. Both restart because the guest boundary configuration and the + host-to-guest channel keys are created from the bundle at boot. +- If the request names the saved launch, it behaves as it does without this + mode. An empty bundle changes nothing. A non-empty bundle restarts the VM + with that bundle, so a retried start restarts the VM again. A VM that was + created and never started records no gateway generation, and the driver + refuses such a start for it. + +After a driver restart, the driver relaunches a running-intent sandbox with its +saved bundle, so a new supervisor process carries the saved launch ID. + +The driver does not attest supervisors. It starts every host supervisor +itself, as its own user and from one executable. The Unix selectors that SPIRE +provides (user, group, path, and SHA-256) are therefore the same for every +supervisor from one install: a registration entry that matches one supervisor +matches all of them, and each can obtain the identity registered for any +sandbox. Per-sandbox identity on this driver needs an external attestor that +maps a supervisor process to its sandbox launch. The driver does not provide +one. + ## Verifying the gateway The gateway is auto-registered by `mise run gateway:vm`. In another terminal: diff --git a/crates/openshell-driver-vm/src/driver.rs b/crates/openshell-driver-vm/src/driver.rs index eb939c85bc..5649fbb2b0 100644 --- a/crates/openshell-driver-vm/src/driver.rs +++ b/crates/openshell-driver-vm/src/driver.rs @@ -47,6 +47,13 @@ use oci_client::{Reference, RegistryOperation}; use openshell_core::UpstreamProxyConfig; use openshell_core::config::DEFAULT_STOP_TIMEOUT_SECS; use openshell_core::driver_mounts; +use openshell_core::driver_utils::{ + PROVIDER_WORKLOAD_IDENTITY_PROBE, PROVIDER_WORKLOAD_SOCKET_PROBE_PRESENT, + PROVIDER_WORKLOAD_SOCKET_PROBE_UNAVAILABLE, + VM_HOST_GATEWAY_ALIAS as OPENSHELL_HOST_GATEWAY_ALIAS, + VM_HOST_LOOPBACK_ALIASES as HOST_LOOPBACK_ALIASES, validate_provider_launch_identity, +}; +use openshell_core::extension_protocol::COMPUTE_PROVIDER_WORKLOAD_IDENTITY; use openshell_core::gpu::{ driver_gpu_requirements, effective_driver_gpu_count, validate_specific_gpu_device_request, }; @@ -195,12 +202,6 @@ impl VmSandboxDriverConfig { } } -const OPENSHELL_HOST_GATEWAY_ALIAS: &str = "host.openshell.internal"; -const HOST_LOOPBACK_ALIASES: &[&str] = &[ - OPENSHELL_HOST_GATEWAY_ALIAS, - "host.containers.internal", - "host.docker.internal", -]; #[allow(dead_code)] const GUEST_SSH_SOCKET_PATH: &str = openshell_core::container_paths::SSH_SOCKET_PATH; #[allow(dead_code)] @@ -391,9 +392,15 @@ pub struct VmDriverConfig { /// Gateway-host PEM CA bundle staged into the guest overlay for the /// corporate proxy and TLS-intercepted server certificates. pub proxy_ca_bundle: Option, - /// Guest-reachable SPIFFE Workload API TCP endpoint. A VM cannot safely - /// project a host UNIX socket; this must be a deliberately exposed TCP - /// listener and requires `provider_spiffe_allow_guest_tcp`. + /// SPIFFE Workload API Unix socket on the driver host. Each host + /// supervisor receives its path; it never enters a VM. + pub provider_spiffe_workload_api_socket: Option, + /// Whether a managed gateway selected verified provider workload identity + /// in `Configure`. `None` for a standalone driver. + #[serde(skip)] + pub verified_provider_workload_identity: Option, + /// Legacy guest TCP endpoint. It is validated with + /// `provider_spiffe_allow_guest_tcp` and otherwise unused. pub provider_spiffe_workload_api_tcp_endpoint: Option, #[serde(default)] pub provider_spiffe_allow_guest_tcp: bool, @@ -481,6 +488,10 @@ impl std::fmt::Debug for VmDriverConfig { &self.proxy_ca_bundle.is_some(), ) .field("ipv6_egress", &self.ipv6_egress) + .field( + "provider_spiffe_workload_api_socket_configured", + &self.provider_spiffe_workload_api_socket.is_some(), + ) .field( "provider_spiffe_workload_api_tcp_endpoint_configured", &self.provider_spiffe_workload_api_tcp_endpoint.is_some(), @@ -529,6 +540,8 @@ impl Default for VmDriverConfig { upstream_proxy: UpstreamProxyConfig::default(), ipv6_egress: openshell_core::SupervisorIpv6EgressConfig::default(), proxy_ca_bundle: None, + provider_spiffe_workload_api_socket: None, + verified_provider_workload_identity: None, provider_spiffe_workload_api_tcp_endpoint: None, provider_spiffe_allow_guest_tcp: false, gpu_enabled: false, @@ -565,6 +578,9 @@ impl VmDriverConfig { return Err("proxy_ca_bundle is set but no https_proxy is configured".to_string()); } } + if let Some(socket) = self.provider_spiffe_workload_api_socket.as_deref() { + openshell_core::driver_utils::validate_provider_spiffe_unix_socket(socket)?; + } if let Some(endpoint) = self.provider_spiffe_workload_api_tcp_endpoint.as_deref() { openshell_core::driver_utils::validate_guest_spiffe_tcp_endpoint( endpoint, @@ -1060,6 +1076,73 @@ fn host_control_openshell_endpoint(endpoint: &str) -> Result<(String, Option Result<(), String> { + let mut command = Command::new(supervisor); + command + .arg(PROVIDER_WORKLOAD_IDENTITY_PROBE) + .arg(socket) + .env_clear() + .kill_on_drop(true) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()); + let probe = tokio::time::timeout(Duration::from_secs(5), command.status()).await; + match probe + .ok() + .and_then(Result::ok) + .and_then(|status| status.code()) + { + Some(PROVIDER_WORKLOAD_SOCKET_PROBE_PRESENT) => Ok(()), + Some(PROVIDER_WORKLOAD_SOCKET_PROBE_UNAVAILABLE) => Err( + "the host supervisor cannot see the configured Workload API Unix socket".to_string(), + ), + _ => Err(format!( + "host supervisor '{}' did not report support for verified provider workload identity", + supervisor.display() + )), + } +} + +/// Check the provider identities of a launch bundle that carries them. They +/// must name this sandbox and generation before a host supervisor runs with them. +#[allow(clippy::result_large_err)] +fn validate_provider_launch( + sandbox_id: &str, + generation_id: &str, + authentication: &openshell_core::jwt::SandboxLaunchAuthentication, +) -> Result<(), Status> { + let supervisor = &authentication.supervisor; + if supervisor.provider_spiffe_id.is_none() && supervisor.provider_launch_spiffe_id.is_none() { + return Ok(()); + } + validate_provider_launch_identity(sandbox_id, generation_id, authentication) +} + +/// Whether a start request's bundle names a provider launch other than the one +/// in the saved bundle, which the running host supervisor carries. The launch +/// ID changes exactly when the gateway issues a new runtime generation. +async fn names_another_provider_launch(state_dir: &Path, launch_authentication: &[u8]) -> bool { + let launch = |encoded: &[u8]| { + decode_launch_authentication(encoded) + .ok() + .and_then(|authentication| authentication.supervisor.provider_launch_spiffe_id) + }; + let Some(requested) = launch(launch_authentication) else { + return false; + }; + let running = read_sandbox_request(&state_dir.join(SANDBOX_REQUEST_FILE)) + .await + .ok() + .and_then(|sandbox| sandbox.spec) + .and_then(|spec| launch(&spec.launch_authentication)); + running != Some(requested) +} + #[derive(Debug)] struct VmProcess { child: Child, @@ -1182,6 +1265,11 @@ impl VmDriver { .map_err(|err| err.message().to_string())?; config.validate_sandbox_identity()?; config.validate_runtime_security_config()?; + if config.provider_spiffe_workload_api_tcp_endpoint.is_some() { + warn!( + "The VM SPIFFE guest TCP settings have no effect. Configure provider_spiffe_workload_api_socket for the host supervisor." + ); + } config.validate_bootstrap_image_config()?; config.validate_rootfs_tar_config()?; if config.grpc_endpoint.trim().is_empty() { @@ -1359,6 +1447,40 @@ impl VmDriver { Ok(destination) } + /// Whether to advertise verified provider workload identity. The mode is + /// offered when the gateway selected it, or when a standalone driver has a + /// Workload API socket. The host supervisor must then be able to use it. + async fn provider_workload_identity_supported(&self) -> bool { + use openshell_core::grpc_client::{ + token_grant_gateway_endpoint, validate_attested_token_grant_transport, + }; + + let selected = self.config.verified_provider_workload_identity; + let socket = self.config.provider_spiffe_workload_api_socket.as_deref(); + if !selected.unwrap_or_else(|| socket.is_some()) { + return false; + } + let qualified = async { + let socket = socket.ok_or("provider_spiffe_workload_api_socket is not configured")?; + let (endpoint, _) = host_control_openshell_endpoint(&self.config.grpc_endpoint)?; + token_grant_gateway_endpoint(&endpoint) + .and_then(|endpoint| validate_attested_token_grant_transport(&endpoint)) + .map_err(|_| { + "the host supervisor needs a gateway endpoint using HTTPS or a numeric loopback HTTP address" + })?; + let supervisor = self + .host_supervisor_binary() + .await + .map_err(|error| error.message().to_string())?; + probe_supervisor_provider_workload_identity(&supervisor, socket).await + }; + let qualified: Result<(), String> = qualified.await; + if let Err(reason) = &qualified { + warn!(%reason, "VM driver cannot offer verified provider workload identity"); + } + qualified.is_ok() + } + /// Stage the captured destination trust into this sandbox's host-only /// state directory. This intentionally happens per launch so stopped /// sandboxes do not carry a stale source generation into a later host @@ -1494,6 +1616,7 @@ impl VmDriver { openshell_core::telemetry::enabled_env_value(), ); command.envs(supervisor_otlp_environment(&self.config)); + command.envs(provider_spiffe_environment(&self.config)); if let Some(server_name) = gateway_tls_server_name { command.env( openshell_core::sandbox_env::GATEWAY_TLS_SERVER_NAME, @@ -1621,12 +1744,18 @@ impl VmDriver { #[allow(clippy::result_large_err)] pub async fn create_sandbox(&self, sandbox: &Sandbox) -> Result { self.validate_sandbox(sandbox)?; - decode_launch_authentication( + let authentication = decode_launch_authentication( sandbox .spec .as_ref() .map_or(&[], |spec| spec.launch_authentication.as_slice()), )?; + // Create carries no generation of its own; the bundle names it. + validate_provider_launch( + &sandbox.id, + authentication.supervisor.runtime_generation.as_str(), + &authentication, + )?; info!( sandbox_id = %sandbox.id, sandbox_name = %sandbox.name, @@ -2464,7 +2593,12 @@ impl VmDriver { record.process.is_some() || record.provisioning_task.is_some(), ) }; - if already_running { + // A bundle that names another provider launch, so another runtime + // generation, replaces the running VM and its host supervisor instead + // of being refused. Every other start keeps the checks below. + let replaces_launch = already_running + && names_another_provider_launch(&state_dir, &launch_authentication).await; + if already_running && !replaces_launch { let active_generation = tokio::fs::read_to_string(state_dir.join(HOST_BOUNDARY_GENERATION_FILE)) .await @@ -2486,7 +2620,8 @@ impl VmDriver { // An invalid replacement must not stop the active VM or remove the // previous generation's credentials. Preserve the empty idempotent // replay above, which does not request a new launch. - decode_launch_authentication(&launch_authentication)?; + let authentication = decode_launch_authentication(&launch_authentication)?; + validate_provider_launch(&record_id, generation.as_str(), &authentication)?; let mut sandbox = read_sandbox_request(&state_dir.join(SANDBOX_REQUEST_FILE)) .await .map_err(|error| { @@ -5331,7 +5466,7 @@ impl ComputeDriver for VmDriver { &self, request: Request, ) -> Result, Status> { - let capabilities = self.capabilities(); + let mut capabilities = self.capabilities(); openshell_core::extension_protocol::validate_gateway_metadata( openshell_core::extension_protocol::ExtensionFamily::Compute, DRIVER_NAME, @@ -5339,6 +5474,13 @@ impl ComputeDriver for VmDriver { request.into_inner().gateway, ) .map_err(|error| Status::failed_precondition(error.to_string()))?; + if self.provider_workload_identity_supported().await + && let Some(extension) = capabilities.extension.as_mut() + { + extension + .supported_capabilities + .push(COMPUTE_PROVIDER_WORKLOAD_IDENTITY.to_string()); + } Ok(Response::new(capabilities)) } @@ -8098,6 +8240,20 @@ fn supervisor_otlp_environment(config: &VmDriverConfig) -> Vec<(&'static str, St environment } +/// The Workload API socket path for the host supervisor. The guest never +/// receives it. +fn provider_spiffe_environment(config: &VmDriverConfig) -> Option<(&'static str, &Path)> { + config + .provider_spiffe_workload_api_socket + .as_deref() + .map(|socket| { + ( + openshell_core::sandbox_env::PROVIDER_SPIFFE_WORKLOAD_API_SOCKET, + socket, + ) + }) +} + #[tracing::instrument( name = "vm.launch", skip(command), @@ -11245,6 +11401,241 @@ mod tests { } } + #[tokio::test] + async fn start_replaces_a_running_vm_only_for_another_provider_launch() { + let id = "sb-launch"; + let launch = |generation| test_provider_launch_authentication(id, generation); + // `None` expects the replacement. The boundary generation marker never + // matches the request, so every other start is refused as on `main`. + for (saved, requested, generation, refused) in [ + ( + launch("generation-1"), + launch("generation-2"), + "generation-2", + None, + ), + ( + launch("generation-1"), + launch("generation-1"), + "generation-1", + Some(Code::FailedPrecondition), + ), + ( + test_launch_authentication("saved").0, + test_launch_authentication("requested").0, + "generation-1", + Some(Code::FailedPrecondition), + ), + ( + launch("generation-1"), + test_provider_launch_authentication("sb-other", "generation-2"), + "generation-2", + Some(Code::InvalidArgument), + ), + ] { + let temp = tempfile::tempdir().unwrap(); + let mut driver = test_driver_with_extensions(LifecycleExtensionRegistry::new()); + driver.config.state_dir = temp.path().to_path_buf(); + driver.config.default_image = "test/image:latest".to_string(); + let sandbox = Sandbox { + id: id.to_string(), + name: id.to_string(), + spec: Some(SandboxSpec { + launch_authentication: saved.clone(), + ..Default::default() + }), + ..Default::default() + }; + let state_dir = temp.path().join("sandboxes").join(id); + create_private_dir_all(&state_dir).await.unwrap(); + write_sandbox_request(&state_dir, &sandbox).await.unwrap(); + // An empty marker keeps the replacement from invoking debugfs. + std::fs::write(state_dir.join(HOST_BOUNDARY_GENERATION_FILE), "").unwrap(); + // A launcher and a host supervisor that run until they are signalled. + let spawn = || { + Command::new("/bin/sh") + .args(["-c", "read line || true"]) + .stdin(Stdio::piped()) + .kill_on_drop(true) + .spawn() + .unwrap() + }; + let process = Arc::new(Mutex::new(VmProcess { + child: spawn(), + supervisor: spawn(), + supervisor_liveness: None, + deleting: false, + })); + driver.registry.lock().await.insert( + sandbox.id.clone(), + SandboxRecord { + snapshot: sandbox_snapshot(&sandbox, provisioning_condition(), false), + state_dir: state_dir.clone(), + process: Some(process.clone()), + provisioning_task: None, + preparation: None, + gpu_bdf: None, + deleting: false, + }, + ); + + let result = driver + .start_sandbox(id, id, generation, requested.clone()) + .await; + + let record = driver.registry.lock().await.remove(id).unwrap(); + let relaunch = record.provisioning_task.inspect(JoinHandle::abort); + let mut process = process.lock().await; + let exited = [ + process.child.try_wait().unwrap().is_some(), + process.supervisor.try_wait().unwrap().is_some(), + ]; + let saved_bundle = read_sandbox_request(&state_dir.join(SANDBOX_REQUEST_FILE)) + .await + .unwrap() + .spec + .unwrap() + .launch_authentication; + if let Some(code) = refused { + assert_eq!(result.unwrap_err().code(), code); + assert_eq!(exited, [false, false], "the VM and supervisor keep running"); + assert!(relaunch.is_none()); + assert_eq!(saved_bundle, saved); + } else { + result.expect("another launch replaces the running VM"); + assert_eq!(exited, [true, true], "the VM and supervisor were stopped"); + assert!(record.process.is_none()); + assert!(relaunch.is_some(), "the VM is relaunched"); + assert_eq!(saved_bundle, requested); + } + } + } + + #[tokio::test] + async fn create_rejects_provider_identities_of_another_sandbox() { + let directory = tempfile::tempdir().unwrap(); + let mut driver = test_driver_with_extensions(LifecycleExtensionRegistry::new()); + driver.config.state_dir = directory.path().to_path_buf(); + driver.config.default_image = "test/image:latest".to_string(); + let sandbox = Sandbox { + id: "sb-identity".to_string(), + name: "identity".to_string(), + spec: Some(SandboxSpec { + launch_authentication: test_provider_launch_authentication( + "sb-other", + "generation-1", + ), + ..Default::default() + }), + ..Default::default() + }; + + let error = driver.create_sandbox(&sandbox).await.unwrap_err(); + + assert_eq!(error.code(), Code::InvalidArgument); + assert!(driver.registry.lock().await.is_empty()); + assert!(directory.path().read_dir().unwrap().next().is_none()); + } + + #[cfg(unix)] + #[test] + fn provider_workload_identity_is_advertised_only_when_offered_and_probed() { + use openshell_core::extension_protocol::{ + ExtensionFamily, gateway_metadata, has_capability, + }; + + let directory = tempfile::tempdir().unwrap(); + let socket = directory.path().join("agent.sock"); + let _listener = std::os::unix::net::UnixListener::bind(&socket).unwrap(); + let missing = directory.path().join("missing.sock"); + // Shell stand-ins for a supervisor with and without the provider probe. + let supervisor = directory.path().join("openshell-supervisor"); + fs::write( + &supervisor, + format!( + "#!/bin/sh\n\ + [ \"$1\" = \"{PROVIDER_WORKLOAD_IDENTITY_PROBE}\" ] || exit 2\n\ + [ -S \"$2\" ] && exit {PROVIDER_WORKLOAD_SOCKET_PROBE_PRESENT}\n\ + exit {PROVIDER_WORKLOAD_SOCKET_PROBE_UNAVAILABLE}\n" + ), + ) + .unwrap(); + let baseline = directory.path().join("baseline-supervisor"); + fs::write(&baseline, "#!/bin/sh\nexit 2\n").unwrap(); + for binary in [&supervisor, &baseline] { + fs::set_permissions(binary, fs::Permissions::from_mode(0o700)).unwrap(); + } + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + + let _guard = ENV_LOCK.lock().unwrap(); + let loopback = "http://127.0.0.1:8080"; + for (selected, socket, binary, endpoint, advertised) in [ + (Some(true), Some(&socket), &supervisor, loopback, true), + (None, Some(&socket), &supervisor, loopback, true), + (Some(false), Some(&socket), &supervisor, loopback, false), + (Some(true), None, &supervisor, loopback, false), + (None, None, &supervisor, loopback, false), + (Some(true), Some(&missing), &supervisor, loopback, false), + (Some(true), Some(&socket), &baseline, loopback, false), + ( + Some(true), + Some(&socket), + &supervisor, + "http://gateway.example:8080", + false, + ), + ] { + let mut driver = test_driver_with_extensions(LifecycleExtensionRegistry::new()); + driver.config.grpc_endpoint = endpoint.to_string(); + driver.config.verified_provider_workload_identity = selected; + driver.config.provider_spiffe_workload_api_socket = socket.cloned(); + // The host supervisor receives a configured socket in either mode. + assert_eq!( + provider_spiffe_environment(&driver.config), + socket.map(|socket| { + ( + openshell_core::sandbox_env::PROVIDER_SPIFFE_WORKLOAD_API_SOCKET, + socket.as_path(), + ) + }) + ); + let request = Request::new(GetCapabilitiesRequest { + gateway: Some(gateway_metadata(ExtensionFamily::Compute)), + }); + let capabilities = + temp_env::with_var("OPENSHELL_VM_SUPERVISOR_BIN", Some(binary), || { + runtime.block_on(ComputeDriver::get_capabilities(&driver, request)) + }) + .unwrap() + .into_inner(); + assert_eq!( + has_capability( + &capabilities.extension.unwrap().supported_capabilities, + COMPUTE_PROVIDER_WORKLOAD_IDENTITY, + ), + advertised, + "selected {selected:?}, socket {socket:?}, supervisor {binary:?}, {endpoint}" + ); + } + } + + /// Launch bundle for `generation` of `sandbox_id` with its provider + /// identities. The launch ID is the stable ID and the generation. + fn test_provider_launch_authentication(sandbox_id: &str, generation: &str) -> Vec { + let mut authentication = + decode_launch_authentication(&test_launch_authentication(generation).0).unwrap(); + let stable = format!("spiffe://example.test/gateway/gateway-a/sandbox/{sandbox_id}"); + authentication.supervisor.runtime_generation = + openshell_core::sandbox_generation::SandboxGenerationId::parse(generation).unwrap(); + authentication.supervisor.provider_launch_spiffe_id = + Some(format!("{stable}/launch/{generation}")); + authentication.supervisor.provider_spiffe_id = Some(stable); + serde_json::to_vec(&authentication).unwrap() + } + fn test_launch_authentication(label: &str) -> (Vec, openshell_core::SandboxSessionId) { use openshell_core::jwt::{ SandboxLaunchAuthentication, SecretJwt, SessionVerificationKey, SupervisorAuthBundle, diff --git a/crates/openshell-driver-vm/src/main.rs b/crates/openshell-driver-vm/src/main.rs index 407ad3e150..c2198bb356 100644 --- a/crates/openshell-driver-vm/src/main.rs +++ b/crates/openshell-driver-vm/src/main.rs @@ -196,14 +196,18 @@ struct Args { )] nat64_prefixes: Vec, - /// Guest-reachable SPIFFE Workload API endpoint (`tcp:IP:port`). + /// Host SPIFFE Workload API Unix socket for the host supervisors. + #[arg(long, env = "OPENSHELL_VM_PROVIDER_SPIFFE_WORKLOAD_API_SOCKET")] + provider_spiffe_workload_api_socket: Option, + + /// Legacy SPIFFE guest TCP endpoint (`tcp:IP:port`). Validated but unused. #[arg( long = "provider-spiffe-workload-api-tcp-endpoint", env = "OPENSHELL_PROVIDER_SPIFFE_WORKLOAD_API_TCP_ENDPOINT" )] provider_spiffe_workload_api_tcp_endpoint: Option, - /// Explicit acknowledgement that the configured Workload API listener is exposed to VM guests. + /// Acknowledgement required by the legacy SPIFFE guest TCP endpoint. #[arg( long, env = "OPENSHELL_PROVIDER_SPIFFE_ALLOW_GUEST_TCP", @@ -382,6 +386,8 @@ async fn main() -> Result<()> { policy_dns_ipv6_egress: args.policy_dns_ipv6_egress, nat64_prefixes: args.nat64_prefixes.clone(), }, + provider_spiffe_workload_api_socket: args.provider_spiffe_workload_api_socket.clone(), + verified_provider_workload_identity: None, provider_spiffe_workload_api_tcp_endpoint: args .provider_spiffe_workload_api_tcp_endpoint .clone(), diff --git a/crates/openshell-driver-vm/src/serve.rs b/crates/openshell-driver-vm/src/serve.rs index b419ae2b19..850d321196 100644 --- a/crates/openshell-driver-vm/src/serve.rs +++ b/crates/openshell-driver-vm/src/serve.rs @@ -171,7 +171,7 @@ async fn apply_configure( let supervisor_otlp = openshell_driver_sdk::supervisor_otlp(request.telemetry.as_ref())?; let admission = openshell_driver_sdk::admission_from_json(&request.resource_admission_policy_json)?; - let config = driver_config( + let mut config = driver_config( settings, &gateway, request.network_trust.as_ref(), @@ -180,6 +180,8 @@ async fn apply_configure( log_level, gpu, )?; + config.verified_provider_workload_identity = + Some(request.verified_provider_workload_identity == Some(true)); VmDriver::new(config).await.map_err(Status::internal) } @@ -242,6 +244,8 @@ fn driver_config( upstream_proxy: settings.upstream_proxy, proxy_ca_bundle: settings.proxy_ca_bundle, ipv6_egress: settings.ipv6_egress, + provider_spiffe_workload_api_socket: settings.provider_spiffe_workload_api_socket, + verified_provider_workload_identity: None, provider_spiffe_workload_api_tcp_endpoint: settings .provider_spiffe_workload_api_tcp_endpoint, provider_spiffe_allow_guest_tcp: settings.provider_spiffe_allow_guest_tcp, @@ -313,6 +317,24 @@ mod tests { assert_eq!(built.supervisor_gateway_name.as_deref(), Some("gw")); } + #[test] + fn the_host_workload_api_socket_reaches_the_driver() { + let gateway = GatewayContext { + gateway_port: Some(8080), + ..Default::default() + }; + let built = config( + "provider_spiffe_workload_api_socket = \"/run/spire/agent.sock\"", + &gateway, + None, + ) + .unwrap(); + assert_eq!( + built.provider_spiffe_workload_api_socket, + Some("/run/spire/agent.sock".into()) + ); + } + #[test] fn the_admission_policy_comes_from_configure() { let gateway = GatewayContext { diff --git a/crates/openshell-driver-vm/src/settings.rs b/crates/openshell-driver-vm/src/settings.rs index 580884ce7c..fa0766af74 100644 --- a/crates/openshell-driver-vm/src/settings.rs +++ b/crates/openshell-driver-vm/src/settings.rs @@ -71,8 +71,10 @@ pub struct VmSettings { /// supervisors. #[serde(flatten)] pub ipv6_egress: openshell_core::SupervisorIpv6EgressConfig, - /// Explicit guest-reachable SPIFFE Workload API TCP listener. VM guests - /// cannot receive a host UNIX socket, so this requires acknowledgement. + /// SPIFFE Workload API Unix socket on the driver host, for host supervisors. + pub provider_spiffe_workload_api_socket: Option, + /// Legacy guest TCP endpoint. It is validated with + /// `provider_spiffe_allow_guest_tcp` and otherwise unused. pub provider_spiffe_workload_api_tcp_endpoint: Option, pub provider_spiffe_allow_guest_tcp: bool, /// Allow bind-mounting host directories into VM sandboxes. @@ -143,6 +145,10 @@ impl VmSettings { )); } } + if let Some(socket) = self.provider_spiffe_workload_api_socket.as_deref() { + openshell_core::driver_utils::validate_provider_spiffe_unix_socket(socket) + .map_err(ConfigError)?; + } if let Some(endpoint) = self.provider_spiffe_workload_api_tcp_endpoint.as_deref() { openshell_core::driver_utils::validate_guest_spiffe_tcp_endpoint( endpoint, @@ -177,6 +183,7 @@ impl Default for VmSettings { upstream_proxy: UpstreamProxyConfig::default(), proxy_ca_bundle: None, ipv6_egress: openshell_core::SupervisorIpv6EgressConfig::default(), + provider_spiffe_workload_api_socket: None, provider_spiffe_workload_api_tcp_endpoint: None, provider_spiffe_allow_guest_tcp: false, enable_bind_mounts: false, @@ -296,6 +303,10 @@ impl VmSettings { self.proxy_ca_bundle = get("OPENSHELL_VM_UPSTREAM_PROXY_CA_BUNDLE").map(Into::into); } + if self.provider_spiffe_workload_api_socket.is_none() { + self.provider_spiffe_workload_api_socket = + get("OPENSHELL_VM_PROVIDER_SPIFFE_WORKLOAD_API_SOCKET").map(Into::into); + } if self.provider_spiffe_workload_api_tcp_endpoint.is_none() { self.provider_spiffe_workload_api_tcp_endpoint = get("OPENSHELL_PROVIDER_SPIFFE_WORKLOAD_API_TCP_ENDPOINT"); @@ -541,6 +552,7 @@ mod tests { "bootstrap_extraction_max_bytes = 0", "rootfs_tar_staging_dir = \"\"", "proxy_ca_bundle = \"/ca.pem\"", + "provider_spiffe_workload_api_socket = \"tcp:127.0.0.1:8081\"", "provider_spiffe_allow_guest_tcp = true", "default_image = \"\"\nbootstrap_image = \"\"", ] { diff --git a/docs/how-it-works/gateways/configuration.mdx b/docs/how-it-works/gateways/configuration.mdx index db461f8d66..f7aa1b4996 100644 --- a/docs/how-it-works/gateways/configuration.mdx +++ b/docs/how-it-works/gateways/configuration.mdx @@ -2221,11 +2221,9 @@ overlay_disk_mib = 4096 # see IPv6 Egress and NAT64. # policy_dns_ipv6_egress = "auto" # nat64_prefixes = ["2001:db8:64::/96"] -# VM guests cannot mount a host Workload API Unix socket. Configure only a -# separately operated guest-reachable TCP listener and explicitly acknowledge -# the exposure; host-only sockets are never exposed automatically. -# provider_spiffe_workload_api_tcp_endpoint = "tcp:192.0.2.10:8081" -# provider_spiffe_allow_guest_tcp = true +# Workload API Unix socket on the VM driver host for provider token grants. +# The host supervisor uses it. The guest never receives it. +# provider_spiffe_workload_api_socket = "/run/spire/agent.sock" # Unsafe operator override. Host bind mounts expose gateway-host paths inside # VM sandboxes and can negate OpenShell isolation and filesystem controls. # Requires allow_driver_config = true and @@ -2257,6 +2255,14 @@ externally managed `vm` socket owned by another user, the driver cannot read the gateway's staging directory and rootfs tar sources fail with a `FAILED_PRECONDITION` error; use a registry image reference instead. +Set `provider_spiffe_workload_api_socket`, or +`OPENSHELL_VM_PROVIDER_SPIFFE_WORKLOAD_API_SOCKET`, to the absolute path of a +Workload API Unix socket on the VM driver host. The driver passes the path to +each host supervisor for provider token grants. The legacy +`provider_spiffe_workload_api_tcp_endpoint` and +`provider_spiffe_allow_guest_tcp` settings have no effect. The driver logs a +warning when an endpoint is set. + ### Extension Driver Extension drivers run outside the gateway and expose the