Skip to content

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

test(security): add workspace policy tests

Steven Enamakel74b0a601031f
diff --git a/crates/openhuman-core/src/security/policy/policy_tests.rs b/crates/openhuman-core/src/security/policy/policy_tests.rs
index 6f8f2aa49d..52db13009b 100644
--- a/crates/openhuman-core/src/security/policy/policy_tests.rs
+++ b/crates/openhuman-core/src/security/policy/policy_tests.rs
@@ -45,14 +45,13 @@ fn ws_and_outside() -> (tempfile::TempDir, StdPathBuf, StdPathBuf) {
(tmp, workspace, outside)
}
-// -- Per-turn workspace grant (agent::turn_workspace) ------------------------
+// -- Workspace boundary -------------------------------------------------------
//
-// These drive the grant through the real `validate_parent_path` gate every file
-// write funnels through, so they prove the tightening/loosening lands at the
-// shared call site rather than only in the standalone predicate.
+// These drive the boundary through the real `validate_parent_path` gate every
+// file write funnels through.
/// A `workspace_only` policy whose workspace is `<root>/home`, plus a separate
-/// `<root>/checkout` directory standing in for the run's own tree.
+/// `<root>/checkout` directory standing in for a tree outside it.
fn turn_workspace_policy() -> (tempfile::TempDir, PathBuf, SecurityPolicy) {
let root = tempfile::tempdir().expect("root tempdir");
let workspace = root.path().join("home");
diff --git a/crates/openhuman-core/src/security/policy/policy_workspace_internal_tests.rs b/crates/openhuman-core/src/security/policy/policy_workspace_internal_tests.rs
index 8e922f6f05..e767432dbe 100644
--- a/crates/openhuman-core/src/security/policy/policy_workspace_internal_tests.rs
+++ b/crates/openhuman-core/src/security/policy/policy_workspace_internal_tests.rs
@@ -170,10 +170,10 @@ fn action_dir_in_default_policy() {
assert_eq!(policy.action_dir, std::path::PathBuf::from("."));
}
-/// Without a scoped root the checkout is simply outside the workspace, and a
-/// write into it is refused — the behaviour every existing caller keeps.
+/// A checkout beside the workspace is simply outside it, and a write into it
+/// is refused unless a configured trusted root names it.
#[tokio::test]
-async fn write_outside_the_workspace_is_refused_without_a_turn_root() {
+async fn write_outside_the_workspace_is_refused_without_a_trusted_root() {
let (_root, checkout, policy) = turn_workspace_policy();
let target = checkout.join("notes.md");
let err = policy
@@ -186,64 +186,6 @@ async fn write_outside_the_workspace_is_refused_without_a_turn_root() {
);
}
-/// With the checkout scoped as this turn's workspace, the same write validates:
-/// the grant is what lets an embedded turn work in the tree its host named.
-#[tokio::test]
-async fn write_into_the_scoped_turn_root_is_allowed() {
- let (_root, checkout, policy) = turn_workspace_policy();
- let target = checkout.join("notes.md");
- let resolved = crate::agent::turn_workspace::with_workspace(checkout.clone(), {
- let policy = &policy;
- let target = target.clone();
- async move { policy.validate_parent_path(target.to_str().unwrap()).await }
- })
- .await
- .expect("the scoped turn root must be writable");
- assert!(resolved.ends_with("notes.md"), "resolved: {resolved:?}");
-}
-
-/// The grant covers its own subtree and nothing beside it: a sibling directory
-/// stays outside, so scoping one checkout does not open the whole parent.
-#[tokio::test]
-async fn the_turn_root_grant_does_not_reach_a_sibling_directory() {
- let (root, checkout, policy) = turn_workspace_policy();
- let sibling = root.path().join("other");
- std::fs::create_dir_all(&sibling).unwrap();
- let target = sibling.join("notes.md");
- let err = crate::agent::turn_workspace::with_workspace(checkout, {
- let policy = &policy;
- let target = target.clone();
- async move { policy.validate_parent_path(target.to_str().unwrap()).await }
- })
- .await
- .expect_err("a sibling of the scoped root must stay outside it");
- assert!(
- err.contains(POLICY_BLOCKED_MARKER),
- "unexpected error: {err}"
- );
-}
-
-/// The grant is exactly as strong as a configured trusted root and no stronger:
-/// a credential store under the scoped tree is still unreachable.
-#[tokio::test]
-async fn the_turn_root_grant_never_reaches_a_credential_store() {
- let (_root, checkout, policy) = turn_workspace_policy();
- let ssh = checkout.join(".ssh");
- std::fs::create_dir_all(&ssh).unwrap();
- let target = ssh.join("id_rsa");
- let err = crate::agent::turn_workspace::with_workspace(checkout, {
- let policy = &policy;
- let target = target.clone();
- async move { policy.validate_parent_path(target.to_str().unwrap()).await }
- })
- .await
- .expect_err("credential stores stay forbidden inside a granted root");
- assert!(
- err.contains(POLICY_BLOCKED_MARKER),
- "unexpected error: {err}"
- );
-}
-
/// #5505: the account config beside the workspace holds the autonomy policy
/// and the files folders the artifact escape guard trusts, so a trusted root
/// over the account dir must not make it readable or writable, while other