Skip to content

Commit 32f0264

Browse files
authored
feat(sandbox): initiate supervisor connections across compute drivers (#4656)
* feat(sandbox): support sandbox-initiated supervisor connections Signed-off-by: Drew Newberry <anewberry@nvidia.com> * refactor(sandbox): consolidate control transport setup Signed-off-by: Drew Newberry <anewberry@nvidia.com> * test(sandbox): remove prototype-specific unit tests Signed-off-by: Drew Newberry <anewberry@nvidia.com> * feat(kubernetes): migrate legacy control flow on restart Signed-off-by: Drew Newberry <anewberry@nvidia.com> * docs: remove prototype changes from published docs Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(sandbox): adapt reverse control to published backend protocol Signed-off-by: Drew Newberry <anewberry@nvidia.com> * feat(sandbox): initiate supervisor connections across compute drivers Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(docker): stage reverse control socket for the supervisor identity Signed-off-by: Drew Newberry <anewberry@nvidia.com> * refactor(sandbox): keep runtime transports behind the backend Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(docker): mount the runtime control volume read-only The sandbox runtime only dials the supervisor-owned control socket, so it does not need write access to the control volume. Mount it read-only in the runtime container and stop staging the control directory through the runtime bundle; the supervisor stager already initializes it through its own writable mount. Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(kubernetes): separate legacy and runtime-initiated control services Keep os-boundary selecting the workload and add os-supervisor for runtime-initiated connections. Bind the mode marker to its runtime generation so a restart by an older gateway does not inherit stale mode metadata. Preserve the legacy Service across creation and restart, validate the active endpoint, and drop the Service patch permission. Signed-off-by: Drew Newberry <anewberry@nvidia.com> --------- Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent a24340b commit 32f0264

35 files changed

Lines changed: 2465 additions & 595 deletions

File tree

‎.agents/skills/helm-dev-environment/SKILL.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,16 @@ The Skaffold flow builds distinct `gateway`, `sandbox`, and `supervisor` images
8181
and deploys the OpenShell Helm chart. The Kubernetes driver creates a
8282
capability-free workload Pod and a directly managed capability-free supervisor
8383
Pod. One namespace-wide NetworkPolicy denies direct egress from every OpenShell
84-
workload Pod. The
84+
workload Pod. New sandbox generations use `runtime-initiated` control: the sandbox
85+
runtime dials its supervisor through `os-supervisor-<id>`. The legacy
86+
`os-boundary-<id>` Service keeps selecting the workload for old gateways during
87+
rolling upgrades. New gateways create both Services and bind the control-mode
88+
annotation to its runtime generation. The driver adds a per-sandbox
89+
`os-control-<id>` NetworkPolicy for that path only. Existing running generations
90+
keep their connection until replaced; stop/start and gateway recovery that
91+
recreates both Pods upgrade legacy generations automatically. Use compatible
92+
gateway, supervisor, and sandbox runtime images together; there is no legacy
93+
rollout flag. The
8594
`pkiInitJob` hook (a pre-install Job that runs `openshell-gateway generate-certs`)
8695
generates gateway and CLI TLS secrets on first install. Supervisor Pods project
8796
only `ca.crt` and authenticate gateway RPCs with sandbox bearer tokens. User

‎crates/openshell-driver-docker/README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ LSM decisions remain authoritative.
108108
| `network_mode = host` on the supervisor | Lets the trusted supervisor reach the gateway's primary loopback listener and originate approved upstream connections. |
109109
| `restart_policy = no` | Keeps canonical main-process exit terminal. |
110110
| `PidsLimit` | Applies the configured sandbox PID budget. Omit `sandbox_pids_limit` to use OpenShell's default. Explicit zero is invalid. |
111-
| Private named volumes | One carries the authenticated sandbox/supervisor channel. The other is mounted only into the supervisor and contains its JWT and private gateway credentials. |
111+
| Private named volumes | Separate volumes carry sandbox bootstrap keys, the runtime-initiated Unix socket, and supervisor-only credentials. The supervisor mounts bootstrap keys read-only and only the socket volume writable. |
112112
| In-memory `/run/openshell-supervisor-ca` tmpfs | Holds only the public supervisor CA certificate and trust bundle without making all of `/run` writable. |
113113
| CDI GPU request | Assigns the exact validated CDI devices requested by driver config or count-based selection. |
114114

115+
New containers dial the supervisor at `/.openshell/channel/control/supervisor/control.sock`.
116+
The runtime remains the TLS/gRPC server; the supervisor verifies its pinned
117+
identity and supplies the existing bearer credential. Saved descriptors retain
118+
the legacy Unix listener for existing containers, including across restart.
119+
New generations require matching supervisor and sandbox runtime binaries.
120+
115121
## Stop, Start, and Delete
116122

117123
Stop terminates the supervisor companion and stops the workload container

‎crates/openshell-driver-docker/src/isolation.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl DockerBoundarySpec {
109109
auth_epoch: self.auth_epoch,
110110
gateway_id: self.gateway_id,
111111
verification_keys: self.verification_keys,
112-
listener: BoundaryListener::Unix {
112+
listener: BoundaryListener::RuntimeInitiatedUnix {
113113
socket_path: self.listener_socket,
114114
tls: self.sandbox_tls,
115115
},
@@ -124,7 +124,7 @@ impl DockerBoundarySpec {
124124
generation: self.generation,
125125
session_id: self.session_id,
126126
workload_identity: self.workload_identity,
127-
transport: SandboxTransport::Unix {
127+
transport: SandboxTransport::RuntimeInitiatedUnix {
128128
socket_path: self.control_socket,
129129
},
130130
tls: self.supervisor_tls,

‎crates/openshell-driver-docker/src/lib.rs‎

Lines changed: 137 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ const SUPERVISOR_UID: u32 = 65_534;
107107
const SUPERVISOR_GID: u32 = 65_534;
108108
const BOUNDARY_MOUNT_PATH: &str = "/.openshell/channel";
109109
const BOUNDARY_CONFIG_MOUNT_PATH: &str = "/.openshell/channel/sandbox/bootstrap.json";
110-
const BOUNDARY_SOCKET_MOUNT_PATH: &str = "/.openshell/channel/sandbox/control.sock";
110+
const BOUNDARY_CONTROL_MOUNT_PATH: &str = "/.openshell/channel/control";
111+
const BOUNDARY_SOCKET_MOUNT_PATH: &str = "/.openshell/channel/control/supervisor/control.sock";
111112
const BOUNDARY_CERTIFICATE_MOUNT_PATH: &str = "/.openshell/channel/sandbox/server.crt";
112113
const BOUNDARY_PRIVATE_KEY_MOUNT_PATH: &str = "/.openshell/channel/sandbox/server.key";
113114
const SUPERVISOR_STATE_MOUNT_PATH: &str = "/.openshell/supervisor";
@@ -1309,7 +1310,9 @@ impl DockerComputeDriver {
13091310
Status::unavailable("volume admission lookup failed")
13101311
}
13111312
})?;
1312-
if name == docker_channel_volume_name_by_id(sandbox_id, &self.config) {
1313+
if name == docker_channel_volume_name_by_id(sandbox_id, &self.config)
1314+
|| name == docker_control_volume_name_by_id(sandbox_id, &self.config)
1315+
{
13131316
if volume.driver != "local"
13141317
|| !volume.options.is_empty()
13151318
|| volume.labels.get(LABEL_SANDBOX_ID) != Some(sandbox_id)
@@ -4126,28 +4129,36 @@ fn docker_supervisor_volume_name_by_id(
41264129
format!("openshell-supervisor-{}", &digest[..32])
41274130
}
41284131

4132+
fn docker_control_volume_name_by_id(
4133+
sandbox_id: &str,
4134+
config: &DockerDriverRuntimeConfig,
4135+
) -> String {
4136+
docker_channel_volume_name_by_id(sandbox_id, config).replacen(
4137+
"openshell-channel-",
4138+
"openshell-control-",
4139+
1,
4140+
)
4141+
}
4142+
41294143
async fn create_docker_channel_volume(
41304144
docker: &Docker,
41314145
sandbox: &DriverSandbox,
41324146
config: &DockerDriverRuntimeConfig,
41334147
) -> Result<(), Status> {
4134-
create_docker_runtime_volume(
4135-
docker,
4136-
sandbox,
4137-
config,
4148+
let names = [
41384149
docker_channel_volume_name(sandbox, config),
4139-
)
4140-
.await?;
4141-
if let Err(error) = create_docker_runtime_volume(
4142-
docker,
4143-
sandbox,
4144-
config,
41454150
docker_supervisor_volume_name(sandbox, config),
4146-
)
4147-
.await
4148-
{
4149-
let _ = remove_docker_volume(docker, &docker_channel_volume_name(sandbox, config)).await;
4150-
return Err(error);
4151+
docker_control_volume_name_by_id(&sandbox.id, config),
4152+
];
4153+
for (index, name) in names.iter().enumerate() {
4154+
if let Err(error) =
4155+
create_docker_runtime_volume(docker, sandbox, config, name.clone()).await
4156+
{
4157+
for created in &names[..index] {
4158+
let _ = remove_docker_volume(docker, created).await;
4159+
}
4160+
return Err(error);
4161+
}
41514162
}
41524163
Ok(())
41534164
}
@@ -4213,6 +4224,11 @@ async fn remove_docker_channel_volume_by_id(
42134224
docker,
42144225
&docker_supervisor_volume_name_by_id(sandbox_id, config),
42154226
)
4227+
.await?;
4228+
remove_docker_volume(
4229+
docker,
4230+
&docker_control_volume_name_by_id(sandbox_id, config),
4231+
)
42164232
.await
42174233
}
42184234

@@ -4472,6 +4488,8 @@ fn docker_sandbox_bundle_archive(
44724488
identity.uid,
44734489
identity.gid,
44744490
)?;
4491+
// The control volume is read-only in the runtime container; the
4492+
// supervisor stager initializes it.
44754493
append_docker_archive_file(
44764494
&mut archive,
44774495
".openshell/runtime/openshell-sandbox",
@@ -4551,7 +4569,8 @@ async fn stage_docker_sandbox_bundle(
45514569
bollard::body_full(Bytes::from(archive)),
45524570
)
45534571
.await
4554-
.map_err(|error| Status::internal(format!("stage Docker sandbox bundle: {error}")))
4572+
.map_err(|error| Status::internal(format!("stage Docker sandbox bundle: {error}")))?;
4573+
Ok(())
45554574
}
45564575

45574576
fn decode_docker_launch_authentication(
@@ -4964,6 +4983,32 @@ async fn stage_docker_supervisor_bundle(
49644983
Some(RemoveContainerOptionsBuilder::default().force(true).build()),
49654984
)
49664985
.await;
4986+
let runtime_initiated = read_docker_runtime_descriptor(&sandbox.id, config).await?
4987+
.is_some_and(|descriptor| matches!(descriptor.transport, openshell_sandbox_backend::boundary_protocol::SandboxTransport::RuntimeInitiatedUnix { .. }));
4988+
let mut mounts = vec![Mount {
4989+
target: Some(SUPERVISOR_STATE_MOUNT_PATH.to_string()),
4990+
source: Some(docker_supervisor_volume_name(sandbox, config)),
4991+
typ: Some(MountTypeEnum::VOLUME),
4992+
read_only: Some(false),
4993+
volume_options: Some(MountVolumeOptions {
4994+
no_copy: Some(true),
4995+
..Default::default()
4996+
}),
4997+
..Default::default()
4998+
}];
4999+
if runtime_initiated {
5000+
mounts.push(Mount {
5001+
target: Some(BOUNDARY_CONTROL_MOUNT_PATH.to_string()),
5002+
source: Some(docker_control_volume_name_by_id(&sandbox.id, config)),
5003+
typ: Some(MountTypeEnum::VOLUME),
5004+
read_only: Some(false),
5005+
volume_options: Some(MountVolumeOptions {
5006+
no_copy: Some(true),
5007+
..Default::default()
5008+
}),
5009+
..Default::default()
5010+
});
5011+
}
49675012
let created = docker
49685013
.create_container(
49695014
Some(
@@ -4985,17 +5030,7 @@ async fn stage_docker_supervisor_bundle(
49855030
)),
49865031
host_config: Some(HostConfig {
49875032
network_mode: Some("none".to_string()),
4988-
mounts: Some(vec![Mount {
4989-
target: Some(SUPERVISOR_STATE_MOUNT_PATH.to_string()),
4990-
source: Some(docker_supervisor_volume_name(sandbox, config)),
4991-
typ: Some(MountTypeEnum::VOLUME),
4992-
read_only: Some(false),
4993-
volume_options: Some(MountVolumeOptions {
4994-
no_copy: Some(true),
4995-
..Default::default()
4996-
}),
4997-
..Default::default()
4998-
}]),
5033+
mounts: Some(mounts),
49995034
cap_drop: Some(vec!["ALL".to_string()]),
50005035
security_opt: Some(vec!["no-new-privileges:true".to_string()]),
50015036
..Default::default()
@@ -5013,14 +5048,50 @@ async fn stage_docker_supervisor_bundle(
50135048
.path(SUPERVISOR_STATE_MOUNT_PATH)
50145049
.copy_uidgid("true")
50155050
.build();
5016-
let result = docker
5017-
.upload_to_container(
5018-
&created.id,
5019-
Some(options),
5020-
bollard::body_full(Bytes::from(archive)),
5021-
)
5022-
.await
5023-
.map_err(|error| Status::internal(format!("stage Docker supervisor bundle: {error}")));
5051+
let result: Result<(), Status> = async {
5052+
docker
5053+
.upload_to_container(
5054+
&created.id,
5055+
Some(options),
5056+
bollard::body_full(Bytes::from(archive)),
5057+
)
5058+
.await
5059+
.map_err(|error| {
5060+
Status::internal(format!("stage Docker supervisor bundle: {error}"))
5061+
})?;
5062+
if runtime_initiated {
5063+
// Initialize the socket volume using the supervisor's staging user.
5064+
// Docker preserves the existing volume root's ownership, so use
5065+
// a child directory created by the supervisor's staging user.
5066+
let mut archive = tar::Builder::new(Vec::new());
5067+
append_docker_archive_directory(
5068+
&mut archive,
5069+
"supervisor",
5070+
0o711,
5071+
SUPERVISOR_UID,
5072+
SUPERVISOR_GID,
5073+
)?;
5074+
let bytes = archive.into_inner().map_err(|error| {
5075+
Status::internal(format!("finish control socket archive: {error}"))
5076+
})?;
5077+
let options = UploadToContainerOptionsBuilder::default()
5078+
.path(BOUNDARY_CONTROL_MOUNT_PATH)
5079+
.copy_uidgid("true")
5080+
.build();
5081+
docker
5082+
.upload_to_container(
5083+
&created.id,
5084+
Some(options),
5085+
bollard::body_full(Bytes::from(bytes)),
5086+
)
5087+
.await
5088+
.map_err(|error| {
5089+
Status::internal(format!("stage Docker control socket volume: {error}"))
5090+
})?;
5091+
}
5092+
Ok(())
5093+
}
5094+
.await;
50245095
let cleanup = docker
50255096
.remove_container(
50265097
&created.id,
@@ -5245,6 +5316,8 @@ async fn spawn_docker_control_process(
52455316
&config.upstream_proxy,
52465317
config.proxy_ca_bundle.is_some(),
52475318
));
5319+
let runtime_initiated = read_docker_runtime_descriptor(&sandbox.id, config).await?
5320+
.is_some_and(|descriptor| matches!(descriptor.transport, openshell_sandbox_backend::boundary_protocol::SandboxTransport::RuntimeInitiatedUnix { .. }));
52485321
let mut supervisor_mounts = vec![
52495322
Mount {
52505323
target: Some(BOUNDARY_MOUNT_PATH.to_string()),
@@ -5269,6 +5342,20 @@ async fn spawn_docker_control_process(
52695342
..Default::default()
52705343
},
52715344
];
5345+
if runtime_initiated {
5346+
supervisor_mounts.push(Mount {
5347+
target: Some(BOUNDARY_CONTROL_MOUNT_PATH.to_string()),
5348+
source: Some(docker_control_volume_name_by_id(&sandbox.id, config)),
5349+
typ: Some(MountTypeEnum::VOLUME),
5350+
read_only: Some(false),
5351+
volume_options: Some(MountVolumeOptions {
5352+
no_copy: Some(true),
5353+
..Default::default()
5354+
}),
5355+
..Default::default()
5356+
});
5357+
}
5358+
52725359
if let Some(socket) = config.provider_spiffe_workload_api_socket.as_ref() {
52735360
let parent = socket.parent().ok_or_else(|| {
52745361
Status::failed_precondition("provider SPIFFE socket has no parent directory")
@@ -5931,6 +6018,19 @@ fn build_container_create_body_for_image(
59316018
}),
59326019
..Default::default()
59336020
});
6021+
// The runtime only dials the supervisor-owned socket; it never writes here.
6022+
user_mounts.push(Mount {
6023+
target: Some(BOUNDARY_CONTROL_MOUNT_PATH.to_string()),
6024+
source: Some(docker_control_volume_name_by_id(&sandbox.id, config)),
6025+
typ: Some(MountTypeEnum::VOLUME),
6026+
read_only: Some(true),
6027+
volume_options: Some(MountVolumeOptions {
6028+
no_copy: Some(true),
6029+
..Default::default()
6030+
}),
6031+
..Default::default()
6032+
});
6033+
59346034
let user_bind_strings = docker_driver_bind_strings(driver_config)?;
59356035
let device_requests = gpu_device_ids.map(|device_ids| {
59366036
vec![DeviceRequest {

‎crates/openshell-driver-docker/src/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ fn build_container_create_body_includes_driver_config_mounts() {
20562056
.mounts
20572057
.expect("driver config mounts should be set");
20582058

2059-
assert_eq!(mounts.len(), 3);
2059+
assert_eq!(mounts.len(), 4);
20602060
assert_eq!(mounts[0].typ, Some(MountTypeEnum::VOLUME));
20612061
assert_eq!(mounts[0].source.as_deref(), Some("work-nfs"));
20622062
assert_eq!(mounts[0].target.as_deref(), Some("/sandbox/work"));

‎crates/openshell-driver-kubernetes/README.md‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,70 @@ them. The cluster CNI must enforce ingress and egress `NetworkPolicy` for every
103103
sandbox namespace. Kubernetes accepts policy objects without confirming
104104
enforcement, so operators must verify CNI support before running sandboxes.
105105

106+
### Control connection direction
107+
108+
Every new runtime generation uses `runtime-initiated` control. The Sandbox
109+
annotation `openshell.ai/sandbox-runtime-control-connection` records the mode,
110+
bound to `openshell.ai/sandbox-runtime-control-generation`. A missing marker or
111+
a different current runtime generation identifies a legacy,
112+
`supervisor-initiated` generation, which keeps working until replaced. Stop/start
113+
upgrades it automatically: with both old Pods removed, the driver adds the
114+
supervisor Service and records the new mode and generation
115+
before releasing the replacement workload. Gateway recovery that recreates both
116+
Pods also upgrades the generation. Reconciliation never migrates a running
117+
generation. An unknown annotation value fails closed; there is no rollout flag.
118+
119+
Only the dial direction differs. In both modes the sandbox runtime presents the
120+
generation-pinned TLS server identity and serves gRPC, and the supervisor
121+
verifies that identity, acts as the gRPC client, and sends the Sandbox Protocol
122+
JWT. The per-sandbox Service `os-boundary-<id>` always selects the paired
123+
workload Pod. A separate `os-supervisor-<id>` Service always selects the paired
124+
supervisor Pod. New gateways create both Services, retaining the legacy
125+
Service's UID, ClusterIP, and selector across restarts so an older gateway can
126+
still replace the generation during a rolling upgrade.
127+
128+
For `runtime-initiated`:
129+
130+
- The bootstrap Secret gives the runtime the Service ClusterIP and port. The
131+
runtime retries with capped backoff until the supervisor listens, so neither
132+
Pod waits on the other during bootstrap. The Service sets
133+
`publishNotReadyAddresses` because the supervisor becomes Ready only after
134+
the runtime attaches through it. The workload still cannot reach the control
135+
port.
136+
- A per-sandbox `NetworkPolicy` `os-control-<id>` selects only this sandbox's
137+
two Pods and admits one flow, from its workload Pod to its supervisor Pod on
138+
`boundary_port` over TCP, as workload egress and supervisor ingress.
139+
Supervisors may already be ingress-isolated by the managed SSH ingress policy;
140+
when that policy is disabled, this one isolates them. Exec, file sync, and
141+
logs need no other supervisor ingress because the supervisor opens those
142+
connections. The CNI must still allow kubelet readiness probes. The
143+
namespace-wide policies are unchanged.
144+
- The policy's UID and resourceVersion are bound into the boundary resource
145+
claims and outer-fence evidence. Reconciliation suspends the workload if the
146+
policy disappears, diverges, or changes generation, or if the active control
147+
Service no longer selects the role the recorded mode requires.
148+
- Both Services and the control policy are owned by the Sandbox resource and are
149+
deleted only with that sandbox.
150+
151+
Deploy a gateway, supervisor image, and sandbox runtime image that all support
152+
`runtime-initiated` before using it. Older binaries reject the new descriptor
153+
shapes and fail closed.
154+
155+
During a mixed-version rollout, an old gateway can restart a sandbox by
156+
creating its own compatible supervisor/runtime pair through the legacy
157+
Service. It preserves unknown annotations, so the mode marker is accepted only
158+
for its recorded generation. Do not replace an individual generation's
159+
supervisor or runtime binary with one that cannot read its descriptor.
160+
106161
Each sandbox generation uses two immutable bootstrap Secrets. A trusted init
107162
container stages the sandbox bootstrap into memory, and the sandbox removes it
108163
before starting untrusted code. The other Secret is mounted only by the
109164
supervisor; when `proxy_ca_bundle` is configured it also carries the operator's
110165
corporate proxy CA bundle, which the gateway reads from its own filesystem so
111166
the anchor stays in the gateway's trust domain rather than the sandbox
112167
namespace. The TLS channel binds the namespace, Sandbox CR, workload Pod,
113-
supervisor Pod, and shared network-policy identities. Stop deletes the workload
168+
supervisor Pod, and shared network-policy identities, plus the per-sandbox
169+
control policy for `runtime-initiated` sandboxes. Stop deletes the workload
114170
and supervisor Pods. Start rotates both Secrets and creates a new supervisor
115171
Pod before releasing a new workload Pod. It also renders the trusted init
116172
container again from gateway config, so a sandbox created by an older gateway

0 commit comments

Comments
 (0)