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): local-only refuses Ollama cloud tags and non-loopback endpoints
M3gA-Mind8d664671dcca
diff --git a/crates/openhuman-core/src/inference/provider/factory.rs b/crates/openhuman-core/src/inference/provider/factory.rsindex 68022d2b3c..eaee763ef9 100644--- a/crates/openhuman-core/src/inference/provider/factory.rs+++ b/crates/openhuman-core/src/inference/provider/factory.rs@@ -43,7 +43,7 @@ pub use routing::{provider_for_role, role_bypasses_managed_credits};pub(crate) use routing::{workload_router, ConfigRouteSource};// Factory-internal helpers shared across the implementation modules.-use access_gates::{emit_inference_egress, enforce_local_only_inference};+use access_gates::enforce_local_only_inference;#[cfg(test)]use cloud_slug::try_create_cloud_slug_chat_model;pub(crate) use managed_backend::{diff --git a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs b/crates/openhuman-core/src/inference/provider/factory/access_gates.rsindex bcce11271a..4760492720 100644--- a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs+++ b/crates/openhuman-core/src/inference/provider/factory/access_gates.rs@@ -62,12 +62,56 @@ pub(super) fn local_only_violation(// Deferred: re-resolves to a concrete string on the recursive call.return None;}- if tinyinference_local::profile::is_local_provider_string(p) {+ if tinyinference_local::profile::is_local_provider_string(p) && !is_ollama_cloud_model(p) {return None;}Some(external_provider_label(p))}+/// An Ollama `*-cloud` tag: the local daemon proxies it to ollama.com, so+/// the prompt leaves the machine although the route is named local.+pub(super) fn is_ollama_cloud_model(provider: &str) -> bool {+ let Some((prefix, model)) = provider.trim().split_once(':') else {+ return false;+ };+ let tag = model+ .rsplit_once('@')+ .map_or(model, |(tag, _temperature)| tag);+ prefix.eq_ignore_ascii_case("ollama") && tag.to_ascii_lowercase().ends_with("-cloud")+}++/// Whether `endpoint` stays on this machine. Only loopback counts: a LAN+/// address is another machine.+pub(super) fn is_loopback_endpoint(endpoint: &str) -> bool {+ match url::Url::parse(endpoint.trim())+ .ok()+ .and_then(|url| url.host().map(|h| h.to_owned()))+ {+ Some(url::Host::Domain(host)) => {+ let host = host.to_ascii_lowercase();+ host == "localhost" || host.ends_with(".localhost")+ }+ // A client dialling the unspecified address reaches this machine.+ Some(url::Host::Ipv4(ip)) => ip.is_loopback() || ip.is_unspecified(),+ Some(url::Host::Ipv6(ip)) => ip.is_loopback() || ip.is_unspecified(),+ None => false,+ }+}++/// Privacy Mode `LocalOnly` for a resolved local-runtime endpoint: refuse+/// one that is not loopback (the prompt and the `local_ai` key would go there).+pub(super) fn enforce_local_only_endpoint(role: &str, endpoint: &str) -> anyhow::Result<()> {+ let mode = crate::security::live_policy::current_privacy_mode();+ if mode != crate::config::PrivacyMode::LocalOnly || is_loopback_endpoint(endpoint) {+ return Ok(());+ }+ log::warn!("[privacy][chat-factory] LocalOnly BLOCK: role={role} local runtime endpoint is not loopback");+ anyhow::bail!(+ "Local-only privacy mode is active: this local model's endpoint is on another machine. \+ Point it at this computer (localhost) or change privacy mode in Settings."+ )+}+/// Enforce Privacy Mode `LocalOnly` at the inference chokepoint: refuse to build/// an external chat provider when the live policy is local-only. Reads the live/// privacy mode (defaults to `Standard`/allow when no session policy isdiff --git a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rsindex 370e5bb93f..618b6e757e 100644--- a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs+++ b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs@@ -2,7 +2,10 @@//! local-openai) as crate-native `ChatModel`s.use super::*;-use crate::inference::provider::factory::access_gates::verify_provider_session;+use crate::inference::provider::factory::access_gates::{+ enforce_local_only_endpoint, is_loopback_endpoint, is_ollama_cloud_model,+ verify_provider_session,+};use tinyinference_llm::providers::openai::build_local_runtime_chat_model;use tinyinference_llm::providers::openai::AuthStyle as CompatAuthStyle;@@ -103,13 +106,6 @@ fn try_create_local_runtime_chat_model_from_string_with_identity(}}- // Egress spine (privacy epic S2, #4436): committed to a local runtime here- // (past the non-local `None` return + access gates). Disclose it as- // NON-external — local inference never leaves the device, so- // `emit_external_transfer` records it without firing a pending event. This- // is the single local chokepoint for every ChatModel/turn entry.- emit_inference_egress(role, &p, egress);-// Endpoint, auth, model and `@temp` resolution is the module's pure// `resolve_local_runtime`; the host only supplies config + env.let inputs = LocalRuntimeInputs {@@ -122,6 +118,26 @@ fn try_create_local_runtime_chat_model_from_string_with_identity(Ok(r) => r,Err(e) => return Some(Err(anyhow::anyhow!("{e}"))),};+ if let Err(e) = enforce_local_only_endpoint(role, &resolved.endpoint) {+ return Some(Err(e));+ }+ // Egress spine (privacy epic S2, #4436): the single local chokepoint for+ // every ChatModel/turn entry. A loopback runtime is disclosed as+ // non-external; another host, or an Ollama `-cloud` tag, is external.+ let external = !is_loopback_endpoint(&resolved.endpoint) || is_ollama_cloud_model(&p);+ let service = if resolved.model.is_empty() {+ role+ } else {+ &resolved.model+ };+ crate::security::egress::emit_external_transfer_in(+ egress,+ crate::security::egress::EgressDescriptor::inference(+ resolved.kind.as_str().to_string(),+ service.to_string(),+ external,+ ),+ );if let Some(identity) = inspection_identity {let credential = match &resolved.auth {LocalRuntimeAuth::None => String::new(),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.rsnew file mode 100644index 0000000000..be5fd3b336--- /dev/null+++ b/crates/openhuman-core/src/inference/provider/factory_local_only_endpoint_tests.rs@@ -0,0 +1,114 @@+//! Local-only privacy mode means the prompt stays on this machine. Two routes+//! named "local" break that: an Ollama `-cloud` tag, which the local daemon+//! proxies to ollama.com, and a local-runtime prefix whose endpoint is another+//! host (it gets the prompt and the `local_ai` bearer key). Only loopback counts+//! as local; a LAN address is another machine.++use super::*;+use crate::config::PrivacyMode;+use crate::inference::provider::factory::access_gates::local_only_violation;++fn local_ai_at(base_url: &str) -> Config {+ let mut config = Config::default();+ config.local_ai.base_url = Some(base_url.to_string());+ config+}++#[test]+fn local_only_refuses_ollama_cloud_proxied_models() {+ for provider in [+ "ollama:gpt-oss:120b-cloud",+ "ollama:kimi-k2:[email protected]",+ "ollama:deepseek-v3.1:671B-Cloud",+ ] {+ assert!(+ local_only_violation(PrivacyMode::LocalOnly, provider).is_some(),+ "LocalOnly permitted the cloud-proxied model {provider}"+ );+ }+ assert_eq!(+ local_only_violation(PrivacyMode::LocalOnly, "ollama:llama3.1:8b"),+ None+ );+ assert_eq!(+ local_only_violation(PrivacyMode::Standard, "ollama:gpt-oss:120b-cloud"),+ None+ );+}++#[test]+fn local_only_refuses_a_local_runtime_pointed_at_another_host() {+ let _guard = crate::inference::inference_test_guard();+ let _mode = crate::security::live_policy::test_privacy_scope(PrivacyMode::LocalOnly);+ for (provider, base_url) in [+ ("local-openai:m", "https://gpu.example.invalid/v1"),+ ("lmstudio:m", "http://192.168.1.20:1234/v1"),+ ("ollama:m", "http://gpu.example.invalid:11434"),+ ] {+ let result = create_test_chat_model_from_string("chat", provider, &local_ai_at(base_url));+ let error = match result {+ Ok(_) => panic!("LocalOnly built {provider} against {base_url}"),+ Err(error) => error.to_string(),+ };+ assert!(+ error.contains("Local-only"),+ "{provider} at {base_url}: unexpected error {error}"+ );+ }+ for base_url in [+ "http://127.0.0.1:1234/v1",+ "http://localhost:11434/v1",+ "http://[::1]:8080/v1",+ ] {+ assert!(+ create_test_chat_model_from_string("chat", "local-openai:m", &local_ai_at(base_url))+ .is_ok(),+ "LocalOnly refused the loopback endpoint {base_url}"+ );+ }+}++#[tokio::test]+async fn a_local_runtime_pointed_at_another_host_is_recorded_as_external_egress() {+ use crate::core::bus::BUS;+ use crate::core::events::DomainEvent;+ use crate::security::egress::EgressDescriptor;+ use std::time::Duration;++ crate::core::bus::init().await.expect("bus init");+ let mut rx = BUS.get().unwrap().receiver();++ let marker = "egress-remote-local-runtime-marker";+ let mut config = local_ai_at("https://gpu.example.invalid/v1");+ config.chat_provider = Some(format!("local-openai:{marker}"));+ let _ = create_chat_model_with_model_id_in(+ &crate::core::runtime::DispatchCtx::ambient(),+ "chat",+ &config,+ 0.7,+ );++ let sentinel = "egress-remote-local-runtime-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 {+ break;+ }+ assert_ne!(+ descriptor.service, sentinel,+ "a remote local-runtime endpoint was recorded as local egress"+ );+ }+ Ok(Some(_)) => continue,+ Ok(None) => panic!("the bus closed before the sentinel arrived"),+ Err(_) => panic!("timed out before egress sentinel arrived"),+ }+ }+}diff --git a/crates/openhuman-core/src/inference/provider/factory_tests.rs b/crates/openhuman-core/src/inference/provider/factory_tests.rsindex b0f0358172..66c2b7c89e 100644--- a/crates/openhuman-core/src/inference/provider/factory_tests.rs+++ b/crates/openhuman-core/src/inference/provider/factory_tests.rs@@ -630,6 +630,8 @@ mod crate_native_tests;mod egress_fallback_tests;#[path = "factory_explicit_ctx_tests.rs"]mod explicit_ctx_tests;+#[path = "factory_local_only_endpoint_tests.rs"]+mod local_only_endpoint_tests;#[path = "factory_managed_ledger_tests.rs"]mod managed_ledger_tests;#[path = "factory_model_gate_tests.rs"]