Skip to content

mecak8s: default workspace is the entire container filesystem — an injected agent reads the service-account token #448

Closed

Description

@jhrozek

Proven end-to-end in a kind cluster against deploy/mecak8s as shipped, at
--posture=auto, headless, on the distroless image with no shell.

Impact

The Read tool serves /var/run/secrets/kubernetes.io/serviceaccount/token. The
token is live:

username: system:serviceaccount:mecatl:mecak8s-agent
rules:    get/create/update/delete on coordination.k8s.io/leases (namespace mecatl)

Those Leases are mecak8s's single-writer guarantee (ADR 0048). An agent that
obtains this token can delete or hijack session leases — session denial of
service, and plausibly split-brain writes where two replicas write one session.

No shell is involved. The image is cgr.dev/chainguard/static (shell-less),
readOnlyRootFilesystem: true, runAsNonRoot, drop: ALL. None of that is
relevant, because the attack is an ordinary file read through a tool the agent
is supposed to have.

Root cause

--workspace defaults to the process working directory. The chainguard base
sets no WorkingDir, so cwd is /, and deploy/mecak8s/agent-deployment.yaml
never passes --workspace. The session workspace root is therefore the entire
container filesystem: the SA token is inside the workspace, so neither the
out-of-workspace escape guardrail nor any containment check fires. There is
nothing to escape.

Reproduction

A controlled OpenAI-compatible endpoint stood in for the model, so the result is
deterministic and offline. That choice bounds the claim: this proves the HARNESS
executes the read and returns the bytes to the model. It does not prove an LLM
can be induced to ask via injected content — a separate test needing a live
model.

  1. Deploy deploy/mecak8s with --default-provider=opencode and
    --opencode-base-url pointing at the stand-in (it must serve on :443; the
    agent NetworkPolicy permits egress only on DNS, redis:6379, and 443).
  2. Create a session with workspace: "/" (the server default is cwd = /).
  3. Have the model emit Read{path: "var/run/secrets/kubernetes.io/serviceaccount/token"}.
  4. The tool result carries the token; it is echoed into the model's final
    message and out through the API response.

Verified against the API server with SelfSubjectReview and
SelfSubjectRulesReview.

What correctly held

Worth recording so a fix does not over-rotate — three controls worked:

  • The pseudo-filesystem guard. Read{path: "proc/self/environ"} was refused
    with "path lies under a pseudo-filesystem (/proc, /sys, /dev): an in-process
    FS read would expose the server's raw environment — never relaxed at any
    posture"
    (internal/app/escapeclassifier.go). It correctly canonicalised the
    RELATIVE path against the workspace root before judging. The provider API key
    in the process environment was not reachable this way.
  • RBAC. Namespace-scoped, no list, no secrets access. list leases was
    refused. The blast radius is bounded by this and nothing else.
  • NetworkPolicy. Egress restricted to DNS, redis, and 443. A first attempt to
    reach a stand-in provider on :9000 was silently dropped.

The gap is specifically that file-based credentials inside the workspace root are
served, while environment-based ones are protected.

Suggested fixes

  1. Set --workspace to a real project directory in
    deploy/mecak8s/agent-deployment.yaml. One line; closes this.
  2. Consider warning — or refusing — when a session workspace resolves to /.
    A workspace of "the entire filesystem" is almost always misconfiguration
    rather than intent, and this is not mecak8s-specific: any containerised
    deployment that omits --workspace inherits cwd.
  3. Consider a projected service-account token with a narrow audience and short
    expiry. automountServiceAccountToken: true is required for leases, so the
    token cannot simply be removed.

Related

The environment-versus-disk asymmetry is directly relevant to the agent-identity
work: material held in process memory is behind a working guard, while material
loaded from a mounted file is not.

Activity

  1. jhrozek commented on Aug 26, 2026

    @jhrozek
    ContributorAuthor

    Fixed in merged commit 1bf8998 (PR #763, Listener-scoped workspace authority). mecak8s now defaults --workspace to empty and uses the file-less authority, so the container root is no longer an implicit agent workspace. Configured workspaces are operator-assigned clean absolute roots; client-selected roots, filesystem profiles in file-less mode, and persisted off-root sessions fail closed. Coverage is in cmd/mecak8s/main_test.go and internal/adapter/server/workspace_authority_scenario_test.go. The Helm chart defaults workspace: "" and passes --workspace only when explicitly configured.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions