Skip to content
Merged
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
165 changes: 160 additions & 5 deletions crates/minvmd/src/net/egress_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,16 @@ fn infrastructure_destination(
/// rules ([`GateAdmit::ProxyLane`]).
const PROXY_LANE_RULE: &str = "egress-uncredentialed-proxy-destination";

/// The rule name for the ingress drop of an opening TCP packet (SYN set, ACK
/// clear) sourced from the Box Egress Proxy's address toward a box's
/// published inside port (NET-134's ingress arm): the proxy only answers a
/// credentialed box's dial and never opens toward a box, so such a packet has
/// no legitimate origin. Its own rule, not [`PROXY_LANE_RULE`]'s: that one
/// names a box reaching for the proxy, this one the proxy's address reaching
/// for a box. The proxy's answers (SYN-ACK, ACK, data, FIN, RST) are never
/// dropped under it.
const PROXY_OPENING_RULE: &str = "egress-proxy-opening-toward-box";

/// The rule name for the drop of an in-plan source no published namespace
/// holds (NET-085): a frame whose source is an address the plan could hand
/// to a box but no row does. It carries its own rule — beside rule 0's
Expand Down Expand Up @@ -3213,6 +3223,27 @@ async fn relay_switch_frames_to_guest(
&& let Some(record) = table.by_source(pkt.dst.ip().octets())
&& forwards.inside_published(record.switch_addr().octets(), pkt.dst.port())
{
// NET-134's ingress arm: the box egress proxy answers and never
// opens toward a box, so a bare SYN from its address to a
// published inside port has no legitimate origin. Dropping the
// opening packet here — before any observation or delivery —
// keeps the proxy's address from planting an inbound flow toward
// a box at all. Only opening packets are dropped: SYN-ACKs and
// ACKs the proxy sends back to the box on a credentialed dial
// still reach it untouched.
let proxy = table.subnet().box_egress_proxy_address().octets();
if pkt.src.ip().octets() == proxy
&& pkt.proto == egress::IPPROTO_TCP
&& pkt.tcp_flags & egress::TCP_SYN != 0
&& pkt.tcp_flags & egress::TCP_ACK == 0
{
limiter.warn_proxy_opening(
record.switch_addr().octets(),
record.name(),
pkt.dst.port(),
);
continue;
}
let now = Instant::now();
if matches!(
replies.observe_delivered(&record, &pkt, &limiter, table.subnet(), now),
Expand Down Expand Up @@ -3756,11 +3787,15 @@ impl ReplyTables {
///
/// A frame sourced from the switch subnet's Box Egress Proxy address
/// records nothing: the decline comes before any record is consulted or
/// minted, and the frame itself is still delivered (only the reply-flow
/// recording is declined). A box on a credentialed lane does dial the
/// proxy's listener (NET-134), but the proxy only answers: it never opens
/// a connection toward a box, so a proxy-sourced opening packet at a
/// box's published port has no legitimate origin, and the stream it
/// minted. Of such frames the ingress leg never hands this an opening TCP
/// packet (SYN set, ACK clear) — it drops that one before calling here
/// ([`PROXY_OPENING_RULE`]) — while every other proxy-sourced frame, the
/// proxy's answers to a box's dial included, is still delivered with only
/// the reply-flow recording declined.
/// A box on a credentialed lane does dial the proxy's listener
/// (NET-134), but the proxy only answers: it never opens a connection
/// toward a box, so a proxy-sourced opening packet at a box's published
/// port has no legitimate origin, and the stream it
/// would open must never become a reply flow the box could reverse-answer
/// ([`gate_verdict`]'s reply-flow admit). Defense in depth — the
/// reply-flow admit in [`gate_verdict`] itself never admits a frame to
Expand Down Expand Up @@ -4890,6 +4925,39 @@ impl DropLimiter {
}
}
}

/// Emits the drop's line for one opening TCP packet from the Box Egress
/// Proxy's address toward a box's published inside port
/// ([`PROXY_OPENING_RULE`]): the same rate limit a drop's line answers
/// to, keyed by the box's address and the rule — the source is always
/// the proxy, so keying by it would fold every box into one window —
/// and naming the box and the port. Returns whether a line was written.
fn warn_proxy_opening(&self, box_addr: [u8; 4], namespace: &str, port: u16) -> bool {
match self.should_warn_at(Some(box_addr), PROXY_OPENING_RULE, Instant::now()) {
WarnDecision::Silent => false,
WarnDecision::Named => {
tracing::warn!(
destination = %Ipv4Addr::from(box_addr),
namespace,
port,
rule_matched = PROXY_OPENING_RULE,
"dropped an opening TCP packet from the box egress proxy's address \
toward a box's published port; the proxy only answers and never \
opens toward a box",
);
true
}
WarnDecision::Overflow => {
tracing::warn!(
rule_matched = PROXY_OPENING_RULE,
"dropped opening TCP packets from the box egress proxy's address toward \
more distinct boxes than the gate keeps a window per address for; one \
line per rule covers the rest",
);
true
}
}
}
}

/// Reads the head of the guest's first request — through the first
Expand Down Expand Up @@ -8909,6 +8977,82 @@ mod tests {
expect_silence(&mut switch).await;
}

/// NET-134's ingress arm: a bare-SYN TCP frame from the Box Egress
/// Proxy's address toward a box's published inside port has no
/// legitimate origin — the proxy only answers (NET-134) and never opens
/// toward a box — so the ingress relay drops it before it can open a
/// reply-flow record or reach the box. The proxy's answers to a
/// credentialed box's dial (SYN-ACK, ACK) are not opening packets and
/// still pass, and a proxy-sourced bare SYN toward a port no publish
/// names is out of the recording bound's reach, so it is not this rule's
/// and continues to its normal decision.
#[tokio::test]
async fn box_egress_proxy_syn_to_published_port_dropped() {
let registry = BoxRegistry::new(SUBNET);
registry.register_node_namespace(7654);
let node_addr = SUBNET.daemon_ip().octets();
let publish = expose_request(
"127.0.0.1:7654",
&format!("{}:7654", SUBNET.daemon_ip()),
"tcp",
);
let h = gate_over_control(registry, publish).await;
let (mut guest, mut switch) = connect_over(&h).await;
let proxy = SUBNET.box_egress_proxy_address().octets();

// The proxy's bare SYN toward the published inside port — the
// opening packet no one legitimately sends — never reaches the
// guest; the marker below proves it was decided.
let opening = dns_pins::tests::tcp_frame(
Ipv4Addr::from(proxy),
40000,
Ipv4Addr::from(node_addr),
7654,
sessions::core::egress::TCP_SYN,
);
send_frame(&mut switch, &opening).await;
// A SYN carrying other flags but no ACK is still an opening packet by
// the reply-flow table's own shape, and is dropped the same way.
let odd_opening = dns_pins::tests::tcp_frame(
Ipv4Addr::from(proxy),
40001,
Ipv4Addr::from(node_addr),
7654,
sessions::core::egress::TCP_SYN | sessions::core::egress::TCP_FIN,
);
send_frame(&mut switch, &odd_opening).await;

// The proxy's answer to a credentialed box's dial — a SYN-ACK from
// the proxy's address toward the published inside port — is not an
// opening packet, so it is not dropped by this rule. Delivered
// toward the guest, it is the exact frame this hardening must never
// withhold.
let answer = dns_pins::tests::tcp_frame(
Ipv4Addr::from(proxy),
40000,
Ipv4Addr::from(node_addr),
7654,
sessions::core::egress::TCP_SYN | sessions::core::egress::TCP_ACK,
);
send_frame(&mut switch, &answer).await;
assert_eq!(
expect_frame(&mut guest).await,
answer,
"the proxy's SYN-ACK answer reaches the guest"
);

// The marker after them proves the dropped bare SYN was decided, and
// nothing but the answer reached the guest.
let marker = arp_frame(node_addr);
send_frame(&mut switch, &marker).await;
assert_eq!(
expect_frame(&mut guest).await,
marker,
"the bare SYN never arrived; only the answer and the marker did"
);
expect_silence(&mut guest).await;
}

/// The §5.3 infrastructure deny set as a host frame rule
/// ([`INFRASTRUCTURE_RULE`]), decided for every row before the row's own
/// rules and before the deferral: a name-declaring row and a CIDR row
Expand Down Expand Up @@ -12700,6 +12844,17 @@ mod tests {
);
}

/// The proxy-opening drop's line answers to the drop cadence per box:
/// one line for a box's first dropped opening packet, silence for the
/// next within the interval, and its own line for another box.
#[test]
fn proxy_opening_drop_line_is_rate_limited_per_box() {
let limiter = DropLimiter::new();
assert!(limiter.warn_proxy_opening([100, 64, 0, 10], "web", 7654));
assert!(!limiter.warn_proxy_opening([100, 64, 0, 10], "web", 7654));
assert!(limiter.warn_proxy_opening([100, 64, 0, 11], "api", 7654));
}

/// The limiter's window table is bounded, because the source address it
/// keys by is the dropped frame's own bytes and a hostile guest chooses
/// those: flooding distinct spoofed addresses must not grow host memory
Expand Down
Loading