Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/openshell-driver-podman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ supplementary groups. Root and unresolved identities fail before provisioning.
Images must not prepopulate the reserved `/.openshell` hierarchy; this prevents
image-controlled symlinks from aliasing private control state into user mounts.

The sandbox requires the workload's supplementary groups to equal the resolved
identity. The driver relaxes that to "must include the resolved groups" only
when a GPU or CDI device is requested (CDI `containerEdits.additionalGids` adds
groups at container creation) or the user namespace is `keep-id`. Extra groups
may extend but never replace the image-derived identity. The claim is persisted
in the restart metadata so restarts keep it.

`sandbox_runtime_image` supplies the statically linked musl
`/openshell-sandbox` binary. Podman's read-only image volume delivers it to the
workload; user-namespace modes that cannot use image volumes retain the trusted
Expand Down
7 changes: 5 additions & 2 deletions crates/openshell-driver-podman/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,8 +1540,9 @@ impl PodmanComputeDriver {
host_gateway_ip,
identity: &identity,
allow_extra_supplementary_groups:
crate::isolation::userns_preserves_host_groups(
crate::isolation::allow_extra_supplementary_groups(
self.config.userns.as_deref(),
gpu_devices.is_some(),
),
child_env,
launch_authentication: &launch_authentication,
Expand Down Expand Up @@ -2160,8 +2161,9 @@ impl PodmanComputeDriver {
.map_err(ComputeDriverError::from)?,
identity: &restart_metadata.workload_identity,
allow_extra_supplementary_groups:
crate::isolation::userns_preserves_host_groups(
crate::isolation::allow_extra_supplementary_groups(
self.config.userns.as_deref(),
restart_metadata.allow_extra_supplementary_groups,
),
child_env: restart_metadata.child_env,
launch_authentication: launch_authentication.as_ref().expect("checked above"),
Expand Down Expand Up @@ -4474,6 +4476,7 @@ mod tests {
generation: "generation-1".to_string(),
workload_identity: identity,
child_env: HashMap::new(),
allow_extra_supplementary_groups: false,
})
.unwrap();
let mut header = tar::Header::new_gnu();
Expand Down
69 changes: 69 additions & 0 deletions crates/openshell-driver-podman/src/isolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ pub fn userns_preserves_host_groups(userns: Option<&str>) -> bool {
userns.is_some_and(|mode| mode.split(':').next() == Some("keep-id"))
}

/// Whether the sandbox process may hold supplementary groups beyond the
/// resolved workload identity. A GPU or CDI device request can add groups at
/// container creation (CDI `containerEdits.additionalGids`), independent of the
/// user-namespace mode, so the claim is set for either reason.
pub fn allow_extra_supplementary_groups(userns: Option<&str>, gpu_requested: bool) -> bool {
gpu_requested || userns_preserves_host_groups(userns)
}

fn invalid(error: impl std::fmt::Display) -> ComputeDriverError {
ComputeDriverError::Precondition(error.to_string())
}
Expand Down Expand Up @@ -188,6 +196,9 @@ pub struct RestartMetadata {
pub(crate) runtime_initiated: bool,
pub(crate) workload_identity: ResolvedWorkloadIdentity,
pub(crate) child_env: HashMap<String, String>,
/// Persisted so a restart keeps the claim a GPU/CDI request required.
#[serde(default)]
pub(crate) allow_extra_supplementary_groups: bool,
}

pub struct BootstrapArchivesInput<'a> {
Expand Down Expand Up @@ -341,6 +352,7 @@ pub fn bootstrap_archives(
generation: generation.to_string(),
workload_identity: identity.clone(),
child_env,
allow_extra_supplementary_groups,
};
supervisor.file(
RESTART_METADATA_PATH,
Expand Down Expand Up @@ -646,4 +658,61 @@ mod tests {
assert!(!userns_preserves_host_groups(Some("private")));
assert!(!userns_preserves_host_groups(None));
}

#[test]
fn gpu_or_cdi_request_allows_extra_groups_under_any_userns_mode() {
assert!(allow_extra_supplementary_groups(None, true));
assert!(allow_extra_supplementary_groups(Some("auto"), true));
assert!(allow_extra_supplementary_groups(Some("keep-id"), false));
assert!(!allow_extra_supplementary_groups(None, false));
assert!(!allow_extra_supplementary_groups(Some("auto"), false));
}

#[test]
fn extra_groups_claim_is_projected_and_persisted_for_restart() {
let identity = ResolvedWorkloadIdentity::new(
1000,
1001,
vec![],
"image".into(),
"sha256:image".into(),
)
.unwrap();
let archives = bootstrap_archives(BootstrapArchivesInput {
runtime_initiated: false,
sandbox_id: "sandbox",
container_id: "container",
generation: "generation-1",
host_gateway_ip: "127.0.0.1".parse().unwrap(),
identity: &identity,
allow_extra_supplementary_groups: allow_extra_supplementary_groups(None, true),
child_env: HashMap::new(),
launch_authentication: &authentication(),
})
.unwrap();
let workload = files(&archives.channel);
let supervisor = files(&archives.supervisor);
let config: BoundaryConfig = serde_json::from_slice(
workload
.get(&PathBuf::from("sandbox/bootstrap.json"))
.unwrap(),
)
.unwrap();
assert_eq!(
config
.resource_claims
.get(ALLOW_EXTRA_SUPPLEMENTARY_GROUPS_RESOURCE_CLAIM)
.map(String::as_str),
Some("true")
);
let restart_metadata: RestartMetadata = serde_json::from_slice(
supervisor
.get(&PathBuf::from(
RESTART_METADATA_PATH.trim_start_matches('/'),
))
.unwrap(),
)
.unwrap();
assert!(restart_metadata.allow_extra_supplementary_groups);
}
}
10 changes: 10 additions & 0 deletions tests/suites/features/cdi/tests/injection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ async fn device_node(cx: &mut Context) -> testkit::Result {
async fn unix_socket(cx: &mut Context) -> testkit::Result {
cdi::scenario(cx, "unix-socket").await
}

/// A device node that is mode 0660 with a group only the CDI spec's
/// `additionalGids` grants. The workload must run as a non-root user, be a
/// member of the node's group, and be denied the write the expectations record.
/// This covers a group added at runtime, which the sandbox must accept from the
/// Docker and Podman drivers alike.
#[testkit::test]
async fn device_node_with_gid(cx: &mut Context) -> testkit::Result {
cdi::scenario(cx, "device-node-with-gid").await
}
Loading