Repository navigation
Description
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:
- It creates that tag and that build, and moves
vmcontrolbehind them. - It makes the build start the way moca starts its egress proxy: from the environment alone, under systemd
Type=notify. - 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
-
A second kind of build tag in
scripts/profile-tags. Addtype DriverName stringand adrivers map[DriverName][]ProfileNamenext tomembership, with one entry:"moca": {ProfileHostegress}.Tags()also emitsinclude_driver_<name>for each driver that the profile carries. The driver ismoca, so the tag isinclude_driver_moca. The output stays one sorted CSV, so every call site works unchanged. -
A new profile,
hostegress, for the shared egress proxy on a host. It carries themocadriver and thestaticinjectplugin.Tags()still refuses a profile with no plugins: it counts only plugin tags, before it adds driver tags. Add ahostegressrow toTestTags_ReproduceTodaysDefaults. Its helper putsinclude_plugin_before each wanted name (profiles_test.go:55), so let a row list full tag strings, and skip the prefix for them. -
Guard tests for drivers:
- A walker over
cmd/matchesinclude_driver_(\w+)anywhere in a//go:buildline. Driver files use compound lines such as//go:build unix && include_driver_moca. The walker also sees!include_driver_mocain the stub, which is correct. Skip.claude/worktreeswith the existingskipDir. - Every driver tag found has an entry in
drivers. No entry is stale. Every entry names known profiles. - No profile other than
hostegresscarriesmoca. That includescpexandfullcpex.
- A walker over
-
Move
vmcontrolbehind the tag incmd/cortex:vmcontrol.go→//go:build include_driver_mocavmcontrol_unix.go→//go:build unix && include_driver_mocavmcontrol_other.go→//go:build !unix && include_driver_mocavmcontrol_test.go→//go:build include_driver_moca
-
A stub for builds without the driver: a new
cmd/cortex/vmcontrol_off.gowith//go:build !include_driver_moca. It defines whatmain.gouses:controlConfig, with onlySocket string.vmControlServer.resolveControlConfig, which returns a zero config and reads no environment.startVMControl, which is never called becauseSocketis empty.checkVMControlStarted(cc controlConfig, srv vmControlServer), the check moved frommain.go:1267-1269. The stub's version does nothing.builtinConfig() ([]byte, bool)for item 6. The stub returnsnil, false.
The driver's
checkVMControlStartedkeeps today's check and message, so the stub names no moca setting. A build without the driver ignoresMOCA_EGRESS_CONTROL_SOCK. That is safe, because moca fails closed when nothing serves its control socket:microvm-worker's start-up probe sends aRegisterand fails (deploy/microvm/microvm-worker.service). -
Start from the environment alone. In the
hostegressbuild, when-configis empty andbuiltinConfig()returns true (the driver returns true whenMOCA_EGRESS_CONTROL_SOCKis set):-
Split a
config.Parse(data []byte) (*Config, error)out ofconfig.Load, with the same${ENV}expansion. This adds exported API tocore.Loadcalls it. -
main.go:464-466accepts the empty path in this case. SkipstartedFromLocalInstallandopenPluginStorefor it, and letbuildPipelinesuseconfig.Parse(builtin)on every call. -
Keep
reloader.New, becauserldis used later. Skip onlyrld.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
0avoids 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 setscfg.SharedModein 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 addsstatic-inject. Check the exact key names againstcore/configwhile you write it. -
Need no
PATHand noHOME. Nothing on this path may fail becauseos.UserHomeDirfails. -
Use a shutdown budget of 4 s on this path, so
SIGTERMexits 0 before the runner's 5 sSIGKILL. Check it with a test that has an open tunnel.
With
-configset, Cortex uses the file as today. -
-
A general
sd_notify:bootstrap.NotifyReady()incore/bootstrap.cmd/cortexcalls it once, after the control socket is bound and every server serves (after aboutmain.go:1334).cmd/cortex-envoydoes not call it in this issue. WhenNOTIFY_SOCKETis set, it sendsREADY=1. When it is not set (launchd, containers), do nothing. Add no dependency: write the datagram withnet.DialUnix("unixgram", …), and accept an abstract socket name (a leading@). -
CI, in
ci.yaml:- In "Build + test each shipped profile": add
hostegressto thecortexlist, and rungo vet -tags "${TAGS}" ./...inside the loop. Forlocal,fullandlite, fail when the binary links the driver. Do not pipego listintogrep -q: underbash -eo pipefailthe pipe fails onSIGPIPE. Usedeps=$(go list -deps -tags "$TAGS" .); if grep -q core/listener/vmcontrol <<<"$deps"; then exit 1; fi. - Add
hostegressto the "Every profile resolves" loop (ci.yaml:342).TestCallSitesUseKnownProfilesdoes not see that loop, so a missing entry would stay silent. - A new job,
moca-conformance(Linux only):- Build
cmd/cortexwith thehostegresstags. - Clone
https://github.com/rossoctl/mocaat the commit inscripts/moca-conformance/MOCA_COMMIT(a full SHA. A bump is a PR), and rungo build ./cmd/moca-egress-conformancein itsremote-worker/directory.go install …@<commit>does not work, because of thereplacedirective. - Run the runner with
-bin. Parse^FAIL ([a-z0-9_]+):from its output, and compare those names withscripts/moca-conformance/known-failures.txt: one case name per line,#starts a comment, and each line's comment names the step that fixes it. Exit code 2 from the runner ("no case named") fails the job. - Fail when a case fails that is not on the list, and when a listed case passes. So the list can only get shorter.
- Build
- Fill the list from the first run. Expect most of the 30 cases on it. Every case sets
MOCA_EGRESS_RESOLVERto a fake DNS server and dials the nameup.test(mocaconformance.go:210-215, 764), and Cortex reads that setting only after feat: Answer egress refusals in Cortex's own shape and move moca's format and MOCA_EGRESS_ALLOW into the moca driver #2086. Thedestination_privateshape is feat: Answer egress refusals in Cortex's own shape and move moca's format and MOCA_EGRESS_ALLOW into the moca driver #2086, the credential cases are feat: Resolve credentials per caller through a resolver seam, with moca's resolver in the moca driver #2088, and the audit cases are feat: Write one complete, asynchronous audit event per request through Binding.Record #2089.
- In "Build + test each shipped profile": add
-
Docs:
core/listener/vmcontrol/CLAUDE.md: the channel exists only in thehostegressbuild.cmd/README.md: thehostegressbuild, 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: themoca-conformancejob and how to bumpMOCA_COMMIT.
Not in scope
- An image or a release binary for
hostegress(design: A general multi-tenant egress core in Cortex, with moca's code behind one build tag #2042 step 9). - The refusal format and
MOCA_EGRESS_ALLOW(feat: Answer egress refusals in Cortex's own shape and move moca's format and MOCA_EGRESS_ALLOW into the moca driver #2086). - Changes inside
core/listener/vmcontrol. No other binary links it, so it stays incore/.
Tests
scripts/profile-tags:hostegressemitsinclude_driver_mocaandinclude_plugin_staticinject. No other profile emitsinclude_driver_moca. Each new guard test fails when its rule is broken on purpose.cmd/cortexwith thehostegresstags: all existingvmcontroltests pass unchanged.cmd/cortexwith thehostegresstags and no-config: build the binary in the test with thehostegresstags (asrestart_test.gobuilds it), and run it withenv -i MOCA_EGRESS_CONTROL_SOCK=… MOCA_EGRESS_CONTROL_UIDS=<uid>. It starts, the control socket accepts, no listener binds on a non-loopback address, andSIGTERMexits 0 within 5 s, also with an open tunnel.core/bootstrap:sd_notifysendsREADY=1to a testunixgramsocket after the listeners bind. It sends nothing whenNOTIFY_SOCKETis not set.cmd/cortexwith thelocaltags: it builds,go list -depsshows nocore/listener/vmcontrol, and withMOCA_EGRESS_CONTROL_SOCKset it starts and serves as it does without it.- The
moca-conformancejob 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 . hostegressprints a CSV that containsinclude_driver_moca.- CI builds, vets and tests
hostegress. It fails iflocal,fullorlitelinkscore/listener/vmcontrol. It runs moca's suite againsthostegresswith a checked-in list of known failures. - Request behavior is unchanged. The
cmd/cortexvmcontroltests now run only in the Linuxhostegressrow, 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-conformancejob may fetch moca's module from GitHub in CI.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn progress
Activity