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

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

5 changes: 4 additions & 1 deletion pkgs/fleet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
# root. Crates land one step at a time: step 1 (#5429) the skeleton
# (platform crates + the bin's dispatch/stub machinery + variant
# builds); step 2 (#5430) the queue domain (crates/fleet-queue);
# step 3 (#5431) the proxy domain (crates/fleet-proxy).
# step 3 (#5431) the proxy domain (crates/fleet-proxy); step 4
# (#5432) the dispatch thin client (crates/fleet-dispatch).
[workspace]
members = [
"crates/fleet-registry",
"crates/fleet-config",
"crates/fleet-secrets",
"crates/fleet-proxy-proto",
"crates/fleet-queue",
"crates/fleet-dispatch",
"crates/fleet-proxy",
"crates/fleet",
]
Expand All @@ -31,6 +33,7 @@ fleet-config = { path = "crates/fleet-config" }
fleet-secrets = { path = "crates/fleet-secrets" }
fleet-proxy-proto = { path = "crates/fleet-proxy-proto" }
fleet-queue = { path = "crates/fleet-queue" }
fleet-dispatch = { path = "crates/fleet-dispatch" }
fleet-proxy = { path = "crates/fleet-proxy" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
32 changes: 28 additions & 4 deletions pkgs/fleet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ config, secrets-by-name and proxy-protocol platform crates. Step 2
(#5430) landed the queue domain — the repo-queue client and the
queue-broker / secrets-broker serve roles are real below. Step 3
(#5431) landed the proxy domain — the session broker, its client,
the hello negotiation and the PATH shims. The remaining domains
are capability stubs until their own steps land (dispatch #5432,
search #5433).
the hello negotiation and the PATH shims. Step 4 (#5432) landed
the dispatch domain — a thin client over pm-stack dispatch. The
remaining domain is a capability stub until its own step lands
(search #5433).

## Layout

Expand All @@ -23,7 +24,8 @@ crates/fleet-registry/ the FULL domain registry — every domain's
capability ids behind them. Compiled into
every variant, so --help is always complete.
crates/fleet-config/ fleet.toml: [domains] switches, [proxy],
[secrets]; path/ports/socket constants.
[secrets], [dispatch]; path/ports/socket
constants.
crates/fleet-secrets/ secrets by NAME only (broker first, then
`bws` fallback). Values never appear in
code, tests, errors or logs.
Expand Down Expand Up @@ -51,6 +53,17 @@ crates/fleet-queue/ the queue domain (step 2): the repo-queue
repo-queue / queue-broker / secrets-broker
artifacts (the `fleet-brokers` package):
the migration's rollback inventory.
crates/fleet-dispatch/ the dispatch domain (step 4): a THIN
client over pm-stack's pm-dispatch —
`dispatch status` (GET /health),
`dispatch launch` (POST /v1/sessions),
`dispatch enqueue` (POST /v1/tasks).
pm-stack is not rewritten (D6); the
bearer token resolves by name through
fleet-secrets, and the client reaches
the service directly (laptop seat) or
through its own CONNECT on the proxy
egress (sandbox seat).
crates/fleet/ the binary: multicall dispatch, capability
stubs, `version`, `capabilities`, help.
default.nix the four variant packages (see below)
Expand Down Expand Up @@ -126,3 +139,14 @@ fleet artifact — each verified by health plus a real
enqueue→claim→complete round-trip before the next begins (the
evidence lives on #5430). The standalone artifacts above are the
rollback for every flip.

Step 4 flips nothing live: the dispatch domain is a client, and
pm-stack keeps running exactly as it did (the step's gate is a
zero pm-stack diff). What changes is the caller's side — agents
hold `fleet dispatch status|launch|enqueue` instead of
hand-rolled curl against pm-dispatch, with the bearer token
resolved by name (`pm-dispatch.api-token`) through fleet-secrets
and the transport chosen by seat: direct on the laptop, a CONNECT
tunnel on the proxy egress from the sandbox. The steward cron's
call sites move to these verbs only if they want them; no cron
is rewritten by this epic (the evidence lives on #5432).
79 changes: 79 additions & 0 deletions pkgs/fleet/crates/fleet-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,25 @@ pub const DEFAULT_BROKER_TOKEN_FILE: &str = "tools/laptop-agent-token";
/// files, read per request, never stored, never logged).
pub const DEFAULT_SECRETS_TOKEN_FILE: &str = "tools/secrets-broker-token";

/// pm-dispatch's port on the laptop (pm-stack/dispatch: the intake
/// service binds loopback + the tailnet address there).
pub const PORT_DISPATCH: u16 = 4879;

/// The fleet-secrets name the dispatch domain resolves its bearer
/// token by (step 4, #5432). The value is pm-dispatch's
/// `DISPATCH_API_TOKEN`; its by-name home is the vault, per the
/// platform rule that secrets resolve by name through fleet-secrets
/// only.
pub const DEFAULT_DISPATCH_TOKEN_NAME: &str = "pm-dispatch.api-token";

#[derive(Debug, Clone, Default, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct Config {
/// `[domains]` — domain name → enabled. Absent means enabled.
pub domains: BTreeMap<String, bool>,
pub proxy: ProxyConfig,
pub secrets: SecretsConfig,
pub dispatch: DispatchConfig,
}

#[derive(Debug, Clone, Default, Deserialize)]
Expand Down Expand Up @@ -102,6 +114,25 @@ pub struct SecretsConfig {
pub token_file: Option<String>,
}

/// `[dispatch]` — the dispatch thin client's view of pm-dispatch
/// (step 4, #5432). All optional: the laptop seat needs no config
/// at all (the client probes the loopback bind), and the sandbox
/// seat rides the proxy egress to the target host's dispatch port.
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(default, deny_unknown_fields)]
pub struct DispatchConfig {
/// Direct base URL (`http://host[:port]`) for pm-dispatch,
/// bypassing transport selection. `FLEET_DISPATCH_URL` beats
/// the file (the fleet-queue client's env-first pattern).
pub url: Option<String>,
/// The fleet-secrets name the bearer token resolves by
/// (default [`DEFAULT_DISPATCH_TOKEN_NAME`]).
pub token_name: Option<String>,
/// pm-dispatch's port on the target host (default
/// [`PORT_DISPATCH`]).
pub port: Option<u16>,
}

#[derive(Debug)]
pub enum ConfigError {
/// The config file exists but does not parse. Carries the path and
Expand Down Expand Up @@ -293,6 +324,29 @@ impl Config {
resolve_under_home(DEFAULT_BROKER_TOKEN_FILE)
}

/// The dispatch base URL when one is configured:
/// `FLEET_DISPATCH_URL` (empty counts as unset, as with every
/// env path here) beats `[dispatch] url`.
pub fn dispatch_url(&self) -> Option<String> {
match std::env::var("FLEET_DISPATCH_URL") {
Ok(v) if !v.trim().is_empty() => Some(v.trim().to_string()),
_ => self.dispatch.url.clone(),
}
}

/// The fleet-secrets name the dispatch bearer token resolves by.
pub fn dispatch_token_name(&self) -> &str {
self.dispatch
.token_name
.as_deref()
.unwrap_or(DEFAULT_DISPATCH_TOKEN_NAME)
}

/// pm-dispatch's port on the target host.
pub fn dispatch_port(&self) -> u16 {
self.dispatch.port.unwrap_or(PORT_DISPATCH)
}

/// The secrets-broker token *file path* (never its contents).
pub fn secrets_token_file(&self) -> PathBuf {
match &self.secrets.token_file {
Expand Down Expand Up @@ -453,6 +507,31 @@ mod tests {
);
}

#[test]
fn dispatch_settings_default_to_the_live_service() {
let cfg = Config::default();
assert_eq!(cfg.dispatch_port(), PORT_DISPATCH);
assert_eq!(cfg.dispatch_token_name(), DEFAULT_DISPATCH_TOKEN_NAME);
assert_eq!(cfg.dispatch_url(), None);
}

#[test]
fn dispatch_settings_resolve() {
let (_dir, path) = write_temp(
"[dispatch]\nport = 14879\ntoken_name = \"other.token\"\nurl = \"http://127.0.0.1:9\"\n",
);
let cfg = Config::load_from(&path).unwrap();
assert_eq!(cfg.dispatch_port(), 14879);
assert_eq!(cfg.dispatch_token_name(), "other.token");
assert_eq!(cfg.dispatch_url().as_deref(), Some("http://127.0.0.1:9"));
// A misspelled dispatch key is a loud error like any other.
let (_dir2, path2) = write_temp("[dispatch]\nprt = 1\n");
match Config::load_from(&path2) {
Err(ConfigError::Parse { .. }) => {}
other => panic!("expected Parse error, got {other:?}"),
}
}

#[test]
fn proxy_settings_resolve() {
let (_dir, path) =
Expand Down
20 changes: 20 additions & 0 deletions pkgs/fleet/crates/fleet-dispatch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "fleet-dispatch"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
description = "The fleet dispatch domain: a thin client over pm-stack's pm-dispatch service — status, launch, and enqueue verbs (epic developing-today/code#5412, step 4 #5432)."

[dependencies]
fleet-config = { workspace = true }
fleet-secrets = { workspace = true }
# The tunnel half only: the dispatch client opens its own CONNECT
# through the proxy egress (see lib.rs docs for why the framed
# session-broker path cannot carry its Authorization header). The
# broker half (`serve` feature) is not part of this domain.
fleet-proxy = { workspace = true, default-features = false }
serde = { workspace = true }
# preserve_order, as in fleet-queue: the service's JSON key order is
# part of the output shape agents consume.
serde_json = { version = "1", features = ["preserve_order"] }
Loading