Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
- "crates/minvmd/**"
- "crates/minimald/**" # guest daemon: pid-1 in the e2e/boot VM
- "crates/minimal/**"
- "crates/minzoned/**" # the box-name service: the zoned job
- "crates/sessions/**" # platform-sensitive: canonicalization, symlinks
- "Cargo.toml"
- "Cargo.lock"
Expand Down Expand Up @@ -565,13 +566,55 @@ jobs:
if-no-files-found: error
retention-days: 3

zoned:
# The box-name service (minzoned) as a real LaunchDaemon: the
# privileged command `min` hands an operator, run for real, then the
# service proved through the system resolver, its channel, a restart
# and a clean teardown (scripts/zoned-macos-e2e.sh). It needs root,
# and the self-hosted fleet has no sudo because it runs PR code, so
# this runs on a GitHub-hosted runner: ephemeral, sudo without a
# password, no VM needed (a script stands in for the node). The
# debug `min` skips the codesign requirement check, so that part
# stays unproved here.
needs: [changes]
if: github.event_name != 'merge_group' && (github.event_name != 'pull_request' || needs.changes.outputs.macos == 'true')
runs-on: macos-latest
timeout-minutes: 30
env:
CARGO_PROFILE_DEV_DEBUG: line-tables-only
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Toolchain
uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable
with:
toolchain: stable
- name: Cache cargo registry and build artifacts
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 # zizmor: ignore[cache-poisoning] test-only lane, nothing published; save-if keeps every non-main ref read-only
with:
shared-key: mac-zoned
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Build minzoned and min
# Two invocations, as the unit job builds its testbed: one
# cargo call would unify features across both packages.
# `min` finds `minzoned` beside its own executable.
run: |
set -euo pipefail
cargo build -p minzoned --locked
cargo build -p minimal --bin min --locked
- name: Prove the service install
env:
MINIMAL_E2E_PRIVILEGED: "1"
run: scripts/zoned-macos-e2e.sh target/debug/min

# Single required status check for this lane (branch-protection context:
# ci-macos-success). Green when every gating job succeeded OR was
# path-skipped (or the RUN_MACOS_CI kill-switch skipped the e2e); red only
# on failure/cancellation.
ci-macos-success:
if: always()
needs: [changes, artifacts, e2e, unit]
needs: [changes, artifacts, e2e, unit, zoned]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand Down
9 changes: 9 additions & 0 deletions crates/minimal/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ pub enum Command {
/// on Ctrl-C, whichever comes first.
#[command(hide = true)]
Spin(SpinArgs),
/// Print the privileged command that installs this host's resolver,
/// local range and box-name service (development aid).
///
/// The command a session start's advisory prints, rendered without a
/// daemon, so the service install can be tested on a host that cannot
/// boot a VM. Debug builds only.
#[cfg(debug_assertions)]
#[command(name = "debug-answerer-command", hide = true)]
DebugAnswererCommand,
/// Print session-identifier completion candidates (used by the shell).
///
/// The completion path a shell actually takes runs in-process (see
Expand Down
8 changes: 8 additions & 0 deletions crates/minimal/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ pub(crate) async fn run_command(cli: Cli) -> Result<(), anyhow::Error> {
// logging may need stdout too.
Some(Command::Version) => cmd_version(&cli.global_args, &mut std::io::stdout()).await,
Some(Command::Spin(args)) => cmd_spin(&cli.global_args, args).await,
#[cfg(debug_assertions)]
Some(Command::DebugAnswererCommand) => {
println!(
"{}",
crate::resolver::answerer_command_for_this_host().await?
);
Ok(())
}
Some(Command::Init(args)) => cmd_init(&cli.global_args, args)
.await
.map_err(|e| anyhow::anyhow!("{e}")),
Expand Down
22 changes: 22 additions & 0 deletions crates/minimal/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,28 @@ pub(crate) fn command(port: u16, install: Option<&AnswererInstall>) -> String {
linux_command(port, install)
}

/// The command [`command`] renders for this host with the answerer step
/// carried, from the same reads a session start's advisory makes — so a
/// test can run the exact privileged command without starting a daemon.
/// An error when the step cannot be carried (no `minzoned` beside this
/// `min` or on `PATH`, or a path the command cannot quote): a test must
/// not pass on a command without the service in it. Debug builds only,
/// where the identity check offers every source (see
/// [`answerer_source_identity`]).
#[cfg(debug_assertions)]
pub(crate) async fn answerer_command_for_this_host() -> anyhow::Result<String> {
let step = read_answerer_step().await;
let install = match &step {
AnswererStep::SourceVerified { source, .. } => answerer_install(source),
_ => None,
}
.ok_or_else(|| anyhow::anyhow!("the answerer service step cannot be carried: {step:?}"))?;
Ok(command(
minvmd::net::answerer::DEFAULT_ANSWERER_PORT,
Some(&install),
))
}

/// The answerer service's own state as an advisory fact, beside the
/// range's. Every state but the first two is a fact the user has no other
/// way to see; `carried` is whether the command below carries the service
Expand Down
108 changes: 108 additions & 0 deletions scripts/zoned-e2e-publisher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env python3
"""A stand-in node for scripts/zoned-macos-e2e.sh: publishes one box row
into the installed minzoned service over its channel, the way a VM host
daemon does, without a VM.

The channel is newline-delimited JSON over a unix stream
(crates/minvmd/src/net/answerer.rs): a hello, then an address allocation for
the box, then a publish of the box's row. The service holds the row only
while the connection stays open, so `hold` keeps it open, and reconnects and
re-publishes when the service restarts, as a node does.

zoned-e2e-publisher.py once CHANNEL NODE BOX VERSION
Connect, hello, allocate, publish, print the reply lines, exit.
Exits non-zero if any reply is not ok.
zoned-e2e-publisher.py hold CHANNEL NODE BOX VERSION ADDRESS_FILE
Publish, write the allocated address to ADDRESS_FILE, and hold the
connection until SIGTERM; reconnect and re-publish when it drops.

Stdlib only.
"""

import json
import os
import signal
import socket
import sys
import time


def request(stream, sock, message):
sock.sendall((json.dumps(message) + "\n").encode())
line = stream.readline()
if not line:
raise ConnectionError("the channel closed before replying")
reply = json.loads(line)
print(json.dumps({"sent": message, "reply": reply}), flush=True)
return reply


def publish(channel, node, box, version):
"""Connect and publish the box's row. Returns (socket, address), or
raises with the refusal the service gave."""
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(channel)
stream = sock.makefile("r")
hello = request(stream, sock, {"node": node, "version": version})
if not hello.get("ok"):
raise PermissionError(hello.get("error", "hello refused"))
allocated = request(stream, sock, {"allocate": box})
if not allocated.get("ok") or not allocated.get("address"):
raise RuntimeError(f"allocation refused: {allocated}")
address = allocated["address"]
row = {"name": f"{box}.min.internal", "address": address, "live": True}
published = request(stream, sock, {"rows": [row]})
if not published.get("ok") or published.get("refused"):
raise RuntimeError(f"publish refused: {published}")
return sock, address


def hold(channel, node, box, version, address_file):
stopping = []
signal.signal(signal.SIGTERM, lambda *_: stopping.append(True))
while not stopping:
try:
sock, address = publish(channel, node, box, version)
except (OSError, ConnectionError, RuntimeError) as error:
print(f"publish failed, retrying: {error}", flush=True)
time.sleep(0.25)
continue
tmp = address_file + ".tmp"
with open(tmp, "w") as f:
f.write(address + "\n")
os.replace(tmp, address_file)
# Block until the service drops the connection (a restart) or
# SIGTERM arrives; the timeout lets the loop see the signal.
sock.settimeout(0.25)
while not stopping:
try:
if not sock.recv(1):
print("the channel closed; reconnecting", flush=True)
break
except socket.timeout:
continue
except OSError:
break
sock.close()


def main(argv):
if len(argv) >= 5 and argv[0] == "once":
_, channel, node, box, version = argv[:5]
try:
sock, _ = publish(channel, node, box, int(version))
except (OSError, ConnectionError, PermissionError, RuntimeError) as error:
print(f"refused: {error}", flush=True)
return 1
sock.close()
return 0
if len(argv) >= 6 and argv[0] == "hold":
_, channel, node, box, version, address_file = argv[:6]
hold(channel, node, box, int(version), address_file)
return 0
print(__doc__, file=sys.stderr)
return 2


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
Loading
Loading