fix(remote): preserve moved pairing state and Windows test coverage
This commit is contained in:
1 parent
192ca6e49e
commit
af847165a5
4 files changed
+94
-6
No files matched your search
@@ -78,8 +78,17 @@ class RemoteInstances:
|
||||
raw = json.loads(self.path.read_text(encoding="utf-8"))
|
||||
if not isinstance(raw, dict):
|
||||
raise ValueError
|
||||
return {str(uuid.UUID(key)): _SavedProfile.model_validate(value)
|
||||
for key, value in cast(dict[str, Any], raw).items()}
|
||||
profiles = {str(uuid.UUID(key)): _SavedProfile.model_validate(value)
|
||||
for key, value in cast(dict[str, Any], raw).items()}
|
||||
for profile in profiles.values():
|
||||
if profile.pair_id:
|
||||
# These are managed files, not external SSH settings. Resolve
|
||||
# them from the current root after a backup restore or move.
|
||||
directory = self.pairing.path(profile.pair_id)
|
||||
profile.identity_file = str(directory / "identity")
|
||||
if profile.ssh_config:
|
||||
profile.ssh_config = str(directory / "ssh_route")
|
||||
return profiles
|
||||
except (ValueError, TypeError, OSError):
|
||||
raise RemoteError("profile_store_invalid") from None
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ stdio bridge, with all OpenSSH forwarding and interactive features disabled.
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import fcntl
|
||||
import json
|
||||
import os
|
||||
import shlex
|
||||
@@ -84,6 +83,8 @@ def _directory(path: Path) -> None:
|
||||
|
||||
def write_authorization(home: Path, request: PairRequest, port: int, until: int) -> None:
|
||||
"""Runs as the SSH account, never with root privileges over another home."""
|
||||
import fcntl
|
||||
|
||||
request.check_expiry()
|
||||
ssh = home / ".ssh"
|
||||
_directory(ssh)
|
||||
@@ -114,6 +115,8 @@ def write_authorization(home: Path, request: PairRequest, port: int, until: int)
|
||||
|
||||
|
||||
def _update_keys(path: Path, *, add: str = "", remove: str = "") -> None:
|
||||
import fcntl
|
||||
|
||||
fd = os.open(path, os.O_RDWR | os.O_CREAT | os.O_NOFOLLOW, 0o600)
|
||||
with os.fdopen(fd, "r+") as handle:
|
||||
info = os.fstat(handle.fileno())
|
||||
@@ -146,6 +149,8 @@ def _update_keys(path: Path, *, add: str = "", remove: str = "") -> None:
|
||||
|
||||
|
||||
def remove_authorization(home: Path, key: str) -> None:
|
||||
import fcntl
|
||||
|
||||
from nanobot.webui.remote_pairing import PairStore
|
||||
|
||||
# Validate before joining any path, even for a manually typed revoke command.
|
||||
|
||||
Reference in new issue
Block a user