Skip to content

Commit 272a2b3

Browse files
fix(podman): use container filesystem for image workdirs
Signed-off-by: Matthew Grossman <[email protected]>
1 parent 93c61b0 commit 272a2b3

6 files changed

Lines changed: 43 additions & 45 deletions

File tree

‎architecture/compute-runtimes.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,10 @@ resolved identity.
430430
Podman reads the image user and working directory from one pinned image. Empty,
431431
`/`, and explicit `/sandbox` values use the managed `/sandbox` workspace. A
432432
custom path must be absolute, normalized, and outside system and OpenShell
433-
reserved paths. Image and driver mounts cannot cover the workspace. Podman
434-
mounts the persistent workspace volume there and copies any existing image
435-
files into it on first use. OpenShell preserves their ownership and permissions;
436-
the final non-root user must be able to write the resulting workspace.
433+
reserved paths. Image and driver mounts cannot cover the workspace. Custom
434+
paths use the image's container filesystem directly; the final non-root user
435+
must be able to write the existing directory. The managed `/sandbox` fallback
436+
uses a driver-owned workspace volume.
437437
Kubernetes and VM use `/sandbox`.
438438

439439
### Executable Identity Binding

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ The supervisor joins the workload's **user namespace only** to preserve UID/GID
3737
mapping for shared-volume access. PID, mount, and network namespaces remain
3838
separate. The channel volume uses shared SELinux relabeling (`:z`).
3939

40-
Before starting either container, the driver uploads volume-relative archives
41-
directly to the channel and workspace volume destinations. A rootfs upload on a
42-
stopped Podman container does not populate nested named volumes. Restart restores
43-
only the channel bootstrap into the existing channel volume, preserving the
44-
workspace. The workload starts before the supervisor so its user namespace exists
45-
when the supervisor joins it; a stopped supervisor resolves that namespace again
46-
on its next start.
40+
Before starting either container, the driver uploads bootstrap files to the
41+
channel volume. For managed `/sandbox`, it also prepares the workspace volume;
42+
custom image workspaces need no upload. Restart restores only the channel
43+
bootstrap, preserving the workspace. The workload starts before the supervisor
44+
so its user namespace exists when the supervisor joins it; a stopped supervisor
45+
resolves that namespace again on its next start.
4746

4847
The runtime must pass the sandbox's unprivileged enforcement probe, including
4948
nested seccomp notification and Landlock. Unsupported runtime defaults fail
@@ -100,16 +99,15 @@ mounts. For a custom path, image volumes and driver mounts cannot cover the
10099
workspace or one of its parents; mounts nested below it remain valid. Podman
101100
creates a private volume for each image-declared path nested below it.
102101

103-
For a custom path, Podman mounts a persistent workspace volume there. When the
104-
volume is first created, Podman copies any files already in that image directory
105-
into it. OpenShell keeps their ownership and permissions, starts as the final
106-
non-root user, and rejects the image if that user cannot reach and write the
107-
directory. Agent commands use the path as their working directory;
102+
For a custom path, Podman uses the image's container filesystem directly.
103+
OpenShell keeps the image directory's ownership and permissions, starts as the
104+
final non-root user, and rejects the image if that user cannot reach and write
105+
the directory. Agent commands use the path as their working directory;
108106
`filesystem.include_workdir` grants access to it when enabled.
109107

110-
For `/sandbox`, OpenShell prepares the managed workspace before switching to
111-
the non-root user. The separate supervisor receives the path but does not mount
112-
the workspace. Test custom images with the Podman configuration you will use.
108+
For `/sandbox`, OpenShell creates a workspace volume and prepares it before
109+
switching to the non-root user. The separate supervisor receives the path but
110+
does not mount the workspace.
113111

114112
## Lifecycle and readiness
115113

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,11 +1257,14 @@ fn build_base_spec(
12571257
let mut networks = BTreeMap::new();
12581258
networks.insert(config.network_name.clone(), NetworkAttachment {});
12591259

1260-
let mut volumes = vec![NamedVolume {
1261-
name: vol,
1262-
dest: image.workspace_root.clone(),
1263-
options: vec!["rw".into()],
1264-
}];
1260+
let mut volumes = Vec::new();
1261+
if image.uses_managed_workspace() {
1262+
volumes.push(NamedVolume {
1263+
name: vol,
1264+
dest: image.workspace_root.clone(),
1265+
options: vec!["rw".into()],
1266+
});
1267+
}
12651268
volumes.extend(user_mounts.volumes);
12661269

12671270
let mut image_volumes = if supervisor_bin_path.is_some() {
@@ -2303,12 +2306,7 @@ mod tests {
23032306
container["command"],
23042307
serde_json::json!(["--workdir", "/workspace/project"])
23052308
);
2306-
assert!(container["volumes"].as_array().is_some_and(|volumes| {
2307-
volumes.iter().any(|volume| {
2308-
volume["name"].as_str() == Some("openshell-sandbox-test-id-workspace")
2309-
&& volume["dest"].as_str() == Some("/workspace/project")
2310-
})
2311-
}));
2309+
assert!(container["volumes"].as_array().is_some_and(Vec::is_empty));
23122310
assert_eq!(
23132311
container["env"][openshell_core::sandbox_env::OCI_IMAGE_USER].as_str(),
23142312
Some("app:staff")

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ impl PodmanComputeDriver {
10041004
otel.status_code = tracing::field::Empty,
10051005
))
10061006
.await?;
1007+
let managed_workspace = resolved_image.uses_managed_workspace();
10071008

10081009
// Fail closed on a missing/unreadable corporate proxy CA bundle before
10091010
// creating any resources, so the operator gets a clear error
@@ -1042,14 +1043,16 @@ impl PodmanComputeDriver {
10421043
));
10431044
}
10441045

1045-
// Create the workspace volume and per-sandbox runtime files.
1046+
// Create the managed workspace volume, if needed, and runtime files.
10461047
let (resolver_secret_name, token_secret_name, proxy_auth_secret_name) = async {
10471048
let phase_status = openshell_otel::ErrorStatusGuard::current();
10481049
let result = async {
1049-
self.client
1050-
.create_owned_volume(&vol_name, &sandbox.id, &sandbox.workspace)
1051-
.await
1052-
.map_err(ComputeDriverError::from)?;
1050+
if managed_workspace {
1051+
self.client
1052+
.create_owned_volume(&vol_name, &sandbox.id, &sandbox.workspace)
1053+
.await
1054+
.map_err(ComputeDriverError::from)?;
1055+
}
10531056
let resolver_secret_name =
10541057
match create_sandbox_resolver_secret(&self.client, &sandbox.id).await {
10551058
Ok(name) => name,
@@ -1231,7 +1234,7 @@ impl PodmanComputeDriver {
12311234
archives.channel,
12321235
)
12331236
.await?;
1234-
if resolved_image.uses_managed_workspace() {
1237+
if managed_workspace {
12351238
self.client
12361239
.copy_to_container(
12371240
&workload_id,

‎docs/how-it-works/sandboxes/runtimes.mdx‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ On Docker, the image's `WORKDIR` becomes the workspace. Images with no `WORKDIR`
272272
Podman also uses the image's `WORKDIR` as the workspace, falling back to
273273
`/sandbox` for an empty, `/`, or `/sandbox` value. A custom path must be an
274274
absolute, normalized path outside system and OpenShell-reserved paths.
275-
Image volumes and driver mounts cannot cover it. Podman mounts the persistent
276-
workspace volume there and copies existing image-directory files into a new
277-
volume. OpenShell preserves their permissions and requires the final non-root
278-
user to be able to write there. Kubernetes and MicroVM continue to use
279-
`/sandbox`.
275+
Image volumes and driver mounts cannot cover it. Podman uses the image's
276+
container filesystem directly and requires the final non-root user to be able
277+
to write the existing directory. The managed `/sandbox` fallback uses a
278+
workspace volume. Kubernetes and MicroVM continue to use `/sandbox`.

‎e2e/rust/tests/podman_oci_identity.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#![cfg(feature = "e2e-podman")]
55

66
//! Podman-specific E2E coverage for OCI identity/workspace inspection,
7-
//! workspace-volume copy-up, and immutable-image launch.
7+
//! direct image-workspace access, and immutable-image launch.
88
//!
99
//! The test builds an image through the selected Podman engine, creates a
10-
//! sandbox from its mutable tag, and verifies the child identity, copied image
10+
//! sandbox from its mutable tag, and verifies the child identity, image
1111
//! content, workspace placement, and image ID recorded on the real sandbox
1212
//! container.
1313
@@ -184,7 +184,7 @@ fn normalized_image_id(image_id: &str) -> &str {
184184
}
185185

186186
#[tokio::test]
187-
async fn podman_uses_oci_identity_workspace_copy_up_and_inspected_image_id() {
187+
async fn podman_uses_oci_identity_image_workdir_and_inspected_image_id() {
188188
if !is_e2e_driver("podman") {
189189
eprintln!("Skipping Podman OCI identity test: e2e driver is not podman");
190190
return;
@@ -316,7 +316,7 @@ async fn assert_isolated_pair(image: &ImageGuard, sandbox: &SandboxGuard, contai
316316
.unwrap();
317317
assert!(!mounts.contains("/etc/openshell/tls"));
318318
assert!(!mounts.contains("/.openshell/supervisor"));
319-
assert!(mounts.lines().any(|path| path == "/home/app/project"));
319+
assert!(!mounts.lines().any(|path| path == "/home/app/project"));
320320
assert!(mounts.lines().any(|path| path == "/home/app/project/cache"));
321321
assert!(!mounts.lines().any(|path| path == "/sandbox"));
322322
let posture = sandbox.exec(&["sh", "-c", "set -eu; awk '/^CapEff:|^CapBnd:|^NoNewPrivs:/ {print}' /proc/self/status; test ! -r /.openshell/channel/sandbox/server.key; test ! -r /.openshell/supervisor/runtime-descriptor.json"]).await.expect("workload cannot read either control credential set");

0 commit comments

Comments
 (0)