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
92 changes: 64 additions & 28 deletions crates/openshell-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub fn normalize_compute_driver_name(value: &str) -> Result<String, String> {
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 {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/openshell-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ impl ServerState {
credentials: credentials::CredentialRuntime,
) -> Result<Self> {
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());
Expand Down
15 changes: 15 additions & 0 deletions crates/openshell-server/src/spiffe_broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<Option<Arc<dyn SandboxIdentityProvider<Error = TokenGrantFailure>>>, 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)))
}
Expand All @@ -47,6 +57,11 @@ fn enabled(config: &Config) -> Result<Option<&SpiffeBrokerConfig>, 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());
}
Expand Down
19 changes: 17 additions & 2 deletions docs/how-it-works/gateways/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
Loading