Skip to content
Open
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
42 changes: 41 additions & 1 deletion pkgs/fleet/crates/fleet-proxy/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ impl Broker {
if client {
self.last_used.store(now_secs(), Ordering::Relaxed);
}
let port = req.port.unwrap_or(fleet_config::PORT_LAPTOP_AGENT);
let port = dial_port(req.port);
let token_path = match &req.token_file {
Some(p) => std::path::PathBuf::from(p),
None => self.config.default_token_file(),
Expand Down Expand Up @@ -833,6 +833,27 @@ impl Broker {
/// plan falls to the next leg.
const CF_EDGE_STATUSES: [u16; 3] = [502, 503, 530];

/// The port `do_request` dials for one parsed request
/// (#13464): the client-declared port verbatim, or the
/// laptop-agent default when the frame named none. There is
/// deliberately NO `services_map` membership check here. The
/// advertised table (`Config::services`, the hello map) is a
/// host-local, configurable advertisement — discovery for the
/// hello and the shims — not an access-control list, and the
/// in-tree consumer `fleet proxy connect --request …`
/// `--service-port N` deliberately addresses operator-chosen
/// ports outside it (client.rs pins `--service-port 8080`):
/// refusing unadvertised ports would break that consumer
/// (#6583 disposition (a)). The #6582 contract still holds: the
/// port is validated where it is read — type and range at the
/// frame boundary (`parse_port`, #6516) — and the dial itself
/// stays token-gated. Residual risk, recorded: an unadvertised
/// port receiving an arbitrary body is only as constrained as
/// the service behind it (#6583 (b)).
fn dial_port(requested: Option<u16>) -> u16 {
requested.unwrap_or(fleet_config::PORT_LAPTOP_AGENT)
}

/// The attempt plan for one request, the Python broker's plan
/// exactly (code#10356). The Cloudflare leg is in play only for
/// the laptop-agent daemon port, only when the caller's
Expand Down Expand Up @@ -2178,6 +2199,25 @@ mod tests {
assert_eq!(req.port, Some(65535));
}

#[test]
fn dial_port_passes_any_frame_valid_port_through() {
// The #13464 decision, pinned at the dial site: no
// services_map membership filtering. Absent means the
// laptop-agent default; a table port passes through
// unchanged; a non-table port -- the --service-port case,
// e.g. 8080, which client.rs pins as parseable -- passes
// through verbatim, up to the top of the u16 range the
// frame boundary validated (#6516). A future membership
// refusal must change this test, not slip past it.
assert_eq!(dial_port(None), fleet_config::PORT_LAPTOP_AGENT);
assert_eq!(
dial_port(Some(fleet_config::PORT_LAPTOP_AGENT)),
fleet_config::PORT_LAPTOP_AGENT
);
assert_eq!(dial_port(Some(8080)), 8080);
assert_eq!(dial_port(Some(65535)), 65535);
}

#[test]
fn parse_request_refuses_present_but_invalid_ports() {
// Every shape the pre-fix chain silently collapsed to the
Expand Down