Skip to content

Commit 044e663

Browse files
committed
feat(driver): default to numeric non-root identity for USER-less images
Docker and Podman cleared SANDBOX_UID/GID and forwarded the image's OCI Config.User, so the supervisor rejected any image without a USER (e.g. a plain Alpine base) with 'OCI USER is required'. With the default sandbox image now Alpine, such images must start. When the image declares no OCI USER, the Docker and Podman drivers now supply a numeric non-root identity (DEFAULT_SANDBOX_UID/GID = 1000) instead of an empty declaration, mirroring the Kubernetes and VM drivers. The supervisor's existing resolved-identity path synthesizes the passwd/group entry, so the sandbox runs non-root without the account existing in the image. Images that declare a USER keep the OCI resolution path unchanged. The identity normalization already prefers a resolved numeric pair over an empty OCI declaration (covered by driver_identity_inputs_are_mutually_exclusive_and_complete), so no supervisor logic change is needed. Part of #3116. Signed-off-by: Akram Signed-off-by: Akram <akram.benaissi@gmail.com>
1 parent 7c34a4e commit 044e663

4 files changed

Lines changed: 78 additions & 26 deletions

File tree

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

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

227+
/// Default numeric UID assigned to a sandbox when the image declares no OCI
228+
/// `USER` (e.g. a plain Alpine base).
229+
///
230+
/// Local container drivers (Docker, Podman) supply this in place of an empty
231+
/// OCI declaration so the supervisor runs the sandbox as a synthesized non-root
232+
/// account instead of rejecting the image, matching the numeric-identity
233+
/// behavior of the Kubernetes and VM drivers.
234+
pub const DEFAULT_SANDBOX_UID: u32 = 1000;
235+
236+
/// Default numeric GID paired with [`DEFAULT_SANDBOX_UID`].
237+
pub const DEFAULT_SANDBOX_GID: u32 = 1000;
238+
227239
/// Raw OCI `Config.User` declaration from the immutable image selected by a
228240
/// local container driver.
229241
///

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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,18 +3025,37 @@ fn build_environment_for_oci_user(
30253025
// hostname could otherwise present a certificate for a name they control
30263026
// and intercept the sandbox JWT.
30273027
environment.remove(openshell_core::sandbox_env::GATEWAY_TLS_SERVER_NAME);
3028-
environment.insert(
3029-
openshell_core::sandbox_env::OCI_IMAGE_USER.to_string(),
3030-
oci_user.to_string(),
3031-
);
3032-
environment.insert(
3033-
openshell_core::sandbox_env::SANDBOX_UID.to_string(),
3034-
String::new(),
3035-
);
3036-
environment.insert(
3037-
openshell_core::sandbox_env::SANDBOX_GID.to_string(),
3038-
String::new(),
3039-
);
3028+
if oci_user.is_empty() {
3029+
// The image declares no OCI USER (e.g. a plain Alpine base). Assign a
3030+
// numeric non-root identity like the Kubernetes and VM drivers so the
3031+
// supervisor synthesizes the account instead of rejecting the image.
3032+
environment.insert(
3033+
openshell_core::sandbox_env::OCI_IMAGE_USER.to_string(),
3034+
String::new(),
3035+
);
3036+
environment.insert(
3037+
openshell_core::sandbox_env::SANDBOX_UID.to_string(),
3038+
openshell_core::sandbox_env::DEFAULT_SANDBOX_UID.to_string(),
3039+
);
3040+
environment.insert(
3041+
openshell_core::sandbox_env::SANDBOX_GID.to_string(),
3042+
openshell_core::sandbox_env::DEFAULT_SANDBOX_GID.to_string(),
3043+
);
3044+
} else {
3045+
// The image declares a USER; preserve the OCI resolution path.
3046+
environment.insert(
3047+
openshell_core::sandbox_env::OCI_IMAGE_USER.to_string(),
3048+
oci_user.to_string(),
3049+
);
3050+
environment.insert(
3051+
openshell_core::sandbox_env::SANDBOX_UID.to_string(),
3052+
String::new(),
3053+
);
3054+
environment.insert(
3055+
openshell_core::sandbox_env::SANDBOX_GID.to_string(),
3056+
String::new(),
3057+
);
3058+
}
30403059

30413060
// Gateway-minted sandbox JWT. Keep the raw bearer out of container
30423061
// metadata; the supervisor reads it from this driver-owned bind mount.

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

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

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

‎crates/openshell-supervisor-process/src/identity.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ impl DriverIdentity {
4444
) -> Result<Self> {
4545
// Resolved-identity drivers explicitly clear the OCI declaration so
4646
// an image-baked or user-supplied value cannot select the OCI path.
47-
// Preserve an empty declaration when no resolved pair is present:
48-
// Docker and Podman use that state to reject images without USER.
47+
// Preserve an empty declaration when no resolved pair is present so a
48+
// bare OCI path still rejects a USER-less image; container drivers now
49+
// pair an empty declaration with a numeric default for USER-less images,
50+
// which selects the resolved path here instead of rejecting.
4951
let oci_user = if oci_user.as_deref() == Some("") && (uid.is_some() || gid.is_some()) {
5052
None
5153
} else {

0 commit comments

Comments
 (0)