Skip to content

Commit b0041e4

Browse files
committed
fix(docker): stage reverse control socket for the supervisor identity
Signed-off-by: Drew Newberry <[email protected]>
1 parent 32ced96 commit b0041e4

2 files changed

Lines changed: 73 additions & 50 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ LSM decisions remain authoritative.
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/control.sock`.
115+
New containers dial the supervisor at `/.openshell/channel/control/supervisor/control.sock`.
116116
The runtime remains the TLS/gRPC server; the supervisor verifies its pinned
117117
identity and supplies the existing bearer credential. Saved descriptors retain
118118
the legacy Unix listener for existing containers, including across restart.

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

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ 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";
110110
const BOUNDARY_CONTROL_MOUNT_PATH: &str = "/.openshell/channel/control";
111-
const BOUNDARY_SOCKET_MOUNT_PATH: &str = "/.openshell/channel/control/control.sock";
111+
const BOUNDARY_SOCKET_MOUNT_PATH: &str = "/.openshell/channel/control/supervisor/control.sock";
112112
const BOUNDARY_CERTIFICATE_MOUNT_PATH: &str = "/.openshell/channel/sandbox/server.crt";
113113
const BOUNDARY_PRIVATE_KEY_MOUNT_PATH: &str = "/.openshell/channel/sandbox/server.key";
114114
const SUPERVISOR_STATE_MOUNT_PATH: &str = "/.openshell/supervisor";
@@ -4577,35 +4577,6 @@ async fn stage_docker_sandbox_bundle(
45774577
)
45784578
.await
45794579
.map_err(|error| Status::internal(format!("stage Docker sandbox bundle: {error}")))?;
4580-
let bootstrap: BoundaryConfig = serde_json::from_slice(boundary_config)
4581-
.map_err(|error| Status::internal(format!("decode Docker sandbox bootstrap: {error}")))?;
4582-
if matches!(
4583-
bootstrap.listener,
4584-
openshell_sandbox_backend::boundary_protocol::BoundaryListener::RuntimeInitiatedUnix { .. }
4585-
) {
4586-
// Docker resolves an archive destination to one volume. Initialize the
4587-
// nested socket volume directly instead of writing into its shadowed
4588-
// mountpoint in the read-only bootstrap volume.
4589-
let mut archive = tar::Builder::new(Vec::new());
4590-
append_docker_archive_directory(&mut archive, ".", 0o711, SUPERVISOR_UID, SUPERVISOR_GID)?;
4591-
let bytes = archive
4592-
.into_inner()
4593-
.map_err(|error| Status::internal(format!("finish control volume archive: {error}")))?;
4594-
let options = UploadToContainerOptionsBuilder::default()
4595-
.path(BOUNDARY_CONTROL_MOUNT_PATH)
4596-
.copy_uidgid("true")
4597-
.build();
4598-
docker
4599-
.upload_to_container(
4600-
container_id,
4601-
Some(options),
4602-
bollard::body_full(Bytes::from(bytes)),
4603-
)
4604-
.await
4605-
.map_err(|error| {
4606-
Status::internal(format!("stage Docker control socket volume: {error}"))
4607-
})?;
4608-
}
46094580
Ok(())
46104581
}
46114582

@@ -5019,6 +4990,32 @@ async fn stage_docker_supervisor_bundle(
50194990
Some(RemoveContainerOptionsBuilder::default().force(true).build()),
50204991
)
50214992
.await;
4993+
let runtime_initiated = read_docker_runtime_descriptor(&sandbox.id, config).await?
4994+
.is_some_and(|descriptor| matches!(descriptor.transport, openshell_sandbox_backend::boundary_protocol::SandboxTransport::RuntimeInitiatedUnix { .. }));
4995+
let mut mounts = vec![Mount {
4996+
target: Some(SUPERVISOR_STATE_MOUNT_PATH.to_string()),
4997+
source: Some(docker_supervisor_volume_name(sandbox, config)),
4998+
typ: Some(MountTypeEnum::VOLUME),
4999+
read_only: Some(false),
5000+
volume_options: Some(MountVolumeOptions {
5001+
no_copy: Some(true),
5002+
..Default::default()
5003+
}),
5004+
..Default::default()
5005+
}];
5006+
if runtime_initiated {
5007+
mounts.push(Mount {
5008+
target: Some(BOUNDARY_CONTROL_MOUNT_PATH.to_string()),
5009+
source: Some(docker_control_volume_name_by_id(&sandbox.id, config)),
5010+
typ: Some(MountTypeEnum::VOLUME),
5011+
read_only: Some(false),
5012+
volume_options: Some(MountVolumeOptions {
5013+
no_copy: Some(true),
5014+
..Default::default()
5015+
}),
5016+
..Default::default()
5017+
});
5018+
}
50225019
let created = docker
50235020
.create_container(
50245021
Some(
@@ -5040,17 +5037,7 @@ async fn stage_docker_supervisor_bundle(
50405037
)),
50415038
host_config: Some(HostConfig {
50425039
network_mode: Some("none".to_string()),
5043-
mounts: Some(vec![Mount {
5044-
target: Some(SUPERVISOR_STATE_MOUNT_PATH.to_string()),
5045-
source: Some(docker_supervisor_volume_name(sandbox, config)),
5046-
typ: Some(MountTypeEnum::VOLUME),
5047-
read_only: Some(false),
5048-
volume_options: Some(MountVolumeOptions {
5049-
no_copy: Some(true),
5050-
..Default::default()
5051-
}),
5052-
..Default::default()
5053-
}]),
5040+
mounts: Some(mounts),
50545041
cap_drop: Some(vec!["ALL".to_string()]),
50555042
security_opt: Some(vec!["no-new-privileges:true".to_string()]),
50565043
..Default::default()
@@ -5068,14 +5055,50 @@ async fn stage_docker_supervisor_bundle(
50685055
.path(SUPERVISOR_STATE_MOUNT_PATH)
50695056
.copy_uidgid("true")
50705057
.build();
5071-
let result = docker
5072-
.upload_to_container(
5073-
&created.id,
5074-
Some(options),
5075-
bollard::body_full(Bytes::from(archive)),
5076-
)
5077-
.await
5078-
.map_err(|error| Status::internal(format!("stage Docker supervisor bundle: {error}")));
5058+
let result: Result<(), Status> = async {
5059+
docker
5060+
.upload_to_container(
5061+
&created.id,
5062+
Some(options),
5063+
bollard::body_full(Bytes::from(archive)),
5064+
)
5065+
.await
5066+
.map_err(|error| {
5067+
Status::internal(format!("stage Docker supervisor bundle: {error}"))
5068+
})?;
5069+
if runtime_initiated {
5070+
// Initialize the socket volume using the supervisor's staging user.
5071+
// Docker preserves the existing volume root's ownership, so use
5072+
// a child directory created by the supervisor's staging user.
5073+
let mut archive = tar::Builder::new(Vec::new());
5074+
append_docker_archive_directory(
5075+
&mut archive,
5076+
"supervisor",
5077+
0o711,
5078+
SUPERVISOR_UID,
5079+
SUPERVISOR_GID,
5080+
)?;
5081+
let bytes = archive.into_inner().map_err(|error| {
5082+
Status::internal(format!("finish control socket archive: {error}"))
5083+
})?;
5084+
let options = UploadToContainerOptionsBuilder::default()
5085+
.path(BOUNDARY_CONTROL_MOUNT_PATH)
5086+
.copy_uidgid("true")
5087+
.build();
5088+
docker
5089+
.upload_to_container(
5090+
&created.id,
5091+
Some(options),
5092+
bollard::body_full(Bytes::from(bytes)),
5093+
)
5094+
.await
5095+
.map_err(|error| {
5096+
Status::internal(format!("stage Docker control socket volume: {error}"))
5097+
})?;
5098+
}
5099+
Ok(())
5100+
}
5101+
.await;
50795102
let cleanup = docker
50805103
.remove_container(
50815104
&created.id,

0 commit comments

Comments
 (0)