Skip to content

Commit 362fb75

Browse files
committed
feat(driver): default to numeric non-root identity for USER-less images
With the default sandbox image now Alpine, images that declare no OCI USER must start instead of being rejected. When the image declares no USER and the policy requests none, the Podman and Docker drivers now supply a numeric non-root identity (DEFAULT_SANDBOX_UID/GID = 1000) instead of rejecting, matching the numeric-identity behavior of the Kubernetes and VM drivers. The supervisor's resolved-identity path runs the sandbox as a synthesized non-root account without the account existing in the image. Images that declare a USER keep the OCI resolution path unchanged. Part of #3116. Signed-off-by: Akram <akram.benaissi@gmail.com>
1 parent 778ad02 commit 362fb75

3 files changed

Lines changed: 55 additions & 15 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ pub const SANDBOX_UID: &str = "OPENSHELL_SANDBOX_UID";
243243
/// supervisor drops privileges to a group other than the UID's primary group.
244244
pub const SANDBOX_GID: &str = "OPENSHELL_SANDBOX_GID";
245245

246+
/// Default numeric UID assigned to a sandbox when the image declares no OCI
247+
/// `USER` (e.g. a plain Alpine base).
248+
///
249+
/// Local container drivers (Docker, Podman) supply this in place of an empty
250+
/// OCI declaration so the supervisor runs the sandbox as a synthesized non-root
251+
/// account instead of rejecting the image, matching the numeric-identity
252+
/// behavior of the Kubernetes and VM drivers.
253+
pub const DEFAULT_SANDBOX_UID: u32 = 1000;
254+
255+
/// Default numeric GID paired with [`DEFAULT_SANDBOX_UID`].
256+
pub const DEFAULT_SANDBOX_GID: u32 = 1000;
257+
246258
/// Raw OCI `Config.User` declaration from the immutable image selected by a
247259
/// local container driver.
248260
///

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,18 @@ fn resolve_docker_identity_from_accounts(
654654
requested_user
655655
};
656656
if user_selector.is_empty() {
657-
return Err(Status::failed_precondition(
658-
"the pinned image defaults to root; configure a non-root process.run_as_user",
659-
));
657+
// The image declares no USER (e.g. a plain Alpine base) and the policy
658+
// requested none. Synthesize a numeric non-root identity instead of
659+
// rejecting, matching the Podman driver's USER-less default and the
660+
// numeric-identity behavior of the Kubernetes and VM drivers.
661+
return ResolvedWorkloadIdentity::new(
662+
openshell_core::sandbox_env::DEFAULT_SANDBOX_UID,
663+
openshell_core::sandbox_env::DEFAULT_SANDBOX_GID,
664+
Vec::new(),
665+
"default".to_string(),
666+
image.id.clone(),
667+
)
668+
.map_err(|error| Status::failed_precondition(error.to_string()));
660669
}
661670
let (uid, passwd_entry) = resolve_numeric_or_named_user(user_selector, &passwd)?;
662671
let username = passwd_entry.map(|entry| entry.name.as_str());

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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -593,18 +593,37 @@ fn build_env(
593593
// hostname could otherwise present a certificate for a name they control
594594
// and intercept the sandbox JWT.
595595
env.remove(openshell_core::sandbox_env::GATEWAY_TLS_SERVER_NAME);
596-
env.insert(
597-
openshell_core::sandbox_env::OCI_IMAGE_USER.into(),
598-
oci_user.to_string(),
599-
);
600-
env.insert(
601-
openshell_core::sandbox_env::SANDBOX_UID.into(),
602-
String::new(),
603-
);
604-
env.insert(
605-
openshell_core::sandbox_env::SANDBOX_GID.into(),
606-
String::new(),
607-
);
596+
if oci_user.is_empty() {
597+
// The image declares no OCI USER (e.g. a plain Alpine base). Assign a
598+
// numeric non-root identity like the Kubernetes and VM drivers so the
599+
// supervisor synthesizes the account instead of rejecting the image.
600+
env.insert(
601+
openshell_core::sandbox_env::OCI_IMAGE_USER.into(),
602+
String::new(),
603+
);
604+
env.insert(
605+
openshell_core::sandbox_env::SANDBOX_UID.into(),
606+
openshell_core::sandbox_env::DEFAULT_SANDBOX_UID.to_string(),
607+
);
608+
env.insert(
609+
openshell_core::sandbox_env::SANDBOX_GID.into(),
610+
openshell_core::sandbox_env::DEFAULT_SANDBOX_GID.to_string(),
611+
);
612+
} else {
613+
// The image declares a USER; preserve the OCI resolution path.
614+
env.insert(
615+
openshell_core::sandbox_env::OCI_IMAGE_USER.into(),
616+
oci_user.to_string(),
617+
);
618+
env.insert(
619+
openshell_core::sandbox_env::SANDBOX_UID.into(),
620+
String::new(),
621+
);
622+
env.insert(
623+
openshell_core::sandbox_env::SANDBOX_GID.into(),
624+
String::new(),
625+
);
626+
}
608627

609628
// 4. Gateway-minted sandbox JWT. Keep the raw bearer out of container
610629
// metadata; the supervisor reads it from a driver-owned bind mount.

0 commit comments

Comments
 (0)