The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(privacy): recheck local runtimes at dispatch and disclose per-request models
M3gA-Mind36819ece1578
diff --git a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs b/crates/openhuman-core/src/inference/provider/factory/access_gates.rsindex e732725fc1..2a7618d7dc 100644--- a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs+++ b/crates/openhuman-core/src/inference/provider/factory/access_gates.rs@@ -98,11 +98,24 @@ pub(super) fn is_loopback_endpoint(endpoint: &str) -> bool {}}-/// Local-only for the model a request actually names. A caller may override-/// the route's model per request (a flow node's pinned model, for one), so an-/// Ollama route built for `llama3` can still be asked for a `*-cloud` tag.+/// Privacy at request time for every local runtime. The construction-time+/// checks see only the route as built, and two things can change after that:+/// - the privacy mode is live, so a model built under `Standard` must still+/// stop at a non-loopback endpoint once the mode is local-only;+/// - a caller may override the route's model per request (a flow node's pinned+/// model, for one), so an Ollama route built for `llama3` can still be asked+/// for a `*-cloud` tag, which local-only refuses and every other mode+/// discloses as external egress.pub(super) struct LocalOnlyRequestGuard {pub(super) inner: std::sync::Arc<dyn tinyinference_llm::model::ChatModel<()>>,+ pub(super) role: String,+ /// The runtime's slug (`ollama`, `lmstudio`, ...), resolved endpoint, and+ /// the model the route was built (and disclosed) for.+ pub(super) slug: String,+ pub(super) endpoint: String,+ pub(super) model: String,+ /// The turn's ledger, so a per-request model is disclosed once per turn.+ pub(super) egress: EgressLedger,}impl LocalOnlyRequestGuard {@@ -110,15 +123,27 @@ impl LocalOnlyRequestGuard {&self,request: &tinyinference_llm::model::ModelRequest,) -> tinyinference_llm::Result<()> {- let Some(model) = request- .model- .as_deref()- .filter(|m| is_ollama_cloud_model(&format!("ollama:{m}")))- else {- return Ok(());- };- enforce_local_only_inference("request", &format!("ollama:{model}"))- .map_err(|e| tinyinference_llm::Error::Validation(e.to_string()))+ let refuse = |e: anyhow::Error| tinyinference_llm::Error::Validation(e.to_string());+ enforce_local_only_endpoint(&self.role, &self.endpoint).map_err(refuse)?;+ let model = request.model.as_deref().unwrap_or(&self.model);+ let route = format!("{}:{model}", self.slug);+ let cloud = is_ollama_cloud_model(&route);+ if cloud {+ enforce_local_only_inference(&self.role, &route).map_err(refuse)?;+ }+ if model != self.model {+ // Construction disclosed the route's own model; an override is a+ // different destination, disclosed where the request makes it.+ crate::security::egress::emit_external_transfer_in(+ &self.egress,+ crate::security::egress::EgressDescriptor::inference(+ self.slug.clone(),+ model.to_string(),+ cloud || !is_loopback_endpoint(&self.endpoint),+ ),+ );+ }+ Ok(())}}diff --git a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rsindex 8c748f4276..bc9f6d66a9 100644--- a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs+++ b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs@@ -167,11 +167,14 @@ fn try_create_local_runtime_chat_model_from_string_with_identity(resolved.temperature,resolved.num_ctx,);- let chat: Arc<dyn ChatModel<()>> = if resolved.kind.as_str() == "ollama" {- Arc::new(LocalOnlyRequestGuard { inner: chat })- } else {- chat- };+ let chat: Arc<dyn ChatModel<()>> = Arc::new(LocalOnlyRequestGuard {+ inner: chat,+ role: role.to_string(),+ slug: resolved.kind.as_str().to_string(),+ endpoint: resolved.endpoint.clone(),+ model: resolved.model.clone(),+ egress: egress.clone(),+ });Some(Ok((chat, resolved.model)))}diff --git a/crates/openhuman-core/src/inference/provider/factory_local_only_endpoint_tests.rs b/crates/openhuman-core/src/inference/provider/factory_local_only_endpoint_tests.rsindex 14d40015e1..20071775e7 100644--- a/crates/openhuman-core/src/inference/provider/factory_local_only_endpoint_tests.rs+++ b/crates/openhuman-core/src/inference/provider/factory_local_only_endpoint_tests.rs@@ -155,3 +155,85 @@ async fn local_only_refuses_a_cloud_tag_named_per_request() {.expect_err("a per-request cloud tag must be refused before dispatch");assert!(error.to_string().contains("Local-only"), "{error}");}++/// The privacy mode is live: a local runtime built for another host under+/// `Standard` must still stop there once the mode is local-only, before any+/// request leaves (every local runtime, not only Ollama).+#[tokio::test]+async fn local_only_set_after_construction_refuses_a_remote_local_runtime_at_dispatch() {+ use tinyinference_llm::model::ModelRequest;+ let _guard = crate::inference::inference_test_guard_async().await;+ let _env = EnvVarGuard::locked_unset_many_async(ENDPOINT_ENV).await;+ let _standard = crate::security::live_policy::test_privacy_scope(PrivacyMode::Standard);+ let (model, _) = create_test_chat_model_from_string(+ "chat",+ "local-openai:m",+ &local_ai_at("https://gpu.example.invalid/v1"),+ )+ .expect("Standard builds a remote local runtime");++ let _local_only = crate::security::live_policy::test_privacy_scope(PrivacyMode::LocalOnly);+ let invoked = model.invoke(&(), ModelRequest::new(Vec::new())).await;+ let streamed = model.stream(&(), ModelRequest::new(Vec::new())).await;+ for error in [+ invoked.map(|_| ()).expect_err("invoke is refused before dispatch"),+ streamed.map(|_| ()).expect_err("stream is refused before dispatch"),+ ] {+ assert!(error.to_string().contains("Local-only"), "{error}");+ }+}++/// Outside local-only a per-request `-cloud` tag is allowed, but the prompt+/// goes to ollama.com: it is disclosed as external egress for the model the+/// request names, not the local tag the route was built for.+#[tokio::test]+async fn a_cloud_tag_named_per_request_is_recorded_as_external_egress() {+ use crate::core::bus::BUS;+ use crate::core::events::DomainEvent;+ use crate::security::egress::EgressDescriptor;+ use std::time::Duration;+ use tinyinference_llm::model::ModelRequest;++ let _guard = crate::inference::inference_test_guard_async().await;+ let _env = EnvVarGuard::locked_unset_many_async(ENDPOINT_ENV).await;+ let _mode = crate::security::live_policy::test_privacy_scope(PrivacyMode::Standard);+ crate::core::bus::init().await.expect("bus init");+ let mut rx = BUS.get().unwrap().receiver();++ let (model, _) = create_test_chat_model_from_string(+ "chat",+ "ollama:llama3",+ &local_ai_at("http://127.0.0.1:9/v1"),+ )+ .expect("a local Ollama tag builds");+ let marker = "egress-per-request-marker-cloud";+ // Nothing listens on port 9: the request fails after the guard ran.+ let _ = model+ .invoke(&(), ModelRequest::new(Vec::new()).with_model(marker))+ .await;++ let sentinel = "egress-per-request-sentinel";+ BUS.publish(DomainEvent::ExternalTransferPending {+ descriptor: EgressDescriptor::network_fetch(sentinel),+ thread_id: None,+ client_id: None,+ request_id: None,+ });+ loop {+ match tokio::time::timeout(Duration::from_secs(3), rx.recv()).await {+ Ok(Some(DomainEvent::ExternalTransferPending { descriptor, .. })) => {+ if descriptor.service == marker {+ assert!(descriptor.is_external, "{descriptor:?}");+ break;+ }+ assert_ne!(+ descriptor.service, sentinel,+ "a per-request cloud tag was not recorded as egress"+ );+ }+ Ok(Some(_)) => continue,+ Ok(None) => panic!("the bus closed before the sentinel arrived"),+ Err(_) => panic!("timed out before egress sentinel arrived"),+ }+ }+}