Skip to content

Commit f1f183a

Browse files
committed
fix(podman): stage bootstrap archives at named volume destinations
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 228dc77 commit f1f183a

5 files changed

Lines changed: 140 additions & 43 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ The supervisor joins the workload's **user namespace only** to preserve UID/GID
3030
mapping for shared-volume access. PID, mount, and network namespaces remain
3131
separate. The channel volume uses shared SELinux relabeling (`:z`).
3232

33+
Before starting either container, the driver uploads volume-relative archives
34+
directly to the channel and workspace volume destinations. A rootfs upload on a
35+
stopped Podman container does not populate nested named volumes. Restart restores
36+
only the channel bootstrap into the existing channel volume, preserving the
37+
workspace. The workload starts before the supervisor so its user namespace exists
38+
when the supervisor joins it; a stopped supervisor resolves that namespace again
39+
on its next start.
40+
3341
The runtime must pass the sandbox's unprivileged enforcement probe, including
3442
nested seccomp notification and Landlock. Unsupported runtime defaults fail
3543
closed; do not switch to an unconfined profile or add capabilities.
@@ -77,7 +85,7 @@ children, never the supervisor process.
7785

7886
## Lifecycle and readiness
7987

80-
Create builds both stopped containers and stages both private archives before
88+
Create builds both stopped containers and stages the private archives before
8189
starting either container. The sandbox does not execute the agent until the
8290
supervisor authenticates and confirms the common boundary contract. Failed
8391
creation removes only containers created by that attempt, then cleans up

‎crates/openshell-driver-podman/src/client.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,17 @@ impl PodmanClient {
479479
pub(crate) async fn copy_to_container(
480480
&self,
481481
name: &str,
482+
destination: &str,
482483
archive: Vec<u8>,
483484
) -> Result<(), PodmanApiError> {
484485
validate_name(name)?;
485486
let (status, bytes) = self
486487
.request_raw(
487488
hyper::Method::PUT,
488-
&format!("/libpod/containers/{name}/archive?path=/"),
489+
&format!(
490+
"/libpod/containers/{name}/archive?path={}",
491+
url_encode(destination)
492+
),
489493
"application/x-tar",
490494
archive.into(),
491495
)

‎crates/openshell-driver-podman/src/driver.rs‎

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,14 @@ impl PodmanComputeDriver {
10191019
child_env,
10201020
)?;
10211021
self.client
1022-
.copy_to_container(&workload_id, archives.workload)
1022+
.copy_to_container(
1023+
&workload_id,
1024+
crate::isolation::CHANNEL_ROOT,
1025+
archives.channel,
1026+
)
1027+
.await?;
1028+
self.client
1029+
.copy_to_container(&workload_id, "/sandbox", archives.workspace)
10231030
.await?;
10241031
specs.supervisor.join_user_namespace(&workload_id);
10251032
let supervisor_id = self
@@ -1028,7 +1035,7 @@ impl PodmanComputeDriver {
10281035
.await?;
10291036
created_supervisor = Some(supervisor_id.clone());
10301037
self.client
1031-
.copy_to_container(&supervisor_id, archives.supervisor)
1038+
.copy_to_container(&supervisor_id, "/", archives.supervisor)
10321039
.await?;
10331040
// Both resources and private files exist before either
10341041
// container can run. Only the trusted sandbox starts here;
@@ -1315,7 +1322,9 @@ impl PodmanComputeDriver {
13151322
.await?;
13161323
let bundle =
13171324
extract_first_tar_entry(&archive).map_err(ComputeDriverError::Precondition)?;
1318-
self.client.copy_to_container(&container_id, bundle).await?;
1325+
self.client
1326+
.copy_to_container(&container_id, crate::isolation::CHANNEL_ROOT, bundle)
1327+
.await?;
13191328
self.client.verify_isolation_fence(&container_id).await?;
13201329
self.client.start_container(&container_id).await?;
13211330
if let Err(error) = self.client.start_container(&supervisor).await {
@@ -1889,6 +1898,24 @@ mod tests {
18891898
.await
18901899
.expect("start should succeed");
18911900
start_handle.await.expect("start stub should finish");
1901+
let restart_requests = start_requests.lock().unwrap().clone();
1902+
assert_eq!(
1903+
restart_requests
1904+
.iter()
1905+
.filter(|request| request.starts_with("PUT "))
1906+
.cloned()
1907+
.collect::<Vec<_>>(),
1908+
vec![format!(
1909+
"PUT {}",
1910+
api_path("/libpod/containers/ctr-1/archive?path=%2F.openshell%2Fchannel")
1911+
)]
1912+
);
1913+
assert!(
1914+
!restart_requests
1915+
.iter()
1916+
.any(|request| request.contains("/volumes/create")
1917+
|| request.contains("/containers/create"))
1918+
);
18921919
assert_eq!(
18931920
start_requests
18941921
.lock()
@@ -2037,7 +2064,7 @@ mod tests {
20372064
use tracing_subscriber::layer::SubscriberExt as _;
20382065

20392066
let _tracing_lock = openshell_otel_test_support::tracing_test_lock().await;
2040-
let (socket_path, _requests, handle) = spawn_podman_stub(
2067+
let (socket_path, requests, handle) = spawn_podman_stub(
20412068
"trace-create",
20422069
create_setup_responses(false)
20432070
.into_iter()
@@ -2057,6 +2084,22 @@ mod tests {
20572084
.await
20582085
.expect("create should succeed");
20592086
handle.await.expect("stub should finish");
2087+
let uploads: Vec<_> = requests
2088+
.lock()
2089+
.unwrap()
2090+
.iter()
2091+
.filter(|request| request.starts_with("PUT "))
2092+
.cloned()
2093+
.collect();
2094+
assert_eq!(
2095+
uploads,
2096+
[
2097+
"/libpod/containers/workload/archive?path=%2F.openshell%2Fchannel",
2098+
"/libpod/containers/workload/archive?path=%2Fsandbox",
2099+
"/libpod/containers/supervisor/archive?path=%2F",
2100+
]
2101+
.map(|path| format!("PUT {}", api_path(path)))
2102+
);
20602103
provider.force_flush().unwrap();
20612104

20622105
let spans = exporter.get_finished_spans().unwrap();
@@ -3084,7 +3127,18 @@ mod tests {
30843127

30853128
fn restart_responses() -> Vec<StubResponse> {
30863129
let mut archive = tar::Builder::new(Vec::new());
3087-
let bundle = tar::Builder::new(Vec::new()).into_inner().unwrap();
3130+
let identity = openshell_isolation_interface::contract::ResolvedWorkloadIdentity::new(
3131+
1000,
3132+
1001,
3133+
vec![],
3134+
"image".into(),
3135+
"sha256:image".into(),
3136+
)
3137+
.unwrap();
3138+
let bundle =
3139+
crate::isolation::bootstrap_archives("sandbox-1", "ctr-1", &identity, HashMap::new())
3140+
.unwrap()
3141+
.channel;
30883142
let mut header = tar::Header::new_gnu();
30893143
header.set_size(bundle.len() as u64);
30903144
header.set_mode(0o600);
@@ -3099,7 +3153,7 @@ mod tests {
30993153
r#"{"Id":"supervisor","Name":"supervisor","State":{"Status":"exited","Running":false},"Config":{}}"#,
31003154
),
31013155
StubResponse::new(StatusCode::OK, archive.into_inner().unwrap()),
3102-
StubResponse::new(StatusCode::OK, ""), // restore bootstrap
3156+
StubResponse::new(StatusCode::OK, "").with_archive_members(channel_archive_members()),
31033157
fence_response(),
31043158
StubResponse::new(StatusCode::NO_CONTENT, ""), // workload start
31053159
StubResponse::new(StatusCode::NO_CONTENT, ""), // supervisor start
@@ -3197,14 +3251,26 @@ mod tests {
31973251
vec![
31983252
created_response("workload"),
31993253
fence_response(),
3200-
StubResponse::new(StatusCode::OK, ""), // workload archive
3254+
StubResponse::new(StatusCode::OK, "").with_archive_members(channel_archive_members()),
3255+
StubResponse::new(StatusCode::OK, "").with_archive_members(&["."]),
32013256
created_response("supervisor"),
32023257
StubResponse::new(StatusCode::OK, ""), // supervisor archive
32033258
StubResponse::new(StatusCode::NO_CONTENT, ""), // workload start
32043259
StubResponse::new(StatusCode::NO_CONTENT, ""), // supervisor start
32053260
]
32063261
}
32073262

3263+
fn channel_archive_members() -> &'static [&'static str] {
3264+
&[
3265+
".",
3266+
"sandbox",
3267+
"sandbox/bootstrap.json",
3268+
"sandbox/server.crt",
3269+
"sandbox/server.key",
3270+
"sandbox/client-ca.crt",
3271+
]
3272+
}
3273+
32083274
#[tokio::test]
32093275
async fn reserved_image_control_root_fails_before_workload_or_secrets() {
32103276
let (path, requests, handle) = spawn_podman_stub(
@@ -3283,7 +3349,7 @@ mod tests {
32833349
"create-start-fail",
32843350
create_setup_responses(true)
32853351
.into_iter()
3286-
.chain(create_launch_responses().into_iter().take(6))
3352+
.chain(create_launch_responses().into_iter().take(7))
32873353
.chain([
32883354
StubResponse::new(StatusCode::INTERNAL_SERVER_ERROR, "supervisor start failed"),
32893355
StubResponse::new(StatusCode::NO_CONTENT, ""), // supervisor

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

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ pub fn resolve_identity(
122122
}
123123

124124
pub struct BootstrapArchives {
125-
pub workload: Vec<u8>,
125+
pub channel: Vec<u8>,
126+
pub workspace: Vec<u8>,
126127
pub supervisor: Vec<u8>,
127128
}
128129

@@ -194,38 +195,33 @@ pub fn bootstrap_archives(
194195
workload_identity: identity.clone(),
195196
driver_fence,
196197
};
197-
let mut workload = Archive::new(identity);
198-
workload.directory(".openshell", 0o755, false)?;
199-
workload.directory(".openshell/channel", 0o755, false)?;
200-
workload.directory(".openshell/channel/sandbox", 0o711, true)?;
201-
workload.directory("sandbox", 0o700, true)?;
202-
workload.file(
203-
BOOTSTRAP_PATH,
198+
// Libpod resolves the requested upload destination once for a stopped
199+
// container. Archive entries must be relative to the selected named volume,
200+
// not rootfs paths that the volume would shadow on container start.
201+
let mut channel = Archive::new(identity);
202+
channel.directory(".", 0o755, false)?;
203+
channel.directory("sandbox", 0o711, true)?;
204+
channel.file(
205+
"sandbox/bootstrap.json",
204206
&serde_json::to_vec(&config).map_err(invalid)?,
205207
)?;
206-
workload.file(
207-
"/.openshell/channel/sandbox/server.crt",
208-
tls.sandbox_certificate_pem.as_bytes(),
209-
)?;
210-
workload.file(
211-
"/.openshell/channel/sandbox/server.key",
212-
tls.sandbox_private_key_pem.as_bytes(),
213-
)?;
214-
workload.file(
215-
"/.openshell/channel/sandbox/client-ca.crt",
216-
tls.ca_certificate_pem.as_bytes(),
217-
)?;
218-
let workload = workload.finish()?;
208+
channel.file("sandbox/server.crt", tls.sandbox_certificate_pem.as_bytes())?;
209+
channel.file("sandbox/server.key", tls.sandbox_private_key_pem.as_bytes())?;
210+
channel.file("sandbox/client-ca.crt", tls.ca_certificate_pem.as_bytes())?;
211+
let channel = channel.finish()?;
212+
let mut workspace = Archive::new(identity);
213+
workspace.directory(".", 0o700, true)?;
219214
let mut supervisor = Archive::new(identity);
220215
supervisor.directory(".openshell", 0o755, false)?;
221216
supervisor.directory(".openshell/supervisor", 0o700, true)?;
222217
supervisor.file(
223218
TOPOLOGY_PATH,
224219
&serde_json::to_vec(&topology).map_err(invalid)?,
225220
)?;
226-
supervisor.file(RESTART_BUNDLE_PATH, &workload)?;
221+
supervisor.file(RESTART_BUNDLE_PATH, &channel)?;
227222
Ok(BootstrapArchives {
228-
workload,
223+
channel,
224+
workspace: workspace.finish()?,
229225
supervisor: supervisor.finish()?,
230226
})
231227
}
@@ -337,23 +333,28 @@ mod tests {
337333
.unwrap();
338334
let archives =
339335
bootstrap_archives("sandbox", "container", &identity, HashMap::new()).unwrap();
340-
let workload = files(&archives.workload);
336+
let workload = files(&archives.channel);
341337
let supervisor = files(&archives.supervisor);
338+
let mut workspace = tar::Archive::new(archives.workspace.as_slice());
339+
let mut entries = workspace.entries().unwrap();
340+
let root = entries.next().unwrap().unwrap();
341+
assert_eq!(root.path().unwrap().as_ref(), std::path::Path::new("."));
342+
assert!(root.header().entry_type().is_dir());
343+
assert_eq!(root.header().uid().unwrap(), u64::from(identity.uid));
344+
assert_eq!(root.header().gid().unwrap(), u64::from(identity.gid));
345+
assert_eq!(root.header().mode().unwrap(), 0o700);
346+
assert!(entries.next().is_none());
342347
assert_eq!(workload.len(), 4);
343348
assert_eq!(supervisor.len(), 2);
344-
assert!(
345-
workload
346-
.keys()
347-
.all(|path| path.starts_with(".openshell/channel/sandbox"))
348-
);
349+
assert!(workload.keys().all(|path| path.starts_with("sandbox")));
349350
assert!(
350351
supervisor
351352
.keys()
352353
.all(|path| path.starts_with(".openshell/supervisor"))
353354
);
354355
let config: BoundaryConfig = serde_json::from_slice(
355356
workload
356-
.get(&PathBuf::from(BOOTSTRAP_PATH.trim_start_matches('/')))
357+
.get(&PathBuf::from("sandbox/bootstrap.json"))
357358
.unwrap(),
358359
)
359360
.unwrap();
@@ -375,7 +376,7 @@ mod tests {
375376
supervisor
376377
.get(&PathBuf::from(RESTART_BUNDLE_PATH.trim_start_matches('/')))
377378
.unwrap(),
378-
&archives.workload
379+
&archives.channel
379380
);
380381
}
381382
}

‎crates/openshell-driver-podman/src/test_utils.rs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
//! Shared test helpers for openshell-driver-podman unit tests.
55
6-
use http_body_util::Full;
6+
use http_body_util::{BodyExt as _, Full};
77
use hyper::StatusCode;
88
use hyper::body::Bytes;
99
use hyper::server::conn::http1;
@@ -22,6 +22,7 @@ pub struct StubResponse {
2222
pub status: StatusCode,
2323
pub body: Bytes,
2424
pub delay: Duration,
25+
pub archive_members: Option<Vec<PathBuf>>,
2526
}
2627

2728
impl StubResponse {
@@ -30,13 +31,19 @@ impl StubResponse {
3031
status,
3132
body: body.into(),
3233
delay: Duration::ZERO,
34+
archive_members: None,
3335
}
3436
}
3537

3638
pub fn with_delay(mut self, delay: Duration) -> Self {
3739
self.delay = delay;
3840
self
3941
}
42+
43+
pub fn with_archive_members(mut self, members: &[&str]) -> Self {
44+
self.archive_members = Some(members.iter().map(PathBuf::from).collect());
45+
self
46+
}
4047
}
4148

4249
/// Generate a unique Unix socket path for a test.
@@ -88,7 +95,7 @@ pub fn spawn_podman_stub(
8895
let result = http1::Builder::new()
8996
.serve_connection(
9097
TokioIo::new(stream),
91-
service_fn(move |req| {
98+
service_fn(move |req: hyper::Request<hyper::body::Incoming>| {
9299
let log = log.clone();
93100
let queue = queue.clone();
94101
async move {
@@ -104,6 +111,17 @@ pub fn spawn_podman_stub(
104111
.expect("response queue lock should not be poisoned")
105112
.pop_front()
106113
.expect("stub response should exist");
114+
if let Some(expected_members) = &response.archive_members {
115+
assert_eq!(req.method(), hyper::Method::PUT);
116+
let body = req.into_body().collect().await.unwrap().to_bytes();
117+
let mut archive = tar::Archive::new(body.as_ref());
118+
let members: Vec<_> = archive
119+
.entries()
120+
.unwrap()
121+
.map(|entry| entry.unwrap().path().unwrap().into_owned())
122+
.collect();
123+
assert_eq!(&members, expected_members);
124+
}
107125
tokio::time::sleep(response.delay).await;
108126
Ok::<_, Infallible>(
109127
hyper::Response::builder()

0 commit comments

Comments
 (0)