Skip to content

feat(remote-worker/egress): allow-everything mode for MOCA_EGRESS_ALLOW=* - #886

Merged
pdettori merged 2 commits into
mainfrom
feat/egress-allow-all
Nov 18, 2026
Merged

pdettori merged 2 commits into
mainfrom
feat/egress-allow-all

Conversation

@galmasi

@galmasi galmasi commented Nov 18, 2026

Copy link
Copy Markdown

What

A bare MOCA_EGRESS_ALLOW=* (nothing else on the line) is an explicit operator opt-in that removes every destination restriction from the egress proxy: the hostname allowlist and the private/loopback-address refusal are both skipped. For trusted research rigs whose sandboxes are deliberately unconstrained; the default allowlist behavior is unchanged.

Guardrails

  • Recognition happens in ConfigFromEnv before ParseAllow, which still refuses * as an ordinary list entry — *,example.com and a separator-only list remain errors, so the wildcard cannot smuggle itself into an ordinary allowlist
  • NewProxy accepts an empty Allow only when AllowAll is set; a normal allowlist Proxy is unchanged
  • The handler skips the allowlist check and the address refusal only when AllowAll is set
  • deploy/sbx/egress-allow.env documents the mode where the seed allowlist lives

Tests

Unit tests on both paths (config_test: the bare * accepted, mixed lists still refused; proxy_test: allow-all proxies to a private address that an allowlist proxy refuses). go test ./internal/egress/ green.

Deployed and running on two rigs (both tiers, P6 harness and SBX0) with MOCA_EGRESS_ALLOW=*.

Assisted-By: Claude Code

…OW=*

A bare MOCA_EGRESS_ALLOW=* (nothing else on the line) is an explicit
operator opt-in that removes every destination restriction: the hostname
allowlist and the private/loopback-address refusal (CheckAddr) are both
skipped, so a sandbox may reach any destination. For trusted research
rigs whose sandboxes are deliberately unconstrained.

Recognition happens in ConfigFromEnv before ParseAllow, which keeps
refusing "*" as an ordinary list entry -- "*,example.com" and a list
that is only separators remain errors, so the wildcard cannot smuggle
itself into an ordinary allowlist. NewProxy accepts an empty Allow only
when AllowAll is set (an allowlist Proxy is unchanged), and the handler
skips the address refusal only in allow-all mode.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 18, 2026

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Summary

This adds a narrowly recognised MOCA_EGRESS_ALLOW=* sentinel. The parsing guardrails hold: mixed lists, padded values and separator-only lists are still refused, and the default allowlist path is unchanged. The blocker is that allow-all also turns off the always-on refusal of link-local and cloud metadata addresses, which the egress design treats as fixed regardless of what the operator permits. Keeping that tier is a small change and costs nothing for a research rig.

Author: galmasi (MEMBER, maintainer)
Areas reviewed: Go (egress config/handler/proxy + tests), deploy docs/env
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed off: yes
CI status: all checks passing. Locally, go test ./internal/egress/... ./cmd/moca-egress/... passes at the PR head.

}
// Allow-everything mode skips every address refusal, private and local
// included (Config.AllowAll).
if pc.p.cfg.AllowAll {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

must-fix: This early return skips all of CheckAddr, not just the private/loopback refusal. addr.go says link-local (which includes 169.254.169.254), unspecified, multicast, broadcast and the cloud metadata endpoints (AWS IMDSv6 fd00:ec2::254, Azure WireServer, Alibaba) are "always refused, whatever the permit list". The cloudMetadata comment adds that permitting a range "must not thereby open the instance's credentials". With *, a sandbox on an AWS/Azure rig can fetch the host's instance-role credentials. Agent code runs on untrusted content (prompt injection), so "trusted rig" doesn't cover that.

Proposed fix: in allow-all mode, keep calling CheckAddr with an all-covering permit list and no local:

var allPrefixes = []netip.Prefix{netip.MustParsePrefix("0.0.0.0/0"), netip.MustParsePrefix("::/0")}

permit, local := pc.p.cfg.PermitCIDRs, ...
if pc.p.cfg.AllowAll {
	permit, local = allPrefixes, nil
}

Loopback, private, CGNAT, special-purpose and host-local addresses then pass, and only the always-refused tier stays refused. I checked locally against CheckAddr at this head: 127.0.0.1, 10.0.0.5, ::1, 100.64.1.1 and a local address pass; 169.254.169.254, fd00:ec2::254, 168.63.129.16, 0.0.0.0 and 224.0.0.1 are still refused. The doc on Config.AllowAll (proxy.go:25) and in egress-allow.env would need the same wording change.

func TestAllowAllTunnelsOffAllowlistAndPrivate(t *testing.T) {
up := newTCPUpstream(t, echo)
h := newHarness(t, "up.test:443", func(c *Config) {
c.AllowAll = true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion: (a) After the handler.go fix, add a check that allow-all still refuses 169.254.169.254 / fd00:ec2::254 with destination_private. (b) The harness still passes the up.test:443 allowlist, so the NewProxy change (empty Allow accepted only with AllowAll) has no test. Setting c.Allow = nil here, plus one NewProxy(Config{AllowAll: false}) empty-allowlist case, would cover both branches.

// and a list that is only separators remain errors.
var err error
if allowRaw == "*" {
cfg.AllowAll = true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion: cmd/moca-egress/main.go:80 logs serving %d allowlist entries, which reads serving 0 allowlist entries in this mode. For a mode that turns off the allowlist, the startup line should say so plainly (e.g. moca-egress: allow-all mode: every destination permitted (MOCA_EGRESS_ALLOW=*)), so an operator reading the journal can't miss it.

# install-host.sh; it overrides this file for that run's seed only.
# Editing this file does not reach hosts that are already seeded (the seed is written only
# when absent); copy it to each host as above.
# A bare MOCA_EGRESS_ALLOW=* (nothing else on the line) is allow-everything mode: the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: The mode is only documented in this seed file. deploy/sbx/RUNBOOK.md (the allowlist bullet, ~L592) and deploy/microvm/P4-ON-P6.md (Guest egress → Allowlist, ~L709) describe MOCA_EGRESS_ALLOW but don't mention *. The PR says it is deployed on the P6 tier too, which the microVM doc covers.

… tier

Review #886 must-fix: the early return skipped all of CheckAddr, not
just the private/loopback refusal. Link-local (169.254.169.254
included), unspecified, multicast, broadcast and the cloud metadata
endpoints (AWS IMDSv6 fd00:ec2::254, Azure WireServer, Alibaba) are
always refused, whatever the permit list, and the cloudMetadata comment
is explicit that permitting a range must not thereby open the
instance's credentials. Agent code runs on untrusted content, so
'trusted rig' does not cover that.

In allow-all mode, resolveAndCheck now calls CheckAddr with an
all-covering permit list (0.0.0.0/0 and ::/0) and no local addresses:
the always-refused tier still runs, everything else is permitted.

Also from the review: tests that allow-all still refuses the cloud
metadata endpoints and link-local with destination_private, and that
NewProxy accepts an empty Allow only with AllowAll; the proxy's startup
log says 'allow-all mode' plainly instead of 'serving 0 allowlist
entries'; and the mode is documented beside MOCA_EGRESS_ALLOW in the
RUNBOOK and P4-ON-P6.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: George Almasi <[email protected]>
@galmasi

galmasi commented Nov 18, 2026

Copy link
Copy Markdown
Author

All review points addressed in 002d60f:

  • must-fix (always-refused tier skipped): resolveAndCheck in allow-all mode now calls CheckAddr with an all-covering permit list (0.0.0.0/0, ::/0) and no local addresses — the always-refused tier (link-local, unspecified, multicast, broadcast, cloud metadata endpoints) still runs, everything else is permitted. You were right that "trusted rig" doesn't cover instance credentials; it doesn't anymore.
  • suggestion (a): TestAllowAllStillRefusesCloudMetadata asserts 169.254.169.254, fd00:ec2::254 and link-local still refuse with destination_private in allow-all mode.
  • suggestion (b): TestNewProxyEmptyAllowOnlyWithAllowAll covers both NewProxy branches (empty Allow accepted with AllowAll, refused without).
  • suggestion (c): the startup log now says allow-all mode: every destination permitted (MOCA_EGRESS_ALLOW=*) instead of serving 0 allowlist entries.
  • nit (docs): the mode is documented beside MOCA_EGRESS_ALLOW in deploy/sbx/RUNBOOK.md and deploy/microvm/P4-ON-P6.md, both naming what the always-refused tier still protects.

go test ./internal/egress/ green.

Assisted-By: Claude Code

@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.

Summary

The previous must-fix is fixed and verified. In allow-all mode resolveAndCheck now calls CheckAddr with an all-covering permit list (0.0.0.0/0, ::/0) and no local addresses, so link-local, the cloud metadata endpoints, unspecified, multicast and broadcast are still refused while private/loopback pass; handle skips only the allowlist check (handler.go:224,282). Tests cover both the private-address tunnel and the metadata refusal, and NewProxy rejects an empty allowlist unless AllowAll is set. check (Go tests) is green at this head.

Remaining non-blocking items are wording: three comments still describe the pre-fix behavior (proxy.go:26, config.go:69, egress-allow.env:18) and understate the always-refused tier. Two required checks (deploy-scripts-bash32, k8s-kind-e2e) were still queued when this review was written.

Author: galmasi (MEMBER — maintainer)
Areas reviewed: Go (egress config/handler/proxy + tests), deploy docs/env
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: green so far (check, lint, proto, microvm-gates, deploy-scripts pass); deploy-scripts-bash32 and k8s-kind-e2e pending

Allow []AllowEntry
Allow []AllowEntry
// AllowAll removes every destination restriction: the hostname allowlist
// and the private/loopback-address refusal (CheckAddr) are both skipped.

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: This is now stale after the handler fix: CheckAddr is not skipped in allow-all mode -- it runs with an all-covering permit list and no local addresses (handler.go:282). config.go:69 ("every destination restriction is off") and deploy/sbx/egress-allow.env:18 say the same thing. Consider matching the P4-ON-P6/RUNBOOK wording: every destination is permitted except the always-refused tier (cloud metadata endpoints, link-local, multicast).

# Editing this file does not reach hosts that are already seeded (the seed is written only
# when absent); copy it to each host as above.
# A bare MOCA_EGRESS_ALLOW=* (nothing else on the line) is allow-everything mode: the
# allowlist and the private-address refusal are both off. For trusted research rigs only.

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: As with the Config.AllowAll comment: the always-refused tier (cloud metadata, link-local, unspecified/broadcast, multicast) still applies, so "the private-address refusal is off" understates what is kept. The RUNBOOK / P4-ON-P6 wording is accurate; mirror it here.

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@pdettori
pdettori merged commit 1ab9b28 into main Nov 18, 2026
23 of 24 checks passed
@pdettori
pdettori deleted the feat/egress-allow-all branch November 18, 2026 19:53
webchang added a commit to webchang/moca that referenced this pull request Nov 19, 2026
Brings 15 upstream merges since 2eb0219, among them the R2 host sampler
in its reviewed form (rossoctl#904), the workspace-reset marker (rossoctl#895), turn
budgets and cancel (rossoctl#856), the egress allow-all option (rossoctl#886), the sbx
installer token (rossoctl#888), and the docs site with the product-name prose
(rossoctl#884, rossoctl#885, rossoctl#899).

One conflict, deploy/sbx/template-onboarding/README.md: upstream's
product-name wording for the deploy/sbx table, keeping the fork's
mint-login.sh row.

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.

3 participants