diff --git a/docs/guides/remote-instances.md b/docs/guides/remote-instances.md index 45e19dd3d..072ccecac 100644 --- a/docs/guides/remote-instances.md +++ b/docs/guides/remote-instances.md @@ -25,8 +25,6 @@ The return link targets only an HTTP loopback origin (`127.0.0.1`, `localhost`, No relay, public WebUI, uploaded private key, QR scan or new firewall rule is involved. The public invitation expires after ten minutes. The returned code is encrypted for that local instance; another computer/request cannot import it. The server host key is pinned from the code copied through your trusted terminal. Do not accept a connection code supplied by someone you do not trust. -Quick pairing can coexist with an existing HTTPS reverse proxy and a configured `publicWsUrl`. Keep that URL for browsers that connect directly. SSH uses the Gateway's plain HTTP listener on loopback, not the public URL. Quick pairing does not support TLS on the Gateway listener itself or `trustedProxyAuth`; it still requires a configured WebUI secret and explicit authorization. - The dedicated device SSH key expires after 90 days. OpenSSH `restrict` disables shell-adjacent features and all SSH forwarding; a forced, fixed Python stdio bridge connects only to the selected loopback nanobot port. It cannot execute the client's SSH command. No extra daemon is installed or started. The server requires OpenSSH with `restrict` and `expiry-time` support, `/usr/bin/python3`, an Ed25519 host key, and the conventional `~/.ssh/authorized_keys` layout. Custom SSH policies/layouts may reject the grant; use existing SSH settings in that case. Windows servers and containers are not supported by quick pairing. This is still **full access to nanobot**, not read-only access. Its configured tools may themselves run commands or modify files. The WebUI credential stays in the local backend, encrypted at rest alongside a private local decryption key and dedicated SSH identity (directories `0700`, files `0600`). This protects against other OS users, not compromise of your logged-in account. Provider keys are not exported by the pairing protocol. Changes to the remote WebUI secret or port require pairing again; they are not silently refreshed through sudo. @@ -68,7 +66,8 @@ You can also paste a simple command, for example `ssh -p 2222 -i "~/.ssh/team ke - Run the local WebUI on a loopback address, using the system OpenSSH client. - For **existing SSH settings**, your key must already have access to the server. Encrypted keys should be unlocked in the system SSH agent. Interactive SSH passwords are not collected by this UI. - For **existing SSH settings**, make Python 3 available to the SSH login as `python3` or `python`. A separate Linux service account still needs `python3` under `sudo`. The running nanobot WebUI needs a `tokenIssueSecret` (or `token`) in its UTF-8 JSON configuration. -- The remote gateway must support the authenticated `/webui/terminal` identity probe and the supported WebUI client contract. The local installation must have its WebUI bundle; the remote host only needs the backend endpoints. The transport uses HTTP on the server's loopback address; SSH encrypts the connection. The **Use existing SSH settings** flow does not support a configured public WebSocket URL or trusted-proxy authentication. +- The remote gateway must support the authenticated `/webui/terminal` identity probe and the supported WebUI client contract. The local installation must have its WebUI bundle; the remote host only needs the backend endpoints. +- Both SSH flows can coexist with an HTTPS reverse proxy. Keep `publicWsUrl` for browsers that connect directly. SSH always uses the gateway's plain HTTP loopback listener and does not support TLS on that listener or `trustedProxyAuth`. If this machine has never connected to the server, nanobot displays its SSH fingerprint. Compare it with the server console or your administrator before confirming in the same dialog. **Back** returns to the filled-in form when adding a server. The public key is pinned for this connection, without changing your system `known_hosts`. A **changed** host key is blocked, not automatically accepted. Jump-host-only or non-Ed25519 hosts can use a previously verified system SSH configuration instead of the in-app first-contact verifier. diff --git a/nanobot/webui/remote_ssh.py b/nanobot/webui/remote_ssh.py index e13cd2c86..3e589147b 100644 --- a/nanobot/webui/remote_ssh.py +++ b/nanobot/webui/remote_ssh.py @@ -76,9 +76,8 @@ try: raise ValueError("webui_disabled") if not isinstance(secret, str) or not secret.strip() or "${" in secret: raise ValueError("webui_auth_required") - if ws.get("publicWsUrl") or ws.get("public_ws_url"): - raise ValueError("public_ws_unsupported") - if ws.get("trustedProxyAuth") or ws.get("trusted_proxy_auth"): + certfile = ws.get("sslCertfile") or ws.get("ssl_certfile") or "" + if (isinstance(certfile, str) and certfile.strip()) or ws.get("trustedProxyAuth") or ws.get("trusted_proxy_auth"): raise ValueError("incompatible_gateway") emit({"port": ws.get("port", 8765), "secret": secret, "token_issue_path": ws.get("tokenIssuePath") or ws.get("token_issue_path") or "", @@ -89,7 +88,7 @@ except PermissionError: emit({"error": "config_permission"}) except ValueError as e: code = str(e) - emit({"error": code if code in {"webui_disabled", "webui_auth_required", "public_ws_unsupported", "incompatible_gateway"} else "config_invalid"}) + emit({"error": code if code in {"webui_disabled", "webui_auth_required", "incompatible_gateway"} else "config_invalid"}) except (AttributeError, TypeError): emit({"error": "config_invalid"}) ''' diff --git a/tests/webui/test_remote_instances.py b/tests/webui/test_remote_instances.py index 5136f8a68..0f9fa9136 100644 --- a/tests/webui/test_remote_instances.py +++ b/tests/webui/test_remote_instances.py @@ -1019,16 +1019,24 @@ async def test_cancellation_reaps_inflight_probe(monkeypatch): process.terminate.assert_called_once() -@pytest.mark.parametrize("field", ["trustedProxyAuth", "trusted_proxy_auth"]) -def test_ssh_probe_rejects_trusted_assertion_bypass(tmp_path, field): +@pytest.mark.parametrize(("overrides", "error"), [ + ({"trustedProxyAuth": {"assertionHeader": "X-User", "trustedPeerCidrs": ["127.0.0.1/32"]}}, + "incompatible_gateway"), + ({"trusted_proxy_auth": {"assertion_header": "X-User", "trusted_peer_cidrs": ["127.0.0.1/32"]}}, + "incompatible_gateway"), + ({"sslCertfile": "/etc/nanobot/cert.pem", "sslKeyfile": "/etc/nanobot/key.pem"}, "incompatible_gateway"), + ({"ssl_certfile": "/etc/nanobot/cert.pem", "ssl_keyfile": "/etc/nanobot/key.pem"}, "incompatible_gateway"), + ({"tokenIssueSecret": ""}, "webui_auth_required"), +]) +def test_ssh_probe_keeps_gateway_requirements_with_public_ws_url(tmp_path, overrides, error): path = tmp_path / "config.json" path.write_text(json.dumps({"channels": {"websocket": { "enabled": True, "tokenIssueSecret": "synthetic-root", - field: {"assertionHeader": "Host", "trustedPeers": ["127.0.0.0/8"]}, + "publicWsUrl": "wss://public.test/edge/ws", **overrides, }}})) result = subprocess.run([sys.executable, "-c", remote_ssh._PROBE, str(path)], capture_output=True, text=True, check=True) - assert json.loads(result.stdout.split("NANOBOT_REMOTE:")[1]) == {"error": "incompatible_gateway"} + assert json.loads(result.stdout.split("NANOBOT_REMOTE:")[1]) == {"error": error} @pytest.mark.parametrize("banner", [b"", b"Welcome to the server\n", b"{\"port\": 1}\nWelcome without newline"]) @@ -1095,17 +1103,22 @@ def test_probe_reports_malformed_config_as_config_error(tmp_path, config): assert json.loads(result.stdout.split("NANOBOT_REMOTE:")[1]) == {"error": "config_invalid"} -def test_probe_reads_config_as_utf8_independently_of_locale(tmp_path, monkeypatch): +@pytest.mark.parametrize("field", ["publicWsUrl", "public_ws_url"]) +def test_ssh_probe_reads_utf8_config_with_public_ws_url(tmp_path, monkeypatch, field): path = tmp_path / "config.json" path.write_text(json.dumps({"channels": {"websocket": { - "enabled": True, "token": "synthetic-root", "tokenIssuePath": "/测试", + "enabled": True, "token": "synthetic-root", "port": 8865, "tokenIssuePath": "/测试", + field: "wss://public.test/edge/ws", }}}, ensure_ascii=False), encoding="utf-8") monkeypatch.setenv("PYTHONUTF8", "0") monkeypatch.setenv("PYTHONCOERCECLOCALE", "0") monkeypatch.setenv("LC_ALL", "C") result = subprocess.run([sys.executable, "-c", remote_ssh._PROBE, str(path)], capture_output=True, text=True, check=True) - assert json.loads(result.stdout.split("NANOBOT_REMOTE:")[1])["token_issue_path"] == "/测试" + assert json.loads(result.stdout.split("NANOBOT_REMOTE:")[1]) == { + "port": 8865, "secret": "synthetic-root", "token_issue_path": "/测试", + "hostname": socket.gethostname(), "config_path": str(path), + } async def test_tunnel_refuses_an_existing_listener(monkeypatch): diff --git a/webui/src/components/remote/RemoteConnectionsPage.tsx b/webui/src/components/remote/RemoteConnectionsPage.tsx index b05193421..9568fc9f9 100644 --- a/webui/src/components/remote/RemoteConnectionsPage.tsx +++ b/webui/src/components/remote/RemoteConnectionsPage.tsx @@ -275,7 +275,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro finally { if (mounted.current) setBusy(""); } }; const pageError = error || (directoryError ? t("remote.errors.directory_unavailable") : ""); - const nanobotError = /^(config_|runtime_user_|webui_|remote_auth_|remote_unreachable|incompatible_gateway|public_ws_|python_|probe_failed)/.test(errorCode); + const nanobotError = /^(config_|runtime_user_|webui_|remote_auth_|remote_unreachable|incompatible_gateway|python_|probe_failed)/.test(errorCode); const locationStep = !!inspection || manualLocation || nanobotError; const openingProfile = !editorOpen && !fingerprint && !removing && !disconnecting ? directory?.profiles.find((profile) => profile.id === busy) : null; diff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.json index 7f0c550c0..f58630861 100644 --- a/webui/src/i18n/locales/en/common.json +++ b/webui/src/i18n/locales/en/common.json @@ -337,7 +337,6 @@ "config_invalid": "Couldn't read the server's nanobot configuration. Check that the selected file is valid UTF-8 JSON.", "webui_disabled": "The server's WebUI is disabled. Enable it on the server first.", "webui_auth_required": "The server needs a WebUI login secret in its config. No model key is needed here.", - "public_ws_unsupported": "This server uses a public WebSocket URL. This first version supports a loopback WebUI over SSH.", "remote_auth_failed": "The server rejected its saved WebUI credential. Check its running configuration.", "incompatible_gateway": "This endpoint isn't a compatible nanobot gateway. Update the server or check its configuration.", "webui_unavailable": "The gateway is running, but its WebUI isn't installed.", diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.json index ea0890c48..f81b568e2 100644 --- a/webui/src/i18n/locales/es/common.json +++ b/webui/src/i18n/locales/es/common.json @@ -337,7 +337,6 @@ "config_invalid": "Couldn't read the server's nanobot configuration. Check that the selected file is valid UTF-8 JSON.", "webui_disabled": "The server's WebUI is disabled. Enable it on the server first.", "webui_auth_required": "The server needs a WebUI login secret in its config. No model key is needed here.", - "public_ws_unsupported": "This server uses a public WebSocket URL. This first version supports a loopback WebUI over SSH.", "remote_auth_failed": "The server rejected its saved WebUI credential. Check its running configuration.", "incompatible_gateway": "This endpoint isn't a compatible nanobot gateway. Update the server or check its configuration.", "webui_unavailable": "The gateway is running, but its WebUI isn't installed.", diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.json index e4de245f3..b6c44ebf9 100644 --- a/webui/src/i18n/locales/fr/common.json +++ b/webui/src/i18n/locales/fr/common.json @@ -337,7 +337,6 @@ "config_invalid": "Couldn't read the server's nanobot configuration. Check that the selected file is valid UTF-8 JSON.", "webui_disabled": "The server's WebUI is disabled. Enable it on the server first.", "webui_auth_required": "The server needs a WebUI login secret in its config. No model key is needed here.", - "public_ws_unsupported": "This server uses a public WebSocket URL. This first version supports a loopback WebUI over SSH.", "remote_auth_failed": "The server rejected its saved WebUI credential. Check its running configuration.", "incompatible_gateway": "This endpoint isn't a compatible nanobot gateway. Update the server or check its configuration.", "webui_unavailable": "The gateway is running, but its WebUI isn't installed.", diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.json index 3803facbe..b2c539cff 100644 --- a/webui/src/i18n/locales/id/common.json +++ b/webui/src/i18n/locales/id/common.json @@ -337,7 +337,6 @@ "config_invalid": "Couldn't read the server's nanobot configuration. Check that the selected file is valid UTF-8 JSON.", "webui_disabled": "The server's WebUI is disabled. Enable it on the server first.", "webui_auth_required": "The server needs a WebUI login secret in its config. No model key is needed here.", - "public_ws_unsupported": "This server uses a public WebSocket URL. This first version supports a loopback WebUI over SSH.", "remote_auth_failed": "The server rejected its saved WebUI credential. Check its running configuration.", "incompatible_gateway": "This endpoint isn't a compatible nanobot gateway. Update the server or check its configuration.", "webui_unavailable": "The gateway is running, but its WebUI isn't installed.", diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.json index 879a556f8..6e827840c 100644 --- a/webui/src/i18n/locales/ja/common.json +++ b/webui/src/i18n/locales/ja/common.json @@ -337,7 +337,6 @@ "config_invalid": "Couldn't read the server's nanobot configuration. Check that the selected file is valid UTF-8 JSON.", "webui_disabled": "The server's WebUI is disabled. Enable it on the server first.", "webui_auth_required": "The server needs a WebUI login secret in its config. No model key is needed here.", - "public_ws_unsupported": "This server uses a public WebSocket URL. This first version supports a loopback WebUI over SSH.", "remote_auth_failed": "The server rejected its saved WebUI credential. Check its running configuration.", "incompatible_gateway": "This endpoint isn't a compatible nanobot gateway. Update the server or check its configuration.", "webui_unavailable": "The gateway is running, but its WebUI isn't installed.", diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.json index 2fad0ffe2..46ac46c8b 100644 --- a/webui/src/i18n/locales/ko/common.json +++ b/webui/src/i18n/locales/ko/common.json @@ -337,7 +337,6 @@ "config_invalid": "Couldn't read the server's nanobot configuration. Check that the selected file is valid UTF-8 JSON.", "webui_disabled": "The server's WebUI is disabled. Enable it on the server first.", "webui_auth_required": "The server needs a WebUI login secret in its config. No model key is needed here.", - "public_ws_unsupported": "This server uses a public WebSocket URL. This first version supports a loopback WebUI over SSH.", "remote_auth_failed": "The server rejected its saved WebUI credential. Check its running configuration.", "incompatible_gateway": "This endpoint isn't a compatible nanobot gateway. Update the server or check its configuration.", "webui_unavailable": "The gateway is running, but its WebUI isn't installed.", diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.json index 22adcb595..408473316 100644 --- a/webui/src/i18n/locales/pt-BR/common.json +++ b/webui/src/i18n/locales/pt-BR/common.json @@ -337,7 +337,6 @@ "config_invalid": "Couldn't read the server's nanobot configuration. Check that the selected file is valid UTF-8 JSON.", "webui_disabled": "The server's WebUI is disabled. Enable it on the server first.", "webui_auth_required": "The server needs a WebUI login secret in its config. No model key is needed here.", - "public_ws_unsupported": "This server uses a public WebSocket URL. This first version supports a loopback WebUI over SSH.", "remote_auth_failed": "The server rejected its saved WebUI credential. Check its running configuration.", "incompatible_gateway": "This endpoint isn't a compatible nanobot gateway. Update the server or check its configuration.", "webui_unavailable": "The gateway is running, but its WebUI isn't installed.", diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.json index 176174141..09e174642 100644 --- a/webui/src/i18n/locales/vi/common.json +++ b/webui/src/i18n/locales/vi/common.json @@ -337,7 +337,6 @@ "config_invalid": "Couldn't read the server's nanobot configuration. Check that the selected file is valid UTF-8 JSON.", "webui_disabled": "The server's WebUI is disabled. Enable it on the server first.", "webui_auth_required": "The server needs a WebUI login secret in its config. No model key is needed here.", - "public_ws_unsupported": "This server uses a public WebSocket URL. This first version supports a loopback WebUI over SSH.", "remote_auth_failed": "The server rejected its saved WebUI credential. Check its running configuration.", "incompatible_gateway": "This endpoint isn't a compatible nanobot gateway. Update the server or check its configuration.", "webui_unavailable": "The gateway is running, but its WebUI isn't installed.", diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.json index 779a569cf..12b3957e6 100644 --- a/webui/src/i18n/locales/zh-CN/common.json +++ b/webui/src/i18n/locales/zh-CN/common.json @@ -337,7 +337,6 @@ "config_invalid": "无法读取服务器上的 nanobot 配置。请确认所选文件是有效的 UTF-8 JSON。", "webui_disabled": "服务器的 WebUI 尚未启用,请先在服务器上开启。", "webui_auth_required": "服务器需要在配置中设置 WebUI 登录密钥。这里不需要模型 Key。", - "public_ws_unsupported": "这台服务器设置了公网 WebSocket 地址。首版支持通过 SSH 连接回环地址上的 WebUI。", "remote_auth_failed": "服务器拒绝了 WebUI 登录凭据,请检查它实际运行的配置。", "incompatible_gateway": "该地址不是兼容的 nanobot gateway,请检查配置或更新服务器版本。", "webui_unavailable": "Gateway 在运行,但没有安装 WebUI。", diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.json index 0bb4d25af..d83fb73be 100644 --- a/webui/src/i18n/locales/zh-TW/common.json +++ b/webui/src/i18n/locales/zh-TW/common.json @@ -337,7 +337,6 @@ "config_invalid": "Couldn't read the server's nanobot configuration. Check that the selected file is valid UTF-8 JSON.", "webui_disabled": "The server's WebUI is disabled. Enable it on the server first.", "webui_auth_required": "The server needs a WebUI login secret in its config. No model key is needed here.", - "public_ws_unsupported": "This server uses a public WebSocket URL. This first version supports a loopback WebUI over SSH.", "remote_auth_failed": "The server rejected its saved WebUI credential. Check its running configuration.", "incompatible_gateway": "This endpoint isn't a compatible nanobot gateway. Update the server or check its configuration.", "webui_unavailable": "The gateway is running, but its WebUI isn't installed.",