Skip to content

Commit 08b333d

Browse files
committed
feat(drivers): gate bind mounts behind gateway config
1 parent 113bbea commit 08b333d

16 files changed

Lines changed: 424 additions & 35 deletions

File tree

‎architecture/compute-runtimes.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ but currently ignores them.
4343
Docker and Podman also accept per-sandbox driver-config mounts for existing
4444
runtime-managed named volumes and tmpfs mounts. Podman additionally accepts
4545
image mounts through its image-volume API. User-supplied host bind mounts are
46-
excluded from the driver-config contract; bind mounts remain reserved for
47-
driver-owned supervisor, token, and TLS material.
46+
available only when explicitly enabled in the active local driver table of
47+
`gateway.toml`; driver-owned supervisor, token, and TLS bind mounts stay
48+
reserved.
4849

4950
Kubernetes deployments may set an AppArmor profile on sandbox agent containers
5051
through the driver configuration. The Helm chart defaults sandbox agents to

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ The gateway forwards the `docker` block from `--driver-config-json` to this
4242
driver. The driver accepts user-supplied `mounts` entries with these Docker
4343
mount types:
4444

45+
- `bind`: mounts an absolute host path when `[openshell.drivers.docker]`
46+
has `enable_bind_mounts = true`.
4547
- `volume`: mounts an existing Docker named volume. The driver validates that
4648
the volume exists before provisioning and never creates or removes it.
4749
- `tmpfs`: mounts an in-memory filesystem with optional `options`,
4850
`size_bytes`, and `mode`.
4951

50-
Host bind mounts and image mounts are intentionally not part of the Docker
52+
Host bind mounts are disabled by default because they expose gateway host
53+
paths to sandbox requests. Image mounts are not part of the Docker
5154
driver-config schema. The driver still uses internal bind mounts for
5255
OpenShell-owned supervisor, token, and TLS material.
5356

57+
Docker `bind` mounts accept `source`, `target`, and optional `read_only`.
5458
Docker `volume` mounts may include `subpath`. Mount targets must be absolute
5559
container paths and must not replace the workspace root (`/sandbox`) or overlap
5660
OpenShell supervisor files, auth material, TLS material, or `/run/netns`.

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

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ pub struct DockerComputeConfig {
177177
///
178178
/// Set to `0` to leave Docker's runtime/default PID limit unchanged.
179179
pub sandbox_pids_limit: i64,
180+
181+
/// Allow sandbox requests to attach host bind mounts through
182+
/// `template.driver_config`.
183+
#[serde(default)]
184+
pub enable_bind_mounts: bool,
180185
}
181186

182187
impl Default for DockerComputeConfig {
@@ -195,6 +200,7 @@ impl Default for DockerComputeConfig {
195200
host_gateway_ip: String::new(),
196201
ssh_socket_path: "/run/openshell/ssh.sock".to_string(),
197202
sandbox_pids_limit: DEFAULT_SANDBOX_PIDS_LIMIT,
203+
enable_bind_mounts: false,
198204
}
199205
}
200206
}
@@ -222,6 +228,7 @@ struct DockerDriverRuntimeConfig {
222228
daemon_version: String,
223229
supports_gpu: bool,
224230
sandbox_pids_limit: i64,
231+
enable_bind_mounts: bool,
225232
}
226233

227234
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -268,6 +275,12 @@ struct DockerSandboxDriverConfig {
268275
#[derive(Debug, Clone, serde::Deserialize)]
269276
#[serde(tag = "type", rename_all = "snake_case", deny_unknown_fields)]
270277
enum DockerDriverMountConfig {
278+
Bind {
279+
source: String,
280+
target: String,
281+
#[serde(default)]
282+
read_only: bool,
283+
},
271284
Volume {
272285
source: String,
273286
target: String,
@@ -356,6 +369,7 @@ impl DockerComputeDriver {
356369
daemon_version: version.version.unwrap_or_else(|| "unknown".to_string()),
357370
supports_gpu,
358371
sandbox_pids_limit: docker_config.sandbox_pids_limit,
372+
enable_bind_mounts: docker_config.enable_bind_mounts,
359373
},
360374
events: broadcast::channel(WATCH_BUFFER).0,
361375
pending: Arc::new(Mutex::new(HashMap::new())),
@@ -420,7 +434,7 @@ impl DockerComputeDriver {
420434
));
421435
}
422436

423-
let _ = docker_driver_config(template)?;
437+
let _ = docker_driver_config(template, config.enable_bind_mounts)?;
424438
let _ = docker_resource_limits(template)?;
425439
Ok(())
426440
}
@@ -457,7 +471,7 @@ impl DockerComputeDriver {
457471
.as_ref()
458472
.and_then(|spec| spec.template.as_ref())
459473
.ok_or_else(|| Status::invalid_argument("sandbox.spec.template is required"))?;
460-
let config = docker_driver_config(template)?;
474+
let config = docker_driver_config(template, self.config.enable_bind_mounts)?;
461475
for mount in config.mounts {
462476
if let DockerDriverMountConfig::Volume { source, .. } = mount {
463477
match self.docker.inspect_volume(source.trim()).await {
@@ -1568,6 +1582,7 @@ fn attach_docker_progress_metadata(
15681582

15691583
fn docker_driver_config(
15701584
template: &DriverSandboxTemplate,
1585+
enable_bind_mounts: bool,
15711586
) -> Result<DockerSandboxDriverConfig, Status> {
15721587
let Some(config) = template.driver_config.as_ref() else {
15731588
return Ok(DockerSandboxDriverConfig::default());
@@ -1577,17 +1592,31 @@ fn docker_driver_config(
15771592
let config: DockerSandboxDriverConfig = serde_json::from_value(json).map_err(|err| {
15781593
Status::failed_precondition(format!("invalid docker driver_config: {err}"))
15791594
})?;
1580-
validate_docker_driver_mounts(&config.mounts)?;
1595+
validate_docker_driver_mounts(&config.mounts, enable_bind_mounts)?;
15811596
Ok(config)
15821597
}
15831598

1584-
fn docker_driver_mounts(template: &DriverSandboxTemplate) -> Result<Vec<Mount>, Status> {
1585-
let config = docker_driver_config(template)?;
1599+
fn docker_driver_mounts(
1600+
template: &DriverSandboxTemplate,
1601+
enable_bind_mounts: bool,
1602+
) -> Result<Vec<Mount>, Status> {
1603+
let config = docker_driver_config(template, enable_bind_mounts)?;
15861604
config.mounts.iter().map(docker_mount_from_config).collect()
15871605
}
15881606

15891607
fn docker_mount_from_config(config: &DockerDriverMountConfig) -> Result<Mount, Status> {
15901608
match config {
1609+
DockerDriverMountConfig::Bind {
1610+
source,
1611+
target,
1612+
read_only,
1613+
} => Ok(Mount {
1614+
typ: Some(MountTypeEnum::BIND),
1615+
source: Some(validate_absolute_mount_source(source, "bind source")?),
1616+
target: Some(validate_container_mount_target(target)?),
1617+
read_only: Some(*read_only),
1618+
..Default::default()
1619+
}),
15911620
DockerDriverMountConfig::Volume {
15921621
source,
15931622
target,
@@ -1637,10 +1666,22 @@ fn docker_mount_from_config(config: &DockerDriverMountConfig) -> Result<Mount, S
16371666
}
16381667
}
16391668

1640-
fn validate_docker_driver_mounts(mounts: &[DockerDriverMountConfig]) -> Result<(), Status> {
1669+
fn validate_docker_driver_mounts(
1670+
mounts: &[DockerDriverMountConfig],
1671+
enable_bind_mounts: bool,
1672+
) -> Result<(), Status> {
16411673
let mut targets = HashSet::new();
16421674
for mount in mounts {
16431675
let target = match mount {
1676+
DockerDriverMountConfig::Bind { source, target, .. } => {
1677+
if !enable_bind_mounts {
1678+
return Err(Status::failed_precondition(
1679+
"docker bind mounts require enable_bind_mounts = true in [openshell.drivers.docker]",
1680+
));
1681+
}
1682+
validate_absolute_mount_source(source, "bind source")?;
1683+
target
1684+
}
16441685
DockerDriverMountConfig::Volume {
16451686
source,
16461687
target,
@@ -1677,6 +1718,16 @@ fn validate_docker_driver_mounts(mounts: &[DockerDriverMountConfig]) -> Result<(
16771718
Ok(())
16781719
}
16791720

1721+
fn validate_absolute_mount_source(source: &str, field: &str) -> Result<String, Status> {
1722+
let source = validate_mount_source(source, field)?;
1723+
if !Path::new(&source).is_absolute() {
1724+
return Err(Status::failed_precondition(format!(
1725+
"{field} must be an absolute host path"
1726+
)));
1727+
}
1728+
Ok(source)
1729+
}
1730+
16801731
fn validate_mount_source(source: &str, field: &str) -> Result<String, Status> {
16811732
let source = source.trim();
16821733
if source.is_empty() {
@@ -2100,7 +2151,7 @@ fn build_container_create_body(
21002151
.as_ref()
21012152
.ok_or_else(|| Status::invalid_argument("sandbox.spec.template is required"))?;
21022153
let resource_limits = docker_resource_limits(template)?;
2103-
let user_mounts = docker_driver_mounts(template)?;
2154+
let user_mounts = docker_driver_mounts(template, config.enable_bind_mounts)?;
21042155
let mut labels = template.labels.clone();
21052156
labels.insert(
21062157
LABEL_MANAGED_BY.to_string(),

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

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ fn runtime_config() -> DockerDriverRuntimeConfig {
7575
daemon_version: "28.0.0".to_string(),
7676
supports_gpu: false,
7777
sandbox_pids_limit: DEFAULT_SANDBOX_PIDS_LIMIT,
78+
enable_bind_mounts: false,
7879
}
7980
}
8081

@@ -465,6 +466,12 @@ fn docker_pids_limit_uses_driver_default_and_allows_runtime_inherit() {
465466
assert!(docker_pids_limit(-1).is_err());
466467
}
467468

469+
#[test]
470+
fn docker_compute_config_disables_bind_mounts_by_default() {
471+
let cfg = DockerComputeConfig::default();
472+
assert!(!cfg.enable_bind_mounts);
473+
}
474+
468475
#[test]
469476
fn container_create_body_sets_driver_owned_pids_limit() {
470477
let body = build_container_create_body(&test_sandbox(), &runtime_config()).unwrap();
@@ -613,7 +620,7 @@ fn build_container_create_body_includes_driver_config_mounts() {
613620
}
614621

615622
#[test]
616-
fn driver_config_rejects_bind_mounts() {
623+
fn driver_config_rejects_bind_mounts_unless_enabled() {
617624
let mut sandbox = test_sandbox();
618625
sandbox
619626
.spec
@@ -633,7 +640,71 @@ fn driver_config_rejects_bind_mounts() {
633640
let err = build_container_create_body(&sandbox, &runtime_config()).unwrap_err();
634641

635642
assert_eq!(err.code(), tonic::Code::FailedPrecondition);
636-
assert!(err.message().contains("invalid docker driver_config"));
643+
assert!(err.message().contains("enable_bind_mounts = true"));
644+
}
645+
646+
#[test]
647+
fn build_container_create_body_includes_bind_mounts_when_enabled() {
648+
let mut sandbox = test_sandbox();
649+
sandbox
650+
.spec
651+
.as_mut()
652+
.unwrap()
653+
.template
654+
.as_mut()
655+
.unwrap()
656+
.driver_config = Some(json_struct(serde_json::json!({
657+
"mounts": [{
658+
"type": "bind",
659+
"source": "/host/path",
660+
"target": "/sandbox/host",
661+
"read_only": true
662+
}]
663+
})));
664+
let mut config = runtime_config();
665+
config.enable_bind_mounts = true;
666+
667+
let body = build_container_create_body(&sandbox, &config).unwrap();
668+
let mounts = body
669+
.host_config
670+
.unwrap()
671+
.mounts
672+
.expect("driver config mounts should be set");
673+
674+
assert_eq!(mounts.len(), 1);
675+
assert_eq!(mounts[0].typ, Some(MountTypeEnum::BIND));
676+
assert_eq!(mounts[0].source.as_deref(), Some("/host/path"));
677+
assert_eq!(mounts[0].target.as_deref(), Some("/sandbox/host"));
678+
assert_eq!(mounts[0].read_only, Some(true));
679+
}
680+
681+
#[test]
682+
fn driver_config_rejects_relative_bind_sources_when_enabled() {
683+
let mut sandbox = test_sandbox();
684+
sandbox
685+
.spec
686+
.as_mut()
687+
.unwrap()
688+
.template
689+
.as_mut()
690+
.unwrap()
691+
.driver_config = Some(json_struct(serde_json::json!({
692+
"mounts": [{
693+
"type": "bind",
694+
"source": "relative/path",
695+
"target": "/sandbox/host"
696+
}]
697+
})));
698+
let mut config = runtime_config();
699+
config.enable_bind_mounts = true;
700+
701+
let err = build_container_create_body(&sandbox, &config).unwrap_err();
702+
703+
assert_eq!(err.code(), tonic::Code::FailedPrecondition);
704+
assert!(
705+
err.message()
706+
.contains("bind source must be an absolute host path")
707+
);
637708
}
638709

639710
#[test]

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@ The gateway forwards the `podman` block from `--driver-config-json` to this
5656
driver. The driver accepts user-supplied `mounts` entries with these Podman
5757
mount types:
5858

59+
- `bind`: mounts an absolute host path when `[openshell.drivers.podman]`
60+
has `enable_bind_mounts = true`.
5961
- `volume`: mounts an existing Podman named volume. The driver validates that
6062
the volume exists before provisioning and never creates or removes it.
6163
- `tmpfs`: mounts an in-memory filesystem with optional `options`,
6264
`size_bytes`, and `mode`.
6365
- `image`: mounts an OCI image through Podman's image-volume API. The driver
6466
pulls the image during provisioning using the sandbox image pull policy.
6567

66-
Host bind mounts are intentionally not part of the driver-config schema. The
67-
driver still uses internal bind mounts for OpenShell-owned token and TLS
68-
material.
68+
Host bind mounts are disabled by default because they expose gateway host paths
69+
to sandbox requests. The driver still uses internal bind mounts for
70+
OpenShell-owned token and TLS material.
6971

72+
Podman `bind` mounts accept `source`, `target`, and optional `read_only`.
7073
Podman image and volume mounts do not support `subpath` in OpenShell driver
7174
config. Mount targets must be absolute container paths and must not replace the
7275
workspace root (`/sandbox`) or overlap OpenShell supervisor files, auth

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ pub struct PodmanComputeConfig {
122122
///
123123
/// Set to `0` to leave Podman's runtime/default PID limit unchanged.
124124
pub sandbox_pids_limit: i64,
125+
/// Allow sandbox requests to attach host bind mounts through
126+
/// `template.driver_config`.
127+
#[serde(default)]
128+
pub enable_bind_mounts: bool,
125129
}
126130

127131
impl PodmanComputeConfig {
@@ -246,6 +250,7 @@ impl Default for PodmanComputeConfig {
246250
guest_tls_cert: None,
247251
guest_tls_key: None,
248252
sandbox_pids_limit: DEFAULT_SANDBOX_PIDS_LIMIT,
253+
enable_bind_mounts: false,
249254
}
250255
}
251256
}
@@ -267,6 +272,7 @@ impl std::fmt::Debug for PodmanComputeConfig {
267272
.field("guest_tls_cert", &self.guest_tls_cert)
268273
.field("guest_tls_key", &self.guest_tls_key)
269274
.field("sandbox_pids_limit", &self.sandbox_pids_limit)
275+
.field("enable_bind_mounts", &self.enable_bind_mounts)
270276
.finish()
271277
}
272278
}
@@ -312,6 +318,7 @@ mod tests {
312318
fn default_config_sets_driver_owned_pids_limit() {
313319
let cfg = PodmanComputeConfig::default();
314320
assert_eq!(cfg.sandbox_pids_limit, DEFAULT_SANDBOX_PIDS_LIMIT);
321+
assert!(!cfg.enable_bind_mounts);
315322
assert!(cfg.validate_runtime_limits().is_ok());
316323
}
317324

0 commit comments

Comments
 (0)