feat(settings): check sandbox launchers and configure protected paths
This commit is contained in:
1 parent
f158779c60
commit
5b84b78cac
33 files changed
+1179
-20
No files matched your search
@@ -28,6 +28,7 @@ UPDATE_FLOW_CAPABILITY = "webui.update-flow.v1"
|
||||
UPDATE_CHANNEL_CAPABILITY = "webui.update-channels.v1"
|
||||
CONTEXT_GRAPH_REFERENCES_CAPABILITY = "webui.context-graph.references.v1"
|
||||
PROMPT_NAVIGATION_CAPABILITY = "webui.prompt-navigation.v1"
|
||||
SANDBOX_SETTINGS_CAPABILITY = "webui.sandbox-settings.v1"
|
||||
|
||||
|
||||
class Compatibility(TypedDict):
|
||||
@@ -48,6 +49,7 @@ def webui_contract() -> dict[str, object]:
|
||||
UPDATE_JOB_CAPABILITY, UPDATE_PREPARATION_CAPABILITY, UPDATE_EXECUTION_CAPABILITY,
|
||||
UPDATE_RETRY_CAPABILITY, UPDATE_SETTLE_HANDOFF_CAPABILITY, UPDATE_FLOW_CAPABILITY, UPDATE_CHANNEL_CAPABILITY,
|
||||
PROMPT_NAVIGATION_CAPABILITY, CONTEXT_GRAPH_REFERENCES_CAPABILITY,
|
||||
SANDBOX_SETTINGS_CAPABILITY,
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +131,7 @@ _CAPABILITY_ROUTES = {
|
||||
}
|
||||
|
||||
_SYSTEM_ROUTES = {
|
||||
"/api/settings/sandbox/check": "sandbox-check",
|
||||
"/api/settings/runtime-config/update": "runtime-config-update",
|
||||
"/api/settings/cli-apps": "cli-list",
|
||||
"/api/settings/cli-apps/install": "cli-install",
|
||||
@@ -162,6 +163,7 @@ _SYSTEM_ROUTES = {
|
||||
}
|
||||
|
||||
_SETTINGS_MUTATION_PATHS = frozenset({
|
||||
"/api/settings/sandbox/check",
|
||||
"/api/settings/nanobot-update/channel",
|
||||
"/api/settings/nanobot-update/plan/create",
|
||||
"/api/settings/nanobot-update/job/prepare",
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import ipaddress
|
||||
import math
|
||||
import re
|
||||
from pathlib import PurePosixPath, PureWindowsPath
|
||||
from pathlib import Path, PurePosixPath, PureWindowsPath
|
||||
from typing import Any, cast
|
||||
|
||||
from pydantic import BaseModel, TypeAdapter, ValidationError
|
||||
@@ -33,6 +33,7 @@ RUNTIME_CONFIG_PATHS = (
|
||||
"tools.exec.path_prepend",
|
||||
"tools.exec.path_append",
|
||||
"tools.exec.sandbox",
|
||||
"tools.exec.sandbox_launcher",
|
||||
"tools.exec.sandbox_ro_binds",
|
||||
"tools.exec.sandbox_rw_binds",
|
||||
"tools.exec.allowed_env_keys",
|
||||
@@ -152,6 +153,19 @@ def update_runtime_config(
|
||||
raise WebUISettingsError("Set an API key in System before using a network bind address.")
|
||||
if "tools.exec.sandbox" in values and validated.tools.exec.sandbox not in {"", "bwrap", "seatbelt"}:
|
||||
raise WebUISettingsError("tools.exec.sandbox: choose no sandbox, bwrap, or seatbelt")
|
||||
if {"tools.exec.sandbox_launcher", "tools.exec.sandbox_rw_binds"} & values.keys() and validated.tools.exec.sandbox_launcher:
|
||||
from nanobot.agent.tools.sandbox_launcher import (
|
||||
SandboxLauncherError,
|
||||
resolve_sandbox_launcher,
|
||||
)
|
||||
|
||||
try:
|
||||
resolve_sandbox_launcher(
|
||||
validated.tools.exec.sandbox, validated.tools.exec.sandbox_launcher,
|
||||
writable_roots=(validated.workspace_path, *map(Path, validated.tools.exec.sandbox_rw_binds)),
|
||||
)
|
||||
except SandboxLauncherError as exc:
|
||||
raise WebUISettingsError(f"sandbox_launcher_{exc.reason}") from None
|
||||
if "tools.ssrf_whitelist" in values:
|
||||
for cidr in validated.tools.ssrf_whitelist:
|
||||
try:
|
||||
|
||||
@@ -17,6 +17,7 @@ import httpx
|
||||
from pydantic import ValidationError
|
||||
from pydantic.alias_generators import to_snake
|
||||
|
||||
from nanobot.agent.tools.sandbox_check import check_sandbox, sandbox_settings_status
|
||||
from nanobot.build_info import COMMIT
|
||||
from nanobot.channels._setup import channel_setup_spec
|
||||
from nanobot.channels.connect import ChannelConnectError, ChannelConnector, ManagedChannelConnector
|
||||
@@ -167,6 +168,7 @@ def system_settings_payload(
|
||||
"exec_enabled": exec_config.enable,
|
||||
"exec_max_runtime_limit": exec_config.max_runtime_limit,
|
||||
"exec_sandbox": exec_config.sandbox or None,
|
||||
"exec_sandbox_status": sandbox_settings_status(exec_config, config.workspace_path),
|
||||
"exec_path_prepend_set": bool(exec_config.path_prepend),
|
||||
"exec_path_append_set": bool(exec_config.path_append),
|
||||
},
|
||||
@@ -457,6 +459,7 @@ class SystemSettingsHandler:
|
||||
self._closing_connectors = False
|
||||
self._update_jobs = UpdateJobService()
|
||||
self._remove_update_work: Callable[[], None] | None = None
|
||||
self._sandbox_check_running = False
|
||||
|
||||
def _has_pending_connectors(self) -> bool:
|
||||
return self._closing_connectors or any(
|
||||
@@ -503,6 +506,17 @@ class SystemSettingsHandler:
|
||||
channel_name: str | None = None,
|
||||
connect_action: str | None = None,
|
||||
) -> SettingsRouteResult:
|
||||
if action == "sandbox-check":
|
||||
if self._sandbox_check_running:
|
||||
return SettingsRouteResult.failure(409, "sandbox_check_busy")
|
||||
self._sandbox_check_running = True
|
||||
try:
|
||||
config = await asyncio.to_thread(self.settings.config.load)
|
||||
return SettingsRouteResult.success({
|
||||
"sandbox": await check_sandbox(config.tools.exec, config.workspace_path),
|
||||
})
|
||||
finally:
|
||||
self._sandbox_check_running = False
|
||||
if action == "runtime-config-update":
|
||||
values = (request.payload or {}).get("values")
|
||||
if not isinstance(values, dict):
|
||||
|
||||
@@ -217,6 +217,7 @@ _WEBUI_MUTATION_PATHS = {
|
||||
"settings.image_generation.update": "/api/settings/image-generation/update",
|
||||
"settings.transcription.update": "/api/settings/transcription/update",
|
||||
"settings.runtime_config.update": "/api/settings/runtime-config/update",
|
||||
"settings.sandbox.check": "/api/settings/sandbox/check",
|
||||
"settings.network_safety.update": "/api/settings/network-safety/update",
|
||||
"settings.cli_app.install": "/api/settings/cli-apps/install",
|
||||
"settings.cli_app.update": "/api/settings/cli-apps/update",
|
||||
|
||||
Reference in new issue
Block a user