Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(teleport): push --url reads in the local daemon with Keyvault consent (CUA-2854) (#6193)
ddupont00d7a3015c0c
diff --git a/docs/content/docs/cua-cli/reference/cli/files-teleport-and-keys.mdx b/docs/content/docs/cua-cli/reference/cli/files-teleport-and-keys.mdxindex 992e7789d3..36646f661d 100644--- a/docs/content/docs/cua-cli/reference/cli/files-teleport-and-keys.mdx+++ b/docs/content/docs/cua-cli/reference/cli/files-teleport-and-keys.mdx@@ -585,9 +585,10 @@ cua teleport push [OPTIONS] --app <APP>| <span id="cua-teleport-push--profile"></span>`--profile` | | string | | | Chrome profile to capture: a name ("Profile 1") or a path. || <span id="cua-teleport-push--display-name"></span>`--display-name` | | string | | | Display name for the app (UI only). || <span id="cua-teleport-push--sandbox"></span>`--sandbox` | `-s` | string | | | Destination sandbox (name). |-| <span id="cua-teleport-push--url"></span>`--url` | | string | | | Destination cua-spacesd URL instead of a sandbox. |+| <span id="cua-teleport-push--url"></span>`--url` | | string | | | Destination cua-spacesd URL instead of a sandbox: another daemon's API, or any machine you can reach. The browser is read by the local Cua daemon with the same Keyvault consent, audit record and wipe as `--sandbox`; `--url` only names where it goes. || <span id="cua-teleport-push--token"></span>`--token` | | string | | `CUA_ENV_TOKEN` | Token for `--url`. || <span id="cua-teleport-push--include"></span>`--include` | | string | | | Send exactly this manifest item (repeatable; see `manifest`). Default: the provider's default selection, which leaves credentials-heavy or bulky items (cookies, transcripts) out unless named here. |+| <span id="cua-teleport-push--read-as-caller"></span>`--read-as-caller` | | boolean | `false` | | With `--url`, read the app in this command's own process instead of the Cua daemon. Consent, the audit record and the wipe are skipped, and macOS uses this process's permissions, not Cua's. Scheduled for removal; use `--url` alone. || <span id="cua-teleport-push--all"></span>`--all` | | boolean | `false` | | Send every item the scope offers. || <span id="cua-teleport-push--no-launch"></span>`--no-launch` | | boolean | `false` | | Do not launch the app in the sandbox after importing. || <span id="cua-teleport-push--progress"></span>`--progress` | | boolean | `false` | | Print `progress <sent> <total>` lines while uploading. |diff --git a/docs/content/docs/spaces/guides/teleport-an-app.mdx b/docs/content/docs/spaces/guides/teleport-an-app.mdxindex 67dc021729..9e8439fb92 100644--- a/docs/content/docs/spaces/guides/teleport-an-app.mdx+++ b/docs/content/docs/spaces/guides/teleport-an-app.mdx@@ -246,8 +246,34 @@ cua teleport push --app com.google.Chrome --url http://10.0.0.5:3211 --token "$T`--include PATH` picks items, `--all` sends everything, `--no-launch` importsonly. `--sandbox NAME` routes through your own [Cua Keyvault](/spaces/guides/keyvault)(one combined Touch ID prompt for the whole capture-and-deliver, and nothing-raw ever leaves it); `--url` uploads a bundle straight to a spacesd endpoint-the Keyvault does not manage as a Space, so it never goes through the vault.+raw ever leaves it). `--url` names a destination that is not one of your+Spaces, such as another machine's address, and goes the same way: the Cua+daemon on this machine reads the app, you approve it with the same Keyvault+prompt, it is recorded in the audit log, and the copy is wiped on the same+schedule. The destination is only where it goes, and it is not kept in your+Spaces afterwards. Because the daemon does the reading, macOS uses the Full+Disk Access you gave the Cua app, not the permissions of the terminal you ran+the command in.++### When macOS asks for permission++Sending a browser's signed-in sites reads its files, and macOS decides whether+Cua may do that. Teleport checks first and says what is missing, in words,+before it asks for Touch ID or reads anything:++```bash test="cli-shape" id="cua-teleport-doctor"+cua teleport doctor+cua teleport doctor --app chrome --profile "Profile 1"+```++It reports whether the Keyvault is set up, whether macOS lets Cua read the+browser's files (Full Disk Access) and its open tabs (Automation), and which+browser profiles exist, with the account signed in to each and the one used+last. Cua cannot grant these for you: macOS only lets you, in System Settings,+under Privacy and Security. macOS applies Full Disk Access to a program when it+starts, so after turning it on, restart the Cua daemon. Without Full Disk+Access you can still teleport open tabs only. Without a `--profile`, a push+reads the `Default` profile, so pick the one you are signed in to.### When macOS asks for permissiondiff --git a/libs/cua/crates/cua-cli/src/teleport.rs b/libs/cua/crates/cua-cli/src/teleport.rsindex 4fcd00d69f..9a27e8ea53 100644--- a/libs/cua/crates/cua-cli/src/teleport.rs+++ b/libs/cua/crates/cua-cli/src/teleport.rs@@ -75,9 +75,18 @@ pub struct PushArgs {required_unless_present = "url")]pub sandbox: Option<String>,- /// Destination cua-spacesd URL instead of a sandbox.+ /// Destination cua-spacesd URL instead of a sandbox: another daemon's+ /// API, or any machine you can reach. The browser is read by the local+ /// Cua daemon with the same Keyvault consent, audit record and wipe as+ /// `--sandbox`; `--url` only names where it goes.#[arg(long)]pub url: Option<String>,+ /// With `--url`, read the app in this command's own process instead of+ /// the Cua daemon. Consent, the audit record and the wipe are skipped, and+ /// macOS uses this process's permissions, not Cua's. Scheduled for+ /// removal; use `--url` alone.+ #[arg(long, requires = "url")]+ pub read_as_caller: bool,/// Token for `--url`.#[arg(long, env = "CUA_ENV_TOKEN", hide_env_values = true, requires = "url")]pub token: Option<String>,diff --git a/libs/cua/crates/cua-spaces-cli/src/teleport.rs b/libs/cua/crates/cua-spaces-cli/src/teleport.rsindex e90238a0d4..4e4caf8fab 100644--- a/libs/cua/crates/cua-spaces-cli/src/teleport.rs+++ b/libs/cua/crates/cua-spaces-cli/src/teleport.rs@@ -270,13 +270,110 @@ async fn push() -> Result<i32, CuaError> {match (&args.sandbox, &args.url) {(Some(name), _) => push_through_keyvault(host, name, &args, json, out).await,- (None, Some(_)) => push_direct(cua, host, args, json, out).await,+ (None, Some(_)) if args.read_as_caller => {+ eprintln!("{READ_AS_CALLER_WARNING}");+ push_direct(cua, host, args, json, out).await+ }+ (None, Some(url)) => {+ let spaces = cua.spaces();+ let url = url.clone();+ let token = args.token.clone();+ with_destination(spaces.as_ref(), &url, token, |id| {+ let host = host.clone();+ let args = &args;+ async move { push_through_keyvault(&host, &id, args, json, out).await }+ })+ .await+ }(None, None) => Err(CuaError::InvalidArgument("pass --sandbox NAME or --url URL".into(),)),}}+/// What `--read-as-caller` costs, said once before it reads.+const READ_AS_CALLER_WARNING: &str = "warning: --read-as-caller reads the app in this process, \+not in the Cua daemon: Keyvault consent, the audit record and the wipe are skipped, and macOS \+uses this process's permissions. This flag is going away; use --url without it.";++/// Where the local daemon keeps Spaces: the part of `with_destination` that+/// registers and forgets one, so the order of events can be tested.+#[async_trait::async_trait]+pub trait DestinationRegistry: Send + Sync {+ /// The ids of the Spaces registered now.+ async fn ids(&self) -> Result<Vec<String>, CuaError>;+ /// Registers the destination at `url`; returns its Space id.+ async fn add(&self, url: &str, token: Option<String>, name: &str) -> Result<String, CuaError>;+ /// Forgets a Space (its machine is not touched).+ async fn remove(&self, id: &str) -> Result<(), CuaError>;+}++#[async_trait::async_trait]+impl DestinationRegistry for cua_sdk::Spaces {+ async fn ids(&self) -> Result<Vec<String>, CuaError> {+ Ok(self.list().await?.into_iter().map(|s| s.id).collect())+ }+ async fn add(&self, url: &str, token: Option<String>, name: &str) -> Result<String, CuaError> {+ Ok(self+ .add(url.to_string(), token, Some(name.to_string()))+ .await?+ .id)+ }+ async fn remove(&self, id: &str) -> Result<(), CuaError> {+ self.remove(id.to_string()).await+ }+}++/// The Space id a `--url` destination has once registered: the address+/// (`host:port`) without scheme or path, as `direct:<authority>`; an id given+/// as is stays as it is.+pub fn destination_id(url: &str) -> String {+ let url = url.trim();+ if url.starts_with("space://")+ || ["local:", "cloud:", "direct:", "relay:"]+ .iter()+ .any(|p| url.starts_with(p))+ {+ return url.to_string();+ }+ let rest = url.split_once("://").map_or(url, |(_, r)| r);+ let authority = rest.split('/').next().unwrap_or(rest);+ format!("direct:{authority}")+}++/// Runs `push` against the destination `url` as a Space of the local daemon,+/// so the read, the consent, the audit record and the wipe are the daemon's,+/// as for `--sandbox`. A destination already registered is used as it is (its+/// own token, and it stays). Otherwise it is registered for this push and+/// forgotten after it, whether it worked or not; a destination that does not+/// answer fails here, before anything is read or asked.+pub async fn with_destination<R, F, Fut>(+ registry: &R,+ url: &str,+ token: Option<String>,+ push: F,+) -> Result<i32, CuaError>+where+ R: DestinationRegistry + ?Sized,+ F: FnOnce(String) -> Fut,+ Fut: std::future::Future<Output = Result<i32, CuaError>>,+{+ let wanted = destination_id(url);+ if registry.ids().await?.contains(&wanted) {+ return push(wanted).await;+ }+ let name = format!("teleport-destination-{}", std::process::id());+ let id = registry.add(url, token, &name).await.map_err(|e| match e {+ CuaError::PermissionDenied(_) | CuaError::InvalidArgument(_) => e,+ other => CuaError::Unsupported(format!(+ "the destination {url} did not answer as a Cua Space, so nothing was read: {other}"+ )),+ })?;+ let result = push(id.clone()).await;+ let _ = registry.remove(&id).await;+ result+}+/// `cua teleport push --sandbox NAME`: resolves the selection locally (the/// exact same [`cua_teleport::resolve_selection`] `Teleporter::send` uses,/// so `--include`/`--all`/the default set mean exactly what `teleport@@ -383,8 +480,9 @@ async fn push_through_keyvault(Ok(0)}-/// `cua teleport push --url URL`: the direct path, unchanged -- an arbitrary-/// spacesd endpoint the Keyvault does not manage as a Space.+/// `cua teleport push --url URL --read-as-caller`: the old direct path, kept+/// only behind that flag: this process reads the app and uploads to an+/// arbitrary spacesd endpoint, skipping the Keyvault.async fn push_direct(cua: &Cua,host: &Arc<dyn HostEffects>,@@ -594,6 +692,7 @@ mod tests {&env.url,"--token","t",+ "--read-as-caller","--include","electron/Preferences",]) else {@@ -609,4 +708,190 @@ mod tests {assert_eq!(imports[0].app, "slack");assert!(imports[0].options.launch_after);}++ // --- `--url` is a destination; the daemon reads --------------------++ #[derive(Default)]+ struct FakeRegistry {+ existing: Vec<String>,+ fail_add: bool,+ events: std::sync::Mutex<Vec<String>>,+ }++ #[async_trait::async_trait]+ impl DestinationRegistry for FakeRegistry {+ async fn ids(&self) -> Result<Vec<String>, CuaError> {+ Ok(self.existing.clone())+ }+ async fn add(+ &self,+ url: &str,+ token: Option<String>,+ _name: &str,+ ) -> Result<String, CuaError> {+ self.events+ .lock()+ .unwrap()+ .push(format!("add {url} token={}", token.is_some()));+ if self.fail_add {+ return Err(CuaError::Internal("connection refused".into()));+ }+ Ok(destination_id(url))+ }+ async fn remove(&self, id: &str) -> Result<(), CuaError> {+ self.events.lock().unwrap().push(format!("remove {id}"));+ Ok(())+ }+ }++ #[test]+ fn a_url_destination_has_the_id_the_registry_gives_it() {+ assert_eq!(+ destination_id("http://10.0.0.5:3211"),+ "direct:10.0.0.5:3211"+ );+ assert_eq!(destination_id("10.0.0.5:3211/x"), "direct:10.0.0.5:3211");+ assert_eq!(+ destination_id("https://box.example:443"),+ "direct:box.example:443"+ );+ assert_eq!(destination_id("relay:abc"), "relay:abc");+ assert_eq!(destination_id("direct:h:1"), "direct:h:1");+ }++ #[tokio::test]+ async fn a_new_destination_is_registered_for_the_push_and_forgotten_after_it() {+ let reg = FakeRegistry::default();+ let seen = std::sync::Mutex::new(None);+ let code = with_destination(®, "http://10.0.0.5:3211", Some("t".into()), |id| {+ *seen.lock().unwrap() = Some(id);+ async { Ok(0) }+ })+ .await+ .unwrap();+ assert_eq!(code, 0);+ // The daemon's push targets the registered Space id, not the URL.+ assert_eq!(+ seen.lock().unwrap().as_deref(),+ Some("direct:10.0.0.5:3211")+ );+ assert_eq!(+ *reg.events.lock().unwrap(),+ [+ "add http://10.0.0.5:3211 token=true",+ "remove direct:10.0.0.5:3211"+ ]+ );+ }++ #[tokio::test]+ async fn a_refused_push_still_forgets_the_destination_and_keeps_its_exact_refusal() {+ let reg = FakeRegistry::default();+ let err = with_destination(®, "10.0.0.5:3211", None, |_| async {+ Err::<i32, _>(CuaError::PermissionDenied("chrome: declined".into()))+ })+ .await+ .unwrap_err();+ assert!(+ matches!(&err, CuaError::PermissionDenied(m) if m == "chrome: declined"),+ "{err:?}"+ );+ assert_eq!(+ reg.events.lock().unwrap().last().unwrap(),+ "remove direct:10.0.0.5:3211"+ );+ }++ #[tokio::test]+ async fn a_destination_that_is_already_registered_is_used_and_kept() {+ let reg = FakeRegistry {+ existing: vec!["direct:10.0.0.5:3211".into()],+ ..Default::default()+ };+ let seen = std::sync::Mutex::new(None);+ with_destination(®, "http://10.0.0.5:3211", Some("other".into()), |id| {+ *seen.lock().unwrap() = Some(id);+ async { Ok(0) }+ })+ .await+ .unwrap();+ assert_eq!(+ seen.lock().unwrap().as_deref(),+ Some("direct:10.0.0.5:3211")+ );+ assert!(reg.events.lock().unwrap().is_empty(), "no add, no remove");+ }++ #[tokio::test]+ async fn a_destination_that_does_not_answer_fails_before_anything_is_read() {+ let reg = FakeRegistry {+ fail_add: true,+ ..Default::default()+ };+ let read = std::sync::atomic::AtomicBool::new(false);+ let err = with_destination(®, "10.0.0.5:3211", None, |_| {+ read.store(true, std::sync::atomic::Ordering::SeqCst);+ async { Ok(0) }+ })+ .await+ .unwrap_err();+ assert!(+ !read.load(std::sync::atomic::Ordering::SeqCst),+ "nothing was read or asked"+ );+ assert!(err.to_string().contains("nothing was read"), "{err}");+ // Nothing was registered, so nothing is removed.+ assert!(+ reg.events+ .lock()+ .unwrap()+ .iter()+ .all(|e| !e.starts_with("remove"))+ );+ }++ #[test]+ fn read_as_caller_is_explicit_needs_a_url_and_is_not_the_default() {+ let TeleportCmd::Push(a) = parse(&["teleport", "push", "--app", "chrome", "--url", "x:1"])+ else {+ panic!()+ };+ assert!(!a.read_as_caller);+ let TeleportCmd::Push(a) = parse(&[+ "teleport",+ "push",+ "--app",+ "chrome",+ "--url",+ "x:1",+ "--read-as-caller",+ ]) else {+ panic!()+ };+ assert!(a.read_as_caller);+ // The warning names what is skipped.+ for word in ["consent", "audit", "wipe", "going away"] {+ assert!(READ_AS_CALLER_WARNING.contains(word), "{word}");+ }+ assert!(!READ_AS_CALLER_WARNING.contains('\u{b7}'));+ }++ #[test]+ fn a_profile_is_accepted_with_either_destination() {+ for dest in [["--sandbox", "dev"], ["--url", "10.0.0.5:3211"]] {+ let TeleportCmd::Push(a) = parse(&[+ "teleport",+ "push",+ "--app",+ "chrome",+ dest[0],+ dest[1],+ "--profile",+ "Profile 1",+ ]) else {+ panic!()+ };+ assert_eq!(a.app.profile.as_deref(), Some("Profile 1"));+ }+ }}diff --git a/libs/cua/crates/cua-spaces-cli/tests/keyvault.rs b/libs/cua/crates/cua-spaces-cli/tests/keyvault.rsindex 27f526b516..bd8f1bdc54 100644--- a/libs/cua/crates/cua-spaces-cli/tests/keyvault.rs+++ b/libs/cua/crates/cua-spaces-cli/tests/keyvault.rs@@ -400,3 +400,105 @@ async fn import_session_whole_app_or_named_sites() {assert!(o.stdout.contains("Saved 1 item: 1 new"), "{}", o.stdout);assert!(!o.stdout.contains("teleported") && !o.stdout.contains("delivered to"));}++/// `cua teleport push --url`: the URL is only the destination. The app is read+/// by the Keyvault's daemon (here the test's broker, with a fake backend), so+/// the same presence prompt and capture run as for `--sandbox`; the profile+/// reaches the capture; a refusal is the permission-denied exit code; the+/// destination is registered for the push only; and a destination that does+/// not answer fails before anything is read or asked.+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]+async fn push_to_a_url_is_read_and_approved_by_the_daemon_not_the_caller() {+ let backend = Arc::new(FakeImportBackend::default());+ let mut r = rig_with_backend(backend.clone() as Arc<dyn Backend>).await;+ // The app is a fixture Slack profile under this test's own HOME (a temp+ // dir), so the caller's manifest listing touches nothing real.+ r.home.set("CUA_ENV_TEST_SANDBOX", "0");+ let prof = r._short.path().join("Library/Application Support/Slack");+ std::fs::create_dir_all(&prof).unwrap();+ std::fs::write(prof.join("Cookies"), b"slack-cookies").unwrap();+ std::fs::write(prof.join("Preferences"), b"{}").unwrap();+ let o = with_stdin(+ &r.home,+ &["keyvault", "init", "--passphrase-stdin", "--json"],+ &format!("{PASSPHRASE}\n"),+ )+ .await;+ assert_eq!(o.ok().json()["created"], true);+ let dest = cua_daemon::fixtures::start_env(Some("t"), None).await;+ let url = dest.url.clone();+ let push = |profile: &str| {+ vec![+ "teleport",+ "push",+ "--app",+ "slack",+ "--all",+ "--url",+ url.as_str(),+ "--token",+ "t",+ "--profile",+ profile,+ ]+ .into_iter()+ .map(str::to_string)+ .collect::<Vec<_>>()+ };+ let run = |args: Vec<String>| {+ let home = &r.home;+ async move {+ let a: Vec<&str> = args.iter().map(String::as_str).collect();+ home.run(&a).await+ }+ };++ // Refused consent: the exact permission-denied code, and the capture+ // never ran (nothing was read before the prompt was answered).+ r.presence.set(false);+ let o = run(push("Profile 1")).await;+ assert_eq!(o.code, 6, "stdout:\n{}\nstderr:\n{}", o.stdout, o.stderr);+ assert!(+ backend.specs.lock().unwrap().is_empty(),+ "read before consent"+ );+ assert!(+ !r.presence.asked.lock().unwrap().is_empty(),+ "the daemon asked"+ );++ // Approved: the daemon's capture ran for the named profile (the fake+ // backend cannot deliver, so the push itself fails after that).+ r.presence.set(true);+ let o = run(push("Profile 1")).await;+ assert_ne!(o.code, 0);+ {+ let specs = backend.specs.lock().unwrap();+ let last = specs.last().expect("the daemon captured");+ assert_eq!(last.app, "slack");+ assert_eq!(last.profile.as_deref(), Some("Profile 1"));+ assert!(last.whole_app);+ }+ // Nothing reached the destination, and this process read nothing itself.+ assert!(dest.mock.state.teleport_imports().is_empty());++ // A destination that does not answer: fails before any read or prompt.+ let asked = r.presence.asked.lock().unwrap().len();+ let captured = backend.specs.lock().unwrap().len();+ let o = run([+ "teleport",+ "push",+ "--app",+ "slack",+ "--all",+ "--url",+ "127.0.0.1:1",+ ]+ .map(str::to_string)+ .to_vec())+ .await;+ assert_ne!(o.code, 0);+ assert!(o.stderr.contains("nothing was read"), "{}", o.stderr);+ assert_eq!(r.presence.asked.lock().unwrap().len(), asked);+ assert_eq!(backend.specs.lock().unwrap().len(), captured);+}diff --git a/scripts/docs-generators/cli-specs/cua.json b/scripts/docs-generators/cli-specs/cua.jsonindex 5b58d37e37..37b7b90b57 100644--- a/scripts/docs-generators/cli-specs/cua.json+++ b/scripts/docs-generators/cli-specs/cua.json@@ -17832,6 +17832,17 @@"aliases": [],"arguments": [],"flags": [+ {+ "aliases": [],+ "default_value": false,+ "env": null,+ "help": "With `--url`, read the app in this command's own process instead of the Cua daemon. Consent, the audit record and the wipe are skipped, and macOS uses this process's permissions, not Cua's. Scheduled for removal; use `--url` alone",+ "hidden": false,+ "name": "read-as-caller",+ "repeatable": false,+ "short_name": null,+ "takes_value": false+ },{"aliases": [],"default_value": false,@@ -17965,7 +17976,7 @@"aliases": [],"default_value": null,"env": null,- "help": "Destination cua-spacesd URL instead of a sandbox",+ "help": "Destination cua-spacesd URL instead of a sandbox: another daemon's API, or any machine you can reach. The browser is read by the local Cua daemon with the same Keyvault consent, audit record and wipe as `--sandbox`; `--url` only names where it goes","hidden": false,"is_optional": true,"multiple_values": false,