Skip to content

Commit 1fff8b9

Browse files
feat(podman): honor OCI image working directories (#3982)
* fix(supervisor): report rejected OCI working directories as WorkspaceValidationFailed The RFC 0012 split dropped the supervisor exit status that drivers map to the WorkspaceValidationFailed condition. An image WORKDIR the sandbox identity cannot use then surfaced as ControlSupervisorStartFailed on Docker and as a signal kill on Podman. The supervisor now exits with the reserved status when the sandbox rejects the image working directory. Docker maps that supervisor exit during readiness and monitoring, and Podman maps the supervisor companion's exit instead of the workload's. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com> * feat(podman): honor OCI image working directories Podman sandboxes now use a custom OCI image WORKDIR as the workspace and as the working directory for agent commands, matching Docker. Empty, /, and /sandbox values keep the managed /sandbox workspace volume. A custom workspace stays in the image's container filesystem: no workspace volume, no archive upload, and no root setup step. Resolve the image ID, user, environment, and working directory from one pinned inspection, validate the workdir with the shared OCI rules, and reject Podman control-path overlaps and image volumes or driver mounts that cover it. The runtime starts from / and passes the resolved path to agent commands with --workdir. Add podman_oci_identity to the Podman CI test list. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com> * fix(drivers): preserve custom workspace failures across supervisor cleanup Check the Podman custom workspace rather than the absent managed volume in the OCI identity E2E. Classify Bollard wait errors by exit code and record Docker workspace failures before removing the supervisor so readiness retains the specific failure reason. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com> * fix(docker): use sandbox ID for recorded startup failures Keep the workload container ID for Docker inspection and use the sandbox ID to retrieve the monitor failure. Test with distinct identifiers so the lookup cannot accidentally pass with a container ID. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com> * refactor(podman): keep WORKDIR change focused on workspace behavior Remove the new cross-driver workspace failure classification path and its monitor/readiness workaround. Preserve Podman WORKDIR resolution, mount safety, and workspace rejection without requiring a distinct condition reason. Signed-off-by: Matthew Grossman <mgrossman@nvidia.com> * refactor(podman): simplify inspected image metadata and test fixtures Signed-off-by: Matthew Grossman <mgrossman@nvidia.com> * code review Signed-off-by: Matthew Grossman <mgrossman@nvidia.com> --------- Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent e406c2b commit 1fff8b9

10 files changed

Lines changed: 445 additions & 121 deletions

File tree

‎crates/openshell-core/src/driver_mounts.rs‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,25 @@ pub fn validate_workspace_mount_target(target: &str, workspace_root: &str) -> Re
207207
Ok(())
208208
}
209209

210+
/// Validate mount targets against a workspace and driver-specific control paths.
211+
///
212+
/// Targets must already pass container mount-target validation. This check
213+
/// applies regardless of their native mount type. Mounts below the workspace
214+
/// remain valid; control paths reject overlaps in either direction.
215+
pub fn validate_workspace_mount_targets<'a>(
216+
targets: impl IntoIterator<Item = &'a str>,
217+
workspace_root: &str,
218+
control_paths: &[&str],
219+
) -> Result<(), String> {
220+
for target in targets {
221+
validate_workspace_mount_target(target, workspace_root)?;
222+
for control_path in control_paths {
223+
validate_mount_control_path(target, control_path)?;
224+
}
225+
}
226+
Ok(())
227+
}
228+
210229
/// Normalize a validated container-side mount target for semantic comparison.
211230
pub fn normalize_mount_target(target: &str) -> String {
212231
if target == "/" {
@@ -244,6 +263,44 @@ mod tests {
244263
validate_workspace_mount_target("/workspace-other", "/workspace/project").unwrap();
245264
}
246265

266+
#[test]
267+
fn workspace_mount_targets_allow_empty_and_nested_targets() {
268+
validate_workspace_mount_targets([], "/workspace", &["/.openshell"]).unwrap();
269+
validate_workspace_mount_targets(
270+
["/workspace/cache", "/workspace/data", "/workspace-other"],
271+
"/workspace",
272+
&["/.openshell"],
273+
)
274+
.unwrap();
275+
}
276+
277+
#[test]
278+
fn workspace_mount_targets_reject_covering_mounts_and_control_paths() {
279+
for target in ["/workspace/project/", "/workspace"] {
280+
let error = validate_workspace_mount_targets(
281+
["/workspace/project/cache", target],
282+
"/workspace/project",
283+
&["/.openshell"],
284+
)
285+
.unwrap_err();
286+
assert!(error.contains("reserved for the OpenShell workspace"));
287+
}
288+
for target in [
289+
"/.openshell",
290+
"/.openshell/channel",
291+
"/custom",
292+
"/custom/socket",
293+
] {
294+
let error = validate_workspace_mount_targets(
295+
["/workspace/cache", target],
296+
"/workspace",
297+
&["/.openshell", "/custom/socket"],
298+
)
299+
.unwrap_err();
300+
assert!(error.contains("conflicts with OpenShell control path"));
301+
}
302+
}
303+
247304
#[test]
248305
fn oci_workspace_root_uses_fallback_and_accepts_normalized_absolute_paths() {
249306
assert_eq!(resolve_oci_workspace_root("").unwrap(), "/sandbox");

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5701,18 +5701,21 @@ fn build_container_create_body_for_image(
57015701
driver_mounts::validate_mount_control_path(volume, BOUNDARY_MOUNT_PATH)
57025702
.map_err(Status::failed_precondition)?;
57035703
}
5704-
for mount in &driver_config.mounts {
5705-
let target = match mount {
5704+
let mount_targets = driver_config.mounts.iter().map(|mount| {
5705+
match mount {
57065706
DockerDriverMountConfig::Bind { target, .. }
57075707
| DockerDriverMountConfig::Volume { target, .. }
57085708
| DockerDriverMountConfig::Tmpfs { target, .. }
57095709
| DockerDriverMountConfig::Image { target, .. } => target,
5710-
};
5711-
driver_mounts::validate_workspace_mount_target(target, &workspace_root)
5712-
.map_err(Status::failed_precondition)?;
5713-
driver_mounts::validate_mount_control_path(target, BOUNDARY_MOUNT_PATH)
5714-
.map_err(Status::failed_precondition)?;
5715-
}
5710+
}
5711+
.as_str()
5712+
});
5713+
driver_mounts::validate_workspace_mount_targets(
5714+
mount_targets,
5715+
&workspace_root,
5716+
&[BOUNDARY_MOUNT_PATH],
5717+
)
5718+
.map_err(Status::failed_precondition)?;
57165719
let mut user_mounts = docker_driver_mounts(driver_config)?;
57175720
user_mounts.push(Mount {
57185721
target: Some(BOUNDARY_MOUNT_PATH.to_string()),

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ only the channel bootstrap into the existing channel volume, preserving the
4444
workspace. The workload starts before the supervisor so its user namespace exists
4545
when the supervisor joins it; a stopped supervisor resolves that namespace again
4646
on its next start. The driver creates the managed workspace volume owned by
47-
the workload's final UID and GID, so the workload never starts as root.
47+
the workload's final UID and GID, so the workload never starts as root. Custom
48+
image workspaces have no workspace volume or upload.
4849

4950
The runtime must pass the sandbox's unprivileged enforcement probe, including
5051
nested seccomp notification and Landlock. Unsupported runtime defaults fail
@@ -92,6 +93,24 @@ binary extraction path. `supervisor_image` supplies the dynamically linked
9293
glibc `/openshell-supervisor` binary outside the workload. Image and request
9394
environment belong to agent children, never the supervisor process.
9495

96+
## OCI working directory
97+
98+
OpenShell reads `WORKDIR` from the workload image. If it is unset, `/`, or
99+
`/sandbox`, OpenShell uses its managed `/sandbox` workspace volume. A custom
100+
path must be absolute and normalized, and cannot overlap `/proc`, `/sys`,
101+
`/dev`, OpenShell-reserved paths, or the workload's private control and CA
102+
mounts. Image volumes and driver mounts cannot cover it; mounts nested below it
103+
remain valid.
104+
105+
A custom path stays in the image's container filesystem with its ownership and
106+
permissions. The workload starts as the final non-root user, which must be able
107+
to reach and write the directory. Agent commands use the path as their working
108+
directory.
109+
110+
Custom workspace contents survive stop/start of the same workload container,
111+
but are removed with that container. They do not live in a managed named volume
112+
and are not copied to a replacement container.
113+
95114
## Lifecycle and readiness
96115

97116
Create builds both stopped containers and stages the private archives before

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ pub struct ImageInspect {
181181
}
182182

183183
#[derive(Debug, Clone, Default, serde::Deserialize)]
184-
#[serde(rename_all = "PascalCase")]
184+
#[serde(default, rename_all = "PascalCase")]
185185
pub struct ImageConfig {
186-
#[serde(default)]
187186
pub user: String,
188-
#[serde(default)]
189187
pub env: Vec<String>,
188+
pub working_dir: String,
189+
pub volumes: Option<HashMap<String, Value>>,
190190
}
191191

192192
/// A container summary returned by the list API.
@@ -1284,13 +1284,28 @@ mod tests {
12841284
}
12851285
}
12861286

1287+
#[test]
1288+
fn image_config_defaults_missing_oci_fields() {
1289+
let empty: ImageConfig = serde_json::from_str("{}").unwrap();
1290+
assert!(empty.user.is_empty());
1291+
assert!(empty.env.is_empty());
1292+
assert!(empty.working_dir.is_empty());
1293+
assert!(empty.volumes.is_none());
1294+
1295+
let partial: ImageConfig = serde_json::from_str(r#"{"User":"app:staff"}"#).unwrap();
1296+
assert_eq!(partial.user, "app:staff");
1297+
assert!(partial.env.is_empty());
1298+
assert!(partial.working_dir.is_empty());
1299+
assert!(partial.volumes.is_none());
1300+
}
1301+
12871302
#[tokio::test]
1288-
async fn inspect_image_reads_immutable_id_and_oci_user() {
1303+
async fn inspect_image_reads_immutable_id_and_oci_config() {
12891304
let (socket_path, request_log, handle) = spawn_podman_stub(
12901305
"inspect-image",
12911306
vec![StubResponse::new(
12921307
StatusCode::OK,
1293-
r#"{"Id":"sha256:immutable","Config":{"User":"app:staff"}}"#,
1308+
r#"{"Id":"sha256:immutable","Config":{"User":"app:staff","Env":["A=one"],"WorkingDir":"/workspace/project","Volumes":{"/workspace/project/cache":{}}}}"#,
12941309
)],
12951310
);
12961311
let client = PodmanClient::new(socket_path.clone());
@@ -1301,9 +1316,15 @@ mod tests {
13011316
.expect("image inspect should parse");
13021317

13031318
assert_eq!(image.id, "sha256:immutable");
1304-
assert_eq!(
1305-
image.config.as_ref().map(|config| config.user.as_str()),
1306-
Some("app:staff")
1319+
let config = image.config.expect("fixture image config");
1320+
assert_eq!(config.user, "app:staff");
1321+
assert_eq!(config.env, vec!["A=one"]);
1322+
assert_eq!(config.working_dir, "/workspace/project");
1323+
assert!(
1324+
config
1325+
.volumes
1326+
.as_ref()
1327+
.is_some_and(|volumes| volumes.contains_key("/workspace/project/cache"))
13071328
);
13081329
handle.await.expect("stub task should finish");
13091330
assert_eq!(

0 commit comments

Comments
 (0)