Skip to content

Commit a184d8a

Browse files
committed
feat(docker): launch capability-free sandbox containers
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent ded80b2 commit a184d8a

16 files changed

Lines changed: 3255 additions & 1591 deletions

‎Cargo.lock‎

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

‎crates/openshell-driver-docker/Cargo.toml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ path = "src/main.rs"
1616

1717
[dependencies]
1818
openshell-core = { path = "../openshell-core", default-features = false, features = ["driver-extraction"] }
19+
openshell-isolation-interface = { path = "../openshell-isolation-interface" }
1920
openshell-otel = { path = "../openshell-otel" }
2021

2122
opentelemetry = { workspace = true }
@@ -38,15 +39,19 @@ miette = { workspace = true }
3839
toml = { workspace = true }
3940
tower-http = { workspace = true }
4041
http = { workspace = true }
42+
rand = { workspace = true }
43+
sha2 = { workspace = true }
44+
rustix = { workspace = true }
45+
libc = "0.2"
46+
tar = "0.4"
47+
tempfile = "3"
4148

4249
[dev-dependencies]
4350
openshell-otel-test-support = { path = "../openshell-otel-test-support" }
4451
opentelemetry = { workspace = true }
4552
opentelemetry_sdk = { workspace = true, features = ["testing"] }
4653
prost-types = { workspace = true }
47-
tar = "0.4"
4854
temp-env = "0.3"
49-
tempfile = "3"
5055
tracing-subscriber = { workspace = true }
5156

5257
[lints]

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

Lines changed: 112 additions & 164 deletions
Large diffs are not rendered by default.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Docker provisioning for the shared authenticated boundary protocol.
5+
//!
6+
//! Docker owns only the container/socket topology and immutable OCI resource
7+
//! claims. Lifecycle, process, network, identity, and wire behavior live in
8+
//! `openshell-isolation-interface` and `openshell-sandbox`.
9+
10+
use std::collections::{BTreeMap, HashMap};
11+
use std::net::IpAddr;
12+
use std::path::PathBuf;
13+
14+
use openshell_isolation_interface::boundary_protocol::{
15+
BoundaryClientTls, BoundaryConfig, BoundaryListener, BoundaryServerTls, BoundaryTopology,
16+
BoundaryTransport,
17+
};
18+
use openshell_isolation_interface::contract::{DriverFenceEvidence, ResolvedWorkloadIdentity};
19+
20+
/// Driver-owned inputs that bind one Docker container to one boundary.
21+
pub struct DockerBoundarySpec {
22+
pub boundary_id: String,
23+
pub bootstrap_token: String,
24+
pub generation: String,
25+
pub session_epoch: String,
26+
pub container_id: String,
27+
pub image_identity: String,
28+
pub listener_socket: PathBuf,
29+
pub control_socket: PathBuf,
30+
pub sandbox_tls: BoundaryServerTls,
31+
pub supervisor_tls: BoundaryClientTls,
32+
pub host_gateway_ip: Option<IpAddr>,
33+
pub workload_identity: ResolvedWorkloadIdentity,
34+
pub child_env: HashMap<String, String>,
35+
}
36+
37+
/// Protected container config and matching host descriptor.
38+
pub struct DockerBoundaryProvisioning {
39+
pub boundary_config: BoundaryConfig,
40+
pub topology: BoundaryTopology,
41+
}
42+
43+
impl DockerBoundarySpec {
44+
/// Produce both sides of the common protocol from the same immutable
45+
/// Docker coordinates so attach cannot bind a different container.
46+
#[must_use]
47+
pub fn provision(self) -> DockerBoundaryProvisioning {
48+
let resource_claims = BTreeMap::from([
49+
("docker.container_id".to_string(), self.container_id),
50+
("docker.image_identity".to_string(), self.image_identity),
51+
]);
52+
let driver_fence = DriverFenceEvidence::Docker {
53+
container_id: resource_claims["docker.container_id"].clone(),
54+
network_mode: "none".to_string(),
55+
unexpected_networks: Vec::new(),
56+
};
57+
DockerBoundaryProvisioning {
58+
boundary_config: BoundaryConfig {
59+
boundary_id: self.boundary_id.clone(),
60+
generation: self.generation.clone(),
61+
session_epoch: self.session_epoch.clone(),
62+
bootstrap_token: self.bootstrap_token.clone(),
63+
listener: BoundaryListener::Unix {
64+
socket_path: self.listener_socket,
65+
tls: self.sandbox_tls,
66+
},
67+
resource_claims: resource_claims.clone(),
68+
resource_claim_files: BTreeMap::new(),
69+
workload_identity: self.workload_identity.clone(),
70+
driver_fence: driver_fence.clone(),
71+
child_env: self.child_env,
72+
},
73+
topology: BoundaryTopology {
74+
boundary_id: self.boundary_id,
75+
generation: self.generation,
76+
session_epoch: self.session_epoch,
77+
workload_identity: self.workload_identity,
78+
transport: BoundaryTransport::Unix {
79+
socket_path: self.control_socket,
80+
tls: self.supervisor_tls,
81+
},
82+
host_gateway_ip: self.host_gateway_ip,
83+
resource_claims,
84+
driver_fence,
85+
bootstrap_token: self.bootstrap_token,
86+
},
87+
}
88+
}
89+
}
90+
91+
#[cfg(test)]
92+
mod tests {
93+
use super::*;
94+
95+
#[test]
96+
fn provisioning_binds_container_and_image_claims() {
97+
let tls = openshell_isolation_interface::boundary_protocol::generate_boundary_mutual_tls_material()
98+
.unwrap();
99+
let provisioned = DockerBoundarySpec {
100+
boundary_id: "sandbox-1".to_string(),
101+
bootstrap_token: "a".repeat(64),
102+
generation: "generation-1".to_string(),
103+
session_epoch: "epoch-1".to_string(),
104+
container_id: "sha256:container".to_string(),
105+
image_identity: "sha256:image".to_string(),
106+
listener_socket: PathBuf::from("/run/openshell/boundary/control.sock"),
107+
control_socket: PathBuf::from("/host/control.sock"),
108+
sandbox_tls: BoundaryServerTls {
109+
certificate_chain_path: PathBuf::from("/run/openshell/boundary/server.crt"),
110+
private_key_path: PathBuf::from("/run/openshell/boundary/server.key"),
111+
client_ca_certificate_path: PathBuf::from("/run/openshell/boundary/client-ca.crt"),
112+
},
113+
supervisor_tls: BoundaryClientTls {
114+
server_name: tls.server_name,
115+
ca_certificate_pem: tls.ca_certificate_pem,
116+
certificate_chain_pem: tls.supervisor_certificate_pem,
117+
private_key_pem: tls.supervisor_private_key_pem,
118+
},
119+
host_gateway_ip: Some(IpAddr::from([127, 0, 0, 1])),
120+
workload_identity: ResolvedWorkloadIdentity::new(
121+
1000,
122+
1000,
123+
Vec::new(),
124+
"image".to_string(),
125+
"sha256:image".to_string(),
126+
)
127+
.unwrap(),
128+
child_env: HashMap::new(),
129+
}
130+
.provision();
131+
132+
assert_eq!(
133+
provisioned.boundary_config.resource_claims,
134+
provisioned.topology.resource_claims
135+
);
136+
assert_eq!(
137+
provisioned.topology.resource_claims["docker.container_id"],
138+
"sha256:container"
139+
);
140+
assert_eq!(
141+
provisioned.boundary_config.driver_fence,
142+
provisioned.topology.driver_fence
143+
);
144+
assert!(
145+
provisioned
146+
.topology
147+
.driver_fence
148+
.validate_for_backend("docker")
149+
.is_ok()
150+
);
151+
}
152+
}

0 commit comments

Comments
 (0)