Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Thumbs.db

# Logs
*.log
.clawmetry-fleet.db
26 changes: 19 additions & 7 deletions clawmetry/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ def _register_nemoclaw_sandbox_daemons() -> None:
import shutil
import os
import platform
from xml.sax.saxutils import escape

if platform.system() != "Darwin":
return
Expand Down Expand Up @@ -607,8 +608,9 @@ def _register_nemoclaw_sandbox_daemons() -> None:
docker_path = shutil.which("docker") or "/usr/local/bin/docker"

for pod in pods:
label = f"com.clawmetry.sandbox.{pod}"
plist_path = launch_agents / f"{label}.plist"
label = f"com.clawmetry.sandbox.{escape(pod)}"
pod_xml = escape(pod)
plist_path = launch_agents / f"com.clawmetry.sandbox.{pod}.plist"
sync_script = "/usr/local/lib/python3.11/dist-packages/clawmetry/sync.py"
plist = f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
Expand All @@ -624,16 +626,16 @@ def _register_nemoclaw_sandbox_daemons() -> None:
<string>exec</string>
<string>-n</string>
<string>openshell</string>
<string>{pod}</string>
<string>{pod_xml}</string>
<string>--</string>
<string>python3</string>
<string>{sync_script}</string>
</array>
<key>RunAtLoad</key> <true/>
<key>KeepAlive</key> <true/>
<key>ThrottleInterval</key> <integer>30</integer>
<key>StandardOutPath</key> <string>/tmp/clawmetry-{pod}.log</string>
<key>StandardErrorPath</key> <string>/tmp/clawmetry-{pod}.log</string>
<key>StandardOutPath</key> <string>/tmp/clawmetry-{pod_xml}.log</string>
<key>StandardErrorPath</key> <string>/tmp/clawmetry-{pod_xml}.log</string>
</dict>
</plist>"""
plist_path.write_text(plist)
Expand Down Expand Up @@ -1670,8 +1672,18 @@ def _cmd_update() -> None:
print("Checking for updates...")
try:
result = subprocess.run(
[sys.executable, "-m", "pip", "install", "--upgrade", "--break-system-packages", "clawmetry"],
capture_output=True, text=True, timeout=120,
[
sys.executable,
"-m",
"pip",
"install",
"--upgrade",
"--break-system-packages",
"clawmetry",
],
capture_output=True,
text=True,
timeout=120,
)
if result.returncode == 0:
# Check new version
Expand Down
47 changes: 46 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from pathlib import Path
from xml.etree import ElementTree as ET

import pytest

import clawmetry.cli as cli

Expand Down Expand Up @@ -30,9 +33,51 @@ def test_print_nemoclaw_preset_hint_emits_command(monkeypatch, capsys):
helper = "/tmp/add-nemoclaw-clawmetry-preset.sh"
monkeypatch.setattr(cli, "_get_nemoclaw_preset_script", lambda: helper)

cli._print_nemoclaw_preset_hint(lambda text: text, lambda text: text, lambda text: text)
cli._print_nemoclaw_preset_hint(
lambda text: text, lambda text: text, lambda text: text
)

out = capsys.readouterr().out
assert "NemoClaw detected" in out
assert "allow your NemoClaw sandboxes to reach ClawMetry Cloud" in out
assert helper in out


def test_pod_name_xml_escaping():
from xml.sax.saxutils import escape

malicious_pod = "test-pod&injection</string><string>attacker"
pod_xml = escape(malicious_pod)
docker_path = "/usr/bin/docker"
cluster = "openshell-cluster"
sync_script = "/usr/local/lib/python3.11/dist-packages/clawmetry/sync.py"
label = f"com.clawmetry.sandbox.{escape(malicious_pod)}"

plist = f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key> <string>{label}</string>
<key>ProgramArguments</key>
<array>
<string>{docker_path}</string>
<string>exec</string>
<string>{cluster}</string>
<string>kubectl</string>
<string>exec</string>
<string>-n</string>
<string>openshell</string>
<string>{pod_xml}</string>
<string>--</string>
<string>python3</string>
<string>{sync_script}</string>
</array>
<key>RunAtLoad</key> <true/>
<key>KeepAlive</key> <true/>
<key>ThrottleInterval</key> <integer>30</integer>
<key>StandardOutPath</key> <string>/tmp/clawmetry-{pod_xml}.log</string>
<key>StandardErrorPath</key> <string>/tmp/clawmetry-{pod_xml}.log</string>
</dict>
</plist>"""

ET.fromstring(plist)
Loading