Skip to content

Workspaces phase 2e: platform-only, workspace admins and the switcher (#277) - #320

Merged
antiv merged 3 commits into
mainfrom
workspaces-phase-2e
Nov 3, 2026
Merged

antiv merged 3 commits into
mainfrom
workspaces-phase-2e

Conversation

@antiv

@antiv antiv commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Phase 2e of #277 (documents/design/2.0-plan.md), the last PR of phase 2. Workspace owners and admins now administer their workspace, platform administrators keep the installation, and a switcher picks the workspace. With one workspace every owner is a platform administrator, so an installation sees no change apart from what is listed below.

Workspace admins and platform administrators

  • ctx.is_admin now covers the owners and admins of the request's workspace, and DashboardAuthzMiddleware asks it. ctx.is_platform_admin is the admin role.
  • PLATFORM_ONLY_PATHS need a platform administrator: migrations, server control, settings, system jobs, the wizard and shop, users, audit retention, the template catalogue, reload all and binary builds. The installation's pages check ctx.is_platform_admin, and base.html and the pages hide their links and controls from everyone else.
  • A2A goes through the proxy for a caller who may use the agent, with the agent's roles checked there.

What stays platform-only (shared/utils/platform_only.py)

These run code on the server or read its environment:

  • the code executor;
  • stdio MCP servers;
  • ${VAR} in model_api_key, model_base_url and mcp_servers_config;
  • hardcoded agents, including a name that has a folder in agents/.

A workspace admin can't add one or change its defining part on create, update, rollback or template import (403). An agent import and a template sync skip the agent. At run time both runtimes refuse the code executor and stdio servers to an agent outside the default workspace.

Switcher

GET /dashboard/api/workspaces and PUT /dashboard/api/workspaces/current. The dashboard session keeps the chosen workspace, and a choice the caller has lost falls back to the default. The switcher only shows with more than one workspace.

Security reviews

Two security reviews ran on this branch. Every finding is fixed here, with a test.

First review (afd756d):

  • A clone suffix such as ${MATE_SECRET_KEY} put a ${VAR} into an HTTP MCP URL, and a quote could break out of the JSON. A suffix now holds only letters, digits and underscores.
  • A clone or template could give a workspace admin a name with a folder in agents/, whose code then ran as their agent. For a caller who isn't a platform administrator:
    • a clone bumps the name;
    • a template import refuses with 409 before creating the project;
    • a template sync skips the agent.

Second review (ce1bc46):

  • Placeholders spelled with JSON escapes. The runtimes decode an MCP entry's string headers, args and env a second time, so "${VAR}" was only a placeholder after the check had passed. features_added now decodes them the same way first.
  • Agent names are identifiers. ADK already required this. Create, rename and import refuse anything else, for every caller. Before, an agent named .. deleted with delete_folder=true would rmtree the installation. The delete route now goes through _delete_agent_folder, which only removes agents/<name> itself. The agent server skips a folder for an invalid legacy name at startup.
  • Moving a root agent moves only its own children. The propagation used an unescaped LIKE across the whole installation, so a root named % moved every sub-agent. It now escapes the name, matches the parent exactly and stays in the agent's original workspace.
  • A stored key and a new base URL. A workspace admin who changes the base URL of an agent with a stored key has to type the key again. Otherwise the stored key would be sent to the new host.

Left as they are, platform administrators only: the rmtree in wizard/cleanup.py and name validation in create_agent_tool.

Behaviour changes with one workspace

  • A new agent name, or a rename, must start with a letter or an underscore and hold only letters, digits and underscores. Otherwise it gets a 400. An existing name that breaks the rule can be kept, and its agent can still be edited. An import skips an agent with such a name unless it already exists.
  • delete_folder=true deletes no folder for a name that isn't one folder directly under agents/.
  • A template sync that changes the base URL of an agent with a stored key skips that agent for a workspace admin. With one workspace no workspace admin is anything less than a platform administrator, so nothing changes in practice.

Docs

gen_docs --check passes. Updated: docs/user/agents.md, templates.md, tools-and-mcp.md and users-and-roles.md, and docs/dev/auth-and-access.md, code-executor.md and langgraph-runtime.md. These drift-listed guides still hold:

  • docs/dev/a2a.md and docs/dev/architecture.md: server_control_service.py only skips a folder for an invalid name, and the proxy change is the A2A check described in auth-and-access.md.
  • docs/dev/agent-runtime.md and docs/dev/writing-a-tool.md: the runtime guard is the one line may_run_code, and tool construction is otherwise unchanged.
  • docs/dev/alerts.md, docs/dev/template-format.md and docs/dev/trigger-engine.md: dashboard_server.py changed only in the agent routes and in the platform-only checks. The template format and trigger and alert behaviour are the same.
  • docs/dev/tracing.md: tracing is unchanged.
  • docs/dev/documentation.md: docs.html only hides links to platform-only pages.
  • docs/user/triggers.md, docs/user/usage-and-audit.md and docs/user/settings.md: the templates only hide platform-only controls from workspace admins, and nothing changes for a platform administrator.

Verification

  • Tests. The full suite passes: 1834 tests, 1 skipped. test_client_contract.py is unchanged.

  • Mutation check. I removed each new check one at a time, and a test fails for every one except the exact-parent check in the propagation loop. The escaped LIKE already matches exactly, so that check is a second layer, as it is in the runtime.

  • Local server. I created a temporary workspace with an owner who isn't a platform administrator and tried the reviews' attacks as that owner:

    • names .., ., /tmp/x, a/b, % and a-b got 400;
    • an escaped ${VAR} in string headers got 403;
    • a new base URL with the stored key got 403, and worked once the key was typed again;
    • moving a % root left all 33 sub-agents of the default workspace where they were;
    • deleting with its folder removed only that agent's folder.

    The switcher showed for the platform administrator only, and the owner saw only their workspace. The admin pages answered 200, the server log has no traceback, and cleanup left nothing behind.

antiv added 3 commits November 2, 2026 14:45
…#277)

ctx.is_admin now takes in the owners and admins of the request's workspace, and
DashboardAuthzMiddleware asks it. PLATFORM_ONLY_PATHS (migrations, server control,
settings, system jobs, wizard and shop, users, audit retention, the template
catalogue, reload all and binary builds) need a platform administrator, and the
installation's pages check ctx.is_platform_admin; base.html and the pages hide
their links and controls from everyone else.

Agent features that run code on the server or read its environment are platform-only
(shared/utils/platform_only.py): the code executor, stdio MCP servers, ${VAR} in the
model endpoint and MCP config, and hardcoded agents, including a name with a folder
in agents/. A workspace admin can't add one or change its defining part on create,
update, rollback or template import; an agent import and a template sync skip the
agent. At run time the code executor and stdio servers are refused to an agent
outside the default workspace, on both runtimes.

A2A goes through the proxy for a caller who may use the agent, its roles checked
there. The dashboard session keeps the workspace chosen in the new switcher
(GET /dashboard/api/workspaces, PUT .../current), shown with more than one
workspace; a choice the caller lost falls back to the default.

With one workspace every owner is a platform administrator, so an installation
sees no change. test_client_contract.py is unchanged.
From the security review of phase 2e. A clone writes its suffix into the cloned
configs, so a suffix like ${MATE_SECRET_KEY} put a ${VAR} into an HTTP MCP URL, and
a quote could break out of the JSON; a clone or template could also give a workspace
admin a name with a folder in agents/, whose code then ran as their agent and whose
folder they could delete.

The suffix now holds letters, digits and underscores only. For a caller who is no
platform administrator a clone bumps a name with a code folder and refuses, before
writing anything, a rename that changes a platform-only feature of its source; a
template import refuses such a name before creating the project (409), and a
template sync skips the agent.
From the second security review of phase 2e, on code a workspace admin now reaches.

An agent name must be one ADK accepts, an identifier: create and rename answer 400
otherwise, an import skips the agent, and the agent server's start creates folders
for valid names only. A name like '..' or '/srv' made deleting the agent with
delete_folder=true run rmtree outside agents/; that route now goes through
_delete_agent_folder, which deletes only a folder right under agents/ named exactly
like the agent. An agent keeps a name it already has.

Moving a root agent to another project moved every agent whose parent_agents
matched an unescaped LIKE on its name, in any workspace, so a root named '%' took
every sub-agent of the installation. It now moves the sub-agents of its own
workspace that name it exactly, by the name it had before the update.

The platform-only ${VAR} check reads mcp_servers_config as the runtimes do, which
decode an entry's headers, args and env once more when it is a string, so a
placeholder spelled with JSON escapes there is seen. A new base URL beside a stored
key the request keeps without naming it is refused too: the caller types the key
again.
@antiv
antiv merged commit b1e3fef into main Nov 3, 2026
2 checks passed
@antiv
antiv deleted the workspaces-phase-2e branch November 3, 2026 06:54
antiv added a commit that referenced this pull request Nov 3, 2026
A review of phases 2a-2e together (cb8a218..b1e3fef) found these cross-workspace
paths and 1.x differences; TestReviewOfPhase2 and test_a2a_routes cover each.

- may_run_code() judges a config by its project_id. A subagent made by delegation
  has its parent's project and a name with no row, so it ran the code executor and
  stdio MCP servers for an agent outside the default workspace.
- The Work Room title escapes agent, user and session id in the agent-server URL:
  httpx resolves '..' in a path, so a session id could name another workspace's
  session, read its first message and write its title.
- A rating needs agent_name and a session of the caller with that agent; before, a
  rating with no agent skipped the workspace check, and one through an agent of A
  could point the eval pages at B's session.
- Session detail and delete use the whole ADK key (app, user, id) and read only the
  checked session's events; the rated-answer pages read events by session and agent.
- A widget visitor is a widget_<key id>_ id with the widget role, which only the
  server gives out (V017 gave it to the earlier visitors). Single sign-on and
  Users refuse ids starting widget_ and trigger_runner (is_reserved_user_id).
- Each agent gets its own A2A task store, so tasks/get and tasks/cancel through one
  agent find none of another's.
- A Slack team stays with the first workspace to connect it; the 409 says to ask a
  platform administrator.
- The ${VAR} defining part is each place holding one, so editing an MCP server
  without a placeholder is no longer refused.
- X-MATE-Workspace with a non-ASCII digit is a 404, not a 500.
- The request context is made once a request: the middleware's is reused.

The plan now ships phases 3 and 4 in 2.0.0 too, and records 2e (#320) and 2f.
test_client_contract.py is unchanged and passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant