Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(macos): drop --strict/--deep from local bundle signature verification

Ruben Lütkeeb71236daf73
diff --git a/jarvis/setup/macos_app_bundle.py b/jarvis/setup/macos_app_bundle.py
index 1540637268..b7e081fda7 100644
--- a/jarvis/setup/macos_app_bundle.py
+++ b/jarvis/setup/macos_app_bundle.py
@@ -48,13 +48,9 @@ _MACHO_MAGICS = frozenset(
}
)
-_MIC_USAGE = (
- "Personal Jarvis listens on this microphone for your wake word and "
- "voice commands."
-)
+_MIC_USAGE = "Personal Jarvis listens on this microphone for your wake word and voice commands."
_SCREEN_CAPTURE_USAGE = (
- "Personal Jarvis captures the screen only when you ask it to see or "
- "control applications."
+ "Personal Jarvis captures the screen only when you ask it to see or control applications."
)
@@ -97,27 +93,42 @@ def _is_macho_executable(path: Path) -> bool:
# Windows cannot represent POSIX execute bits. The only Windows caller is
# the explicit cross-platform fixture seam; production validation runs on
# macOS and therefore still requires an executable mode.
- executable_mode = os.name == "nt" or bool(
- mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
- )
+ executable_mode = os.name == "nt" or bool(mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
return executable_mode and magic in _MACHO_MAGICS
-def _codesign_valid(bundle: Path) -> bool:
+def _codesign_issue(bundle: Path) -> str | None:
+ """Return the codesign verification failure detail, or ``None`` if valid.
+
+ Deliberately verifies WITHOUT ``--strict`` and ``--deep``: the local app
+ is a py2app *alias* bundle whose entire design is symlinking the managed
+ checkout and Python runtime, and strict validation rejects every symlink
+ that leaves the bundle ("invalid destination for symbolic link") — it
+ failed on 100% of freshly built bundles on real macOS (Intel and Apple
+ Silicon alike). The ad-hoc signature only has to give the app a stable
+ local TCC identity; distribution-grade validation belongs to the separate
+ Developer-ID signing and notarization pipeline.
+ """
if sys.platform != "darwin":
- return True
+ return None
try:
result = subprocess.run(
- ["/usr/bin/codesign", "--verify", "--deep", "--strict", str(bundle)],
+ ["/usr/bin/codesign", "--verify", str(bundle)],
capture_output=True,
text=True,
timeout=30,
check=False,
creationflags=NO_WINDOW_CREATIONFLAGS,
)
- except (OSError, subprocess.TimeoutExpired):
- return False
- return result.returncode == 0
+ except (OSError, subprocess.TimeoutExpired) as exc:
+ return f"codesign verification did not run: {exc}"
+ if result.returncode == 0:
+ return None
+ return (result.stderr or result.stdout or "unknown codesign error").strip()
+
+
+def _codesign_valid(bundle: Path) -> bool:
+ return _codesign_issue(bundle) is None
def macos_app_bundle_is_launchable(bundle: Path | None = None) -> bool:
@@ -194,9 +205,7 @@ def _try_build_icns(resources_dir: Path) -> str | None:
image = Image.open(source).convert("RGBA")
for size in (16, 32, 64, 128, 256, 512):
image.resize((size, size)).save(iconset / f"icon_{size}x{size}.png")
- image.resize((size * 2, size * 2)).save(
- iconset / f"icon_{size}x{size}@2x.png"
- )
+ image.resize((size * 2, size * 2)).save(iconset / f"icon_{size}x{size}@2x.png")
output = resources_dir / "jarvis.icns"
result = subprocess.run(
["iconutil", "-c", "icns", str(iconset), "-o", str(output)],
@@ -248,12 +257,7 @@ def _write_cross_platform_fixture_bundle(bundle: Path) -> Path:
executable_name = "PersonalJarvis"
executable = macos_dir / executable_name
executable.write_bytes(b"\xcf\xfa\xed\xfeJARVIS_TEST_FIXTURE\n")
- executable.chmod(
- executable.stat().st_mode
- | stat.S_IXUSR
- | stat.S_IXGRP
- | stat.S_IXOTH
- )
+ executable.chmod(executable.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
info = _bundle_plist()
info["CFBundleExecutable"] = executable_name
with (contents / "Info.plist").open("wb") as stream:
@@ -304,9 +308,7 @@ def _build_py2app_alias(install_root: Path, work_dir: Path) -> Path:
raise RuntimeError(f"py2app alias build failed: {detail[-1200:]}")
candidates = tuple((work_dir / "dist").glob("*.app"))
if len(candidates) != 1:
- raise RuntimeError(
- f"py2app produced {len(candidates)} application bundles; expected one"
- )
+ raise RuntimeError(f"py2app produced {len(candidates)} application bundles; expected one")
return candidates[0]
@@ -322,17 +324,18 @@ def _sign_bundle(bundle: Path) -> None:
if result.returncode != 0:
detail = (result.stderr or result.stdout or "unknown codesign error").strip()
raise RuntimeError(f"ad-hoc code signing failed: {detail[-1200:]}")
- if not _codesign_valid(bundle):
- raise RuntimeError("the generated macOS bundle failed code-signature verification")
+ issue = _codesign_issue(bundle)
+ if issue is not None:
+ raise RuntimeError(
+ f"the generated macOS bundle failed code-signature verification: {issue[-1200:]}"
+ )
def _runtime_identity_valid(bundle: Path, *, install_root: Path) -> bool:
"""Verify native identity and imports against the managed checkout."""
if sys.platform != "darwin":
return True
- descriptor, raw_probe = tempfile.mkstemp(
- prefix="jarvis-bundle-probe-", suffix=".json"
- )
+ descriptor, raw_probe = tempfile.mkstemp(prefix="jarvis-bundle-probe-", suffix=".json")
os.close(descriptor)
probe = Path(raw_probe)
probe.unlink(missing_ok=True)
diff --git a/tests/unit/setup/test_macos_app_bundle.py b/tests/unit/setup/test_macos_app_bundle.py
index 2756c4e4d8..5176841200 100644
--- a/tests/unit/setup/test_macos_app_bundle.py
+++ b/tests/unit/setup/test_macos_app_bundle.py
@@ -60,9 +60,9 @@ def test_bundle_layout_and_plist(tmp_path: Path, monkeypatch) -> None:
def test_rerun_preserves_existing_bundle_byte_for_byte(tmp_path: Path, monkeypatch) -> None:
first = _build(tmp_path, monkeypatch)
- executable_name = plistlib.loads(
- (first / "Contents" / "Info.plist").read_bytes()
- )["CFBundleExecutable"]
+ executable_name = plistlib.loads((first / "Contents" / "Info.plist").read_bytes())[
+ "CFBundleExecutable"
+ ]
executable = first / "Contents" / "MacOS" / executable_name
marker = executable.read_bytes()
second = ensure_macos_app_bundle(
@@ -73,9 +73,7 @@ def test_rerun_preserves_existing_bundle_byte_for_byte(tmp_path: Path, monkeypat
assert executable.read_bytes() == marker
-def test_failed_runtime_probe_rebuilds_instead_of_preserving(
- tmp_path: Path, monkeypatch
-) -> None:
+def test_failed_runtime_probe_rebuilds_instead_of_preserving(tmp_path: Path, monkeypatch) -> None:
import jarvis.setup.macos_app_bundle as mab
bundle = _build(tmp_path, monkeypatch)
@@ -100,10 +98,13 @@ def test_failed_runtime_probe_rebuilds_instead_of_preserving(
monkeypatch.setattr(mab, "_install_native_bundle", _rebuild)
install_root = tmp_path / "install"
- assert ensure_macos_app_bundle(
- install_dir=install_root,
- applications_dir=tmp_path / "Applications",
- ) == bundle
+ assert (
+ ensure_macos_app_bundle(
+ install_dir=install_root,
+ applications_dir=tmp_path / "Applications",
+ )
+ == bundle
+ )
assert rebuilt == [(install_root.resolve(), bundle)]
@@ -126,10 +127,13 @@ def test_running_canonical_app_skips_second_launchservices_probe(
lambda *_args, **_kwargs: pytest.fail("must not spawn a second app probe"),
)
- assert ensure_macos_app_bundle(
- install_dir=tmp_path / "install",
- applications_dir=tmp_path / "Applications",
- ) == bundle
+ assert (
+ ensure_macos_app_bundle(
+ install_dir=tmp_path / "install",
+ applications_dir=tmp_path / "Applications",
+ )
+ == bundle
+ )
def test_noop_off_darwin_without_override(monkeypatch) -> None:
@@ -140,9 +144,7 @@ def test_noop_off_darwin_without_override(monkeypatch) -> None:
def test_bundle_path_and_launchservices_command(tmp_path: Path, monkeypatch) -> None:
bundle = _build(tmp_path, monkeypatch)
probe = str(tmp_path / "probe.json")
- assert macos_app_bundle_path(
- applications_dir=tmp_path / "Applications"
- ) == bundle
+ assert macos_app_bundle_path(applications_dir=tmp_path / "Applications") == bundle
assert macos_launch_services_command(
bundle,
background=True,
@@ -191,6 +193,47 @@ def test_incomplete_bundle_is_not_launchable(tmp_path: Path) -> None:
assert macos_app_bundle_is_launchable(bundle) is False
+def test_codesign_verify_never_uses_strict_or_deep(tmp_path: Path, monkeypatch) -> None:
+ """The alias bundle symlinks OUTSIDE itself by design, and strict
+ validation rejects exactly that ("invalid destination for symbolic
+ link") — it failed on every freshly built bundle on real macOS CI.
+ Local verification must stay a plain identity check."""
+ import jarvis.setup.macos_app_bundle as mab
+
+ monkeypatch.setattr(mab.sys, "platform", "darwin")
+ seen: list[list[str]] = []
+
+ def _fake_run(argv, **_kwargs):
+ seen.append(list(argv))
+ return SimpleNamespace(returncode=0, stdout="", stderr="")
+
+ monkeypatch.setattr(mab.subprocess, "run", _fake_run)
+ assert mab._codesign_valid(tmp_path / APP_DIR_NAME) is True
+ assert len(seen) == 1
+ assert seen[0][:2] == ["/usr/bin/codesign", "--verify"]
+ assert "--strict" not in seen[0]
+ assert "--deep" not in seen[0]
+
+
+def test_sign_bundle_reports_the_codesign_verify_detail(tmp_path: Path, monkeypatch) -> None:
+ import jarvis.setup.macos_app_bundle as mab
+
+ monkeypatch.setattr(mab.sys, "platform", "darwin")
+
+ def _fake_run(argv, **_kwargs):
+ if "--verify" in argv:
+ return SimpleNamespace(
+ returncode=1,
+ stdout="",
+ stderr="invalid destination for symbolic link in bundle",
+ )
+ return SimpleNamespace(returncode=0, stdout="", stderr="")
+
+ monkeypatch.setattr(mab.subprocess, "run", _fake_run)
+ with pytest.raises(RuntimeError, match="invalid destination for symbolic link"):
+ mab._sign_bundle(tmp_path / APP_DIR_NAME)
+
+
def test_launcher_identity_probe_uses_main_bundle(tmp_path: Path, monkeypatch) -> None:
from jarvis.setup.macos_launcher_entry import main
@@ -209,15 +252,9 @@ def test_launcher_identity_probe_uses_main_bundle(tmp_path: Path, monkeypatch) -
assert json.loads(probe.read_text(encoding="utf-8")) == {
"bundle_id": "com.personal-jarvis.desktop",
"bundle_path": "/Users/test/Applications/Personal Jarvis.app",
- "executable": (
- "/Users/test/Applications/Personal Jarvis.app/Contents/MacOS/launcher"
- ),
+ "executable": ("/Users/test/Applications/Personal Jarvis.app/Contents/MacOS/launcher"),
"launcher_file": str(
- Path(__file__).resolve().parents[3]
- / "jarvis"
- / "ui"
- / "web"
- / "launcher.py"
+ Path(__file__).resolve().parents[3] / "jarvis" / "ui" / "web" / "launcher.py"
),
"install_root": str(Path(__file__).resolve().parents[3]),
"python_version": f"{sys.version_info.major}.{sys.version_info.minor}",