mirror of
https://github.com/AstrBotDevs/AstrBot.git
synced 2026-10-16 15:06:04 +08:00
fix: tighten default Local permission policy
This commit is contained in:
@@ -180,7 +180,7 @@ DEFAULT_CONFIG = {
|
||||
"admin": {
|
||||
"allow_execution": True,
|
||||
"allow_network": True,
|
||||
"filesystem_scope": "host",
|
||||
"filesystem_scope": "workspace",
|
||||
},
|
||||
},
|
||||
"computer_use_require_admin": True,
|
||||
|
||||
@@ -95,7 +95,7 @@ def get_local_permission_policy(
|
||||
role = "admin" if context.context.event.role == "admin" else "member"
|
||||
default_execution = role == "admin"
|
||||
default_network = role == "admin"
|
||||
default_filesystem = "host" if role == "admin" else "workspace"
|
||||
default_filesystem = "workspace"
|
||||
|
||||
permissions = provider_settings.get("computer_use_local_permissions")
|
||||
role_policy = permissions.get(role) if isinstance(permissions, dict) else None
|
||||
@@ -158,13 +158,18 @@ def check_local_execution_permission(
|
||||
if not policy.allow_execution:
|
||||
return policy, (
|
||||
f"error: Permission denied. {operation_name} is disabled by the "
|
||||
"Local permission policy for this user role."
|
||||
"Local permission policy for this user role. Enable `Execute code` "
|
||||
"for this role in AstrBot WebUI -> Config -> Normal Config -> AI -> "
|
||||
"Agent Computer Use -> Local Permission Policies."
|
||||
)
|
||||
if policy.requires_sandbox and not (
|
||||
sys.platform.startswith("linux") or sys.platform == "darwin"
|
||||
):
|
||||
return policy, (
|
||||
"error: Permission denied. Restricted Local execution is only supported "
|
||||
"on Linux with bubblewrap or macOS with Seatbelt."
|
||||
"on Linux with bubblewrap or macOS with Seatbelt. To use restricted "
|
||||
"execution on this platform, select `Third-party sandbox` under AstrBot "
|
||||
"WebUI -> Config -> Normal Config -> AI -> Agent Computer Use -> "
|
||||
"Computer Use Runtime."
|
||||
)
|
||||
return policy, None
|
||||
|
||||
@@ -91,7 +91,7 @@ const defaults = {
|
||||
admin: {
|
||||
allow_execution: true,
|
||||
allow_network: true,
|
||||
filesystem_scope: 'host'
|
||||
filesystem_scope: 'workspace'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,15 @@ def test_local_permission_policy_treats_unknown_roles_as_members():
|
||||
assert resolved.filesystem_scope == "workspace"
|
||||
|
||||
|
||||
def test_local_permission_policy_defaults_admin_to_workspace_access():
|
||||
resolved = get_local_permission_policy(_make_local_run_context("admin", {}))
|
||||
|
||||
assert resolved.allow_execution is True
|
||||
assert resolved.allow_network is True
|
||||
assert resolved.filesystem_scope == "workspace"
|
||||
assert resolved.requires_sandbox is True
|
||||
|
||||
|
||||
def test_local_permission_policy_denies_disabled_execution():
|
||||
policy = {
|
||||
"member": {
|
||||
@@ -126,6 +135,8 @@ def test_local_permission_policy_denies_disabled_execution():
|
||||
assert resolved.allow_execution is False
|
||||
assert error is not None
|
||||
assert "disabled by the Local permission policy" in error
|
||||
assert "WebUI -> Config -> Normal Config" in error
|
||||
assert "Local Permission Policies" in error
|
||||
|
||||
|
||||
def test_windows_local_execution_requires_a_full_trust_policy(monkeypatch):
|
||||
@@ -158,6 +169,8 @@ def test_windows_local_execution_requires_a_full_trust_policy(monkeypatch):
|
||||
|
||||
assert restricted_error is not None
|
||||
assert "only supported on Linux" in restricted_error
|
||||
assert "Third-party sandbox" in restricted_error
|
||||
assert "Computer Use Runtime" in restricted_error
|
||||
assert full_error is None
|
||||
assert full_policy is not None
|
||||
assert full_policy.requires_sandbox is False
|
||||
|
||||
@@ -110,7 +110,7 @@ class TestAstrBotConfigLoad:
|
||||
"admin": {
|
||||
"allow_execution": True,
|
||||
"allow_network": True,
|
||||
"filesystem_scope": "host",
|
||||
"filesystem_scope": "workspace",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -130,9 +130,7 @@ class TestAstrBotConfigLoad:
|
||||
default_config=default_config,
|
||||
)
|
||||
|
||||
permissions = config["provider_settings"][
|
||||
"computer_use_local_permissions"
|
||||
]
|
||||
permissions = config["provider_settings"]["computer_use_local_permissions"]
|
||||
assert permissions["member"] == {
|
||||
"allow_execution": not require_admin,
|
||||
"allow_network": False,
|
||||
|
||||
@@ -145,12 +145,12 @@ async def test_local_execute_shell_manages_running_and_closed_results(
|
||||
owner_id="umo",
|
||||
creator_id="admin-user",
|
||||
creator_is_admin=True,
|
||||
sandboxed=False,
|
||||
sandboxed=True,
|
||||
allow_network=True,
|
||||
filesystem_scope="host",
|
||||
filesystem_scope="workspace",
|
||||
cwd=str(tmp_path),
|
||||
env={},
|
||||
timeout=None,
|
||||
timeout=300,
|
||||
yield_time_ms=250,
|
||||
)
|
||||
for status, exit_code, wall_time in (
|
||||
|
||||
@@ -74,9 +74,9 @@ async def test_local_python_tool_uses_session_workspace(tmp_path, monkeypatch):
|
||||
timeout=30,
|
||||
silent=False,
|
||||
cwd=str(workspace.resolve(strict=False)),
|
||||
sandboxed=False,
|
||||
sandboxed=True,
|
||||
allow_network=True,
|
||||
filesystem_scope="host",
|
||||
filesystem_scope="workspace",
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user