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
61 changes: 61 additions & 0 deletions pkgs/fleet/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions pkgs/fleet/crates/fleet-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ pub const DEFAULT_TARGET_HOST: &str = "100.99.113.103";
/// `HTTPS_PROXY` — fixed by the tunnel setup, as in
/// laptop-proxy-connect.py (the URL's own port is not used).
pub const DEFAULT_EGRESS_PROXY_PORT: u16 = 3130;
/// The named Cloudflare tunnel hostname the broker's Cloudflare
/// leg dials for the laptop-agent daemon (code#10356, Drew's
/// 2026-11-15 transport ruling): the tunnel's ingress lands on
/// the daemon's own listener from the laptop side, so the daemon
/// is untouched and its token auth is preserved end to end.
pub const DEFAULT_CF_HOST: &str = "sandbox-link.security.cab";
/// The Cloudflare Access service-token file for the tunnel
/// (home-relative, like [`DEFAULT_BROKER_TOKEN_FILE`]): a JSON
/// object with `client_id` / `client_secret`, mode 600, read by
/// the broker per request and sent only as `CF-Access-*` headers
/// — never stored, never logged. The file's EXISTENCE is what
/// puts the Cloudflare leg in play (the Python broker's rule);
/// no file, no leg, the tailnet path carries everything.
pub const DEFAULT_CF_ACCESS_FILE: &str = "tools/laptop-agent-cf-access.json";

/// Default listen address for the CONNECT-UDP endpoint
/// (RFC 9298 spike, #6109) when `[proxy] connect_udp` enables
Expand Down Expand Up @@ -345,6 +359,16 @@ pub struct ProxyConfig {
/// [`DEFAULT_EGRESS_PROXY_PORT`]). `0` is rejected at load
/// (#6412): port 0 cannot be dialled.
pub egress_proxy_port: Option<u16>,
/// Hostname of the named Cloudflare tunnel the broker's
/// Cloudflare leg dials for the laptop-agent daemon (default
/// [`DEFAULT_CF_HOST`]; code#10356). Blank is rejected at load
/// (#6405's rule, same as `target_host`).
pub cf_host: Option<String>,
/// Cloudflare Access service-token file for the tunnel,
/// home-relative (default [`DEFAULT_CF_ACCESS_FILE`]). The
/// broker reads it per request; its existence enables the
/// Cloudflare leg for the daemon port.
pub cf_access_file: Option<String>,
/// Dial the target directly instead of through a CONNECT tunnel
/// (a broker running on the target host itself; also the
/// hermetic-test mode). Default false — today's topology.
Expand Down Expand Up @@ -731,6 +755,8 @@ impl Config {
for (value, field) in [
(&self.proxy.broker_socket, "[proxy] broker_socket"),
(&self.proxy.target_host, "[proxy] target_host"),
(&self.proxy.cf_host, "[proxy] cf_host"),
(&self.proxy.cf_access_file, "[proxy] cf_access_file"),
(&self.proxy.connect_udp_listen, "[proxy] connect_udp_listen"),
(&self.secrets.token_file, "[secrets] token_file"),
(&self.dispatch.url, "[dispatch] url"),
Expand Down Expand Up @@ -1134,6 +1160,22 @@ impl Config {
.unwrap_or(DEFAULT_EGRESS_PROXY_PORT)
}

/// The named Cloudflare tunnel hostname for the broker's
/// Cloudflare leg (see [`DEFAULT_CF_HOST`]).
pub fn cf_host(&self) -> &str {
self.proxy.cf_host.as_deref().unwrap_or(DEFAULT_CF_HOST)
}

/// The Cloudflare Access service-token file (see
/// [`DEFAULT_CF_ACCESS_FILE`]), resolved under $HOME like the
/// other token files.
pub fn cf_access_file(&self) -> PathBuf {
match &self.proxy.cf_access_file {
Some(raw) => resolve_under_home(raw),
None => resolve_under_home(DEFAULT_CF_ACCESS_FILE),
}
}

/// Whether the broker dials the target directly (no CONNECT).
pub fn proxy_direct(&self) -> bool {
self.proxy.direct.unwrap_or(false)
Expand Down
31 changes: 30 additions & 1 deletion pkgs/fleet/crates/fleet-proxy-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ pub struct ServiceInfo {
/// names the file whose contents the broker sends as `X-Agent-Token`
/// for that request — the file is read by the broker per request; the
/// token itself never appears in the frame beyond that name.
///
/// The 2026-11-15 transport fields (code#10356) ride the legacy
/// dialect the Python clients already speak: `trip` is the caller's
/// per-request id (the broker forwards it to the service as the
/// `X-Trip-Id` header, joining the trip logs), `transport` is the
/// caller's transport preference (`auto` | `cf` | `ts` — the broker
/// owns the actual selection and reports the outcome on the
/// response), and `cf_ok` is the caller's verdict that the request
/// may ride the Cloudflare leg (the broker computes the same verdict
/// from the body when the field is absent). All three are optional
/// and additive: pre-field frames parse exactly as before.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Request {
pub method: String,
Expand All @@ -151,14 +162,25 @@ pub struct Request {
pub port: Option<u16>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub token_file: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub trip: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub transport: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cf_ok: Option<bool>,
}

/// A response frame: `{status, body}` — the HTTP status and parsed
/// JSON body of the routed service's reply.
/// JSON body of the routed service's reply. `transport` (2026-11-15,
/// code#10356) names the transport leg the broker actually used
/// (`cf` | `ts`), so a caller's trip record can prove which path a
/// request rode; absent when the broker predates the field.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Response {
pub status: u16,
pub body: serde_json::Value,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub transport: Option<String>,
}

/// Frame-level errors. None of these ever carry payload contents —
Expand Down Expand Up @@ -329,12 +351,18 @@ mod tests {
body: None,
port: None,
token_file: None,
trip: None,
transport: None,
cf_ok: None,
};
let frame = serde_json::to_value(&req).unwrap();
assert_eq!(frame["method"], "GET");
assert!(frame.get("body").is_none());
assert!(frame.get("port").is_none());
assert!(frame.get("token_file").is_none());
assert!(frame.get("trip").is_none());
assert!(frame.get("transport").is_none());
assert!(frame.get("cf_ok").is_none());
assert_eq!(roundtrip(&req), req);
}

Expand All @@ -355,6 +383,7 @@ mod tests {
let resp = Response {
status: 200,
body: serde_json::json!({"ok": true}),
transport: None,
};
assert_eq!(roundtrip(&resp), resp);
}
Expand Down
20 changes: 18 additions & 2 deletions pkgs/fleet/crates/fleet-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,25 @@ required-features = ["serve"]
[features]
# The broker half. The connect variant compiles this crate without
# it: a dropped-on-a-box artifact carries the client and nothing
# else (§2's mechanical-incapability rule).
# else (§2's mechanical-incapability rule). The TLS stack for the
# broker's Cloudflare leg (code#10356) rides this feature for the
# same reason: rustls + two root stores is exactly the weight the
# size-gated connect artifact must not grow.
default = ["serve"]
serve = []
serve = ["dep:rustls", "dep:webpki-roots", "dep:rustls-native-certs"]

[dependencies.rustls]
version = "0.23"
features = ["ring"]
optional = true

[dependencies.webpki-roots]
version = "1"
optional = true

[dependencies.rustls-native-certs]
version = "0.8"
optional = true

[dev-dependencies]
# Property-based tests for the fleet-udp-forward parser invariants
Expand Down
3 changes: 3 additions & 0 deletions pkgs/fleet/crates/fleet-proxy/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ pub fn run_connect(
body: req.body.clone(),
port: req.service_port,
token_file: req.token_file.clone(),
trip: None,
transport: None,
cf_ok: None,
};
// A legacy broker already spent its first reply eating the
// hello; the round-trip proceeds identically from here.
Expand Down
4 changes: 4 additions & 0 deletions pkgs/fleet/crates/fleet-proxy/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ impl FilesTransport for BrokerFilesTransport {
body: Some(body),
port: Some(self.port),
token_file: Some(self.token_file.to_string_lossy().into_owned()),
trip: None,
transport: None,
cf_ok: None,
};
let mut stream = UnixStream::connect(&self.socket).map_err(|e| {
ClientError::Transport(format!("broker socket {}: {e}", self.socket.display()))
Expand Down Expand Up @@ -1517,6 +1520,7 @@ mod tests {
let response = Response {
status,
body: reply,
transport: None,
};
if fleet_proxy_proto::write_frame(&mut stream, &response).is_err() {
return;
Expand Down
Loading