Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

test(cua-driver): accept Developer ID requirements in the Lume TCC seeder (#4185)

Francesco Bonacci097c086e1465
diff --git a/libs/cua-driver/scripts/tests/test_macos_lume_runner.py b/libs/cua-driver/scripts/tests/test_macos_lume_runner.py
index b844046108..d3c1283bdb 100644
--- a/libs/cua-driver/scripts/tests/test_macos_lume_runner.py
+++ b/libs/cua-driver/scripts/tests/test_macos_lume_runner.py
@@ -306,6 +306,132 @@ def test_tcc_guest_seed_requires_certificate_backed_requirement_by_default() ->
assert "^Signature=adhoc$" in text
assert 'certificate (leaf|root) = H"[[:xdigit:]]{40}"' in text
assert "is not signed with a certificate-backed identity" in text
+ assert 'classify_designated_requirement "${REQUIREMENT}" "${SIGNING_IDENTIFIER}"' in text
+
+
+# The designated requirement codesign derives for the released, notarized
+# CuaDriver.app (Developer ID Application: Cua AI, Inc.).
+RELEASED_DEVELOPER_ID_DR = (
+ 'identifier "com.trycua.driver" and anchor apple generic and '
+ "certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and "
+ "certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and "
+ "certificate leaf[subject.OU] = YCK386LBJ7"
+)
+LOCAL_LEAF_HASH_DR = (
+ 'identifier "com.trycua.driver.local" and '
+ 'certificate leaf = H"0123456789abcdef0123456789abcdef01234567"'
+)
+
+
+def _classify_requirement(requirement: str, identifier: str = "") -> subprocess.CompletedProcess[str]:
+ return subprocess.run(
+ [
+ "bash",
+ "-c",
+ 'script="$1" requirement="$2" identifier="$3"; set --; '
+ 'source "$script"; classify_designated_requirement "$requirement" "$identifier"',
+ "classify-test",
+ str(SEED_TCC_GUEST),
+ requirement,
+ identifier,
+ ],
+ capture_output=True,
+ text=True,
+ env={**os.environ, "CUA_TCC_SEED_LIB_ONLY": "1"},
+ check=False,
+ )
+
+
+ ("requirement", "identifier", "kind"),
+ [
+ pytest.param(RELEASED_DEVELOPER_ID_DR, "com.trycua.driver", "developer-id", id="released-developer-id"),
+ pytest.param(RELEASED_DEVELOPER_ID_DR, "", "developer-id", id="released-developer-id-no-identifier"),
+ pytest.param(
+ RELEASED_DEVELOPER_ID_DR.replace("= YCK386LBJ7", '= "YCK386LBJ7"'),
+ "com.trycua.driver",
+ "developer-id",
+ id="quoted-team-id",
+ ),
+ pytest.param(LOCAL_LEAF_HASH_DR, "com.trycua.driver.local", "leaf-hash", id="local-leaf-hash"),
+ pytest.param(
+ 'identifier "com.trycua.driver.local" and anchor apple generic and '
+ 'certificate root = H"89abcdef0123456789abcdef0123456789abcdef"',
+ "com.trycua.driver.local",
+ "leaf-hash",
+ id="root-hash",
+ ),
+ ],
+)
+def test_tcc_guest_seed_accepts_certificate_backed_requirements(
+ requirement: str, identifier: str, kind: str
+) -> None:
+ completed = _classify_requirement(requirement, identifier)
+ assert completed.returncode == 0, completed.stderr
+ assert completed.stdout.strip() == kind
+
+
+ ("requirement", "identifier"),
+ [
+ pytest.param('cdhash H"0123456789abcdef0123456789abcdef01234567"', "", id="adhoc-cdhash"),
+ pytest.param(
+ 'identifier "com.trycua.driver.local" and cdhash H"0123456789abcdef0123456789abcdef01234567"',
+ "com.trycua.driver.local",
+ id="adhoc-identifier-cdhash",
+ ),
+ pytest.param("", "", id="empty"),
+ pytest.param(
+ RELEASED_DEVELOPER_ID_DR.replace("YCK386LBJ7", "YCK386LBJ"),
+ "com.trycua.driver",
+ id="short-team-id",
+ ),
+ pytest.param(
+ RELEASED_DEVELOPER_ID_DR.replace("YCK386LBJ7", "yck386lbj7"),
+ "com.trycua.driver",
+ id="lowercase-team-id",
+ ),
+ pytest.param(
+ RELEASED_DEVELOPER_ID_DR.replace("YCK386LBJ7", "YCK386LBJ7 or cdhash H\"00\""),
+ "com.trycua.driver",
+ id="trailing-disjunction",
+ ),
+ pytest.param(
+ RELEASED_DEVELOPER_ID_DR.replace("= YCK386LBJ7", '= "YCK386LBJ7'),
+ "com.trycua.driver",
+ id="unbalanced-quote",
+ ),
+ pytest.param(
+ RELEASED_DEVELOPER_ID_DR.replace("anchor apple generic and ", ""),
+ "com.trycua.driver",
+ id="missing-apple-anchor",
+ ),
+ pytest.param(
+ RELEASED_DEVELOPER_ID_DR.replace('identifier "com.trycua.driver" and ', ""),
+ "",
+ id="missing-identifier",
+ ),
+ pytest.param(RELEASED_DEVELOPER_ID_DR, "com.trycua.driver.local", id="identifier-mismatch"),
+ ],
+)
+def test_tcc_guest_seed_rejects_non_certificate_backed_requirements(
+ requirement: str, identifier: str
+) -> None:
+ completed = _classify_requirement(requirement, identifier)
+ assert completed.returncode == 1
+ assert completed.stdout.strip() == "rejected"
+
+
+def test_tcc_guest_seed_library_mode_fails_closed_when_executed() -> None:
+ completed = subprocess.run(
+ ["bash", str(SEED_TCC_GUEST)],
+ capture_output=True,
+ text=True,
+ env={**os.environ, "CUA_TCC_SEED_LIB_ONLY": "1"},
+ check=False,
+ )
+ assert completed.returncode == 2
+ assert "valid only when this script is sourced" in completed.stderr
@pytest.mark.parametrize(
@@ -323,6 +449,42 @@ def test_harness_guides_route_automated_tcc_through_guarded_helper(document: Pat
assert "rows alone" in text or "helper exit alone" in text
+def test_tcc_host_seed_parses_lume_json_with_jq_not_python() -> None:
+ text = SEED_TCC.read_text(encoding="utf-8")
+ assert "python3 -c" not in text
+ assert "command -v python3" not in text
+ assert "command -v jq" in text
+ assert "jq -r --arg name" in text
+
+
+@requires_jq
+ ("payload", "message"),
+ [
+ ('[{"status":"stopped","ipAddress":null}]', "expected running VM with an IP"),
+ ('[{"status":"running","ipAddress":"192.0.2.10","sshAvailable":false}]', "SSH is not available yet"),
+ ("[]", "lume get returned no VM record"),
+ ],
+)
+def test_tcc_host_seed_refuses_unready_vms(tmp_path: Path, payload: str, message: str) -> None:
+ fake_bin = tmp_path / "bin"
+ for tool in ("scp", "ssh"):
+ _write_executable(fake_bin / tool, "exit 99\n")
+ _write_executable(fake_bin / "lume", f"printf '%s\\n' '{payload}'\n")
+ completed = subprocess.run(
+ ["bash", str(SEED_TCC), "--timeout", "5", "worker-a"],
+ capture_output=True,
+ stdin=subprocess.DEVNULL,
+ text=True,
+ env={**os.environ, "PATH": f"{fake_bin}:{os.environ['PATH']}"},
+ check=False,
+ )
+ assert completed.returncode != 0
+ assert f"worker-a: {message}" in completed.stderr
+ assert "installing guest TCC seeder" not in completed.stdout
+
+
+@requires_jq
def test_tcc_host_seed_runs_the_guest_helper_once_per_vm(tmp_path: Path) -> None:
fake_bin = tmp_path / "bin"
fake_lume = fake_bin / "lume"
diff --git a/libs/cua-driver/tests/runners/macos-lume/README.md b/libs/cua-driver/tests/runners/macos-lume/README.md
index 5a66e2326a..26d887d80a 100644
--- a/libs/cua-driver/tests/runners/macos-lume/README.md
+++ b/libs/cua-driver/tests/runners/macos-lume/README.md
@@ -304,6 +304,12 @@ The guest helper refuses to write unless `sysctl -n hw.model` reports a
permission identity from `/Applications/CuaDriverLocal.app`, writes only the
Accessibility and Screen Recording entries for that app, restarts `tccd`, and
verifies both entries.
+It accepts a designated requirement that pins a certificate leaf or root hash
+(local stable signing) or the exact Apple-anchored Developer ID requirement of a
+notarized release (`anchor apple generic` with a 10-character team ID). It
+rejects ad hoc `cdhash` requirements unless `--allow-adhoc` is passed. To seed
+the released app, pass `--app /Applications/CuaDriver.app --expected-client
+com.trycua.driver`. The host wrapper parses `lume get` with `jq`.
After seeding, restart `CuaDriverLocal.app` before checking permission status if
`install-local --autostart` or an earlier probe may have started the daemon:
diff --git a/libs/cua-driver/tests/runners/macos-lume/seed-tcc-guest.sh b/libs/cua-driver/tests/runners/macos-lume/seed-tcc-guest.sh
index 20f1e8f01a..40048d5861 100755
--- a/libs/cua-driver/tests/runners/macos-lume/seed-tcc-guest.sh
+++ b/libs/cua-driver/tests/runners/macos-lume/seed-tcc-guest.sh
@@ -73,6 +73,40 @@ bundle_executable_path() {
printf '%s/Contents/MacOS/%s\n' "${app}" "${executable_name}"
}
+# Classify a designated requirement (the text after "designated => " in
+# `codesign -d -r-`). Prints the accepted form and returns 0 when the
+# requirement is certificate-backed; prints "rejected" and returns 1 otherwise.
+#
+# Accepted forms:
+# leaf-hash A requirement that pins a certificate leaf or root SHA-1 hash,
+# as produced by local self-signed or stable signing identities.
+# developer-id The exact Apple-anchored Developer ID Application requirement
+# that codesign derives for notarized releases:
+# identifier "<id>" and anchor apple generic and the Developer
+# ID intermediate and leaf markers and a 10-character team ID.
+# When a second argument is given, the requirement identifier
+# must equal it.
+# Everything else, including ad hoc cdhash-only requirements, is rejected.
+DEVELOPER_ID_REQUIREMENT_RE='^identifier "([A-Za-z0-9][A-Za-z0-9.-]*)" and anchor apple generic and certificate 1\[field\.1\.2\.840\.113635\.100\.6\.2\.6\] /\* exists \*/ and certificate leaf\[field\.1\.2\.840\.113635\.100\.6\.1\.13\] /\* exists \*/ and certificate leaf\[subject\.OU\] = ([A-Z0-9]{10}|"[A-Z0-9]{10}")$'
+LEAF_HASH_REQUIREMENT_RE='certificate (leaf|root) = H"[[:xdigit:]]{40}"'
+
+classify_designated_requirement() {
+ local requirement="$1"
+ local expected_identifier="${2:-}"
+ if [[ "${requirement}" =~ ${LEAF_HASH_REQUIREMENT_RE} ]]; then
+ echo "leaf-hash"
+ return 0
+ fi
+ if [[ "${requirement}" =~ ${DEVELOPER_ID_REQUIREMENT_RE} ]]; then
+ if [[ -z "${expected_identifier}" || "${BASH_REMATCH[1]}" == "${expected_identifier}" ]]; then
+ echo "developer-id"
+ return 0
+ fi
+ fi
+ echo "rejected"
+ return 1
+}
+
sql_escape() {
/usr/bin/sed "s/'/''/g" <<< "$1"
}
@@ -87,6 +121,16 @@ run_sudo() {
fi
}
+# Tests source this script with CUA_TCC_SEED_LIB_ONLY=1 to exercise the
+# classifier without a VM. Executing it in that mode is refused.
+if [[ "${CUA_TCC_SEED_LIB_ONLY:-0}" == 1 ]]; then
+ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
+ echo "CUA_TCC_SEED_LIB_ONLY is valid only when this script is sourced" >&2
+ exit 2
+ fi
+ return 0
+fi
+
MODEL="$(/usr/sbin/sysctl -n hw.model 2>/dev/null || true)"
[[ "${MODEL}" == VirtualMac* ]] || fail "refusing to edit TCC outside a Lume/VirtualMac guest (hw.model=${MODEL:-unknown})"
@@ -158,10 +202,10 @@ if [[ "${ALLOW_ADHOC}" != 1 ]]; then
if printf '%s\n' "${CODESIGN_INFO}" | /usr/bin/grep -q '^Signature=adhoc$'; then
fail "${SIGN_TARGET} has an ad hoc signature; rerun install-local with --require-stable-signing, or use --allow-adhoc only for an explicitly authorized one-build grant"
fi
- if ! printf '%s\n' "${REQUIREMENT}" |
- /usr/bin/grep -Eq 'certificate (leaf|root) = H"[[:xdigit:]]{40}"'; then
- fail "${SIGN_TARGET} is not signed with a certificate-backed identity; expected its designated requirement to bind a certificate leaf or root hash"
+ if ! REQUIREMENT_KIND="$(classify_designated_requirement "${REQUIREMENT}" "${SIGNING_IDENTIFIER}")"; then
+ fail "${SIGN_TARGET} is not signed with a certificate-backed identity; expected its designated requirement to bind a certificate leaf or root hash, or to be an Apple-anchored Developer ID requirement for ${SIGNING_IDENTIFIER} (got: ${REQUIREMENT})"
fi
+ echo "seed-tcc: designated requirement accepted as ${REQUIREMENT_KIND}"
fi
CSREQ_TMPDIR="$(/usr/bin/mktemp -d /tmp/cua-driver-tcc-csreq.XXXXXX)"
diff --git a/libs/cua-driver/tests/runners/macos-lume/seed-tcc.sh b/libs/cua-driver/tests/runners/macos-lume/seed-tcc.sh
index ce147883ff..f9f1856d72 100755
--- a/libs/cua-driver/tests/runners/macos-lume/seed-tcc.sh
+++ b/libs/cua-driver/tests/runners/macos-lume/seed-tcc.sh
@@ -140,8 +140,8 @@ command -v scp >/dev/null 2>&1 || {
echo "scp is not on PATH" >&2
exit 2
}
-command -v python3 >/dev/null 2>&1 || {
- echo "python3 is not on PATH" >&2
+command -v jq >/dev/null 2>&1 || {
+ echo "jq is not on PATH" >&2
exit 2
}
if [[ "${SSH_TIMEOUT}" != 0 && ! -x /usr/bin/perl ]]; then
@@ -171,24 +171,20 @@ resolve_lume_ip() {
args+=(--storage "${STORAGE}")
fi
info="$(lume "${args[@]}")"
- python3 -c '
-import json
-import sys
-
-name = sys.argv[1]
-payload = json.load(sys.stdin)
-vm = payload[0] if isinstance(payload, list) and payload else payload
-status = vm.get("status")
-ip = vm.get("ipAddress")
-ssh_available = vm.get("sshAvailable")
-if status != "running" or not ip:
- print(f"{name}: expected running VM with an IP, got status={status!r} ip={ip!r}", file=sys.stderr)
- sys.exit(1)
-if ssh_available is False:
- print(f"{name}: SSH is not available yet", file=sys.stderr)
- sys.exit(1)
-print(ip)
-' "${vm}" <<< "${info}"
+ # jq (a documented host requirement) avoids host python3, which can be the
+ # Command Line Tools stub that opens an install prompt.
+ jq -r --arg name "${vm}" '
+ (if type == "array" then .[0] else . end) as $vm
+ | if ($vm | type) != "object" then
+ error("\($name): lume get returned no VM record")
+ elif $vm.status != "running" or (($vm.ipAddress // "") == "") then
+ error("\($name): expected running VM with an IP, got status=\($vm.status | tojson) ip=\($vm.ipAddress | tojson)")
+ elif $vm.sshAvailable == false then
+ error("\($name): SSH is not available yet")
+ else
+ $vm.ipAddress
+ end
+ ' <<< "${info}"
}
ssh_base_opts() {