Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(sandbox): correct docker sandbox schema and test coverage

Steven Enamakele887304655f3
diff --git a/crates/openhuman-core/src/sandbox/docker.rs b/crates/openhuman-core/src/sandbox/docker.rs
index fcbf5d7ab8..858679038c 100644
--- a/crates/openhuman-core/src/sandbox/docker.rs
+++ b/crates/openhuman-core/src/sandbox/docker.rs
@@ -215,44 +215,48 @@ fn docker_handle_for_status(available: bool) -> SandboxBackendHandle {
}
}
-/// Validate that a sandbox policy's Docker configuration doesn't have
-/// dangerous settings (host network, privileged mounts, etc.).
-pub fn validate_docker_policy(policy: &SandboxPolicy) -> Result<(), Vec<String>> {
- let mut issues = Vec::new();
-
- if let Some(overrides) = &policy.docker_overrides {
- if overrides.network.as_deref() == Some("host") {
- issues.push("Docker sandbox uses host network — defeats network isolation".into());
- }
- }
-
- // Check for dangerous mount paths.
- let dangerous_mounts = ["/", "/etc", "/var/run/docker.sock", "/proc", "/sys"];
- for mount in &policy.read_only_mounts {
- let path_str = mount.to_string_lossy();
- for &dangerous in &dangerous_mounts {
- if path_str == dangerous {
- issues.push(format!(
- "Dangerous read-only mount: {path_str} — could leak host secrets"
- ));
- }
- }
+/// The parts of a sandbox policy the module's Docker run policy judges.
+#[cfg(feature = "modules")]
+pub(crate) fn policy_request(policy: &SandboxPolicy) -> contract::DockerPolicyRequest {
+ contract::DockerPolicyRequest {
+ network: policy
+ .docker_overrides
+ .as_ref()
+ .and_then(|overrides| overrides.network.clone()),
+ workspace: Some(policy.workspace_root.to_string_lossy().into_owned()),
+ read_only_mounts: policy
+ .read_only_mounts
+ .iter()
+ .map(|mount| mount.to_string_lossy().into_owned())
+ .collect(),
}
+}
- let workspace_str = policy.workspace_root.to_string_lossy();
- for &dangerous in &dangerous_mounts {
- if workspace_str == dangerous {
- issues.push(format!(
- "Workspace root is a dangerous path: {workspace_str}"
- ));
- }
- }
+/// Ask TinyBox whether a sandbox policy's Docker configuration has dangerous
+/// settings (host network, privileged mounts, ...).
+///
+/// The verdict is the module's: the same check `RunDocker` enforces before it
+/// creates a container. `Ok` carries the findings (empty means safe); an `Err`
+/// means no verdict could be obtained, which callers must not read as safe.
+#[cfg(feature = "modules")]
+pub async fn validate_docker_policy(
+ config: &Config,
+ policy: &SandboxPolicy,
+) -> Result<Vec<String>, String> {
+ let report = tinybox::validate_docker_policy(config, policy_request(policy)).await?;
+ tracing::debug!(
+ issues = report.issues.len(),
+ "[sandbox:docker] TinyBox validated the policy"
+ );
+ Ok(report.issues)
+}
- if issues.is_empty() {
- Ok(())
- } else {
- Err(issues)
- }
+#[cfg(not(feature = "modules"))]
+pub async fn validate_docker_policy(
+ _config: &Config,
+ _policy: &SandboxPolicy,
+) -> Result<Vec<String>, String> {
+ Err("TinyBox module support is disabled; policy validation is unavailable".to_owned())
}
#[cfg(test)]
diff --git a/crates/openhuman-core/src/sandbox/docker_tests.rs b/crates/openhuman-core/src/sandbox/docker_tests.rs
index 32e7504ad2..f5c7e6cae6 100644
--- a/crates/openhuman-core/src/sandbox/docker_tests.rs
+++ b/crates/openhuman-core/src/sandbox/docker_tests.rs
@@ -15,50 +15,38 @@ fn test_policy() -> SandboxPolicy {
}
}
+#[cfg(feature = "modules")]
#[test]
-fn validate_docker_policy_accepts_safe_config() {
- let policy = test_policy();
- assert!(validate_docker_policy(&policy).is_ok());
-}
-
-#[test]
-fn validate_docker_policy_rejects_host_network() {
+fn policy_request_carries_network_workspace_and_read_only_mounts() {
let mut policy = test_policy();
+ policy.workspace_root = PathBuf::from("/");
+ policy.read_only_mounts = vec![PathBuf::from("/etc"), PathBuf::from("/usr/lib")];
policy.docker_overrides = Some(DockerOverrides {
network: Some("host".into()),
..DockerOverrides::default()
});
- let issues = validate_docker_policy(&policy).unwrap_err();
- assert!(issues.iter().any(|i| i.contains("host network")));
+ let request = policy_request(&policy);
+ assert_eq!(request.network.as_deref(), Some("host"));
+ assert_eq!(request.workspace.as_deref(), Some("/"));
+ assert_eq!(request.read_only_mounts, ["/etc", "/usr/lib"]);
}
+#[cfg(feature = "modules")]
#[test]
-fn validate_docker_policy_rejects_dangerous_mounts() {
- let mut policy = test_policy();
- policy.read_only_mounts = vec![PathBuf::from("/var/run/docker.sock")];
- let issues = validate_docker_policy(&policy).unwrap_err();
- assert!(issues.iter().any(|i| i.contains("docker.sock")));
+fn policy_request_without_overrides_leaves_the_isolated_default() {
+ let request = policy_request(&test_policy());
+ assert_eq!(request.network, None);
+ assert_eq!(request.workspace.as_deref(), Some("/tmp/test-workspace"));
+ assert!(request.read_only_mounts.is_empty());
}
-#[test]
-fn validate_docker_policy_rejects_root_workspace() {
- let mut policy = test_policy();
- policy.workspace_root = PathBuf::from("/");
- let issues = validate_docker_policy(&policy).unwrap_err();
- assert!(issues.iter().any(|i| i.contains("dangerous path")));
-}
-
-#[test]
-fn validate_docker_policy_multiple_issues() {
- let mut policy = test_policy();
- policy.workspace_root = PathBuf::from("/etc");
- policy.read_only_mounts = vec![PathBuf::from("/proc")];
- policy.docker_overrides = Some(DockerOverrides {
- network: Some("host".into()),
- ..DockerOverrides::default()
- });
- let issues = validate_docker_policy(&policy).unwrap_err();
- assert!(issues.len() >= 3);
+#[cfg(feature = "modules")]
+#[tokio::test]
+async fn validation_never_reports_safe_when_tinybox_is_unavailable() {
+ let mut config = crate::config::Config::default();
+ config.modules.enabled = false;
+ let verdict = validate_docker_policy(&config, &test_policy()).await;
+ assert!(verdict.is_err(), "no module means no verdict, not a clean one");
}
#[cfg(feature = "modules")]
diff --git a/crates/openhuman-core/src/sandbox/schemas.rs b/crates/openhuman-core/src/sandbox/schemas.rs
index d51f699873..5ddec2ef41 100644
--- a/crates/openhuman-core/src/sandbox/schemas.rs
+++ b/crates/openhuman-core/src/sandbox/schemas.rs
@@ -308,10 +308,12 @@ fn handle_validate_policy(params: Map<String, Value>) -> ControllerFuture {
Ok(p) => p,
Err(e) => return Err(format!("Invalid policy: {e}")),
};
- let result = match super::docker::validate_docker_policy(&policy) {
- Ok(()) => serde_json::json!({ "valid": true, "issues": [] }),
- Err(issues) => serde_json::json!({ "valid": false, "issues": issues }),
- };
+ let config = crate::config::ops::load_config_with_timeout().await?;
+ // The module owns the verdict; a missing one is an error, never "valid".
+ let issues = super::docker::validate_docker_policy(&config, &policy)
+ .await
+ .map_err(|error| format!("Policy validation is unavailable: {error}"))?;
+ let result = serde_json::json!({ "valid": issues.is_empty(), "issues": issues });
to_json(Outcome::new(result, vec![]))
})
}