Skip to content

feat: Add a host-egress build and keep moca's vmcontrol driver out of every other build #2085

In progress

Description

@huang195

Parent: #2042, step 1. Next: #2087 (Binding and shared mode) builds on this one.

Problem

core/listener/vmcontrol is moca's driver: moca's control protocol, the SCM_RIGHTS handover and the MOCA_* settings. Today it is compiled into every cortex binary, laptop and sidecar included. Its only build tag is unix. An environment variable (MOCA_EGRESS_CONTROL_SOCK) turns it on at run time.

A build profile cannot leave it out, because scripts/profile-tags emits only include_plugin_* tags and vmcontrol is not a plugin.

#2042 puts all moca code behind one build tag, in one build for the host-egress role. This issue does three things:

  1. It creates that tag and that build, and moves vmcontrol behind them.
  2. It makes the build start the way moca starts its egress proxy: from the environment alone, under systemd Type=notify.
  3. It runs moca's conformance suite against the build in CI, with a list of known failures that later steps make shorter.

It changes no request behavior.

Today

Read at Cortex main 7f3eec7 and moca main e464dd6 (2026-11-23).

What Where
Profiles and their members scripts/profile-tags/profiles.go: allProfiles (local, full, lite, envoy, cpex, fullcpex), membership keyed by plugin. Tags() emits include_plugin_<name> and fails on an empty profile.
Plugin discovery for the guard tests scripts/profile-tags/discover.go:14: discoverTagPattern is anchored at ^//go:build\s+include_plugin_ and scans only plugins_*.go in core/plugins/all
Guard tests scripts/profile-tags/guards_test.go: TestEveryPluginIsAccountedFor, TestNoStaleMembershipEntries, TestMembershipNamesKnownProfiles, TestEveryProfileCarriesSomething, TestCallSitesUseKnownProfiles (call-site shapes at :38-44). profiles_test.go:14: TestTags_ReproduceTodaysDefaults.
The driver files cmd/cortex/vmcontrol.go (no build tag, imports vmcontrol at :8), vmcontrol_unix.go (unix, imports it at :10), vmcontrol_other.go (!unix, imports only forwardproxy, :5-7), vmcontrol_test.go. resolveControlConfig requires MOCA_EGRESS_CONTROL_UIDS with the socket (vmcontrol.go:60-62).
What main.go calls resolveControlConfig(os.Getenv) (main.go:1103), startVMControl(ctrlCfg, fpSrv) when ctrlCfg.Socket != "" (:1226-1228), the type vmControlServer (:1102), the check at :1267-1269 (its fatalf names the moca constant envControlSock), and vmCtrl.Close() at :1371 and :1388
Stub files that already exist cmd/cortex/scripts_noplugin.go (!include_plugin_script), variant_default.go (!cpex)
A config file is required An empty -config is fatal at main.go:464-466 (--config is required). Before the load at :485, startedFromLocalInstall(*configPath) (:467) and openPluginStore(*configPath) (:472) read the path. config.Load is the only loader, and it reads a file (core/config/config.go:1318-1322). buildPipelines loads again for each build (main.go:553). reloader.New reads the file (core/reloader/reloader.go:181) but ignores a failed read. rld is used after Start (main.go:697): rld.ConfigProvider(), rld.Handler() (:1287) and rld.Close (:1396, which stops the pipelines, reloader.go:552).
Shutdown A process that is not a local install drains, with a 15 s budget (main.go:1348-1356). The runner sends SIGKILL after 5 s (moca egress/conformance/process.go:22).
Listeners of the default preset ApplyPreset binds :8081 and :8082 for the forward role (core/config/presets.go:29-34), :9094 and :9091 (:40-46), and Load defaults stats to :9093 (config.go:1335), all on every interface (listenerplan.go:36-49)
No sd_notify Nothing in core/ or cmd/ reads NOTIFY_SOCKET. Listeners are reserved at main.go:652, the control socket binds in startVMControl (:1227), and the servers serve by about :1334.
CI .github/workflows/ci.yaml: "Build + test each shipped profile" has cortex) profiles="local full lite", and its Lint step runs go vet ./... with no tags. The go-ci-profile-tags job has an "Every profile resolves" loop (ci.yaml:342). The macOS job builds local (:106-114). The Windows job builds local and full (:176, :213-222). The cortex no-tags Test step is at :492.
moca's unit deploy/microvm/moca-egress.service: Type=notify (:50), TimeoutStartSec=30s (:59). moca-egress sends READY=1 after its control socket binds (remote-worker/cmd/moca-egress/main.go:88-93). The VM worker's unit waits for it with After=.
moca's suite and runner Module github.com/rossoctl/moca/remote-worker (public repo). Its go.mod has replace github.com/rossoctl/moca/gen/go => ../gen/go, so go install <pkg>@<commit> refuses it: build it from a clone. Runner: cmd/moca-egress-conformance -bin <path> [-run <case>] [-timeout 60s]. It prints PASS <name> or FAIL <name>: <err> for each case, and exits 1 on a failure. The suite is //go:build unix and has 30 cases (egress/conformance/conformance.go:80-111).
How the runner starts the binary ProcessTarget (egress/conformance/process.go) gives the binary exactly the case's environment (no PATH, no HOME), with no arguments and no config file. The binary is ready when MOCA_EGRESS_CONTROL_SOCK accepts within 10 s. The runner stops it with SIGTERM, then SIGKILL after 5 s. A kill or a non-zero exit fails the case.

Change

  1. A second kind of build tag in scripts/profile-tags. Add type DriverName string and a drivers map[DriverName][]ProfileName next to membership, with one entry: "moca": {ProfileHostegress}. Tags() also emits include_driver_<name> for each driver that the profile carries. The driver is moca, so the tag is include_driver_moca. The output stays one sorted CSV, so every call site works unchanged.

  2. A new profile, hostegress, for the shared egress proxy on a host. It carries the moca driver and the staticinject plugin. Tags() still refuses a profile with no plugins: it counts only plugin tags, before it adds driver tags. Add a hostegress row to TestTags_ReproduceTodaysDefaults. Its helper puts include_plugin_ before each wanted name (profiles_test.go:55), so let a row list full tag strings, and skip the prefix for them.

  3. Guard tests for drivers:

    • A walker over cmd/ matches include_driver_(\w+) anywhere in a //go:build line. Driver files use compound lines such as //go:build unix && include_driver_moca. The walker also sees !include_driver_moca in the stub, which is correct. Skip .claude/worktrees with the existing skipDir.
    • Every driver tag found has an entry in drivers. No entry is stale. Every entry names known profiles.
    • No profile other than hostegress carries moca. That includes cpex and fullcpex.
  4. Move vmcontrol behind the tag in cmd/cortex:

    • vmcontrol.go → //go:build include_driver_moca
    • vmcontrol_unix.go → //go:build unix && include_driver_moca
    • vmcontrol_other.go → //go:build !unix && include_driver_moca
    • vmcontrol_test.go → //go:build include_driver_moca
  5. A stub for builds without the driver: a new cmd/cortex/vmcontrol_off.go with //go:build !include_driver_moca. It defines what main.go uses:

    • controlConfig, with only Socket string.
    • vmControlServer.
    • resolveControlConfig, which returns a zero config and reads no environment.
    • startVMControl, which is never called because Socket is empty.
    • checkVMControlStarted(cc controlConfig, srv vmControlServer), the check moved from main.go:1267-1269. The stub's version does nothing.
    • builtinConfig() ([]byte, bool) for item 6. The stub returns nil, false.

    The driver's checkVMControlStarted keeps today's check and message, so the stub names no moca setting. A build without the driver ignores MOCA_EGRESS_CONTROL_SOCK. That is safe, because moca fails closed when nothing serves its control socket: microvm-worker's start-up probe sends a Register and fails (deploy/microvm/microvm-worker.service).

  6. Start from the environment alone. In the hostegress build, when -config is empty and builtinConfig() returns true (the driver returns true when MOCA_EGRESS_CONTROL_SOCK is set):

    • Split a config.Parse(data []byte) (*Config, error) out of config.Load, with the same ${ENV} expansion. This adds exported API to core. Load calls it.

    • main.go:464-466 accepts the empty path in this case. Skip startedFromLocalInstall and openPluginStore for it, and let buildPipelines use config.Parse(builtin) on every call.

    • Keep reloader.New, because rld is used later. Skip only rld.Start (main.go:697).

    • The built-in YAML (one file, read with //go:embed) pins every address to loopback, so nothing is open on the host's network before feat: Add a connection Binding and shared mode, and key VM bindings by control connection #2087's shared mode exists:

      mode: proxy-sidecar
      listener:
        roles: [forward]
        forward_proxy_addr: 127.0.0.1:0
        transparent_proxy_addr: 127.0.0.1:0
        session_api_addr: 127.0.0.1:0
        health_addr: 127.0.0.1:0
        egress_guard: {enabled: true}
      stats: {address: 127.0.0.1:0}
      session: {enabled: false}
      pipeline: {outbound: {plugins: []}}

      Port 0 avoids clashes in parallel tests. The guard is on because moca always refuses private addresses. feat: Add a connection Binding and shared mode, and key VM bindings by control connection #2087 then sets cfg.SharedMode in code (never in this YAML) and closes the rest. feat: Resolve credentials per caller through a resolver seam, with moca's resolver in the moca driver #2088 adds static-inject. Check the exact key names against core/config while you write it.

    • Need no PATH and no HOME. Nothing on this path may fail because os.UserHomeDir fails.

    • Use a shutdown budget of 4 s on this path, so SIGTERM exits 0 before the runner's 5 s SIGKILL. Check it with a test that has an open tunnel.

    With -config set, Cortex uses the file as today.

  7. A general sd_notify: bootstrap.NotifyReady() in core/bootstrap. cmd/cortex calls it once, after the control socket is bound and every server serves (after about main.go:1334). cmd/cortex-envoy does not call it in this issue. When NOTIFY_SOCKET is set, it sends READY=1. When it is not set (launchd, containers), do nothing. Add no dependency: write the datagram with net.DialUnix("unixgram", …), and accept an abstract socket name (a leading @).

  8. CI, in ci.yaml:

  9. Docs:

    • core/listener/vmcontrol/CLAUDE.md: the channel exists only in the hostegress build.
    • cmd/README.md: the hostegress build, the shape it pins, and how it starts with no config file.
    • Root CLAUDE.md, "Plugins are all opt-in": a profile can also carry a driver tag.
    • .github/CLAUDE.md: the moca-conformance job and how to bump MOCA_COMMIT.

Not in scope

Tests

  • scripts/profile-tags: hostegress emits include_driver_moca and include_plugin_staticinject. No other profile emits include_driver_moca. Each new guard test fails when its rule is broken on purpose.
  • cmd/cortex with the hostegress tags: all existing vmcontrol tests pass unchanged.
  • cmd/cortex with the hostegress tags and no -config: build the binary in the test with the hostegress tags (as restart_test.go builds it), and run it with env -i MOCA_EGRESS_CONTROL_SOCK=… MOCA_EGRESS_CONTROL_UIDS=<uid>. It starts, the control socket accepts, no listener binds on a non-loopback address, and SIGTERM exits 0 within 5 s, also with an open tunnel.
  • core/bootstrap: sd_notify sends READY=1 to a test unixgram socket after the listeners bind. It sends nothing when NOTIFY_SOCKET is not set.
  • cmd/cortex with the local tags: it builds, go list -deps shows no core/listener/vmcontrol, and with MOCA_EGRESS_CONTROL_SOCK set it starts and serves as it does without it.
  • The moca-conformance job passes with the list from the first run, and fails when one listed case is taken off the list.

Done when

  • go -C scripts/profile-tags run . hostegress prints a CSV that contains include_driver_moca.
  • CI builds, vets and tests hostegress. It fails if local, full or lite links core/listener/vmcontrol. It runs moca's suite against hostegress with a checked-in list of known failures.
  • Request behavior is unchanged. The cmd/cortex vmcontrol tests now run only in the Linux hostegress row, not on macOS or in the no-tags Test step (ci.yaml:492), and the PR says so. core/listener/vmcontrol's own tests still run in go-ci-core.

For a human after review

  • Confirm that the moca-conformance job may fetch moca's module from GitHub in CI.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions