Skip to content

Commit 70acbaf

Browse files
authored
refactor(driver-utils): centralize container mount path constants (#1841)
Move duplicate in-container path constants from the Docker, Podman, Kubernetes, and VM driver crates into openshell-core::driver_utils: - TLS_CA_MOUNT_PATH, TLS_CERT_MOUNT_PATH, TLS_KEY_MOUNT_PATH, SANDBOX_TOKEN_MOUNT_PATH — identical string literals that were copy-pasted between openshell-driver-docker and openshell-driver-podman. - SUPERVISOR_CONTAINER_DIR (/opt/openshell/bin) and SUPERVISOR_CONTAINER_BINARY (/opt/openshell/bin/openshell-sandbox) — replaces three diverging local constants across docker, kubernetes, podman, and vm-rootfs that referred to the same paths under different names with different string values (the k8s constant was the directory; the docker/vm constant was the full binary path). Each driver crate now assigns its local constant from the canonical core value, keeping existing names visible to tests without any call-site churn. The openshell-core constants carry doc comments explaining when to use the dir vs. the full binary path. Signed-off-by: Eric Curtin <eric.curtin@docker.com>
1 parent 3aba30c commit 70acbaf

5 files changed

Lines changed: 58 additions & 17 deletions

File tree

crates/openshell-core/src/driver_utils.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,42 @@ pub const LABEL_SANDBOX_NAMESPACE: &str = "openshell.ai/sandbox-namespace";
3636
/// path used when building the `openshell-sandbox` image layer.
3737
pub const SUPERVISOR_IMAGE_BINARY_PATH: &str = "/openshell-sandbox";
3838

39+
/// Directory inside sandbox containers where the supervisor binary is mounted.
40+
///
41+
/// Compute drivers that side-load the supervisor into a shared volume mount
42+
/// the binary here so the sandbox container can execute it from a fixed path.
43+
pub const SUPERVISOR_CONTAINER_DIR: &str = "/opt/openshell/bin";
44+
45+
/// Full path to the supervisor binary inside sandbox containers.
46+
///
47+
/// Equals `SUPERVISOR_CONTAINER_DIR + "/openshell-sandbox"`. Use this when
48+
/// the full executable path is needed (Docker entrypoint, Podman entrypoint,
49+
/// VM rootfs injection). Use `SUPERVISOR_CONTAINER_DIR` when only the
50+
/// directory mount-point is needed (Kubernetes emptyDir volume mount).
51+
pub const SUPERVISOR_CONTAINER_BINARY: &str = "/opt/openshell/bin/openshell-sandbox";
52+
53+
// ---------------------------------------------------------------------------
54+
// In-container mount paths for guest TLS materials and the sandbox token.
55+
//
56+
// All container-based drivers (Docker, Podman, Kubernetes) mount the gateway's
57+
// mTLS client credentials at these fixed paths inside every sandbox container.
58+
// The supervisor reads these paths on startup to establish its gRPC-over-mTLS
59+
// connection back to the gateway. The paths must remain stable across driver
60+
// versions since the supervisor binary is built and packaged separately.
61+
// ---------------------------------------------------------------------------
62+
63+
/// Container-side mount path for the guest mTLS CA certificate.
64+
pub const TLS_CA_MOUNT_PATH: &str = "/etc/openshell/tls/client/ca.crt";
65+
66+
/// Container-side mount path for the guest mTLS client certificate.
67+
pub const TLS_CERT_MOUNT_PATH: &str = "/etc/openshell/tls/client/tls.crt";
68+
69+
/// Container-side mount path for the guest mTLS client private key.
70+
pub const TLS_KEY_MOUNT_PATH: &str = "/etc/openshell/tls/client/tls.key";
71+
72+
/// Container-side mount path for the per-sandbox JWT token.
73+
pub const SANDBOX_TOKEN_MOUNT_PATH: &str = "/etc/openshell/auth/sandbox.jwt";
74+
3975
/// Return the XDG state path for a driver's sandbox JWT token file.
4076
///
4177
/// The resulting path is `$XDG_STATE_HOME/openshell/<driver_subdir>[/<namespace>]/<sandbox_id>/sandbox.jwt`.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ const WATCH_BUFFER: usize = 128;
5959
const WATCH_POLL_INTERVAL: Duration = Duration::from_secs(2);
6060
const WATCH_POLL_MAX_BACKOFF: Duration = Duration::from_secs(30);
6161

62-
const SUPERVISOR_MOUNT_PATH: &str = "/opt/openshell/bin/openshell-sandbox";
63-
const TLS_CA_MOUNT_PATH: &str = "/etc/openshell/tls/client/ca.crt";
64-
const TLS_CERT_MOUNT_PATH: &str = "/etc/openshell/tls/client/tls.crt";
65-
const TLS_KEY_MOUNT_PATH: &str = "/etc/openshell/tls/client/tls.key";
66-
const SANDBOX_TOKEN_MOUNT_PATH: &str = "/etc/openshell/auth/sandbox.jwt";
62+
const SUPERVISOR_MOUNT_PATH: &str = openshell_core::driver_utils::SUPERVISOR_CONTAINER_BINARY;
63+
const TLS_CA_MOUNT_PATH: &str = openshell_core::driver_utils::TLS_CA_MOUNT_PATH;
64+
const TLS_CERT_MOUNT_PATH: &str = openshell_core::driver_utils::TLS_CERT_MOUNT_PATH;
65+
const TLS_KEY_MOUNT_PATH: &str = openshell_core::driver_utils::TLS_KEY_MOUNT_PATH;
66+
const SANDBOX_TOKEN_MOUNT_PATH: &str = openshell_core::driver_utils::SANDBOX_TOKEN_MOUNT_PATH;
6767
const SANDBOX_COMMAND: &str = "sleep infinity";
6868
const SUPERVISOR_PATH: &str = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
6969
const HOST_OPENSHELL_INTERNAL: &str = "host.openshell.internal";

crates/openshell-driver-kubernetes/src/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ fn extract_image_size(message: &str) -> Option<u64> {
769769
}
770770

771771
/// Path where the supervisor binary is mounted inside the agent container.
772-
const SUPERVISOR_MOUNT_PATH: &str = "/opt/openshell/bin";
772+
const SUPERVISOR_MOUNT_PATH: &str = openshell_core::driver_utils::SUPERVISOR_CONTAINER_DIR;
773773

774774
/// Name of the volume used to side-load the supervisor binary.
775775
const SUPERVISOR_VOLUME_NAME: &str = "openshell-supervisor-bin";

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ const CONTAINER_PREFIX: &str = "openshell-sandbox-";
4646
/// Volume name prefix.
4747
const VOLUME_PREFIX: &str = "openshell-sandbox-";
4848

49-
/// Container-side mount paths for client TLS materials.
50-
const TLS_CA_MOUNT_PATH: &str = "/etc/openshell/tls/client/ca.crt";
51-
const TLS_CERT_MOUNT_PATH: &str = "/etc/openshell/tls/client/tls.crt";
52-
const TLS_KEY_MOUNT_PATH: &str = "/etc/openshell/tls/client/tls.key";
53-
const SANDBOX_TOKEN_MOUNT_PATH: &str = "/etc/openshell/auth/sandbox.jwt";
49+
/// Container-side mount paths for client TLS materials and the sandbox token.
50+
const TLS_CA_MOUNT_PATH: &str = openshell_core::driver_utils::TLS_CA_MOUNT_PATH;
51+
const TLS_CERT_MOUNT_PATH: &str = openshell_core::driver_utils::TLS_CERT_MOUNT_PATH;
52+
const TLS_KEY_MOUNT_PATH: &str = openshell_core::driver_utils::TLS_KEY_MOUNT_PATH;
53+
const SANDBOX_TOKEN_MOUNT_PATH: &str = openshell_core::driver_utils::SANDBOX_TOKEN_MOUNT_PATH;
54+
55+
/// Directory inside sandbox containers where the supervisor binary is mounted.
56+
const SUPERVISOR_MOUNT_DIR: &str = openshell_core::driver_utils::SUPERVISOR_CONTAINER_DIR;
57+
/// Full path to the supervisor binary inside sandbox containers.
58+
const SUPERVISOR_BINARY_PATH: &str = openshell_core::driver_utils::SUPERVISOR_CONTAINER_BINARY;
5459

5560
/// Build a Podman container name from the sandbox name.
5661
#[must_use]
@@ -443,17 +448,17 @@ pub fn build_container_spec_with_token(
443448
// /opt/openshell/bin/openshell-sandbox.
444449
image_volumes: vec![ImageVolume {
445450
source: config.supervisor_image.clone(),
446-
destination: "/opt/openshell/bin".into(),
451+
destination: SUPERVISOR_MOUNT_DIR.into(),
447452
rw: false,
448453
}],
449454
hostname: format!("sandbox-{}", sandbox.name),
450455
// Override the image's ENTRYPOINT so the supervisor binary runs
451456
// directly. Sandbox images (e.g. the community base image) set
452457
// ENTRYPOINT ["/bin/bash"], and Podman's `command` field only
453458
// overrides CMD — which gets appended as args to the entrypoint.
454-
// Without this, the container would run `/bin/bash /opt/openshell/bin/openshell-sandbox`
455-
// and bash would fail trying to interpret the binary as a script.
456-
entrypoint: vec!["/opt/openshell/bin/openshell-sandbox".into()],
459+
// Without this, the container would run the entrypoint binary with
460+
// the supervisor path as an argument instead of executing it directly.
461+
entrypoint: vec![SUPERVISOR_BINARY_PATH.into()],
457462
command: vec![],
458463
// Force the supervisor to run as root (UID 0). Sandbox images may
459464
// set a non-root USER directive (e.g. `USER sandbox`), but the
@@ -1162,7 +1167,7 @@ mod tests {
11621167
);
11631168
assert_eq!(
11641169
vol["destination"].as_str(),
1165-
Some("/opt/openshell/bin"),
1170+
Some(SUPERVISOR_MOUNT_DIR),
11661171
"image volume destination should be /opt/openshell/bin"
11671172
);
11681173
assert_eq!(

crates/openshell-driver-vm/src/rootfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const SUPERVISOR: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/openshell-sa
1414
const UMOCI: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/umoci.zst"));
1515
const ROOTFS_VARIANT_MARKER: &str = ".openshell-rootfs-variant";
1616
const SANDBOX_GUEST_INIT_PATH: &str = "/srv/openshell-vm-sandbox-init.sh";
17-
const SANDBOX_SUPERVISOR_PATH: &str = "/opt/openshell/bin/openshell-sandbox";
17+
const SANDBOX_SUPERVISOR_PATH: &str = openshell_core::driver_utils::SUPERVISOR_CONTAINER_BINARY;
1818
const SANDBOX_UMOCI_PATH: &str = "/opt/openshell/bin/umoci";
1919
const SANDBOX_OWNER_NORMALIZED_MARKER: &str = "/opt/openshell/.sandbox-owner-normalized";
2020
const ROOTFS_IMAGE_MIN_SIZE_BYTES: u64 = 512 * 1024 * 1024;

0 commit comments

Comments
 (0)