diff --git a/crates/openshell-core/src/config.rs b/crates/openshell-core/src/config.rs index 2d3f37c7eb..42a4484e5d 100644 --- a/crates/openshell-core/src/config.rs +++ b/crates/openshell-core/src/config.rs @@ -250,7 +250,7 @@ pub fn normalize_compute_driver_name(value: &str) -> Result { Ok(value.to_ascii_lowercase()) } -/// Gateway-owned SPIFFE Broker API issuance for Kubernetes sandbox identities. +/// Gateway-owned SPIFFE Broker API issuance for attested sandbox workloads. #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[serde(deny_unknown_fields)] pub struct SpiffeBrokerConfig { @@ -291,33 +291,53 @@ impl SpiffeBrokerConfig { // Validate the mode independently of the startup environment. The // adapter requires and resolves the actual node IP before serving. let endpoint = self.endpoint_for_node(Some("127.0.0.1"))?; - let endpoint = url::Url::parse(&endpoint) - .map_err(|_| "spiffe_broker.endpoint must be an HTTPS endpoint")?; - let socket = std::path::Path::new(&self.workload_api_socket_path); - let valid_socket = socket.is_absolute() - && !self.workload_api_socket_path.ends_with('/') - && socket.file_name().is_some() - && socket - .parent() - .is_some_and(|parent| parent != std::path::Path::new("/")) - && self.workload_api_socket_path.trim() == self.workload_api_socket_path - && !self - .workload_api_socket_path - .split('/') - .any(|segment| matches!(segment, "." | "..")); - if endpoint.scheme() != "https" - || endpoint.host_str().is_none() - || !endpoint.username().is_empty() - || endpoint.password().is_some() - || endpoint.path() != "/" - || endpoint.query().is_some() - || endpoint.fragment().is_some() - || !valid_socket - { - return Err( - "spiffe_broker requires an HTTPS endpoint and absolute Workload API socket path" - .into(), - ); + let valid_socket = |value: &str| { + let path = std::path::Path::new(value); + path.is_absolute() + && !value.ends_with('/') + && path.file_name().is_some() + && path + .parent() + .is_some_and(|p| p != std::path::Path::new("/")) + && value.trim() == value + && !value.contains(char::is_control) + && !value + .split('/') + .any(|segment| matches!(segment, "." | "..")) + }; + if !valid_socket(&self.workload_api_socket_path) { + return Err("spiffe_broker requires an absolute Workload API socket path".into()); + } + if let Some(path) = endpoint.strip_prefix("unix:") { + if self.server_spiffe_id.is_none() || self.server_spiffe_id_prefix.is_some() { + return Err( + "a Unix broker endpoint requires the exact SPIFFE ID of the local agent".into(), + ); + } + // A process reference is meaningful only to the broker on the engine host. + // Pass the same literal filesystem path to the connector without URL decoding. + if !valid_socket(path) + || path.starts_with("//") + || std::path::Path::new(path) + == std::path::Path::new(&self.workload_api_socket_path) + { + return Err( + "spiffe_broker requires a distinct absolute Unix broker socket path".into(), + ); + } + } else { + let endpoint = url::Url::parse(&endpoint) + .map_err(|_| "spiffe_broker.endpoint must be HTTPS or unix:/absolute/path")?; + if endpoint.scheme() != "https" + || endpoint.host_str().is_none() + || !endpoint.username().is_empty() + || endpoint.password().is_some() + || endpoint.path() != "/" + || endpoint.query().is_some() + || endpoint.fragment().is_some() + { + return Err("spiffe_broker.endpoint must be HTTPS or unix:/absolute/path".into()); + } } match (&self.server_spiffe_id, &self.server_spiffe_id_prefix) { (Some(id), None) => { @@ -2381,6 +2401,22 @@ mod tests { workload_api_socket_path: "/spiffe-workload-api/spire-agent.sock".into(), }; config.validate("gw").unwrap(); + let mut unix = config.clone(); + unix.endpoint = "unix:/run/spire/broker/api.sock".into(); + unix.validate("gw").unwrap(); + let mut prefix = unix.clone(); + prefix.server_spiffe_id = None; + prefix.server_spiffe_id_prefix = Some("spiffe://example.org/spire/agent".into()); + assert!(prefix.validate("gw").is_err()); + for endpoint in [ + "unix:relative.sock", + "unix://remote/path", + "unix:/run/spire/../api.sock", + "unix:/spiffe-workload-api/spire-agent.sock", + ] { + unix.endpoint = endpoint.into(); + assert!(unix.validate("gw").is_err(), "{endpoint}"); + } let mut local = config.clone(); local.endpoint.clear(); local.node_local_port = std::num::NonZeroU16::new(8443); diff --git a/crates/openshell-server/src/lib.rs b/crates/openshell-server/src/lib.rs index dd0ef762cc..28ec6317e7 100644 --- a/crates/openshell-server/src/lib.rs +++ b/crates/openshell-server/src/lib.rs @@ -664,7 +664,7 @@ impl ServerState { credentials: credentials::CredentialRuntime, ) -> Result { let sandbox_identity = - spiffe_broker::sandbox_identity_provider(&config).map_err(Error::config)?; + spiffe_broker::sandbox_identity_provider(&config, &compute).map_err(Error::config)?; let replica_id = compute::lease::replica_id(); let compute = compute.with_sandbox_updates(config.enable_sandbox_updates); compute.configure_ssh_identities(credentials.clone()); diff --git a/crates/openshell-server/src/spiffe_broker.rs b/crates/openshell-server/src/spiffe_broker.rs index 886b2b4902..1527489a80 100644 --- a/crates/openshell-server/src/spiffe_broker.rs +++ b/crates/openshell-server/src/spiffe_broker.rs @@ -6,6 +6,7 @@ //! The provider broker depends only on //! [`SandboxIdentityProvider`]; this module chooses the SPIRE adapter when //! `[openshell.gateway.spiffe_broker]` is configured. +use crate::compute::ComputeRuntime; use std::sync::Arc; use openshell_core::config::{Config, SpiffeBrokerConfig}; @@ -29,10 +30,19 @@ pub fn validate_config(config: &Config) -> Result<(), String> { /// Rejects what [`validate_config`] rejects. pub fn sandbox_identity_provider( config: &Config, + compute: &ComputeRuntime, ) -> Result>>, String> { let Some(broker) = enabled(config)? else { return Ok(None); }; + // Static preflight cannot negotiate with a running driver. Check the actual + // private-channel capability before accepting any grants in local mode. + if broker.endpoint.starts_with("unix:") + && (compute.configured_driver_name() == "kubernetes" + || !compute.supports_provider_workload_process()) + { + return Err("a local SPIRE broker requires a Linux compute driver with openshell.compute.workload-reference".into()); + } let provider = openshell_spire::SpireSandboxIdentity::new(broker)?; Ok(Some(Arc::new(provider))) } @@ -47,6 +57,11 @@ fn enabled(config: &Config) -> Result, String> { .as_ref() .ok_or("spiffe_broker requires gateway session JWTs")?; broker.validate(&jwt.gateway_id)?; + if broker.endpoint.starts_with("unix:") && !cfg!(target_os = "linux") { + return Err( + "local SPIRE process references require a Linux gateway on the engine host".into(), + ); + } if jwt.ttl_secs.is_none() { return Err("spiffe_broker requires a positive gateway_jwt.ttl_secs".into()); } diff --git a/docs/how-it-works/gateways/configuration.mdx b/docs/how-it-works/gateways/configuration.mdx index c42bfd01e5..43d52dce20 100644 --- a/docs/how-it-works/gateways/configuration.mdx +++ b/docs/how-it-works/gateways/configuration.mdx @@ -1921,8 +1921,7 @@ agent must expose its mTLS Broker listener on that node address through host networking or a host port. Broker traffic does not traverse a Kubernetes Service. The gateway does not fall back to a remote agent when its local agent is unavailable. -Configure exactly one transport: `node_local_port`, or an explicit HTTPS -`endpoint` for a fixed address or Service. Outside Helm, node-local deployments +For Kubernetes, configure either `node_local_port` or an HTTPS `endpoint` for a fixed address or Service. Outside Helm, node-local deployments must supply `OPENSHELL_NODE_IP` themselves. Both modes retain the same mTLS, SPIFFE peer verification, broker allowlist, and Kubernetes authorization checks. @@ -1971,6 +1970,22 @@ Provider-token requests use a separate instance of the configured gRPC rate budget. Authenticated work is also capped at four concurrent requests per sandbox and 64 per gateway, including when token caching is disabled. +#### Local workload processes on a Linux engine host + +The shared supervisor requests final tokens through `GetSandboxProviderAccessToken` for each sandbox session. This setup requires a driver that runs those sessions and advertises `openshell.compute.workload-reference` over its private gateway channel. A dedicated supervisor configured for local exchange uses a different grant path. To use that driver for sandbox grants, run the gateway, driver and SPIRE agent on the same Linux engine host with the same host PID view. Point the gateway directly at the local SPIRE agent's protected Broker API socket. Pin the exact server SPIFFE ID issued exclusively to that node. A forwarded socket or an identity shared across nodes cannot establish which host a numeric PID belongs to. The gateway uses a separate Workload API socket to authenticate to the broker with its X.509-SVID. + +```toml +[openshell.gateway.spiffe_broker] +spiffe_id_prefix = "spiffe://example.org/openshell" +endpoint = "unix:/run/spire/broker/api.sock" +server_spiffe_id = "spiffe://example.org/spire/agent/engine" +workload_api_socket_path = "/run/spire/workload/api.sock" +``` + +Enable the SPIRE agent's Broker API and authorize the gateway's SPIFFE ID for `spiffe.broker.WorkloadPIDReference` on its Unix listener. Configure workload attestation and registration so only the intended workload matches its stable sandbox SPIFFE ID. Keep both sockets outside sandbox mounts. On VM-backed desktop engines the Linux engine VM is the host for this configuration. A remote gateway needs workload evidence that its issuer can verify across machines. + +At startup the gateway checks the driver's advertised capability. On a grant it checks the live workload and generation and verifies the broker's mTLS identity. A missing registration, stopped process or stale generation denies the grant. To check enrollment, attach one provider to two enrolled sandboxes and an unenrolled third. Verify two distinct client subjects at the token service and a denied third grant. Restart one enrolled sandbox and verify it retains its subject while its old session can no longer obtain a token. + ### MXC The MXC driver runs native Windows workloads through `wxc-exec`. Use this