Skip to content

CreateTeam bypasses listener-scoped workspace authority (ADR 0237) #759

Closed

Description

@jhrozek

Summary

Service.CreateTeam accepts a client-supplied filesystem workspace and builds an osfs workspace + root-bound command runner on it without consulting workspace authority. On a server-assigned deployment (the deployment ADR 0237 exists to protect), an authenticated caller can root an agent team at any absolute path — the identical hole ADR 0237 closed on CreateSession, surviving on a verb the ADR's route list never enumerated.

Found during panel review of the listener-scoped-workspace-authority branch. This is pre-existing and out of scope for that branch's own fix, hence a separate issue.

Affected code

  • internal/adapter/server/team.go:120 — CreateTeam guards only workspace == "", then s.cfg.Workspaces(workspace) and s.cfg.CommandRunnerFactory(workspace). grep WorkspaceAuthority internal/adapter/server/team.go → 0 matches.
  • Wire entries pass the request workspace straight through: internal/adapter/server/grpc_team.go:23, internal/adapter/server/http.go:1044 (POST /v1/teams).
  • Every forked member derives from this base Environment.

Preconditions

  1. Server-assigned deployment (any non-loopback API listener). Loopback-only/embedded is client-selected and unaffected.
  2. Teams enabled — mecated defaults --enable-teams=true (cmd/mecated/main.go:1573). mecak8s defaults it off and is no-FS, so mecak8s is not exposed.
  3. Authenticated caller. This is authenticated-principal privilege escalation: per ADR 0237, authentication does not authorize selecting a host/container path.
  4. Build wires the real osfsWorkspaceFactory (internal/app/build.go:1722), which opens any non-empty absolute root.

Impact (CWE-284 / OWASP A01:2021)

  • Read surface: a member rooted at / runs Read/Grep/Glob over the daemon's filesystem — mounted secret volumes, cloud-credential files, TLS keys, and (in k8s) the pod service-account token → lateral movement per that SA's RBAC.
  • Shell escalation: a mutating:true member gets Edit/Write/Bash via CommandRunnerFactory(workspace) — a shell bound to the attacker-chosen root — so on a trusted/auto posture deployment, command execution in a directory the operator never vouched for.
  • Blast radius is bounded by the daemon process's own uid/mounts; env-var provider secrets are scrubbed by envscrub, but on-disk secret files are not. CreateTeam stamps the caller as owner, so the action is attributable in the session store.

Minimal repro

Against a server-assigned mecated with teams on, an authenticated caller:

  1. POST /v1/teams with workspace:"/" and one lead member whose initial_prompt reads a secret path.
  2. POST /v1/teams/{id}/run.

The member executes file reads against /. Adding mutating:true to the member grants a shell bound to /.

Fix

Route CreateTeam through the same single predicate as every other creation path — root-cause fix, not a per-callsite patch. As the first statement after the MemberEngine nil check, replacing the bare workspace == "" guard:

workspace, _, err := s.workspaceForCreate(workspace, ProfileDefault)
if err != nil { return "", nil, err }

Under client-selected this yields the same ErrInvalidArgument: workspace is required for an empty value (byte-identical local behaviour); under server-assigned it demands empty and substitutes the deployment root.

Also:

  • Drop the emptiness pre-checks in the gRPC (grpc_team.go:20) and HTTP (http.go) handlers so an empty workspace reaches the service gate on a server-assigned deployment (the CreateSession precedent: the wire workspace field stays a request field for compatibility, empty = "assign the operator root"). Existing clients that send a workspace to a server-assigned deployment will start receiving InvalidArgument — the same intentional break CreateSession took.
  • Add a scenario test mirroring TestListenerScopedWorkspaceAuthority_Scenario5_AllCreationPathsRespectAuthority: CreateTeam("/client/root") against a server-assigned Service backed by a counting Workspaces factory; assert ErrInvalidArgument and zero factory calls (rejection precedes construction).
  • Add agent-team creation to ADR 0237's enumerated route list ("persisted-session run entry and rehydration, scheduled-fire creation, legacy adoption, composition-created environment overrides, direct API creation").

Notes

SpawnTeammate / spawnTeammate (POST /v1/teams/{id}/members) inherit the team's base environment, so fixing CreateTeam closes the member path too — but worth a glance during the fix to confirm no member route re-derives a workspace independently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions