Skip to content

Commit 45fa078

Browse files
committed
chore(stack): align supervisor first-parent ancestry
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
2 parents 00b12d3 + 100f11f commit 45fa078

38 files changed

Lines changed: 9601 additions & 1389 deletions

File tree

‎Cargo.lock‎

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ http-body-util = "0.1"
3838
tokio-rustls = { version = "0.26", default-features = false, features = ["logging", "tls12", "ring"] }
3939
rustls = { version = "0.23", default-features = false, features = ["std", "logging", "tls12", "ring"] }
4040
rustls-pemfile = "2"
41-
rcgen = { version = "0.13", features = ["crypto", "pem"] }
41+
rcgen = { version = "0.13", features = ["crypto", "pem", "x509-parser"] }
4242
webpki-roots = "1"
4343
rustls-native-certs = "0.8"
4444

‎architecture/compute-runtimes.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Compute Runtimes
22

33
Compute runtimes create, stop, start, delete, and watch sandbox workloads for the
4-
gateway. They do not replace sandbox policy enforcement. Every runtime starts a
5-
workload that runs the `openshell-sandbox` supervisor, and the supervisor
6-
enforces the sandbox contract locally.
4+
gateway. They do not replace sandbox policy enforcement. A runtime either starts
5+
the co-located `openshell-sandbox` supervisor or provisions its RFC 0012
6+
`--mode=control` and `--mode=boundary` placements.
77

88
## Driver Contract
99

@@ -13,6 +13,11 @@ Each runtime receives a sandbox spec from the gateway and is responsible for:
1313
- Injecting sandbox identity and gateway callback configuration.
1414
- Supplying TLS or secret material for supervisor callbacks.
1515
- Providing the supervisor binary or image in the workload.
16+
- Provisioning protected control and boundary configs plus a private Unix socket,
17+
TLS-authenticated TCP, or vsock transport when the supervisor is separated. Runtime-specific code
18+
supplies immutable resource claims and transport coordinates; the shared
19+
boundary protocol supplies lifecycle, exec, signaling, forwarding, and binary
20+
identity semantics.
1621
- Forwarding the exact canonical main-process argv and TTY mode without shell
1722
reconstruction. The sandbox-level environment and policy workspace apply to
1823
the main process.
@@ -219,10 +224,10 @@ delete, reconciliation removes the row; otherwise it can remain `Deleting`.
219224

220225
| Runtime | Best fit | Sandbox boundary | Notes |
221226
|---|---|---|---|
222-
| Docker | Local development with Docker available. | Container plus nested sandbox namespace. | Uses host networking so loopback gateway endpoints work from the supervisor. Advertises the combined-supervisor policy-DNS and transparent-TCP substrate. |
227+
| Docker | Local development with Docker available. | Container plus nested sandbox namespace. | Creates the workload with Docker `network_mode=none`; a host control process mediates egress and access over a private bind-mounted Unix socket. |
223228
| Podman | Rootless or single-machine deployments. | Container plus nested sandbox namespace. | Uses the Podman REST API and CDI GPU devices when available. Delivers the supervisor via OCI image volume by default; falls back to extracting the binary to a host-side cache and bind-mounting it when `userns` is configured (overlay does not support idmapped mounts). Advertises the combined-supervisor policy-DNS and transparent-TCP substrate. |
224-
| Kubernetes | Cluster deployment through Helm. | Pod plus nested sandbox namespace. | Uses Kubernetes API objects, service accounts, secrets, PVC-backed workspace storage, and GPU resources. |
225-
| VM | Experimental microVM isolation. | Per-sandbox libkrun VM. | Managed endpoint-backed driver. The gateway spawns `openshell-driver-vm`, waits for its Unix socket, and then consumes it through the same remote `compute_driver.proto` path used by unmanaged endpoint drivers. The VM driver boots a cached bootstrap `rootfs.ext4`, prepares requested OCI images inside a bootstrap VM with `umoci`, attaches the prepared image disk read-only, and gives each sandbox a writable `overlay.ext4` for merged-root changes and runtime material. The driver persists each accepted launch request beside the overlay and restarts those VMs on driver startup without recreating the overlay. |
229+
| Kubernetes | Cluster deployment through Helm. | Pod plus nested sandbox namespace. | The proxy-pod topology fences workload egress with NetworkPolicy, runs boundary mode as the workload entrypoint, and runs control mode in a separate zero-capability pod over per-boundary TLS. It requires an enforcing CNI and trusted sandbox namespace. |
230+
| VM | Experimental microVM isolation. | Per-sandbox libkrun VM. | The guest is NIC-less and runs boundary mode as PID 1; host control owns gateway networking and reaches the guest over vsock. The driver persists each accepted launch request and writable overlay for restart. |
226231
| Extension | Out-of-tree drivers operated alongside the gateway. | Whatever boundary the driver implements. | Selected by a custom `compute_drivers = ["<name>"]` entry with `[openshell.drivers.<name>].socket_path`, or at launch time by pairing `--drivers <name>` with `--compute-driver-socket=<path>`. A launch-time endpoint may use a canonical built-in name to preserve its driver-config key while replacing in-process construction. The gateway connects to an operator-provisioned UDS, snapshots `GetCapabilities`, and dispatches all sandbox lifecycle calls through `compute_driver.proto`. The driver process and socket lifecycle are operator-owned; the gateway does not spawn, supervise, or remove unmanaged extension drivers. The trust boundary is the socket's filesystem permissions: the operator must ensure only the gateway uid can read/write it. |
227232

228233
Per-sandbox CPU and memory values currently enter the driver layer through

‎architecture/sandbox.md‎

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Sandbox
22

3-
A sandbox is the runtime boundary where agent code executes. It is created by a
4-
compute runtime and managed inside the workload by `openshell-sandbox`, the
5-
sandbox supervisor.
3+
A sandbox is the runtime boundary where agent code executes. A compute runtime
4+
creates it, and `openshell-sandbox` operates it as one logical supervisor.
65

76
## Runtime Model
87

@@ -21,20 +20,52 @@ container-granted capabilities. This is fail-closed: the supervisor retains
2120
aborts unless the bounding set ends up empty. A `setpcap` `EPERM` is tolerated
2221
only when the set is already empty; any other outcome fails the spawn.
2322

23+
Separated runtimes split the same logical supervisor into two placements:
24+
25+
| Mode | Placement and authority |
26+
|---|---|
27+
| `openshell-sandbox --mode=control` | Runs outside the workload boundary. Owns gateway credentials, the admitted policy, RFC 0012 lifecycle, network-policy decisions, SSH, and gateway relays. |
28+
| `openshell-sandbox --mode=boundary --boundary-config <path>` | Runs inside or adjacent to the workload. Owns process launch and observation, exec signaling, PTY control, loopback forwarding, egress capture, and binary identity. It has no gateway credentials or independent policy authority. |
29+
30+
The compute driver provisions the two protected configurations and their private
31+
Unix-socket, TLS-authenticated TCP, or vsock transport. TCP across a shared or
32+
operator-managed network uses a driver-provisioned trust root and verified server
33+
name; NetworkPolicy alone is not a confidentiality boundary. All configurations carry the
34+
same boundary ID, bootstrap credential, protocol version, and immutable driver resource claims.
35+
The shared remote backend authenticates each request and rejects a resource-claim
36+
mismatch. Driver crates do not appear in generic supervisor lifecycle, network,
37+
SSH, or session code.
38+
39+
Control mode can expose semantic TCP readiness after the boundary reaches
40+
`Running`. The bind IP is explicit and address-family neutral; Kubernetes
41+
drivers inject the pod IP so IPv4 and IPv6 probes reach the same listener.
42+
43+
For cross-UID Unix-socket placements, the driver-owned parent directory limits
44+
socket reachability and the bootstrap credential authenticates every request.
45+
Boundary mode can re-own a bind-mounted config as root-only before starting the
46+
workload when its host ownership could otherwise coincide with the workload UID.
47+
2448
## Startup Flow
2549

2650
1. The compute runtime starts the workload with sandbox identity, callback
2751
endpoint, TLS or secret material, image metadata, and initial command.
28-
2. The supervisor loads policy and runtime settings from local files or the
52+
2. Control mode loads policy and runtime settings from local files or the
2953
gateway, depending on mode.
30-
3. It prepares filesystem access, process restrictions, network namespace
31-
routing, trust stores, provider credential resolution, and inference routes.
32-
4. It launches the persisted canonical main-process argv and retains its PTY
33-
or pipes in the main-session multiplexer.
34-
5. It starts the policy proxy and local SSH server.
35-
6. It opens a supervisor session back to the gateway for connect, exec, file
54+
3. The isolation backend attaches and confirms standing enforcement. Boundary
55+
mode prepares boundary-local filesystem, process, and egress controls.
56+
4. Control mode connects network mediation, then confirms enforcement and starts
57+
the admitted main process through the backend. Boundary
58+
mode applies launch-time controls before its first untrusted instruction.
59+
5. Control mode starts the local SSH server. Exec and loopback
60+
streams cross the shared boundary protocol when the modes are separated.
61+
6. Control mode opens a supervisor session back to the gateway for connect, exec, file
3662
sync, config polling, and log push.
3763

64+
When the admitted main process exits, its status and retained terminal output
65+
remain available. The confirmed boundary and control-owned access plane continue
66+
to serve policy-authorized exec and loopback forwarding until explicit stop or
67+
delete tears down the boundary and terminates any remaining workload processes.
68+
3869
## Isolation Layers
3970

4071
OpenShell uses overlapping controls rather than a single sandbox primitive:
@@ -109,6 +140,15 @@ generation-pinned authorization form the transparent TCP security boundary.
109140
Docker and Podman do not currently advertise usable IPv6 egress for this
110141
substrate, so AAAA queries return NOERROR/NODATA and IPv6 DNS remains fenced.
111142

143+
Network-rule ownership depends on supervisor placement. In legacy combined
144+
mode, `openshell-sandbox` creates the workload network namespace and owns its
145+
`ip`, iptables, and nftables setup and cleanup. In delegated control/boundary
146+
mode, the compute driver provisions the protected network substrate before
147+
control attaches; boundary mode owns only boundary-local observation and the
148+
listener handed to it. Control mode evaluates policy but must not mutate a
149+
driver-owned namespace or assume that legacy `ip`/nft cleanup applies. Drivers
150+
must tear down their own rules and namespace resources with the workload.
151+
112152
Provider credential placeholders are resolved through the live provider state
113153
for each HTTP request, after destination and L7 policy admission. A static
114154
credential resolves only when the request host, port, and path match an endpoint
@@ -487,7 +527,11 @@ engine with a gateway policy revision.
487527
to new connections or the next parsed HTTP request where the proxy can safely
488528
re-evaluate.
489529
- If the supervisor relay drops, the sandbox can keep running, but connect and
490-
exec operations fail until the supervisor registers again.
530+
exec operations fail until the supervisor registers again. In a separated
531+
topology, a replacement control process replays the identical boundary
532+
lifecycle and receives the existing process handle. The boundary rejects
533+
changed launch inputs and releases the single main-process attachment when
534+
the old control transport closes.
491535
- If the canonical main process exits, the supervisor durably reports the
492536
normalized result immediately. A foreground create declares a one-shot main
493537
attachment, so the supervisor accepts it even after a fast process exits,

‎crates/openshell-core/src/provider_credentials.rs‎

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,17 @@ impl ProviderCredentialState {
359359
/// here so SDKs can read them at startup.
360360
/// 3. Everything else stays as placeholders for proxy-time resolution.
361361
pub fn child_env_with_gcp_resolved(&self) -> HashMap<String, String> {
362+
self.child_env_snapshot_with_gcp_resolved().1
363+
}
364+
365+
/// Return the current revision and its workload-facing environment from
366+
/// one state snapshot.
367+
///
368+
/// Remote isolation boundaries use the pair as a revisioned update. The
369+
/// revision must describe the exact environment sent across the boundary,
370+
/// so callers must not obtain the two values through separate lock
371+
/// acquisitions.
372+
pub fn child_env_snapshot_with_gcp_resolved(&self) -> (u64, HashMap<String, String>) {
362373
use crate::google_cloud;
363374

364375
let inner = self
@@ -376,7 +387,7 @@ impl ProviderCredentialState {
376387
.any(|key| env.contains_key(*key) && inner.non_secret_environment_keys.contains(*key));
377388

378389
if !has_gcp_metadata && !has_gcp_config {
379-
return env;
390+
return (inner.current.revision, env);
380391
}
381392

382393
if has_gcp_metadata {
@@ -414,7 +425,44 @@ impl ProviderCredentialState {
414425
}
415426
}
416427

417-
env
428+
(inner.current.revision, env)
429+
}
430+
431+
/// Compare and install a workload-facing environment snapshot.
432+
///
433+
/// Provider environment revisions are opaque content identities, not
434+
/// ordered counters. The expected revision makes retries idempotent while
435+
/// rejecting updates based on a stale view of the boundary state.
436+
pub fn compare_and_install_child_env_snapshot(
437+
&self,
438+
expected_revision: u64,
439+
revision: u64,
440+
mut child_env: HashMap<String, String>,
441+
) -> u64 {
442+
let mut inner = self
443+
.inner
444+
.write()
445+
.expect("provider credential state poisoned");
446+
if revision == inner.current.revision || expected_revision != inner.current.revision {
447+
return inner.current.revision;
448+
}
449+
450+
for key in &inner.suppressed_keys {
451+
child_env.remove(key);
452+
}
453+
inner.current = Arc::new(ProviderCredentialSnapshot {
454+
revision,
455+
child_env,
456+
dynamic_credentials: HashMap::new(),
457+
});
458+
inner.generations.clear();
459+
inner.current_resolver = None;
460+
inner.combined_resolver = None;
461+
inner.non_secret_environment_keys.clear();
462+
inner.static_credential_bindings.clear();
463+
inner.known_static_credential_keys.clear();
464+
inner.static_credential_identity_epochs.clear();
465+
revision
418466
}
419467

420468
/// Return the GCP token placeholder and its remaining lifetime in seconds.
@@ -2117,6 +2165,40 @@ mod tests {
21172165
);
21182166
}
21192167

2168+
#[test]
2169+
fn child_env_snapshot_update_uses_opaque_revision_cas() {
2170+
let state = ProviderCredentialState::from_child_env_snapshot(
2171+
4,
2172+
HashMap::from([("TOKEN".to_string(), "four".to_string())]),
2173+
);
2174+
2175+
assert_eq!(
2176+
state.compare_and_install_child_env_snapshot(
2177+
4,
2178+
6,
2179+
HashMap::from([("TOKEN".to_string(), "six".to_string())]),
2180+
),
2181+
6
2182+
);
2183+
assert_eq!(
2184+
state.compare_and_install_child_env_snapshot(
2185+
4,
2186+
5,
2187+
HashMap::from([("TOKEN".to_string(), "stale".to_string())]),
2188+
),
2189+
6
2190+
);
2191+
assert_eq!(
2192+
state.compare_and_install_child_env_snapshot(6, 2, HashMap::new()),
2193+
2,
2194+
"opaque revisions may move numerically backwards"
2195+
);
2196+
2197+
let (revision, env) = state.child_env_snapshot_with_gcp_resolved();
2198+
assert_eq!(revision, 2);
2199+
assert!(env.is_empty(), "an empty snapshot must revoke the old env");
2200+
}
2201+
21202202
#[test]
21212203
fn stale_generation_falls_back_to_current_credential_after_retention_window() {
21222204
let state = ProviderCredentialState::from_environment(

‎crates/openshell-core/src/sandbox_env.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub const SSH_SOCKET_PATH: &str = "OPENSHELL_SSH_SOCKET_PATH";
2626
/// Log level for the sandbox supervisor (e.g. `"debug"`, `"info"`, `"warn"`).
2727
pub const LOG_LEVEL: &str = "OPENSHELL_LOG_LEVEL";
2828

29+
/// IP address for the control-mode semantic readiness listener.
30+
pub const HEALTH_BIND_IP: &str = "OPENSHELL_HEALTH_BIND_IP";
31+
2932
/// Versioned specification for the exact canonical main process.
3033
///
3134
/// Most drivers use JSON directly. Transports that cannot preserve spaces in
@@ -122,6 +125,13 @@ pub const TELEMETRY_ENABLED: &str = "OPENSHELL_TELEMETRY_ENABLED";
122125
/// `"sidecar"`; the default combined supervisor path omits it.
123126
pub const SUPERVISOR_TOPOLOGY: &str = "OPENSHELL_SUPERVISOR_TOPOLOGY";
124127

128+
/// The isolation backend admitted by the deployment configuration (RFC 0012).
129+
///
130+
/// Delivered on a channel separate from the topology descriptor so descriptor
131+
/// verification against the admitted backend is not self-referential. Required
132+
/// whenever a topology descriptor is supplied.
133+
pub const ADMITTED_ISOLATION_BACKEND: &str = "OPENSHELL_ADMITTED_ISOLATION_BACKEND";
134+
125135
/// Network enforcement backend selected by the compute driver.
126136
pub const NETWORK_ENFORCEMENT_MODE: &str = "OPENSHELL_NETWORK_ENFORCEMENT_MODE";
127137

@@ -154,6 +164,17 @@ pub const GATEWAY_TLS_SERVER_NAME: &str = "OPENSHELL_GATEWAY_TLS_SERVER_NAME";
154164
/// by workload child processes.
155165
pub const PROXY_TLS_DIR: &str = "OPENSHELL_PROXY_TLS_DIR";
156166

167+
/// Optional path to a durable PEM-encoded interception CA certificate.
168+
/// Must be configured together with [`PROXY_CA_KEY`].
169+
pub const PROXY_CA_CERT: &str = "OPENSHELL_PROXY_CA_CERT";
170+
171+
/// Optional path to the private key for [`PROXY_CA_CERT`].
172+
/// Must be configured together with the certificate path.
173+
pub const PROXY_CA_KEY: &str = "OPENSHELL_PROXY_CA_KEY";
174+
175+
/// Whether the control-owned SSH Unix socket is shared across trusted UIDs.
176+
pub const SSH_SOCKET_SHARED: &str = "OPENSHELL_SSH_SOCKET_SHARED";
177+
157178
/// Path to the CA certificate for mTLS communication with the gateway.
158179
pub const TLS_CA: &str = "OPENSHELL_TLS_CA";
159180

‎crates/openshell-isolation-interface/Cargo.toml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@ repository.workspace = true
1313
[dependencies]
1414
openshell-core = { path = "../openshell-core", default-features = false }
1515
async-trait = "0.1"
16+
serde = { workspace = true }
17+
serde_json = { workspace = true }
18+
thiserror = { workspace = true }
1619
tokio = { workspace = true }
20+
rustls = { workspace = true }
21+
rustls-pemfile = { workspace = true }
22+
tokio-rustls = { workspace = true }
23+
socket2 = { workspace = true }
24+
25+
[target.'cfg(unix)'.dependencies]
26+
libc = "0.2"
1727

1828
[dev-dependencies]
29+
rcgen = { workspace = true }
1930
tokio = { workspace = true }
2031

2132
[lints]

0 commit comments

Comments
 (0)