Skip to content

feat(egress,control-plane): an egress refusal says what it means, and the control plane's base URL says what it is - #864

Merged
webchang merged 2 commits into
rossoctl:mainfrom
webchang:pr/i779-egress-hints
Nov 17, 2026
Merged

webchang merged 2 commits into
rossoctl:mainfrom
webchang:pr/i779-egress-hints

Conversation

@webchang

Copy link
Copy Markdown
Member

Closes #779

What changed and why

The docs part of #779 landed in #821: the user guide, the concepts pages, the MCP server's
instructions, the bash tool descriptions and mocactl sbx's status text now say that a sandbox
reaches the hosts on moca-egress's allowlist, not that it has no network. What was still open is
what a user or an agent learns when it meets the allowlist, and what the control plane's own URL says.

  • The 403 destination_denied body says what it means and what to do
    (remote-worker/internal/egress/handler.go, refusalHints). The first line stays
    destination_denied: <host>, and the status and the X-Moca-Egress-Error header are unchanged.
    After the first line, the body now says that the host is not on this sandbox's egress allowlist,
    that retrying will not help, that the operator adds hosts, and that for the sandbox service
    mocactl sbx egress lists the hosts a sandbox reached and was refused. The text is fixed. The proxy
    does not know the deployment's user-facing URL (its credentials URL is the host's view of the
    control plane), and it does not print the allowlist, because no API shows the allowlist to a
    sandbox's user either. Other refusal codes keep their one-line body.
  • The conformance contract allows text after the first line
    (remote-worker/egress/conformance/conformance.go wantRefusal, and the package's doc.go). Its
    first line must still be exactly <code>: <host>. This only relaxes the check: an implementation
    with a one-line body still conforms.
  • GET / on the control plane answers a page instead of 404 not_found
    (packages/control-plane/src/routes.ts, getIndex; indexPage in handlers.ts). It is
    unauthenticated, mounted on every profile, and returns a short text/plain page. The page says
    that this is a Moca control plane (on the sandbox profile, the sandbox service), gives the
    deployment's version if it has one, and says that the API is under /v1, with GET /v1/discovery
    describing the deployment. It shows the install line for mocactl and the login command for each
    profile served, with a link to that profile's guide, and says that a sandbox's egress is an
    allowlist that the operator extends. It names no URL of the deployment and echoes nothing from the
    request (not the Host header either), so it has nothing deployment-specific in it. The only URLs
    it names are the project's public ones. Only the exact path / is routed.
  • OpenAPI 1.27.0 (docs/api/openapi.yaml, CHANGELOG.md, change-policy.md): adds GET /. The
    change is additive, and the page's wording is documented as not a contract.
  • The agent's rules (packages/sandbox-client/src/mcp-server.ts, sandboxRules, which also
    writes the CLAUDE.md/AGENTS.md block): a refused host stays refused. The agent should neither
    retry it nor look for another way to reach it, and should name the host to the user, who can ask
    the operator to allowlist it. This is the behavior the issue reports: an agent that met the 403
    went on probing, or set out to build the packages from source.
  • Docs: the user guide's §5 says what the refusal body says, how to ask for a host (name it to
    the operator; mocactl sbx egress shows the refused ones), and that the service URL describes
    itself. The RUNBOOK's egress section tells the operator that users are sent to them, and where the
    allowlist is.

Tests

Each new test was run before and after the fix.

  • remote-worker/internal/egress: TestOffAllowlistRefusalSaysWhatToDo (new) fails on main.
    The body is only destination_denied: evil.test, and the test reports four missing phrases. It
    passes with the fix. The test also checks that no allowlisted host appears in the body and that
    Content-Length matches the longer body. TestOtherRefusalsKeepOneLine (new) pins the one-line
    body for the other codes. assertRefusal now checks the first line instead of the whole body.
  • packages/control-plane: the new GET / (#779) block in discovery.test.ts (4 tests: harness,
    sandbox and combined pages, version, no deployment URL) and the server test in server.test.ts
    (200, no echo of a Host: cp.example.invalid header, /index.html still 404) fail on
    main
    . So do the updated route lists in routes.test.ts and route-profile.test.ts: 8 failures
    in all. All of them pass with the fix.
  • packages/sandbox-client: the new test in mcp-server.test.ts that checks, for all three modes,
    that the rules say a refused host stays refused fails on main and passes with the fix.
  • Full runs with the change:
    • remote-worker: go vet ./... and go test ./... pass. With -race: the internal/egress
      tests, the egress/conformance package and cmd/moca-egress pass.
    • packages/control-plane: 1943 passed, 3 skipped. tsc --noEmit is clean, and
      openapi-contract.test.ts (version, changelog and change-policy) passes.
    • packages/sandbox-client: 271 passed, and tsc --noEmit is clean.
    • packages/server: all but one test passed in the parallel run (585 tests). The one failure,
      workload-runs.test.ts ("answers 404 for a deleted workload"), is in code this change does not
      touch, and the file passes alone (26 tests, all passing).
    • packages/mocactl (--minWorkers=1 --maxWorkers=2): the full run on a heavily loaded machine had
      46 failures, all were 5000 ms timeouts, in five git-heavy files
      (the push, up, up-cortex, templates and record suites under test/). Those files, and
      sbx-agent-config.test.ts (which checks the rules' wording), were rerun with
      --testTimeout=60000: all 428 tests passed.
    • prettier --check passes on the changed files, and python3 scripts/check-doc-links.py reports
      0 broken links.

Out of scope

  • mocactl sbx info: most of what it would print is already available. The sandbox_info MCP
    tool and mocactl sbx get give the sandbox's template, mode and state. mocactl sbx policy gives
    each profile's egress, and mocactl sbx egress lists the hosts a sandbox reached and was refused.
    The one new fact, the host's allowlist, is not exposed by any API, and adding one is a design
    decision for the maintainers.
  • Listing the allowlist in the 403: for the same reason. The proxy could print
    MOCA_EGRESS_ALLOW, but whether a sandbox may see the operator's whole allowlist is the
    maintainers' call.
  • A per-deployment contact or URL in the page or the 403: neither the control plane nor the
    proxy has a configured user-facing URL or contact today. An optional setting for it could follow.

Every commit is signed off (DCO).

Assisted-By: Claude Code

… base URL is

A sandbox that met moca-egress's allowlist read only
"destination_denied: <host>", and the control plane's own URL answered
{"error":"not_found"}. Neither told a user or an agent that the host is
not allowlisted, that a retry will not help, or whom to ask.

- moca-egress: a destination_denied refusal keeps its status, its
  X-Moca-Egress-Error header and its first line, and adds fixed text
  after it: the host is not on this sandbox's egress allowlist,
  retrying will not help, ask the operator, and `mocactl sbx egress`
  lists the hosts a sandbox was refused. The allowlist itself is not
  echoed, and the proxy knows no user-facing URL to name. Other codes
  keep their one-line body. The conformance suite now pins the first
  line only, which every existing implementation still satisfies.
- control plane: GET / answers a short text/plain page on every profile
  (what this is, the API under /v1 and /v1/discovery, how to install
  mocactl and log in, and that the operator extends a sandbox's
  egress), with no deployment URL and nothing echoed from the request.
  OpenAPI 1.27.0.
- The sandbox rules tell the agent that a refused host stays refused:
  name it to the user, who can ask the operator to allowlist it.
- User guide §5 and the RUNBOOK say the same.

Closes rossoctl#779

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review at 2ac10b0

Adds a fixed hint to moca-egress's 403 destination_denied body (first line, status and X-Moca-Egress-Error unchanged; other codes keep one line), relaxes the conformance contract to a first-line match, adds an unauthenticated plain-text GET / page on every control-plane profile (OpenAPI 1.27.0), and tells the agent (sandboxRules) that a refused host stays refused. I verified that: only exact / matches (the regex is anchored; /index.html and POST / still return 404); the page echoes nothing of the request or the config URLs; BOTH mounts on combined via mountsOn; the install URL and both guide paths exist on main; Content-Length is computed from the longer body; and the conformance change is relax-only. One docs-accuracy suggestion: the hint is invisible to HTTPS clients, because the refusal is a CONNECT 403.

Author: webchang (MEMBER, maintainer)
Areas reviewed: Go (egress handler, conformance), TypeScript (control-plane routes/handlers, sandbox-client rules), tests, OpenAPI/CHANGELOG/change-policy, docs (user guide, RUNBOOK)
Agent/IDE config (.claude/.vscode): none
Commits: 1, all signed off: yes
CI status: all checks passing at submit time
Base: 1 commit behind main (#858, mocactl sbx only, no overlap); mergeable_state blocked (awaiting review)

Heads-up (not blocking): open #856 also bumps the control plane to 1.27.0 (CHANGELOG, openapi.yaml, change-policy). Whichever of the two merges second needs to become 1.28.0.

Drafted by an AI reviewer and approved by a human before posting.

Comment thread docs/sbx/user-guide.md
one carries the common registries (PyPI, npm, crates.io, the Go module proxy), but your operator
may have changed it. The templates carry the toolchains: `mocactl sbx templates` lists them, with
their tools, and `mocactl sbx policy` lists each profile's egress.
their tools, and `mocactl sbx policy` lists each profile's egress. A refused request's body says

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: "A refused request's body says that the host is not on the sandbox's egress allowlist" holds for a plain http:// request only. For HTTPS, the case that matters for pip, npm, cargo, go get and git clone https://, the allowlist check in handle (handler.go:215) refuses the CONNECT itself before any interception. Clients do not show a failed CONNECT's body: curl/libcurl (so git) print CONNECT tunnel failed, response 403, Python's http.client raises Tunnel connection failed: 403 Forbidden, and Go's transport returns the status text. So in the usual case neither the user nor the agent sees the new hint, only the 403 (and with curl -v, the X-Moca-Egress-Error header). The sandboxRules text is what really reaches an agent here. Please say so here (for example: "an HTTPS client typically shows only 403 / CONNECT tunnel failed; the body is visible to plain-HTTP requests and to clients that print it"), and adjust the matching sentence in the RUNBOOK (deploy/sbx/RUNBOOK.md:586) the same way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9a4d559: the user guide and the RUNBOOK now say an HTTPS request is refused at its CONNECT, so most clients show only 403 / CONNECT tunnel failed (and X-Moca-Egress-Error under curl -v), and that for HTTPS the agent gets the rule from its sandbox instructions.

Review follow-up. The allowlist check refuses an HTTPS request at its
CONNECT, and curl, git, pip and Go's transport don't show a failed
CONNECT's body, so the hint reaches plain-HTTP requests and clients that
print it; for HTTPS the agent learns the rule from sandboxRules. The
user guide and the RUNBOOK now say so.

Refs rossoctl#779

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
@webchang
webchang merged commit fcb502a into rossoctl:main Nov 17, 2026
17 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 17, 2026
Main took 1.27.0 (rossoctl#864, the base URL's page), so this PR's contract
version is 1.28.0, the next free one (it was 1.29.0 while rossoctl#874 held
1.28.0; whichever merges second renumbers). Its section goes above
1.27.0, and the change-policy list keeps both entries. rossoctl#863 made /turn a
documented alias of POST /v1/turn, response by response, so the alias
gets the new 422 too (the alias contract test caught it).

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 18, 2026
Brings 25 upstream merges since 1aa8dd6, among them the sbx OIDC
identity provider (rossoctl#851), the Redis schema-version key and config
bundle format marker (rossoctl#868), the provisioner Redis ACL user (rossoctl#869),
the relay keepalive env (rossoctl#866), the per-source OIDC pending bound with
the forwarded-headers Route pin (rossoctl#874), the egress refusal hints and
control-plane index (rossoctl#864), the empty-workspace sweep (rossoctl#872) and the
orphan-sweep log split (rossoctl#849). No conflicts.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature: Self service and docs around sbx sandbox egress

3 participants