From 2d2446b36e0295369be57f62934235a16727efc0 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 20 May 2026 20:20:25 +0200 Subject: [PATCH] mcp/server: pre-populated known_hosts for the restricted SSH The systemd unit's ProtectHome=true blocks ~/.ssh access. SSH then had no place to write known_hosts (StrictHostKeyChecking=accept-new) and silently produced empty results. Use /etc/homelab-mcp/known_hosts (which ProtectSystem=strict still allows reading) and StrictHostKeyChecking=yes. Operator pre-populates the file via: ssh-keyscan -t ed25519 192.168.8.77 > /etc/homelab-mcp/known_hosts Co-Authored-By: Claude Opus 4.7 (1M context) --- mcp/server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mcp/server.py b/mcp/server.py index c483746..89aeccb 100755 --- a/mcp/server.py +++ b/mcp/server.py @@ -35,6 +35,8 @@ HOSTS_DIR = CONTEXT_DIR / "hosts" # hubris validates each command against a strict read-only allowlist. SSH_IDENTITY = os.environ.get("HOMELAB_MCP_SSH_KEY", "/etc/homelab-mcp/mcp-reader.key") SSH_USER = os.environ.get("HOMELAB_MCP_SSH_USER", "root") +SSH_KNOWN_HOSTS = os.environ.get("HOMELAB_MCP_SSH_KNOWN_HOSTS", + "/etc/homelab-mcp/known_hosts") HUBRIS_HOST = os.environ.get("HOMELAB_MCP_HUBRIS_HOST", "192.168.8.77") SSH_TIMEOUT = int(os.environ.get("HOMELAB_MCP_SSH_TIMEOUT", "10")) @@ -89,7 +91,10 @@ def _run_via_hubris(remote_host: str, cmd: list[str], joined = " ".join(full) ssh_args = [ "ssh", "-i", SSH_IDENTITY, "-o", "BatchMode=yes", - "-o", "StrictHostKeyChecking=accept-new", + # The systemd unit runs with ProtectHome=true so ~/.ssh is unreachable. + # Use a pre-populated known_hosts in /etc/homelab-mcp/. + "-o", f"UserKnownHostsFile={SSH_KNOWN_HOSTS}", + "-o", "StrictHostKeyChecking=yes", "-o", f"ConnectTimeout={SSH_TIMEOUT}", f"{SSH_USER}@{HUBRIS_HOST}", joined,