Skip to content

feat: ✨ Start the hostegress proxy from env - #2132

Open
evaline-ju wants to merge 1 commit into
rossoctl:mainfrom
evaline-ju:host-egress-2
Open

evaline-ju wants to merge 1 commit into
rossoctl:mainfrom
evaline-ju:host-egress-2

Conversation

@evaline-ju

@evaline-ju evaline-ju commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A MOCA host can now run Cortex as its egress proxy without a config file. Today the hostegress build exits at startup unless it's given one, so it can't stand in for moca's egress proxy. Now it starts the way moca's proxy does, from the environment alone. It runs a built-in, loopback-only config with the egress guard on. It refuses to start without the control-socket uids and an egress allowlist, so it never runs with open egress. On a stop it exits cleanly at once, as moca's proxy does.

Cortex can also run as a systemd Type=notify service. It tells systemd it's ready once it serves, so services ordered after it, such as moca's VM worker, start only when the proxy can take their connections.

Assisted-By: Claude (Anthropic AI)

Related issue(s)

Part of #2085 (part 2 after #2117)

Summary by CodeRabbit

  • New Features
    • The host-egress build can now start without a configuration file when the required egress settings are provided through the environment.
    • The proxy uses loopback listeners on automatically selected ports, and can notify systemd when it is ready.
  • Documentation
    • Added startup requirements, runtime behavior, and systemd notification guidance for the host-egress build.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The hostegress build can now start Cortex from environment settings without a configuration file. Cortex loads an embedded loopback configuration, starts its listeners, and sends systemd a readiness notification when configured.

Changes: Hostegress startup and readiness

Layer / File(s) Summary
Built-in configuration and parsing
cmd/cortex/hostegress.go, cmd/cortex/hostegress.yaml, core/config/config.go, cmd/cortex/hostegress_test.go, cmd/cortex/vmcontrol_off.go, cmd/cortex/vmcontrol_off_test.go, core/listener/vmcontrol/CLAUDE.md
The hostegress build provides an embedded configuration and validates its startup requirements. In-memory YAML parsing uses the same expansion, defaults, and validation as file loading. The non-MOCA build returns no built-in configuration.
Environment-only startup
cmd/cortex/main.go, cmd/cortex/restart_test.go, cmd/README.md
When --config is omitted, Cortex resolves and loads the built-in configuration. It skips the file reloader for built-in configurations and uses the non-draining shutdown path. The child-process test helper accepts a complete environment.
Readiness notification and runtime checks
core/bootstrap/notify.go, core/bootstrap/notify_unix_test.go, cmd/cortex/main.go, cmd/cortex/hostegress_test.go, cmd/README.md
NotifyReady sends READY=1 to NOTIFY_SOCKET when set. Cortex calls it after listener claims succeed and logs a warning if notification fails. Tests cover notification delivery and environment-only startup.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Cortex
  participant builtinConfig
  participant ConfigParser
  participant Listeners
  participant NotifyReady
  participant NOTIFY_SOCKET
  Cortex->>builtinConfig: Resolve configuration from environment
  Cortex->>ConfigParser: Parse embedded YAML
  Cortex->>Listeners: Start configured listeners
  Cortex->>NotifyReady: Notify after listener claims succeed
  NotifyReady->>NOTIFY_SOCKET: Send READY=1
Loading

Possibly related issues

Possibly related PRs

  • rossoctl/cortex#2117: It adds the hostegress build profile and Moca VM control channel that this startup path uses.

Suggested reviewers: clawgenti, huang195

Merge Risk: Minimal · up to 04f6c

The hostegress build now starts from environment settings with a loopback-only built-in configuration and signals systemd readiness. No actionable merge-blocking defect remains after review, and non-hostegress builds keep their existing behavior.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat: ✨ Start the hostegress proxy from env" matches the main change. The changeset adds a built-in, environment-driven startup path for the hostegress build, so the proxy starts without --…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat: ✨ Start the hostegress proxy from env" matches the main change. The changeset adds a built-in, environment-driven startup path for the hostegress build, so the proxy starts without --config. The title names the feature and the environment-based start. It omits the systemd readiness notification and the loopback-only defaults, which is acceptable because the title does not need every detail.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0bb82927-e238-48ee-a9ea-062764dfabd7
Commits

Reviewing files that changed from the base of the PR and between 52d81b7 and 04f6c15.

Files selected for processing: 12

  • cmd/README.md
  • cmd/cortex/hostegress.go
  • cmd/cortex/hostegress.yaml
  • cmd/cortex/hostegress_test.go
  • cmd/cortex/main.go
  • cmd/cortex/restart_test.go
  • cmd/cortex/vmcontrol_off.go
  • cmd/cortex/vmcontrol_off_test.go
  • core/bootstrap/notify.go
  • core/bootstrap/notify_unix_test.go
  • core/config/config.go
  • core/listener/vmcontrol/CLAUDE.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Signed-off-by: Evaline Ju <69598118+evaline-ju@users.noreply.github.com>
@evaline-ju evaline-ju changed the title feat: ✨ Start the hostegress proxy from env (stacked on 2117) feat: ✨ Start the hostegress proxy from env Dec 1, 2026
@evaline-ju
evaline-ju marked this pull request as ready for review December 1, 2026 19:22
@evaline-ju
evaline-ju requested a review from a team as a code owner December 1, 2026 19:22

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

The env-only start for the hostegress build works as described, and I found nothing blocking. I built the hostegress profile and ran it with env -i, so no PATH or HOME. It refuses to start without MOCA_EGRESS_ALLOW (an empty or comma-only value counts as missing), without MOCA_EGRESS_CONTROL_UIDS, or with a bare-host allow entry. With a valid environment, every listener binds a kernel-picked 127.0.0.1 port, the VM control socket is bound before READY=1, off-list destinations get 403 destination_denied, private destinations are refused by the egress guard, and SIGTERM with an idle client connection and an open control-socket connection stopped in about 70 ms with drain=false. With no MOCA_EGRESS_CONTROL_SOCK the old --config is required error is unchanged, and the non-moca builds never offer the built-in config. The Load to Parse split keeps behaviour the same: no decoder or field changes.

I left one suggestion inline: in built-in mode, the moca variables this build ignores are skipped without any log line.

Author: evaline-ju (CONTRIBUTOR association, admin repo permission — maintainer)
Areas reviewed: Go (cmd/cortex, core/bootstrap, core/config), embedded YAML config, docs (cmd/README.md, vmcontrol CLAUDE.md)
Agent/IDE config (.claude/.vscode): none (core/listener/vmcontrol/CLAUDE.md is a docs-only change; I read it and it is harmless)
Commits: 1 commit, all signed-off: yes
CI status: everything that has finished passes; several Go CI jobs, including Go CI (authbridge cortex), which runs the hostegress profile tests, were still queued when I posted. Locally, go test -tags include_driver_moca,include_plugin_staticinject ./... and the local-profile ./... in cmd/cortex pass, and so do core/bootstrap and core/config with -race.

Comment thread cmd/cortex/hostegress.go
if _, err := interfaceAddrs(); err != nil {
return nil, true, fmt.Errorf("the egress guard cannot read this host's addresses: %w", err)
}
return hostEgressConfig, true, nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: The docs say this mode reads none of the moca harness's other variables (MOCA_EGRESS_RESOLVER, MOCA_EGRESS_PERMIT_CIDRS, the timeouts). But a moca unit that sets them and swaps in this binary gets no sign that they were ignored. For example, a permitted private upstream would start returning destination_private, or the system resolver would be used in place of the configured one, and nothing in the log would say why. A single slog.Warn here naming each of those variables that is set (and ignored) would make the swap much easier to debug. It doesn't block merging.

This branch has not been deployed

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

Labels

None yet

Projects

Status: New/ToDo

Development

Successfully merging this pull request may close these issues.

2 participants