Skip to content

Listener-scoped workspace authority (ADR 0237) - #763

Merged
jhrozek merged 29 commits into
mainfrom
acc/listener-scoped-workspace-authority
Aug 26, 2026
Merged

jhrozek merged 29 commits into
mainfrom
acc/listener-scoped-workspace-authority

Conversation

@jhrozek

@jhrozek jhrozek commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Closes #762. Part of #437 (make the k8s deployment safe to expose). Follow-ups tracked in #759 and #760.

Why

CreateSession and the other session-creating paths accepted a client-supplied workspace path, checked only non-emptiness, then opened it as a real filesystem root. Authentication identified the caller; nothing authorized that principal to name a path — so on a network-facing deployment an authenticated client could root a session at /, /etc, or a service-account secret mount and point the file tools + Bash there. A loopback bind is not evidence the caller is local (a reverse proxy defeats that), so the decision must be deployment policy, not inferred from the request or the socket.

Design: ADR 0237 + docs/acceptance/listener-scoped-workspace-authority.md.

What this delivers

  • server.WorkspaceAuthority — a per-deployment policy (ClientSelected / ServerAssigned / Fileless) chosen in composition, never inferred in the server adapter. A server-assigned deployment rejects a non-empty client workspace with InvalidArgument before cleaning/comparison and assigns the operator-configured root.
  • Enforced on every path, not just direct create: run entry, rehydration, scheduled fire, legacy adoption, environment overrides — with a lexical stored-root identity check that fails a stale off-root value closed.
  • mecated derives the policy from API-listener topology, with an explicit --workspace-authority override; a network filesystem deployment without a configured root fails before listener startup.
  • mecatui rejects an explicit --workspace to a remote target locally and sends no cwd by default.
  • mecak8s is file-less (no-FS) by default, and serves an operator-mounted workspace root (e.g. a PVC) as a server-assigned filesystem deployment when --workspace is set.

Review history (honest notes)

The branch as first assembled did not compile — three merge artifacts plus a missing app.Config→server.Config plumbing layer, so no test on it had ever run despite four plan tasks marked done. The first commit repairs that and lands the plumbing; the rest is the feature.

A panel review then found and this PR fixes inline:

  • server-assigned schedules could never fire (persisted resolved root rejected by the fire-time gate)
  • ForkSession skipped the persisted-workspace check → now enforced at the shared reopenLoadedSession choke point
  • validateEnvironmentOverride used a raw string compare instead of the shared identity rule
  • the authority predicate now fails safe for a future enum value (clientSelectsRoot)
  • the mecak8s mounted-workspace capability (grew from a "silently-ignored flag" finding)
  • adoption-preflight lease churn, mecated flag-layer path validation, and dead-clause cleanup

Deferred to follow-ups: #759 (a CreateTeam bypass of this same authority — Critical, separate branch) and #760 (consolidate the enforcement surfaces + make the config state unrepresentable). A latent ADR-0214 remote-EnvironmentRef interaction is recorded on #760.

Verification

task lint (root + engine + providers + go vet) = 0 issues; task test = full suite green; task docs = 0 broken links; task site:build = SUCCESS.

🤖 Generated with Claude Code

jhrozek and others added 29 commits August 26, 2026 08:28
…mbing

The listener-scoped workspace authority branch did not compile. Three merge
artifacts and a missing composition layer meant no test on it had ever run,
so the plan's own verify tests were unexercised despite four tasks being
marked done.

Merge artifacts:

- service.go carried a stray `<<<<<<< HEAD` marker with no matching sides;
  both halves of the resolution were intact, so the marker alone was removed.
- adoption.go carried one stray `}` after the authority call. The neighbouring
  repeated adoptionSource/reason pair is the pre-existing revalidate-after-lease
  pattern and is unchanged.
- cmd/mecatui referenced `transportResolution`; `prepareRun` returns
  `invocationResolution`. Renamed in main.go and config_test.go.
- A scenario test passed "" to RestoreLabels, whose second parameter is a
  session.Authority struct.

Missing plumbing: cmd/mecated and cmd/mecak8s set app.Config fields that were
never added, and nothing passed authority into server.Config. app.Config gains
WorkspaceAuthority + AuthoritativeWorkspace, threaded into the server.Config
literal in Build.

Authority is one enum rather than an enum plus a file-less bool, so the
meaningless "server-assigned with no configured root" state is unrepresentable
instead of building and then rejecting every filesystem request:

    WorkspaceAuthorityClientSelected  // root ignored
    WorkspaceAuthorityServerAssigned  // requires a clean absolute root
    WorkspaceAuthorityFileless        // requires an empty root; always no-FS

Every authority gate branches on the single serverAssigned() predicate, so a
future value cannot fail open by being missed at one of the five call sites,
and NewService validates the combination once at construction.

workspaceForCreate now returns the effective profile as well as the root. The
schedule manager was persisting the requested profile, so a file-less
deployment's schedule created with an omitted profile stored "" and was then
refused at its own fire-time authority check forever.

The authority hook is installed on the schedule manager only under
server-assigned authority. Under client-selected its sole effect would be to
pre-empt validateScheduleSpec's more specific rejection, which explains why a
default-profile schedule needs a workspace.

Also: the ADR was numbered 0234, already owned by the authority-evaluator ADR
across engine/CHANGELOG.md, IMPLEMENTATION-NOTES.md and ADR 0235's Supersedes
line; renumbered to 0237. The mecak8s telemetry tests passed a workspace to
CreateSession, which this branch's own AC4.3 requires be rejected. NewService's
schedule wiring moved into wireScheduleManager to stay under the gocyclo bound.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Records why file-less is a third authority value rather than a separate bool,
so a later change cannot quietly re-split it and reintroduce the state that
builds and then rejects every filesystem request.

The table walks all nine combinations of authority and configured root: the
three meaningful ones construct, and each meaningless one — server-assigned
with no root, with a relative root, with an unclean root, file-less with a
root, and an unknown value — is rejected as ErrConfig at NewService rather
than per request.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A default-profile schedule created under server-assigned authority could never
fire. The create-time authority hook substituted the resolved deployment root
into the persisted spec, and the fire path re-entered the client-facing create
gate with that non-empty root — which the gate rejects, because a server-assigned
deployment requires an empty workspace on the wire. Every filesystem schedule
fire failed with InvalidArgument, recorded as fireFailed.

A schedule is a deferred session create, so it now carries the same empty wire
workspace a live create does. The authority hook still rejects a non-empty client
workspace and resolves the effective profile, but no longer persists a root;
validateScheduleSpec's required-workspace rule becomes client-selected-only (the
hook, installed only under server-assigned authority, means empty is the correct
wire value there); and validatePersistedScheduleWorkspace requires an empty
persisted workspace under server-assigned authority for both profiles. The fire
path is unchanged — it already forwards spec.Workspace, now empty, so createSession
assigns the deployment root.

Consequence, recorded in ADR 0237: a schedule tracks the current deployment root
rather than freezing a snapshot, so a single-root deployment that reconfigures its
root fires existing schedules at the new root. A non-empty persisted schedule
workspace is stale off-root state and is refused before the fire is claimed.

The Scenario5 test asserted the buggy behaviour (persisted root == deployment
root); it now asserts the empty wire value and adds the round-trip that failed:
re-creating a session from the persisted schedule spec must mint on the
deployment root, not return InvalidArgument.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…oke point

ForkSession loaded a persisted session and called reopenLoadedSession directly,
skipping validatePersistedWorkspace — the check every other run-entry route runs.
A stale off-root source (persisted under an earlier client-selected configuration,
after a --workspace reconfig, or via a shared store) was therefore laundered into a
new persisted record and, because an off-root workspace differs from the default,
triggered rehydrateSession — building a per-session engine whose composition
performs workspace-scoped filesystem ingestion (learned-skill partitions, learning
policy, the child permission resolver) against the off-root path. The forked
session was unrunnable (StartRunContent rejects it), but ADR 0237's promise that a
stale root "fail[s] closed before filesystem access" was already violated by then.

Rather than add a fourth hand-placed check, enforce it at reopenLoadedSession — the
recovery funnel loadAndReopen, startRunContent, and ForkSession all pass through —
so a new recovery route cannot silently skip it. loadAndReopen's now-redundant
explicit check is removed (nothing runs between its load and the reopen);
startRunContent keeps its earlier check deliberately (to reject before its purpose
gate and run-registry cleanup, not as the sole defense); resumeFromAwaiting keeps
its own because it rejects terminal states and structurally bypasses the funnel.
The check is a pure lexical no-op under client-selected authority.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
validateEnvironmentOverride compared the override root to AuthoritativeWorkspace
with a raw `!=`, while its two sibling persisted-root gates route through
isAuthoritativeWorkspace (which also requires both sides non-empty, absolute, and
clean). Under WorkspaceAuthorityServerAssigned the two forms are equivalent, but
under WorkspaceAuthorityFileless the configured root is "" — so the raw compare
ACCEPTS an empty-root override on a ProfileDefault session (both ""), where
isAuthoritativeWorkspace fails closed. A defense-in-depth gate that was strictly
weaker than the layer it backstops.

The path is unreachable via run entry today (validatePersistedWorkspace rejects a
ProfileDefault/Fileless session before engineAndEnvironmentFor runs), so it is
pinned by a white-box unit test that also mutation-checks: it fails on the old
raw compare and passes on the identity rule. Behaviour is unchanged on every
reachable path.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
serverAssigned() returned true for ServerAssigned || Fileless, and its doc claimed
a new authority value could not fail open. That was true of the call sites but not
of the predicate: a fifth constant returns false from serverAssigned(), so all five
gates would treat it as client-selectable — the permissive default. Only
validateWorkspaceAuthorityConfig's default arm kept it out of NewService, and adding
a case there (as a new value requires) would silence the predicate.

Replace it with clientSelectsRoot(), true only for the explicit client-selected
authority. Every other value — server-assigned, file-less, and anything added later
— is deployment-assigned, so a new constant defaults to enforced rather than
caller-chosen. The four gates read `if clientSelectsRoot() { return nil }`; the two
positive uses (schedule-hook install, the create gate's deployment arm) take the
negation. No behaviour change on the three current values; the guarantee is now the
predicate's, not the call sites'. Pinned by a fail-safe table test including an
unhandled value.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
mecak8s was hardcoded file-less: --workspace was registered (defaulting to the
process cwd) but ignored, so an operator who mounted a PVC to give sessions a
shared filesystem root got no error and a no-FS deployment. ADR 0237 anticipated
this ("a future operator-enabled mounted-workspace deployment"); this lands it.

--workspace now drives the authority: empty (the new default) is file-less
(no-FS, unchanged); a non-empty absolute path is a server-assigned filesystem
deployment rooted there. Because authority is server-assigned, a client still
cannot select another root — a non-empty client workspace is rejected before any
filesystem access, exactly as mecated does. The flag default changed from the
process cwd to "" so a container root can never become the agent workspace by
omission (the container-root leak the file-less default originally avoided); a
relative --workspace is refused at parse time with a flag-level message rather
than surfacing later from app.Build.

Storage-free posture is unchanged: harness and session state stay in Redis + the
k8s API (ADR 0048); a mounted volume holds only agent working files, and a root
shared across replicas needs a ReadWriteMany volume. The default Helm chart still
mounts no PVC.

Tests: the two no-FS scenario tests dropped their `cfg.workspace = "/"`
simulations (which encoded the old always-ignored contract) and now assert the
default is file-less; a new test proves a configured mount is server-assigned,
mints a default-profile session on the mount, and still rejects a client-chosen
root; a relative --workspace is rejected. ADR 0237 and the mecak8s deployment
guide document the mode, the RWX caveat, and the storage-free distinction; the
stale quickstart examples that sent a workspace to a file-less deployment are
corrected.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three small consistency fixes from panel review, no behaviour change on any
reachable path except #9's error site:

- isAuthoritativeWorkspace's three `configured`-side clauses were dead once
  `root == configured` (implied by the same tests on root), and the same
  non-empty/abs/clean invariant was written twice (here and in
  validateWorkspaceAuthorityConfig). Extract one isCleanAbs helper used by both,
  so the authoritative-root rule is single-sourced. Also inline a constant that
  was passed through %s.

- PreflightSessionAdoption no longer swallows the authority-normalization error.
  The outcome was already correct — resolveAdoptionBindings re-normalizes and
  returns binding_unresolved regardless — but swallowing meant the ownership,
  source, and mutation-lease steps all ran for a binding doomed to fail
  authority. Rejecting up front skips that (notably the lease acquire/release)
  and matches AdoptSession. (The reviewer's "could report adoptable" was not
  actually reachable; this is a lease-churn + clarity fix, not a correctness one.)

- mecated's validateWorkspaceAuthority now mirrors the clean-absolute rule for a
  configured --workspace, so a relative or unclean value on a network listener
  fails with a flag-level message instead of surfacing two layers down from
  app.Build. Matches the mecak8s flag check.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The #2 fix added a condition to validateScheduleSpec's profile switch, tipping it
over the gocyclo threshold (21 > 20). Lift the profile-aware workspace switch into
validateScheduleWorkspaceProfile — a cohesive, separately-named check — same
pattern as the earlier wireScheduleManager extraction. No behaviour change.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…pollution

Two CI failures surfaced on the first full run of this accumulator branch, both
artifacts of the branch never having run in CI before (green locally, untested in
the CI environment):

- Test (race): three mecak8s Scenario4 tests called app.Build without disabling
  the k8s session lease, so app.Build tried to load a kubeconfig — present on a
  dev machine, absent in CI ("no configuration has been provided"). The sibling
  FixtureRunsNoFS test already set sessionLeaseK8sNamespace="" for exactly this;
  the two pre-existing tests and the new mounted-workspace test now do the same.
  Reproduced locally with KUBECONFIG=/nonexistent before and after the fix.

- go.work.sum: the earlier repair commit accidentally committed a go.work.sum
  with extra toolhive-core v0.0.40 checksums (pulled in during a local task run),
  inconsistent with the v0.0.39 pin in go.mod. `go work sync` reproduces main's
  version exactly, confirming the pollution was spurious. Reverted so the branch's
  module files are byte-identical to main — no dependency change, and the ko
  workspace build the k8s e2e runs is no longer handed an inconsistent workspace.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…go bump

The k8s-e2e ko build fails with "updates to go.mod needed" even on
main-identical module files: dependabot's ssefilter bump to
openai-go v3.52.0 (#735, merged AFTER main's last green k8s-e2e run)
tidied only that submodule, leaving root + provider/openai +
provider/openaichat pinned at v3.50.0. Workspace mode masks the skew
(which is why local builds and the go.work.sum revert both looked
green); ko resolves GOWORK=off under -mod=readonly and refuses.
Reproduced and verified via GOWORK=off GOFLAGS=-mod=readonly go list.
Also raises toolhive-core to v0.0.40 and anthropic-sdk-go (indirect)
to v1.63.1, the versions MVS already selects.

Co-Authored-By: Claude <[email protected]>
Co-authored-by: Cursor <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
… create

With mecak8s now file-less by default (ADR 0237), the k8s e2e failed at run
time — its session/schedule creates sent workspace:"/tmp", which a file-less
deployment rejects ("profile no-fs must not carry a workspace"). The suite last
ran green on main before the no-fs change and was never updated.

Rather than switch the e2e to no-fs (the caller_separation cron schedule needs a
real filesystem), deploy mecak8s WITH a mounted workspace and let the server
assign it — dogfooding the mounted-workspace feature this branch added:

- Chart: a values-gated `--workspace` (the operator knob for a mounted PVC root;
  empty default keeps production file-less), declared in values.schema.json, set
  to /tmp (a writable emptyDir in the pod) in the kind e2e profile.
- baseAgentArgs / the live-provider patch carry --workspace=/tmp too (they
  replace the whole args list).
- Every e2e create/schedule/fork now sends an EMPTY workspace; the server
  assigns its configured root. Under server-assigned authority a client cannot
  select a root, so empty is the correct wire value (a schedule likewise stores
  empty and is assigned the root at fire time).

Verified: `go vet -tags kind_e2e ./e2e/k8s/` compiles, `task deploy:check`
passes, and the kind profile renders `--workspace=/tmp`. The kind suite itself
is only exercisable in CI.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@jhrozek
jhrozek merged commit 1bf8998 into main Aug 26, 2026
19 checks passed
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.

Listener-scoped workspace authority (ADR 0237)

2 participants