mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-10-20 05:15:31 +00:00
feat(serve): add Windows remote backend runtime for Desktop SSH
Add hermes_cli/windows_ssh_runtime.py: a native Windows trust boundary invoked over SSH to manage the Desktop SSH backend lifecycle — ACL-locked one-shot token file (owner+SYSTEM only, SE_DACL_PROTECTED, read-once via DELETE_ON_CLOSE), ownership lock, and detached serve spawn with CREATE_BREAKAWAY_FROM_JOB so the backend survives the SSH session's Job Object teardown. Process ownership is proven by exact pid + creation-time + argv + owner-nonce; state is tri-state (owned / stale / indeterminate) so a live-but-unreadable process is never mistaken for stale. Route _read_ssh_session_token_file to the Windows reader on win32, and move the POSIX token root from a hardcoded ~/.hermes to get_hermes_home() so both platforms honor the active profile.
This commit is contained in:
parent
9e13cd125b
commit
00e9f6dd4d
3 changed files with 536 additions and 18 deletions
|
|
@ -2,6 +2,7 @@ import argparse
|
|||
import os
|
||||
|
||||
import pytest
|
||||
from hermes_constants import set_hermes_home_override, reset_hermes_home_override
|
||||
|
||||
from hermes_cli.main import _read_ssh_session_token_file, cmd_dashboard
|
||||
from hermes_cli.subcommands.dashboard import build_dashboard_parser
|
||||
|
|
@ -43,15 +44,18 @@ def test_one_shot_token_file_rejects_non_starting_operations(operation):
|
|||
|
||||
def test_token_file_is_read_and_unlinked_through_private_directory(tmp_path, monkeypatch):
|
||||
home = tmp_path / "home"
|
||||
token_dir = home / ".hermes" / "desktop-ssh" / ("a" * 32)
|
||||
hermes_home = home / ".hermes"
|
||||
token_dir = hermes_home / "desktop-ssh" / ("a" * 32)
|
||||
token_dir.mkdir(parents=True, mode=0o700)
|
||||
token_path = token_dir / "0123456789abcdef.token"
|
||||
token_path.write_text("b" * 64)
|
||||
token_path.chmod(0o600)
|
||||
monkeypatch.setattr("pathlib.Path.home", lambda: home)
|
||||
|
||||
assert _read_ssh_session_token_file(str(token_path)) == "b" * 64
|
||||
assert not token_path.exists()
|
||||
override = set_hermes_home_override(hermes_home)
|
||||
try:
|
||||
assert _read_ssh_session_token_file(str(token_path)) == "b" * 64
|
||||
assert not token_path.exists()
|
||||
finally:
|
||||
reset_hermes_home_override(override)
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name == "nt", reason="POSIX symlink contract")
|
||||
|
|
@ -64,12 +68,14 @@ def test_token_file_rejects_symlink(tmp_path, monkeypatch):
|
|||
target.chmod(0o600)
|
||||
token_path = token_dir / "0123456789abcdef.token"
|
||||
token_path.symlink_to(target)
|
||||
monkeypatch.setattr("pathlib.Path.home", lambda: home)
|
||||
|
||||
with pytest.raises(SystemExit, match="symlink|not accessible"):
|
||||
_read_ssh_session_token_file(str(token_path))
|
||||
assert not token_path.exists()
|
||||
assert target.read_text() == "b" * 64
|
||||
override = set_hermes_home_override(home / ".hermes")
|
||||
try:
|
||||
with pytest.raises(SystemExit, match="symlink|not accessible"):
|
||||
_read_ssh_session_token_file(str(token_path))
|
||||
assert not token_path.exists()
|
||||
assert target.read_text() == "b" * 64
|
||||
finally:
|
||||
reset_hermes_home_override(override)
|
||||
|
||||
|
||||
def test_token_file_rejects_parent_escape(tmp_path, monkeypatch):
|
||||
|
|
@ -79,8 +85,10 @@ def test_token_file_rejects_parent_escape(tmp_path, monkeypatch):
|
|||
escaped = token_root.parent / "0123456789abcdef.token"
|
||||
escaped.write_text("b" * 64)
|
||||
escaped.chmod(0o600)
|
||||
monkeypatch.setattr("pathlib.Path.home", lambda: home)
|
||||
|
||||
with pytest.raises(SystemExit, match="invalid runtime path"):
|
||||
_read_ssh_session_token_file(str(token_root / ".." / escaped.name))
|
||||
assert escaped.exists()
|
||||
override = set_hermes_home_override(home / ".hermes")
|
||||
try:
|
||||
with pytest.raises(SystemExit, match="invalid runtime path"):
|
||||
_read_ssh_session_token_file(str(token_root / ".." / escaped.name))
|
||||
assert escaped.exists()
|
||||
finally:
|
||||
reset_hermes_home_override(override)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue