diff --git a/crates/minvmd/src/net.rs b/crates/minvmd/src/net.rs index 2483168004..d5311b63d7 100644 --- a/crates/minvmd/src/net.rs +++ b/crates/minvmd/src/net.rs @@ -795,8 +795,12 @@ impl HostGvproxy { // In force, the gate decides a frame from the daemon's own address // by it, beside the boxes' rows; announced — the shipped posture — // the allow-all interim node row still does, and the gate's - // start-up line names the posture deciding. - let baseline = NodePlaneBaseline::built_in(subnet); + // start-up line names the posture deciding. The host exposures the + // alias is opened at for the node row — none unless the deployment + // names ports — are read from the daemon's environment here, on each + // spawn, an unparseable list failing it. + let baseline = NodePlaneBaseline::built_in(subnet) + .with_host_exposure(baseline::host_exposure_ports_from_env()?); let (stop_tx, stop_rx) = tokio::sync::oneshot::channel::<()>(); let (ready_tx, ready_rx) = std::sync::mpsc::channel::>(); diff --git a/crates/minvmd/src/net/baseline.rs b/crates/minvmd/src/net/baseline.rs index 508dc5d1dd..aa60e97387 100644 --- a/crates/minvmd/src/net/baseline.rs +++ b/crates/minvmd/src/net/baseline.rs @@ -33,6 +33,7 @@ //! enumeration by saying it. use boxes::core::egress::{EgressRules, IPPROTO_TCP, Ipv4Cidr}; +use std::io; use switch::SwitchSubnet; /// A category of the node-plane baseline enumeration: one of the design's @@ -154,6 +155,76 @@ impl NodeBaselinePhase { /// listener that feeds [`REGISTRY_CACHE_FETCH_PORTS`]. pub(crate) const NODE_BASELINE_PHASE: NodeBaselinePhase = NodeBaselinePhase::Announced; +/// The environment variable the daemon's host-exposure port list is read +/// from, each time the daemon starts the VM's network — from the daemon's +/// own environment, so a change takes a daemon restart, the same shape the +/// hostname proxy port and the egress-default opt-out carry. +pub(crate) const HOST_EXPOSURE_PORTS_ENV: &str = "MINVMD_HOST_EXPOSURE_PORTS"; + +/// The host-exposure port list the daemon starts with, as the deployment +/// spelled it. The design holds the alias default-deny except explicitly +/// configured host exposures (design §7.1), so absent or empty, the list is +/// empty and the alias is refused at every port for every row. The list is +/// comma-separated, each term a port (`4200`) or an inclusive range +/// (`3000-3999`), port 0 excluded; a term that is neither, a reversed range, +/// or a value that is not Unicode fails the start, the error naming the term +/// and the fix. +pub(crate) fn host_exposure_ports_from_env() -> io::Result> { + match std::env::var(HOST_EXPOSURE_PORTS_ENV) { + Ok(raw) => host_exposure_ports_from_raw(Some(&raw)), + Err(std::env::VarError::NotPresent) => host_exposure_ports_from_raw(None), + Err(std::env::VarError::NotUnicode(_)) => Err(io::Error::other(format!( + "{HOST_EXPOSURE_PORTS_ENV} is not valid Unicode. {HOST_EXPOSURE_FIX}" + ))), + } +} + +/// The correction every parse error ends with. +const HOST_EXPOSURE_FIX: &str = "Set it to ports and ranges such as 8080,3000-3999, \ + or set it empty to close host.min.internal."; + +/// Parses one deployment's spelling of the host-exposure port list: every +/// term a port or an inclusive range from 1 to 65535, whitespace trimmed; +/// absent or empty, no exposure at all. +fn host_exposure_ports_from_raw(raw: Option<&str>) -> io::Result> { + let Some(raw) = raw else { + return Ok(Vec::new()); + }; + let port = |text: &str, term: &str| match text.trim().parse::() { + Ok(0) | Err(_) => Err(bad_host_exposure_term(term)), + Ok(port) => Ok(port), + }; + raw.split(',') + .filter(|term| !term.trim().is_empty()) + .map(|term| { + let term = term.trim(); + match term.split_once('-') { + Some((lo, hi)) => { + let (lo, hi) = (port(lo, term)?, port(hi, term)?); + if lo <= hi { + Ok((lo, hi)) + } else { + Err(io::Error::other(format!( + "{HOST_EXPOSURE_PORTS_ENV}: `{term}` is a reversed range; write it \ + low-high, as `{hi}-{lo}`. {HOST_EXPOSURE_FIX}" + ))) + } + } + None => port(term, term).map(|port| (port, port)), + } + }) + .collect() +} + +/// The start-failing error for one unparseable term: the variable, the term +/// as it was read, and the correction. +fn bad_host_exposure_term(term: &str) -> io::Error { + io::Error::other(format!( + "{HOST_EXPOSURE_PORTS_ENV}: `{term}` is not a port from 1 to 65535 or a low-high port \ + range. {HOST_EXPOSURE_FIX}" + )) +} + /// The IP protocol the in-force arm opens on the switch's host alias: TCP /// alone, because the store surface the built-in endpoints name is HTTPS. /// QUIC is not admitted; carrying it would be a stated choice that adds UDP @@ -202,6 +273,14 @@ pub struct NodePlaneBaseline { /// The posture the gate decides the set under: the shipped constant, /// until the store-surface configuration flips it. phase: NodeBaselinePhase, + /// The configured host exposures over the alias, as inclusive port + /// ranges: the ports the node row still reaches the host alias at while + /// the baseline is announced, every other port refused through the + /// alias. Empty unless the deployment names ports. The host-side gate + /// alone reads it: the guest-side verdict's own alias list starts empty + /// and nothing in the run path fills it, so own-address boxes stay + /// refused at every port. + host_exposure: Vec<(u16, u16)>, } impl NodePlaneBaseline { @@ -282,6 +361,46 @@ impl NodePlaneBaseline { self.phase } + /// The host exposures over the alias this gate carries: the inclusive + /// port ranges the announced node row still reaches the host alias at, + /// empty unless the deployment configured ports. + #[must_use] + pub(crate) fn host_exposure_ports(&self) -> &[(u16, u16)] { + &self.host_exposure + } + + /// Points the host exposures at `ports`, replacing the current list: a + /// host names or clears its own exposure surface, and a cleared list is an + /// alias with no opening — refused at every port for every row — not + /// an absent arm. The compiled set is untouched: the list scopes the + /// alias alone. + #[must_use] + pub fn with_host_exposure(mut self, ports: Vec<(u16, u16)>) -> Self { + self.host_exposure = ports; + self + } + + /// The host-exposure list as the daemon's start-up line spells it: one + /// `lo-hi` term per range, a bare port for a single-port term, and + /// `(none)` when the deployment cleared the list. + #[must_use] + pub(crate) fn render_host_exposure(&self) -> String { + if self.host_exposure.is_empty() { + return "(none)".to_string(); + } + self.host_exposure + .iter() + .map(|&(lo, hi)| { + if lo == hi { + lo.to_string() + } else { + format!("{lo}-{hi}") + } + }) + .collect::>() + .join(",") + } + /// One entry's endpoints as the policy display spells them (NET-061): an /// endpoint naming the host alias carries the in-force arm's bound /// beside it (`100.64.255.254/32 tcp/443`), because the set has no port @@ -371,7 +490,9 @@ impl NodePlaneBaseline { } /// Assembles the set from its parts: the categories carried, and the - /// addresses the compiled rules are keyed to. + /// addresses the compiled rules are keyed to. The host exposures start + /// empty, the alias closed; the deployment's spelling replaces them in + /// the run path's builder. fn from_entries( node_addr: [u8; 4], resolver: [u8; 4], @@ -385,6 +506,7 @@ impl NodePlaneBaseline { rules: Self::compile_rules(&entries, resolver, node_addr), entries, phase: NODE_BASELINE_PHASE, + host_exposure: Vec::new(), } } @@ -407,7 +529,10 @@ impl NodePlaneBaseline { #[cfg(test)] mod tests { - use super::{BaselineCategory, BaselineEntry, NodePlaneBaseline}; + use super::{ + BaselineCategory, BaselineEntry, HOST_EXPOSURE_PORTS_ENV, NodePlaneBaseline, + host_exposure_ports_from_raw, + }; use boxes::core::egress::{FrameVerdict, summarize, verdict}; use std::net::Ipv4Addr; use std::str::FromStr; @@ -587,6 +712,83 @@ mod tests { } } + /// The deployment's spelling of the host-exposure list: absent or + /// empty, no exposure — the alias closed; every term a port or an + /// inclusive range from 1 to 65535; an undecodable term, port 0, or a + /// reversed range a surfaced error naming the variable, the term and + /// the fix. + #[test] + fn host_exposure_ports_read_from_the_environment() { + assert!( + host_exposure_ports_from_raw(None).unwrap().is_empty(), + "an unset variable is no exposure: the alias stays closed" + ); + assert_eq!( + host_exposure_ports_from_raw(Some("8080")).unwrap(), + vec![(8080, 8080)], + "a bare port is a single-port range" + ); + assert_eq!( + host_exposure_ports_from_raw(Some(" 3000-3999, 4200 ")).unwrap(), + vec![(3000, 3999), (4200, 4200)], + "terms are inclusive ranges and ports, whitespace trimmed" + ); + assert!( + host_exposure_ports_from_raw(Some("")).unwrap().is_empty(), + "a set-but-empty list is no exposure" + ); + let garbage = host_exposure_ports_from_raw(Some("8080:nope")) + .expect_err("an undecodable term is a surfaced error") + .to_string(); + assert!( + garbage.contains(HOST_EXPOSURE_PORTS_ENV) + && garbage.contains("`8080:nope` is not a port") + && garbage.contains("set it empty to close host.min.internal"), + "an undecodable term names the variable, the term and the fix, got: {garbage}" + ); + for zero in ["0", "0-65535"] { + let error = host_exposure_ports_from_raw(Some(zero)) + .expect_err("port 0 is refused") + .to_string(); + assert!( + error.contains(&format!("`{zero}` is not a port")), + "port 0 names the term, got: {error}" + ); + } + let reversed = host_exposure_ports_from_raw(Some("4000-3000")) + .expect_err("a reversed range is not an inclusive one") + .to_string(); + assert!( + reversed.contains("`4000-3000` is a reversed range") + && reversed.contains("`3000-4000`") + && !reversed.contains("is not a port"), + "a reversed range gets its own message, got: {reversed}" + ); + } + + /// The baseline carries no exposure until the deployment's spelling + /// replaces the list: the builder replaces rather than merges, and a + /// cleared list reaches the accessor empty. + #[test] + fn baseline_carries_the_configured_host_exposures() { + let built_in = NodePlaneBaseline::built_in(SUBNET); + assert!( + built_in.host_exposure_ports().is_empty(), + "the built-in enumeration carries no host exposure" + ); + let re_exposed = built_in.with_host_exposure(vec![(8080, 8080)]); + assert_eq!( + re_exposed.host_exposure_ports(), + &[(8080, 8080)], + "the builder sets the list" + ); + let cleared = re_exposed.with_host_exposure(vec![]); + assert!( + cleared.host_exposure_ports().is_empty(), + "a cleared list is carried empty" + ); + } + /// NET-061: the policy display spells the in-force arm's bound beside /// an endpoint naming the host alias, and a re-pointed endpoint as the /// set holds it. diff --git a/crates/minvmd/src/net/egress_gate.rs b/crates/minvmd/src/net/egress_gate.rs index b71526c1dc..f9cdf6f768 100644 --- a/crates/minvmd/src/net/egress_gate.rs +++ b/crates/minvmd/src/net/egress_gate.rs @@ -521,8 +521,14 @@ static INFRASTRUCTURE_RANGES: LazyLock = LazyLock::new(|| /// Whether `dst` lies in the infrastructure deny set as the host frame rule /// holds it ([`INFRASTRUCTURE_RULE`]): a fixed range; the host alias, which /// is default-deny at every port for a box row (design §7.1, NET-062) when -/// `refuse_host_alias` says so; the fabric plane -/// outside `own_block`, the subnet the gate's rows live in — a frame to a +/// `refuse_host_alias` says so, and for the node row's frames too outside +/// the host exposures `host_exposure` carries — the inclusive port ranges +/// the deployment configured, empty unless it named ports, matched against +/// `transport_port`, the TCP or UDP destination port, `None` for any other +/// frame. Box rows stay refused at a configured exposure too: the design +/// holds an exposure as local reach under the box's egress rules (§7.1), +/// and that reach is not built yet; the refusal fails closed, and +/// gominimal/inbox#1144 owns the gap. The fabric plane outside `own_block`, the subnet the gate's rows live in — a frame to a /// sibling or to the daemon inside the node's own block is local reach, /// decided by the row's CIDR rules and the target's ingress, never by this /// rule, and the gateway inside it is the control-surface rule's; or RFC @@ -545,14 +551,19 @@ static INFRASTRUCTURE_RANGES: LazyLock = LazyLock::new(|| /// of every box that shares the guest root namespace (a host-address box, /// the default network mode), and those reach the host alias as own-block /// local reach until the in-force baseline, which names the alias as its -/// registry and cache endpoint, decides the node plane instead. This -/// mirrors the shared verdict, whose own-address refusal is attached to box -/// relays only, never to the daemon relay. +/// registry and cache endpoint, decides the node plane instead. Announced, +/// that reach is scoped: the alias is opened at the configured host +/// exposures alone, and a node-row frame to any other port, or with no TCP +/// or UDP port, is this rule's drop. This mirrors the shared verdict, +/// whose own-address refusal is attached to box relays only, never to the +/// daemon relay. fn infrastructure_destination( dst: [u8; 4], + transport_port: Option, own_block: SwitchSubnet, allow: Option<&[Ipv4Cidr]>, refuse_host_alias: bool, + host_exposure: &[(u16, u16)], ) -> bool { let ranges = &*INFRASTRUCTURE_RANGES; if ranges.fixed.iter().any(|cidr| cidr.contains(dst)) { @@ -561,8 +572,16 @@ fn infrastructure_destination( // The host alias is default-deny (design §7.1, NET-062): a box reaches // the host only through a declared exposure, never by addressing the // alias directly, so the alias is refused under this rule at every port - // whatever the row's rules would say about it. - if refuse_host_alias && dst == own_block.host_alias().octets() { + // whatever the row's rules would say about it. The node row's frames + // — the host-address boxes the interim row carries — reach the alias at + // the configured host exposures alone, and only over TCP or UDP: a frame + // with no transport port (ICMP reads as port 0) fails the opening closed. + let exposed = transport_port.is_some_and(|port| { + host_exposure + .iter() + .any(|&(lo, hi)| lo <= port && port <= hi) + }); + if dst == own_block.host_alias().octets() && (refuse_host_alias || !exposed) { return true; } let in_own_block = (u32::from_be_bytes(dst) & u32::from(own_block.netmask())) @@ -1035,6 +1054,7 @@ impl EgressGate { switch_socket = %switch_sock.display(), unregistered_sources = "dropped", undeclared_box_default = phase.as_str(), + host_exposure_ports = %baseline.render_host_exposure(), "host-side egress gate listening", ); // The node-plane baseline set the gate decides the in-VM daemon's own @@ -5388,14 +5408,41 @@ fn gate_verdict( // row, keyed to the daemon's own address, carries the host-address // boxes' frames, whose `host.min.internal` resolves to the alias, and // keeps own-block local reach to it until the in-force baseline (which - // returned above) decides the node plane. + // returned above) decides the node plane. Announced, that reach is + // scoped by the baseline's configured host exposures, which the arm + // below reads for every row: the box rows' refusal stands at every + // port, and the node row's outside the exposures. The scoping holds only + // while the baseline is announced: in force, the arm above returns first + // and admits the alias only at TCP on `REGISTRY_CACHE_FETCH_PORTS` (443), + // with no host exposures, a gap gominimal/inbox#1144 and + // gominimal/inbox#1147 own. let box_row = src != table.subnet().daemon_ip().octets(); + // A non-first IPv4 fragment carries no readable L4 port — `summarize` + // reports destination port 0 for it — so it fails the exposure match + // and the gate drops it, never admits it: a fragmented UDP datagram to + // an exposed port dies at its later fragments. Reviewer ask + // (CodeRabbit, PR #2331) was to associate later fragments with their + // admitted first fragment, or defer the port check to reassembly. + // Declined: the verdict path is stateless and allocation-free by + // design — every input comes from the one frame being judged — and + // fragment association would add per-flow state here (or reassembly + // elsewhere) to recover a packet whose failure mode is a drop, not an + // exposure: deny-by-default keeps the safe direction. In force, the arm + // above admits no host exposure at all, so the fragment case arises only + // while the baseline is announced. + let transport_port = matches!( + summary.protocol(), + Some(egress::IPPROTO_TCP | egress::IPPROTO_UDP) + ) + .then(|| summary.destination_port()); if let Some(dst) = summary.destination() && infrastructure_destination( dst, + transport_port, table.subnet(), record.egress().allow_subnets(), box_row, + baseline.host_exposure_ports(), ) { return Err(GateDrop::Infrastructure { @@ -15002,15 +15049,21 @@ mod tests { ); } - /// The host alias's default-deny is a box row's alone (design §7.1, - /// NET-062). Announced, the interim node row at the daemon's address - /// carries the frames of every box sharing the guest root namespace — a - /// host-address box, the default network mode, whose `host.min.internal` - /// resolves to the alias — so a node-plane frame to the alias is - /// own-block local reach the row admits, while the same frame from a box - /// lease, even an allow-all one, is the infrastructure drop. + /// The host alias's default-deny is a box row's alone, and the node + /// row's reach through it is scoped by the configured host exposures + /// (design §7.1, NET-062). Announced, the interim node row at the + /// daemon's address carries the frames of every box sharing the guest + /// root namespace — a host-address box, the default network mode, whose + /// `host.min.internal` resolves to the alias. The built-in baseline + /// carries no exposure, so the alias is closed at every port until a + /// deployment names ports; with a list, a node-plane TCP or UDP frame to + /// the alias is own-block local reach the row admits inside the list's + /// ranges, edges included, and the infrastructure drop outside them, + /// while an ICMP frame, which carries no port, is refused even by a list + /// spanning every port. The same frames from a box lease, even an + /// allow-all one, are the infrastructure drop whatever the port. #[test] - fn host_alias_refused_for_box_rows_but_not_the_announced_node_row() { + fn host_alias_refused_for_box_rows_and_scoped_by_the_exposures_for_the_node_row() { let registry = BoxRegistry::new(SUBNET); registry.register_node_namespace(7654); registry.register( @@ -15018,40 +15071,62 @@ mod tests { .with_admitted_ports([8080]), ); let table = registry.table(); - let baseline = NodePlaneBaseline::built_in(SUBNET); - assert_eq!(baseline.phase(), NodeBaselinePhase::Announced); + let built_in = NodePlaneBaseline::built_in(SUBNET); + assert_eq!(built_in.phase(), NodeBaselinePhase::Announced); let pins = dns_pins::DnsPins::new(SUBNET); let summarize = boxes::core::egress::summarize; let alias = SUBNET.host_alias().octets(); + let node = SUBNET.daemon_ip().octets(); - let node_frame = summarize(&ipv4_frame(SUBNET.daemon_ip().octets(), 6, alias, 18081)); - assert_eq!( + let verdict = |src: [u8; 4], proto: u8, port: u16, baseline: &NodePlaneBaseline| { gate_verdict( - &node_frame, + &summarize(&ipv4_frame(src, proto, alias, port)), None, &table, - &baseline, + baseline, &pins, - &ReplyTables::new() - ), + &ReplyTables::new(), + ) + }; + let refused = |result: Result| matches!(result, Err(GateDrop::Infrastructure { dst, .. }) if dst == alias); + + assert!( + refused(verdict(node, 6, 8080, &built_in)), + "with no configured exposure the alias is closed to the node row at every port" + ); + + let exposed = built_in + .clone() + .with_host_exposure(vec![(3000, 3999), (8080, 8080)]); + assert!( + refused(verdict(node, 6, 2999, &exposed)), + "the port below a range's low edge is the infrastructure drop" + ); + for port in [3000, 3999, 8080] { + assert_eq!( + verdict(node, 6, port, &exposed), + Ok(GateAdmit::Row), + "the node row reaches the host alias at exposed port {port}" + ); + } + assert!( + refused(verdict(node, 6, 18081, &exposed)), + "the node row's frame to the host alias outside the exposures is the infrastructure drop" + ); + assert_eq!( + verdict(node, 17, 8080, &exposed), Ok(GateAdmit::Row), - "the announced node row keeps own-block reach to the host alias" + "a UDP frame reaches the host alias at an exposed port" + ); + assert!( + refused(verdict(LEASE, 6, 8080, &exposed)), + "a box row's frame to the host alias is the infrastructure drop at an exposed port" ); - let box_frame = summarize(&ipv4_frame(LEASE, 6, alias, 18081)); + let every_port = built_in.with_host_exposure(vec![(0, u16::MAX)]); assert!( - matches!( - gate_verdict( - &box_frame, - None, - &table, - &baseline, - &pins, - &ReplyTables::new() - ), - Err(GateDrop::Infrastructure { dst, .. }) if dst == alias - ), - "a box row's frame to the host alias is the infrastructure drop" + refused(verdict(node, 1, 0, &every_port)), + "an ICMP frame carries no port and never matches an exposure" ); } diff --git a/docs/reference/cli-minvmd.md b/docs/reference/cli-minvmd.md index 61d101dd13..ff30364b05 100644 --- a/docs/reference/cli-minvmd.md +++ b/docs/reference/cli-minvmd.md @@ -55,6 +55,8 @@ An own-IP box that declares no `egress` section gets the deny-all egress default `minvmd` reads the variable only when it starts, and hands it to the guest at boot. Set it in the environment of the process that starts `minvmd`: `minvmd run`, or the first `min` command that starts the VM for you. Setting it for a later `min` command against a running VM changes nothing. To apply a change, stop `minvmd` (`minvmd stop`) and start it again with the new environment. +`minvmd` closes `host.min.internal` at every port unless `MINVMD_HOST_EXPOSURE_PORTS` lists ports. Set the variable to a comma-separated list of ports and ranges, such as `8080,3000-3999`. A box in the default host-address network mode then reaches the host at those ports and no other. The box's egress rules still apply inside an exposure. An own-address box gets a refusal at every port, whatever the list says. Leave the variable unset or empty to keep `host.min.internal` closed. Each port must lie between 1 and 65535, and each range must run from low to high. Any other value fails the start with an error that names the bad term. `minvmd` reads the variable from its own environment each time it boots the VM, so to apply a change, stop `minvmd` and start it again. + ### `status` ``` diff --git a/scripts/session-e2e.sh b/scripts/session-e2e.sh index 19615abe93..6c39f31fe0 100755 --- a/scripts/session-e2e.sh +++ b/scripts/session-e2e.sh @@ -358,6 +358,20 @@ case "${1:-}" in ;; esac +# The host exposure the VM-backed daemon opens host.min.internal at. minvmd +# closes the alias at every port unless MINVMD_HOST_EXPOSURE_PORTS lists +# ports, and it reads the list from its own environment at each VM boot, so +# the export must precede the first `min` call, whose autospawn inherits it. +# The list is the one port NET-003 reaches the host's loopback at from a +# host-address box (the proxy proof's PROXY_HOST_PORT) and nothing wider: +# the same proof asserts the alias stays refused at an unlisted port, and +# own-address boxes stay refused at every port, listed or not. A native +# daemon has no alias gate and ignores the variable. +E2E_HOST_EXPOSURE_PORT=18081 +if [ -n "$E2E_VM" ]; then + export MINVMD_HOST_EXPOSURE_PORTS="$E2E_HOST_EXPOSURE_PORT" +fi + # The non-baseline package the sandbox proof adds and then runs. It must be a # real upstream package that is genuinely ABSENT from a fresh shell-stack # sandbox — the `shell` stack composes `base` (bash, coreutils, tar, gzip, …) @@ -409,6 +423,7 @@ PROXY_SEED_DIR="" # seeded by the min.internal proxy proof; removed on teardown PROXY_OWN_SEED_DIR="" # its own-address box's seed; removed on teardown PROXY_HOST_DIR="" # the host-loopback dir that proof serves; removed on teardown PROXY_HOST_SRV_PID="" # the host-loopback server it starts; killed on teardown +PROXY_UNEXPOSED_SRV_PID="" # its listener at a port outside the host exposure; killed on teardown PAR_SEED_DIR="" # seeded by the proxy-parity proof below; removed on teardown PAR_OWN_SEED_DIR="" # its own-address target box's seed; removed on teardown PAR_CALLER_SEED_DIR="" # its denied-caller box's seed; removed on teardown @@ -1002,6 +1017,9 @@ teardown() { if [ -n "$PROXY_HOST_SRV_PID" ]; then kill "$PROXY_HOST_SRV_PID" 2>/dev/null || true fi + if [ -n "$PROXY_UNEXPOSED_SRV_PID" ]; then + kill "$PROXY_UNEXPOSED_SRV_PID" 2>/dev/null || true + fi [ -n "$PAR_SEED_DIR" ] && rm -rf "$PAR_SEED_DIR" [ -n "$PAR_OWN_SEED_DIR" ] && rm -rf "$PAR_OWN_SEED_DIR" [ -n "$PAR_CALLER_SEED_DIR" ] && rm -rf "$PAR_CALLER_SEED_DIR" @@ -18220,7 +18238,8 @@ proof_min_internal_names_through_proxy() { PROXY_OWN_NAME="e2e-own-proxy" # the own-address box, on switch lanes PROXY_BOX_PORT=18080 # the in-box responders' listen port PROXY_OWN_EXTERNAL_PORT=18082 # ... published externally by --ingress - PROXY_HOST_PORT=18081 # the host-loopback listener (NET-003/004) + PROXY_HOST_PORT="$E2E_HOST_EXPOSURE_PORT" # the host-loopback listener (NET-003/004) + PROXY_UNEXPOSED_PORT=18089 # a host-loopback listener outside the exposure PROXY_DEAD_PORT=19090 # nothing listens: an upstream-refused 502 PROXY_CLOSED_PORT=19091 # not in the own box's ingress map: a 403 PROXY_HOST_ALIAS="100.64.255.254" # the deprecated literal (NET-004) @@ -18435,6 +18454,62 @@ proof_min_internal_names_through_proxy() { # ---- NET-003: host.min.internal from a host-address box ------------------- proxy_assert_host_by_name "$proxy_sid" "NET-003" host + # ---- the host exposure is the only opening (design §7.1) ---------------- + # A VM host's gate opens host.min.internal at the listed exposure alone + # (MINVMD_HOST_EXPOSURE_PORTS, exported at the top), so the same box, the + # same alias, at a port outside the list must not reach the host, even + # with a host-loopback listener answering there. A native host-address box + # shares the host's namespace, with no alias gate to assert. + if [ -n "$E2E_VM" ]; then + ( cd "$PROXY_HOST_DIR" && exec python3 -m http.server "$PROXY_UNEXPOSED_PORT" --bind 127.0.0.1 ) \ + >/dev/null 2>"$WORK/proxy-unexposed-srv.err" & + PROXY_UNEXPOSED_SRV_PID=$! + proxy_unexposed_up=0 + for _ in $(seq 1 40); do + if [ "$(curl -sS --max-time 5 -o /dev/null -w '%{http_code}' \ + "http://127.0.0.1:$PROXY_UNEXPOSED_PORT/marker" 2>/dev/null || true)" = "200" ]; then + proxy_unexposed_up=1 + break + fi + sleep 0.25 + done + if [ "$proxy_unexposed_up" -ne 1 ]; then + echo "::error::the unexposed host-loopback http.server never answered on 127.0.0.1:$PROXY_UNEXPOSED_PORT" + cat "$WORK/proxy-unexposed-srv.err" 2>/dev/null || true + fail + fi + # One exec runs both fetches, so a broken exec, a missing curl or a + # failed lookup shows on the exposed fetch and cannot pass as a refusal. + # The exposed port must answer with the marker. The unexposed port must + # fail as a refused connection (curl exit 7) or a timeout (exit 28). + proxy_unexposed_out="$(mnl session exec "$proxy_sid" \ + "curl -sS --max-time 8 http://host.min.internal:$PROXY_HOST_PORT/marker; echo \"exposed_rc=\$?\"; curl -sS --max-time 8 -o /dev/null http://host.min.internal:$PROXY_UNEXPOSED_PORT/marker; echo \"closed_rc=\$?\"" \ + 2>"$WORK/proxy-unexposed.err" || true)" + printf '%s\n' "$proxy_unexposed_out" >"$WORK/proxy-unexposed.out" + proxy_exposed_rc="$(sed -n 's/^.*exposed_rc=\([0-9]*\)$/\1/p' "$WORK/proxy-unexposed.out" | head -n1)" + proxy_unexposed_rc="$(sed -n 's/^closed_rc=\([0-9]*\)$/\1/p' "$WORK/proxy-unexposed.out" | tail -n1)" + if [ "$proxy_exposed_rc" != "0" ] || [[ "$proxy_unexposed_out" != *"$PROXY_HOST_MARKER"* ]]; then + echo "::error::the host-address box did not fetch the marker from host.min.internal at the exposed port $PROXY_HOST_PORT (curl exit '${proxy_exposed_rc:-none}'), so the unexposed-port check proves nothing" + echo "--- exec stdout ---"; cat "$WORK/proxy-unexposed.out" 2>/dev/null || true + echo "--- exec stderr ---"; cat "$WORK/proxy-unexposed.err" 2>/dev/null || true + fail + fi + case "$proxy_unexposed_rc" in + 7 | 28) ;; + 0) + echo "::error::the host-address box reached the host through host.min.internal at port $PROXY_UNEXPOSED_PORT, outside MINVMD_HOST_EXPOSURE_PORTS=$MINVMD_HOST_EXPOSURE_PORTS" + fail + ;; + *) + echo "::error::the fetch from host.min.internal at port $PROXY_UNEXPOSED_PORT failed with curl exit '${proxy_unexposed_rc:-none}', not a refused connection (7) or a timeout (28)" + echo "--- exec stdout ---"; cat "$WORK/proxy-unexposed.out" 2>/dev/null || true + echo "--- exec stderr ---"; cat "$WORK/proxy-unexposed.err" 2>/dev/null || true + fail + ;; + esac + echo "host exposure: host.min.internal:$PROXY_HOST_PORT reached and host.min.internal:$PROXY_UNEXPOSED_PORT refused from the host-address box (curl exit $proxy_unexposed_rc: $(tail -n1 "$WORK/proxy-unexposed.err" 2>/dev/null)) OK" + fi + # ---- NET-001's own-address half: a VM host's lease route ----------------- # Gated like the own-IP proof: MINVMD_GVPROXY_BIN is the one signal that a # switch exists. On every lane that sets it the daemon is in a VM, so its @@ -18501,8 +18576,9 @@ proof_min_internal_names_through_proxy() { # NET-003's own-address half, narrowed to resolution: the box resolves # host.min.internal through the switch zone, to the host alias. Box→host # reach over that alias is default-deny except configured host exposures - # (design §7.1), and this box's switch has none, so the reach is not - # asserted here. TODO(host-exposure): the positive reach arm comes back + # (design §7.1), and an own-address box is refused even at the one + # exposure this run lists, so the reach is not asserted here. + # TODO(host-exposure): the positive reach arm comes back # with a configured exposure (gominimal/inbox#867). proxy_own_resolved="$(mnl session exec "$PROXY_OWN_SID" \ "getent ahostsv4 host.min.internal" 2>"$WORK/proxy-own-resolve.err" \ @@ -18516,7 +18592,9 @@ proof_min_internal_names_through_proxy() { # NET-004: the deprecated literal itself. Box→host reach over the alias # is default-deny except configured host exposures (design §7.1), and - # none is configured, so the box's own relay drops the connect — though + # an own-address box gets none — not even PROXY_HOST_PORT, the one this + # run lists for host-address boxes — so the box's own relay drops the + # connect — though # its egress rules admit every address (0.0.0.0/0 above), so the drop # is the infrastructure deny set's and not the deny-all default's: no # answer and no reset until the timeout, and the relay names the drop @@ -18538,7 +18616,7 @@ proof_min_internal_names_through_proxy() { mnl session exec "$PROXY_OWN_SID" \ "/usr/bin/socat /dev/null TCP:$PROXY_HOST_ALIAS:$PROXY_HOST_PORT,connect-timeout=10" \ >/dev/null 2>"$WORK/proxy-alias.err" && { - echo "::error::NET-004: the own-address box completed a connection to the host alias $PROXY_HOST_ALIAS:$PROXY_HOST_PORT with no host exposure configured" + echo "::error::NET-004: the own-address box completed a connection to the host alias $PROXY_HOST_ALIAS:$PROXY_HOST_PORT, which an own-address box must never reach" fail } proxy_alias_elapsed_ms=$(( $(now_ms) - proxy_alias_start_ms ))