diff --git a/MODULE.md b/MODULE.md index 918cba155..51206bb8a 100644 --- a/MODULE.md +++ b/MODULE.md @@ -80,7 +80,10 @@ is optional: `settle` (`prompt`, the default, or `steady`: how long a page is let settle after an action), and `prelaunch` (a boolean, `true` by default: open a browser-only task's browser while it is planned, at the one web - address the task's text names, if it names one). + address the task's text names, if it names one). Its `profile` (the folder + kept between sessions, the only one a launch may name under egress) applies + only when a session or task names it as its profile (`user_data_dir` or + `browser_profile`); one that names none starts fresh. Configuration is delivered as sensitive host-control traffic and is never shown to monitors. diff --git a/crates/tinycomputer-browser/src/linked/linked_tests.rs b/crates/tinycomputer-browser/src/linked/linked_tests.rs index 3bf99e96e..169458c53 100644 --- a/crates/tinycomputer-browser/src/linked/linked_tests.rs +++ b/crates/tinycomputer-browser/src/linked/linked_tests.rs @@ -101,7 +101,7 @@ async fn a_closed_or_lost_browser_cannot_implicitly_launch_without_the_proxy() { proxy: None, proxy_session_id: "private-session-id".into(), proxy_password: "private-proxy-password".into(), - host_executable: None, + host: super::HostBrowser::default(), enforced_launch: true, }; let reply = engine @@ -124,7 +124,7 @@ async fn an_exited_enforced_browser_can_still_be_closed() { proxy: None, proxy_session_id: "private-session-id".into(), proxy_password: "private-proxy-password".into(), - host_executable: None, + host: super::HostBrowser::default(), enforced_launch: true, }; @@ -143,7 +143,7 @@ async fn enforced_browser_refuses_process_side_reads_with_a_url() { proxy: None, proxy_session_id: "private-session-id".into(), proxy_password: "private-proxy-password".into(), - host_executable: None, + host: super::HostBrowser::default(), enforced_launch: true, }; let reply = engine @@ -170,7 +170,7 @@ async fn enforced_browser_rechecks_liveness_after_waiting_for_engine_lock() { proxy: None, proxy_session_id: "private-session-id".into(), proxy_password: "private-proxy-password".into(), - host_executable: None, + host: super::HostBrowser::default(), enforced_launch: true, }; let serialized = ENGINE.lock().await; diff --git a/crates/tinycomputer-browser/src/linked/linked_tests/launch_tests.rs b/crates/tinycomputer-browser/src/linked/linked_tests/launch_tests.rs index e8cebe517..07cae4a32 100644 --- a/crates/tinycomputer-browser/src/linked/linked_tests/launch_tests.rs +++ b/crates/tinycomputer-browser/src/linked/linked_tests/launch_tests.rs @@ -1,7 +1,7 @@ //! Tests for browser launch command rewriting and policy refusal. #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] -use super::super::{AMBIENT_BROWSER_ENV, enforce_launch_with_config}; +use super::super::{AMBIENT_BROWSER_ENV, HostBrowser, enforce_launch_with_config}; use serde_json::json; #[test] @@ -11,7 +11,7 @@ fn enforced_launch_uses_only_the_host_proxy_and_network_containment_flags() { "http://127.0.0.1:39123", "session-secret", false, - None, + &HostBrowser::default(), ) .expect("enforced launch"); assert_eq!(launch["proxy"]["server"], "http://127.0.0.1:39123"); @@ -36,7 +36,7 @@ fn enforced_launch_refuses_external_cdp_and_caller_flags() { "http://127.0.0.1:39123", "session-secret", false, - None, + &HostBrowser::default(), ); assert!(cdp.is_err()); let args = enforce_launch_with_config( @@ -44,7 +44,7 @@ fn enforced_launch_refuses_external_cdp_and_caller_flags() { "http://127.0.0.1:39123", "session-secret", false, - None, + &HostBrowser::default(), ); assert!(args.is_err()); let executable = enforce_launch_with_config( @@ -52,7 +52,7 @@ fn enforced_launch_refuses_external_cdp_and_caller_flags() { "http://127.0.0.1:39123", "session-secret", false, - None, + &HostBrowser::default(), ); assert!(executable.is_err()); let ambient = enforce_launch_with_config( @@ -60,7 +60,7 @@ fn enforced_launch_refuses_external_cdp_and_caller_flags() { "http://127.0.0.1:39123", "session-secret", true, - None, + &HostBrowser::default(), ); assert!(ambient.is_err()); } @@ -92,7 +92,7 @@ fn enforced_launch_refuses_caller_plugins_extensions_and_init_scripts() { "http://127.0.0.1:39123", "session-secret", false, - None, + &HostBrowser::default(), ) .is_err(), "{field} was accepted" @@ -111,7 +111,7 @@ fn a_host_executable_launches_under_the_enforced_proxy() { "http://127.0.0.1:39123", "session-secret", false, - Some("/opt/host/chrome"), + &HostBrowser::executable("/opt/host/chrome"), ) .expect("host executable launches"); assert_eq!(launch["executablePath"], "/opt/host/chrome"); @@ -138,7 +138,10 @@ fn a_request_cannot_name_an_executable_the_host_did_not_configure() { "http://127.0.0.1:39123", "session-secret", false, - host, + &HostBrowser { + executable: host.map(str::to_owned), + profile: None, + }, ) .is_err(), "{requested} with host {host:?}" @@ -151,8 +154,87 @@ fn a_request_cannot_name_an_executable_the_host_did_not_configure() { "http://127.0.0.1:39123", "session-secret", true, - Some("/opt/host/chrome"), + &HostBrowser::executable("/opt/host/chrome"), ) .is_err() ); } + +fn host_profile() -> HostBrowser { + HostBrowser { + executable: Some("/opt/host/chrome".into()), + profile: Some("/srv/state/browser/profile".into()), + } +} + +/// The host's own profile folder keeps cookies and sign-ins between +/// sessions; it launches under the proxy with extensions off, so nothing +/// stored in the profile can install a proxy of its own. +#[test] +fn a_host_profile_launches_under_the_enforced_proxy_without_extensions() { + for command in [ + json!({"action":"launch"}), + json!({"action":"launch","profile":"/srv/state/browser/profile"}), + ] { + let launch = enforce_launch_with_config( + command.clone(), + "http://127.0.0.1:39123", + "session-secret", + false, + &host_profile(), + ) + .expect("host profile launches"); + let args = launch["args"].as_array().expect("args"); + assert_eq!( + args.contains(&json!("--disable-extensions")), + command.get("profile").is_some(), + "{command}" + ); + assert_eq!(launch["proxy"]["server"], "http://127.0.0.1:39123"); + // The profile is used only when the session asked for it: a session + // that named none still starts fresh. + assert_eq!(launch.get("profile"), command.get("profile")); + } +} + +#[test] +fn a_request_cannot_name_a_profile_the_host_did_not_configure() { + for (requested, host) in [ + (json!("/tmp/attacker-profile"), host_profile()), + (json!(7), host_profile()), + (json!("/srv/state/browser/profile"), HostBrowser::default()), + ( + json!("/srv/state/browser/profile"), + HostBrowser::executable("/opt/host/chrome"), + ), + ] { + assert!( + enforce_launch_with_config( + json!({"action":"launch","profile":requested}), + "http://127.0.0.1:39123", + "session-secret", + false, + &host, + ) + .is_err(), + "{requested} with host {:?}", + host.profile + ); + } + // The host profile does not lift the other refusals. + for field in ["storageState", "restore", "cdpUrl"] { + let mut command = json!({"action":"launch","profile":"/srv/state/browser/profile"}); + command[field] = json!("x"); + assert!( + enforce_launch_with_config( + command, + "http://127.0.0.1:39123", + "session-secret", + false, + &host_profile(), + ) + .is_err(), + "{field}" + ); + } +} diff --git a/crates/tinycomputer-browser/src/linked/mod.rs b/crates/tinycomputer-browser/src/linked/mod.rs index 12e029d88..85becf837 100644 --- a/crates/tinycomputer-browser/src/linked/mod.rs +++ b/crates/tinycomputer-browser/src/linked/mod.rs @@ -30,7 +30,25 @@ pub struct AgentBrowser; #[derive(Clone)] pub struct EnforcedAgentBrowser { authorizer: Arc, - executable: Option, + host: HostBrowser, +} + +/// What the host, never a browser call, chooses for an enforced launch: the +/// Chrome binary and the profile folder kept between sessions. +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub(crate) struct HostBrowser { + pub(crate) executable: Option, + pub(crate) profile: Option, +} + +impl HostBrowser { + #[cfg(test)] + pub(crate) fn executable(executable: &str) -> Self { + Self { + executable: Some(executable.to_owned()), + profile: None, + } + } } impl std::fmt::Debug for EnforcedAgentBrowser { @@ -45,7 +63,7 @@ impl EnforcedAgentBrowser { pub fn new(authorizer: Arc) -> Self { Self { authorizer, - executable: None, + host: HostBrowser::default(), } } @@ -53,7 +71,18 @@ impl EnforcedAgentBrowser { /// control, like the proxy: a launch may repeat it but never name another. #[must_use] pub fn with_executable(mut self, executable: Option) -> Self { - self.executable = executable; + self.host.executable = executable; + self + } + + /// Let a launch use the host-configured profile folder, so cookies and + /// sign-ins survive between sessions. It is host control, like the + /// executable: a launch may name this folder but never another, and it + /// runs with extensions off, since an extension stored in the profile + /// could set a proxy that outranks the enforced one. + #[must_use] + pub fn with_profile(mut self, profile: Option) -> Self { + self.host.profile = profile; self } } @@ -66,7 +95,7 @@ impl Launcher for AgentBrowser { proxy: None, proxy_session_id: String::new(), proxy_password: String::new(), - host_executable: None, + host: HostBrowser::default(), enforced_launch: false, }) } @@ -75,7 +104,7 @@ impl Launcher for AgentBrowser { impl Launcher for EnforcedAgentBrowser { fn open(&self, session: &str) -> Box { let mut engine = enforced(self.authorizer.clone(), session); - engine.host_executable.clone_from(&self.executable); + engine.host.clone_from(&self.host); Box::new(engine) } } @@ -90,7 +119,7 @@ fn enforced(authorizer: Arc, session: &str) -> Linked { proxy: None, proxy_session_id: private_session_id(), proxy_password: private_session_id(), - host_executable: None, + host: HostBrowser::default(), enforced_launch: false, } } @@ -101,7 +130,7 @@ struct Linked { proxy: Option, proxy_session_id: String, proxy_password: String, - host_executable: Option, + host: HostBrowser, enforced_launch: bool, } @@ -144,7 +173,7 @@ impl Engine for Linked { command.clone(), &proxy.url(), &self.proxy_password, - self.host_executable.as_deref(), + &self.host, ) { Ok(command) => command, Err(reason) => return failure_reply(&command, reason), @@ -232,7 +261,7 @@ fn enforce_launch( command: Value, proxy: &str, proxy_password: &str, - host_executable: Option<&str>, + host: &HostBrowser, ) -> Result { let has_ambient_browser_config = command.get("action").and_then(Value::as_str) == Some("launch") @@ -242,7 +271,7 @@ fn enforce_launch( proxy, proxy_password, has_ambient_browser_config, - host_executable, + host, ) } @@ -251,8 +280,9 @@ fn enforce_launch_with_config( proxy: &str, proxy_password: &str, has_ambient_browser_config: bool, - host_executable: Option<&str>, + host: &HostBrowser, ) -> Result { + let host_executable = host.executable.as_deref(); if command.get("action").and_then(Value::as_str) != Some("launch") { return Ok(command); } @@ -261,7 +291,6 @@ fn enforce_launch_with_config( "cdpPort", "autoConnect", "provider", - "profile", "storageState", "restore", ] @@ -270,6 +299,13 @@ fn enforce_launch_with_config( { return Err("network policy refuses attached or externally managed browsers"); } + // Only the host chooses the profile folder, as it does the binary: a + // launch may name the host's own folder, or none for a fresh profile. + if let Some(requested) = command.get("profile") + && (host.profile.is_none() || requested.as_str() != host.profile.as_deref()) + { + return Err("network policy refuses a browser profile the host did not configure"); + } // Only the host chooses the binary. A launch may repeat the host's own // executable (hosts send it with each session) but not name another. if let Some(requested) = command.get("executablePath") @@ -309,12 +345,18 @@ fn enforce_launch_with_config( if let Some(executable) = host_executable { command["executablePath"] = json!(executable); } - command["args"] = json!([ + let mut args = vec![ "--disable-quic", "--disable-http2", "--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1", - "--force-webrtc-ip-handling-policy=disable_non_proxied_udp" - ]); + "--force-webrtc-ip-handling-policy=disable_non_proxied_udp", + ]; + // Chrome ranks an extension's proxy above the command line's, and a kept + // profile can carry installed extensions. + if command.get("profile").is_some() { + args.push("--disable-extensions"); + } + command["args"] = json!(args); Ok(command) } diff --git a/crates/tinycomputer-bus/src/config/browser.rs b/crates/tinycomputer-bus/src/config/browser.rs index 6c217fd13..7267bfa3c 100644 --- a/crates/tinycomputer-bus/src/config/browser.rs +++ b/crates/tinycomputer-bus/src/config/browser.rs @@ -34,6 +34,12 @@ pub struct BrowserConfig { /// The Chrome or Chromium executable to launch, if the host selected one. #[serde(skip_serializing_if = "Option::is_none")] pub executable: Option, + /// The Chrome profile folder (an absolute path) the host keeps between + /// sessions, so cookies and sign-ins survive a restart. Host control, + /// like `executable`: under an egress policy a launch may name this + /// folder and no other. + #[serde(skip_serializing_if = "Option::is_none")] + pub profile: Option, /// The User-Agent sent by every launched browser, when set. #[serde(skip_serializing_if = "Option::is_none")] pub user_agent: Option, @@ -55,6 +61,7 @@ impl Default for BrowserConfig { fn default() -> Self { Self { executable: None, + profile: None, user_agent: None, args: Vec::new(), perception: BrowserPerception::default(), @@ -72,6 +79,7 @@ impl std::fmt::Debug for BrowserConfig { "executable", &self.executable.as_ref().map(|_| "[REDACTED]"), ) + .field("profile", &self.profile.as_ref().map(|_| "[REDACTED]")) .field( "user_agent", &self.user_agent.as_ref().map(|_| "[REDACTED]"), diff --git a/crates/tinycomputer-bus/src/config/config_tests.rs b/crates/tinycomputer-bus/src/config/config_tests.rs index a11463371..0bb2f1b2f 100644 --- a/crates/tinycomputer-bus/src/config/config_tests.rs +++ b/crates/tinycomputer-bus/src/config/config_tests.rs @@ -86,6 +86,7 @@ fn browser_config_defaults_and_serializes_non_default_fields() { fn browser_config_debug_redacts_sensitive_values() { let config = BrowserConfig { executable: Some("/secret/chromium".into()), + profile: Some("/secret/profile".into()), user_agent: Some("private agent string".into()), args: vec!["--private-argument".into()], ..BrowserConfig::default() @@ -93,6 +94,7 @@ fn browser_config_debug_redacts_sensitive_values() { let debug = format!("{config:?}"); assert!(!debug.contains("/secret/chromium")); + assert!(!debug.contains("/secret/profile")); assert!(!debug.contains("private agent string")); assert!(!debug.contains("--private-argument")); assert!(debug.contains("args_count: 1")); diff --git a/crates/tinycomputer-bus/src/version/mod.rs b/crates/tinycomputer-bus/src/version/mod.rs index 7cb6ede70..44aad09cb 100644 --- a/crates/tinycomputer-bus/src/version/mod.rs +++ b/crates/tinycomputer-bus/src/version/mod.rs @@ -8,7 +8,7 @@ //! release workflow bumps, which tracks the shipped artifact. /// The wire contract version this crate defines. -pub const CONTRACT_VERSION: (u32, u32) = (3, 0); +pub const CONTRACT_VERSION: (u32, u32) = (3, 1); /// Returns whether a host holding [`CONTRACT_VERSION`] can bind to a module /// reporting `module`. @@ -22,7 +22,8 @@ pub const CONTRACT_VERSION: (u32, u32) = (3, 0); /// ``` /// # use tinycomputer_bus::{is_compatible, CONTRACT_VERSION}; /// assert!(is_compatible(CONTRACT_VERSION)); -/// assert!(is_compatible((3, 0))); +/// assert!(is_compatible((3, 1))); +/// assert!(!is_compatible((3, 0))); /// assert!(!is_compatible((2, 29))); /// assert!(!is_compatible((1, 8))); /// ``` diff --git a/crates/tinycomputer-bus/src/version/version_tests.rs b/crates/tinycomputer-bus/src/version/version_tests.rs index d101323cf..b134a5eab 100644 --- a/crates/tinycomputer-bus/src/version/version_tests.rs +++ b/crates/tinycomputer-bus/src/version/version_tests.rs @@ -6,7 +6,7 @@ use super::{CONTRACT_VERSION, binds, is_compatible}; #[test] fn the_shipped_contract_version_is_pinned() { - assert_eq!(CONTRACT_VERSION, (3, 0)); + assert_eq!(CONTRACT_VERSION, (3, 1)); } #[test] @@ -16,8 +16,11 @@ fn the_contract_binds_to_itself() { #[test] fn a_newer_minor_on_the_module_side_binds() { - assert!(is_compatible((3, 0))); + assert!(is_compatible((3, 1))); assert!(is_compatible((3, 97))); + // 3.1 adds the optional `browser.profile` module configuration field. A + // 3.0 module rejects it as unknown, so a 3.1 host cannot bind to one. + assert!(!is_compatible((3, 0))); // The history below is the 2.x line, which 3.0 no longer binds at all. // 2.24 adds same-task flow-to-planner handoff to StartTask. // 2.22 adds optional host-held secret handles to StartTask and RunFlow. diff --git a/crates/tinycomputer-engine/src/agentic/runtime.rs b/crates/tinycomputer-engine/src/agentic/runtime.rs index e034459a5..f177ad85b 100644 --- a/crates/tinycomputer-engine/src/agentic/runtime.rs +++ b/crates/tinycomputer-engine/src/agentic/runtime.rs @@ -414,15 +414,11 @@ pub(super) const fn approved_endpoint(provider: JevProvider) -> &'static str { pub(super) fn trusted_endpoint(provider: JevProvider, endpoint: &str) -> bool { let approved = approved_endpoint(provider); // Sage's endpoint is its API root, so its trailing slash is optional. - if endpoint == approved - || (provider == JevProvider::Sage && endpoint == approved.trim_end_matches('/')) - { - return true; - } + let trusted = endpoint == approved + || (provider == JevProvider::Sage && endpoint == approved.trim_end_matches('/')); #[cfg(test)] - return endpoint.starts_with("http://127.0.0.1:"); - #[cfg(not(test))] - false + let trusted = trusted || endpoint.starts_with("http://127.0.0.1:"); + trusted } /// The HTTP client configuration for a Jev `request`: its provider's diff --git a/crates/tinycomputer/src/tinybus_module/README.md b/crates/tinycomputer/src/tinybus_module/README.md index 680722040..a2557ef2f 100644 --- a/crates/tinycomputer/src/tinybus_module/README.md +++ b/crates/tinycomputer/src/tinybus_module/README.md @@ -59,7 +59,9 @@ types used by the engine. The module adapter converts `trace_path` into `Desktop` settings and applies the typed browser defaults: `browser` sets how every browser launches — `executable`, `user_agent`, `args`, a task's page `perception`, how a page `settle`s after an action, and whether to `prelaunch` -a planned browser task's browser. +a planned browser task's browser. The kept `profile` applies only when a +session or task names it as its profile (`user_data_dir` or +`browser_profile`); one that names none starts fresh. Setting `trace_sink` to an object with the unique `destination` supplied by `ModuleHost::prepare_host_callbacks` opts into the host's confidential diff --git a/crates/tinycomputer/src/tinybus_module/dispatch/service.rs b/crates/tinycomputer/src/tinybus_module/dispatch/service.rs index 829437c31..d5322b46c 100644 --- a/crates/tinycomputer/src/tinybus_module/dispatch/service.rs +++ b/crates/tinycomputer/src/tinybus_module/dispatch/service.rs @@ -117,17 +117,18 @@ impl DesktopService { let egress = BrowserDefaults::egress_from_raw(config) .map_err(|error| TinyBusError::failed(error.to_string()))?; let browser = if let Some(egress) = &egress { - let executable = computer_config(config) + let host = computer_config(config) .map_err(|error| TinyBusError::failed(error.to_string()))? .browser - .and_then(|browser| browser.executable); + .unwrap_or_default(); Arc::new(Browser::new(Arc::new( EnforcedAgentBrowser::new(Arc::new(BusAuthorizer::new( connection.clone(), egress.policy_id.clone(), egress.generation, ))) - .with_executable(executable), + .with_executable(host.executable) + .with_profile(host.profile), ))) } else { Arc::new(Browser::new(Arc::new(AgentBrowser))) diff --git a/crates/tinycomputer/src/tinybus_module/dispatch/service_tests.rs b/crates/tinycomputer/src/tinybus_module/dispatch/service_tests.rs index 7f9b1016e..114eb057e 100644 --- a/crates/tinycomputer/src/tinybus_module/dispatch/service_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/dispatch/service_tests.rs @@ -13,6 +13,7 @@ fn module_service_consumes_shared_config_and_preserves_its_extensions() { let shared = ComputerConfig { browser: Some(BrowserConfig { executable: Some("/opt/chromium".into()), + profile: None, user_agent: None, args: vec!["--disable-gpu".into()], perception: BrowserPerception::Tree, diff --git a/crates/tinycomputer/src/tinybus_module/static_link_tests.rs b/crates/tinycomputer/src/tinybus_module/static_link_tests.rs index eab01b44b..968b9ada5 100644 --- a/crates/tinycomputer/src/tinybus_module/static_link_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/static_link_tests.rs @@ -21,3 +21,65 @@ async fn linked_module_is_admitted_by_the_module_host() { assert_eq!(host.list().len(), 1); broker_task.abort(); } + +/// Loads the linked module with an egress scope and the host's profile folder, +/// then opens a session asking for `user_data_dir`, returning the reply. +async fn open_with_profile(user_data_dir: &str) -> tinycomputer_bus::DesktopResponse { + use tinybus::Connection; + use tinycomputer_bus::{DesktopResponse, browser::names::methods, names}; + + let bus = MemoryBus::new(); + let broker = Broker::new(); + let broker_task = broker.spawn(bus.clone()); + let host = ModuleHost::new(broker); + host.attach_linked_with_config( + super::linked_module().expect("manifest is valid"), + serde_json::json!({"browser": { + // A binary that cannot start, so a permitted launch fails fast + // instead of looking for or starting a real Chrome. + "executable": "/nonexistent/host-chrome", + "profile": "/srv/state/browser/profile", + "egress": {"policy_id": "host-policy", "generation": 7} + }}), + ) + .expect("linked tinycomputer is admitted"); + let client = Connection::connect(bus.connect().await.expect("transport")) + .await + .expect("client connection"); + let proxy = client + .proxy(names::INTERFACE, names::OBJECT_PATH, names::INTERFACE) + .expect("proxy"); + let reply: DesktopResponse = proxy + .call( + methods::OPEN_SESSION, + (serde_json::json!({"user_data_dir": user_data_dir}),), + ) + .await + .expect("the call reaches the module"); + broker_task.abort(); + reply +} + +#[tokio::test] +async fn a_session_may_not_name_a_profile_the_host_did_not_configure() { + let reply = open_with_profile("/tmp/some-other-profile").await; + assert!(!reply.ok, "another folder must be refused"); + let error = format!("{:?}", reply.error); + assert!( + error.contains("a browser profile the host did not configure"), + "unexpected error: {error}" + ); +} + +#[tokio::test] +async fn a_session_may_name_the_host_profile_through_the_enforced_launcher() { + // Without the host's `with_profile` wiring this launch is refused by the + // profile gate; with it the gate passes, and whatever happens next (no + // Chrome here, or a launch) is not the profile refusal. + let reply = open_with_profile("/srv/state/browser/profile").await; + let error = format!("{:?}", reply.error); + assert!( + !error.contains("a browser profile the host did not configure"), + "the host's own profile was refused: {error}" + ); +} diff --git a/crates/tinycomputer/src/tinybus_module/tinybus_module_tests/config_tests.rs b/crates/tinycomputer/src/tinybus_module/tinybus_module_tests/config_tests.rs index 31d933de8..e8601f20f 100644 --- a/crates/tinycomputer/src/tinybus_module/tinybus_module_tests/config_tests.rs +++ b/crates/tinycomputer/src/tinybus_module/tinybus_module_tests/config_tests.rs @@ -230,6 +230,26 @@ fn the_browser_configuration_is_read_or_refused() { }})) .is_ok() ); + // So does the host's kept profile folder: the enforced launcher lets a + // session use that folder and no other. + let with_profile = json!({"browser": { + "executable": "/usr/bin/chromium", + "profile": "/srv/state/browser/profile", + "egress": {"policy_id": "host-policy", "generation": 7} + }}); + assert!( + BrowserDefaults::egress_from_raw(&with_profile) + .unwrap() + .is_some() + ); + let parsed = serde_json::from_value::(json!({"browser": { + "profile": "/srv/state/browser/profile" + }})) + .unwrap(); + assert_eq!( + parsed.browser.unwrap().profile.as_deref(), + Some("/srv/state/browser/profile") + ); // Settling promptly and opening the browser early are on unless turned // off. let unset = BrowserDefaults::default(); diff --git a/crates/tinycomputer/tests/public_api_tests.rs b/crates/tinycomputer/tests/public_api_tests.rs index bb2cbf446..6dac0ac25 100644 --- a/crates/tinycomputer/tests/public_api_tests.rs +++ b/crates/tinycomputer/tests/public_api_tests.rs @@ -34,7 +34,7 @@ fn the_crate_re_exports_the_contract_rather_than_redefining_it() { #[test] fn the_shipped_contract_binds_to_itself() { assert!(is_compatible(CONTRACT_VERSION)); - assert_eq!(CONTRACT_VERSION, (3, 0)); + assert_eq!(CONTRACT_VERSION, (3, 1)); assert!(!is_compatible((2, 29))); assert!(!is_compatible((2, 25))); } diff --git a/docs/crates/tinycomputer/configuration.md b/docs/crates/tinycomputer/configuration.md index 305cd89e1..0de535a96 100644 --- a/docs/crates/tinycomputer/configuration.md +++ b/docs/crates/tinycomputer/configuration.md @@ -278,18 +278,23 @@ optional: | Key | What it does | |---|---| | `executable` | the Chrome or Chromium binary to launch, for when the platform's own discovery would not find one, for example a container with Chrome installed somewhere nonstandard | +| `profile` | the Chrome profile folder (an absolute path) the host keeps between sessions, so cookies and sign-ins survive a restart. It is not applied by itself: a session or task names it as its profile (`user_data_dir`, `browser_profile`), and one that names none starts fresh. With `egress` set it is the only profile a launch may name | | `user_agent` | the `User-Agent` every launched browser sends; booking sites turn away a browser that announces itself as headless | | `args` | extra launch arguments, as an array of strings | | `perception` | how a task reads a page: `sight` (the default) reads the rendered page as a person sees it, `tree` the accessibility tree alone ([`browser-sight.md`](../../technical/specs/browser-sight.md)) | | `settle` | how a task lets a page settle after an action before reading it again: `prompt` (the default) counts the network's 500 ms of quiet from the start, counting only requests that can change the page and for at most 1 s, and then waits only while the page is still changing (at most 400 ms), so an idle page is read again after about 0.6 s; `steady` waits for the network to go idle, at least about 1.1 s, then 400 ms more | | `prelaunch` | `true` (the default) opens a browser-only task's browser while `StartTask` plans it (a `task` with no `flow`), so the first step does not wait for the launch, and loads in it the one web address the task's text names, if it names one, so a first step that browses there does not wait for the page either; `false` opens it at the first step | -| `egress` | Host-private TinySecurity scope. When present, `policy_id` and `generation` are required; browser `args`, attached DevTools endpoints, caller-supplied launch flags, and any executable other than this section's `executable` are refused. The scope is never a browser or task argument. | +| `egress` | Host-private TinySecurity scope. When present, `policy_id` and `generation` are required; browser `args`, attached DevTools endpoints, caller-supplied launch flags, and any executable or profile other than this section's `executable` and `profile` are refused. The scope is never a browser or task argument. | The launch and attach options above apply only when `egress` is absent, except -`executable`. With `egress` set, TinyComputer owns the launch arguments and +`executable` and `profile`. With `egress` set, TinyComputer owns the launch arguments and launches the host's `executable` (or the discovered Chrome) with its proxy and resolver flags. A task `browser_executable` or session `executable` may repeat the host's path; any other is refused, as are attached DevTools endpoints. +Likewise a session's profile may only be this section's `profile` (or none, +for a fresh one), and a launch that uses it runs with `--disable-extensions`: +Chrome ranks an extension's proxy above the command line's, and a kept profile +can carry installed extensions. `storageState` and `restore` stay refused. With `egress`, every launched browser session uses a private, authenticated loopback proxy. TinyComputer parses each HTTP request, asks the authenticated diff --git a/docs/technical/architecture.md b/docs/technical/architecture.md index 5036b776a..f18dae823 100644 --- a/docs/technical/architecture.md +++ b/docs/technical/architecture.md @@ -227,6 +227,7 @@ configuration validates. | `jev` | object | decision provider (`type_safe`, `open_router`, `tiny_humans_open_router`, `open_jev`, `sage`), API key, optional model, approved endpoint, timeout, retries, `sdk_name` for the TinyHumans proxy, and `fast` for Sage | | `planner` | object | `api_key`, `provider` (`open_router` or `tiny_humans`), approved `endpoint_url`, `sdk_name`, and optional `model` for the planner, optional `rescue_route` giving the rescuer its own route and key, optional `rescue_model` for rescuing failed steps (`docs/technical/specs/task-rescue.md`), and optional `output_model` for shaping a finished task's answer (`docs/technical/specs/task-output.md`); absent means no planner, no rescues, and no output shapes | | `browser.executable` | string | the Chrome or Chromium binary to launch, when discovery would not find one | +| `browser.profile` | string | the profile folder kept between sessions; under egress the only profile a launch may name, and it launches with extensions off | | `cursor` | string or object | the agent's on-screen cursor for desktop and browser: a pace (`off`, `brisk`, `natural` (default), `calm`) or `{pace, overlay}` with the overlay helper's path ([spec](specs/virtual-cursor.md)) | Without `jev`, `ResolveIntent`, `RunGoal`, `RunFlow`, and task runs answer diff --git a/docs/technical/specs/desktop-module-contract.md b/docs/technical/specs/desktop-module-contract.md index 5b258dab6..36b907a1c 100644 --- a/docs/technical/specs/desktop-module-contract.md +++ b/docs/technical/specs/desktop-module-contract.md @@ -348,3 +348,15 @@ endpoints directly. `BrowserReleaseOutput` stay ordinary: they never carry the bytes. A screenshot reply's `OutputRef` does expose the output's id, size, SHA-256 digest, media type, and pixel dimensions in ordinary traffic. + +## Host browser profile (3.1) + +- `browser.profile` is a new optional field of the module's `browser` + configuration: the profile folder the host keeps between sessions. A 3.0 + module rejects it as an unknown field, so this is a minor bump and a 3.1 + host binds only to a 3.1 or newer module. +- The enforced launcher lets a session name that folder through + `user_data_dir`, or none, and refuses any other folder. A profiled launch + runs with `--disable-extensions`, because Chrome ranks an extension's proxy + above the command-line proxy. `storageState`, `restore`, and CDP attach + stay refused.