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
133 changes: 133 additions & 0 deletions pkgs/fleet/crates/fleet-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ central (owner token):
agents registered agents, groups, unread counts
log [--agent A] [--direction inbound|outbound] [--kind message|command]
[--since-id N] [--before-id N] [--limit N] [--order asc|desc]
pipeline [--kind K] [--sender S] [--receiver R] [--surface S]
[--batch B] [--unread] [--work-state W] [--since-id N]
[--before-id N] [--limit N] [--order asc|desc]
the unified owner feed over connector messages, fleet
mailboxes and notes, real senders shown
directory the unified agents list: fleet registry
and note identities, each row marked by surface
credentials per-agent credential state (active or
revoked, live scopes; never a hash)
revoke (--agent A | --identity I)
revoke an agent's fleet credentials, or a notes identity's
tokens (the owner's kill switch, #14368)

agent (fleet token):
hello [--agent A] [--groups g1,g2] register / refresh groups
Expand Down Expand Up @@ -128,6 +140,45 @@ usage: fleet bridge log [--agent A] [--direction inbound|outbound] [--kind messa
[--since-id N] [--before-id N] [--limit N] [--order asc|desc]

central (owner token). The central message log, filtered."
}
"pipeline" => {
"\
usage: fleet bridge pipeline [--kind K] [--sender S] [--receiver R] [--surface S]
[--batch B] [--unread] [--work-state W] [--since-id N]
[--before-id N] [--limit N] [--order asc|desc]

central (owner token). The unified owner feed over connector
messages, fleet mailboxes and notes (#14369), real senders shown:
kind is message, instruction, command or note; sender and receiver
name an address or its bare name; surface is connector, fleet or
notes. --work-state is passed through for the work-item lifecycle
(#14372)."
}
"directory" => {
"\
usage: fleet bridge directory

central (owner token). The unified agents list (#14369): fleet
registry rows (groups, first/last seen, unread counts) and note
identities (scopes, signal counter), each row marked by surface.
Notes identities have no presence; the row says so."
}
"credentials" => {
"\
usage: fleet bridge credentials

central (owner token). Per-agent credential state (#14368): one row
per agent that has held a credential — active or revoked, the scopes
its live credentials carry, mint and revocation times. State only:
no hash or value is ever shown."
}
"revoke" => {
"\
usage: fleet bridge revoke (--agent A | --identity I)

central (owner token). Revoke every live fleet credential of an
agent (--agent), or every notes token of an identity (--identity):
the per-agent kill switch (#14368). Prints how many were revoked."
}
"hello" => {
"\
Expand Down Expand Up @@ -471,7 +522,12 @@ struct Args {
const VALUE_FLAGS: &[&str] = &[
"--to",
"--sender",
"--receiver",
"--surface",
"--batch",
"--work-state",
"--agent",
"--identity",
"--groups",
"--direction",
"--kind",
Expand Down Expand Up @@ -701,6 +757,83 @@ pub fn execute(ctx: &mut Ctx, args: &[String]) -> R<Value> {
let token = owner_token(ctx)?;
client_with(ctx, &token).call("GET", &format!("/api/{token}/fleet/messages{q}"), None)
}
"pipeline" => {
let a = parse(
rest,
&["--unread"],
&[
"--kind",
"--sender",
"--receiver",
"--surface",
"--batch",
"--work-state",
"--since-id",
"--before-id",
"--limit",
"--order",
],
)?;
a.no_positional("pipeline")?;
let q = query(&[
("kind", a.last("--kind")),
("sender", a.last("--sender")),
("receiver", a.last("--receiver")),
("surface", a.last("--surface")),
("batch", a.last("--batch")),
(
"unread_only",
a.has("--unread").then(|| "true".to_string()),
),
("work_state", a.last("--work-state")),
("since_id", a.uint("--since-id")?.map(|n| n.to_string())),
("before_id", a.uint("--before-id")?.map(|n| n.to_string())),
("limit", a.uint("--limit")?.map(|n| n.to_string())),
("order", a.last("--order")),
]);
let token = owner_token(ctx)?;
client_with(ctx, &token).call("GET", &format!("/api/{token}/pipeline{q}"), None)
}
"directory" => {
let a = parse(rest, &[], &[])?;
a.no_positional("directory")?;
let token = owner_token(ctx)?;
client_with(ctx, &token).call("GET", &format!("/api/{token}/agents"), None)
}
"credentials" => {
let a = parse(rest, &[], &[])?;
a.no_positional("credentials")?;
let token = owner_token(ctx)?;
client_with(ctx, &token).call("GET", &format!("/api/{token}/fleet/credentials"), None)
}
"revoke" => {
let a = parse(rest, &[], &["--agent", "--identity"])?;
a.no_positional("revoke")?;
// Checked before any credential is resolved: a usage error
// is a usage error even on a seat with no tokens.
let target = match (a.last("--agent"), a.last("--identity")) {
(Some(agent), None) => ("fleet", agent),
(None, Some(identity)) => ("notes", identity),
_ => {
return Err(usage(
"revoke needs exactly one of --agent or --identity",
));
}
};
let token = owner_token(ctx)?;
match target {
("fleet", agent) => client_with(ctx, &token).call(
"POST",
&format!("/api/{token}/fleet/credentials/revoke"),
Some(&json!({ "agent": agent })),
),
(_, identity) => client_with(ctx, &token).call(
"POST",
&format!("/api/{token}/notes-tokens/revoke"),
Some(&json!({ "identity": identity })),
),
}
}
"hello" => {
let a = parse(rest, &[], &["--agent", "--groups"])?;
a.no_positional("hello")?;
Expand Down
70 changes: 69 additions & 1 deletion pkgs/fleet/crates/fleet-bridge/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,18 @@ fn every_verb_has_its_own_help() {
// usage — its own usage line, the shared footer, and never the
// whole-domain USAGE text.
for verb in [
"send", "agents", "log", "hello", "inbox", "post", "ack", "health",
"send",
"agents",
"log",
"pipeline",
"directory",
"credentials",
"revoke",
"hello",
"inbox",
"post",
"ack",
"health",
] {
let text = verb_usage(verb).unwrap_or_else(|| panic!("no per-verb help for {verb}"));
assert!(
Expand Down Expand Up @@ -200,6 +211,13 @@ fn usage_errors_exit_2_before_any_request() {
vec!["ack", "--agent", "a"],
vec!["ack", "--agent", "a", "0"],
vec!["log", "--limit", "many"],
vec!["pipeline", "--limit", "many"],
vec!["pipeline", "--bogus", "x"],
vec!["directory", "extra"],
vec!["credentials", "extra"],
vec!["revoke"],
vec!["revoke", "--agent", "a", "--identity", "muse/a"],
vec!["revoke", "felix"],
] {
let e = run_with(url, &s, &args, "").unwrap_err();
assert_eq!(e.exit_code(), EXIT_USAGE, "{args:?}: {e}");
Expand Down Expand Up @@ -421,6 +439,56 @@ fn ack_log_and_agents_shapes() {
);
}

#[test]
fn pipeline_directory_credentials_and_revoke_shapes() {
// #14374: the console's unified views and its revoke control, as
// owner-token calls on the bridge's own routes.
let (url, seen) = fake_bridge(|_, _, _| (200, r#"{"ok":true}"#.into()));
let s = secrets(&[(DEFAULT_BRIDGE_OWNER_TOKEN_NAME, OWNER)]);
run_with(
&url,
&s,
&[
"pipeline",
"--kind",
"command",
"--sender",
"felix",
"--unread",
"--limit",
"25",
"--order",
"desc",
],
"",
)
.unwrap();
run_with(&url, &s, &["directory"], "").unwrap();
run_with(&url, &s, &["credentials"], "").unwrap();
run_with(&url, &s, &["revoke", "--agent", "felix"], "").unwrap();
run_with(&url, &s, &["revoke", "--identity", "muse/felix"], "").unwrap();
let seen = seen.lock().unwrap();
assert_eq!(
seen[0].url,
format!("/api/{OWNER}/pipeline?kind=command&sender=felix&unread_only=true&limit=25&order=desc")
);
assert_eq!(seen[1].url, format!("/api/{OWNER}/agents"));
assert_eq!(seen[2].url, format!("/api/{OWNER}/fleet/credentials"));
assert_eq!(
seen[3].url,
format!("/api/{OWNER}/fleet/credentials/revoke")
);
assert_eq!(
seen[3].body.as_ref().unwrap(),
&json!({"agent": "felix"})
);
assert_eq!(seen[4].url, format!("/api/{OWNER}/notes-tokens/revoke"));
assert_eq!(
seen[4].body.as_ref().unwrap(),
&json!({"identity": "muse/felix"})
);
}

#[test]
fn http_errors_exit_4_and_never_show_the_token() {
let (url, _) = fake_bridge(|_, path, _| {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/fleet/crates/fleet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,8 +1075,8 @@ fn run_domain_with_initializer(
return fleet_orgs::run(&surface.config, args);
}
// The bridge domain runs for real: fleet mailboxes on the
// message bridge (central send/agents/log; agent
// hello/inbox/post/ack).
// message bridge (central send/agents/log/pipeline/
// directory/credentials/revoke; agent hello/inbox/post/ack).
#[cfg(feature = "bridge")]
if d.name == "bridge" {
return fleet_bridge::run(&surface.config, args);
Expand Down
4 changes: 4 additions & 0 deletions pkgs/message-bridge/worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ their mailbox, mark what they handled, and post replies and reports back
| `POST /api/<token>/fleet/credentials/mint` | owner | `{agent, scopes?, addr?}`: mint a credential for an agent or a service (below); the value is returned once, only its hash stored |
| `GET /fleet/<credential>/agents` | credential (`read`) | the agents list, as the owner's |
| `GET /fleet/<credential>/messages` | credential (`read`) | the fleet message log, as the owner's (`agent`, `direction`, `kind`, `since_id`, `before_id`, `limit`, `order`) |
| `GET /api/<token>/fleet/credentials` | owner | per-agent credential state: active or revoked, live scopes, service addr, mint and revocation times — never a hash |
| `GET /fleet/<credential>/pipeline` | credential (`read`) | the unified pipeline feed, as the owner's `/api/<token>/pipeline` (#14374) |
| `GET /fleet/<credential>/directory` | credential (`read`) | the unified agents list, as the owner's `/api/<token>/agents` (#14374) |
| `GET /fleet/<credential>/credentials` | credential (`read`) | per-agent credential state, as the owner's (state only: a credential can see a revocation, never make one) |
| `POST /api/<token>/fleet/offer` | owner | `{body, to, kind?, slots, sender?, ttl_seconds?}`: post an offer (below) |
| `GET /api/<token>/fleet/offers` | owner | every offer with its claims (agent, time, delivered row) |
| `POST /fleet/<fleet token>/offer` | fleet | `{agent, body, to, kind?, slots, ttl_seconds?}`: an agent posts an offer |
Expand Down
Loading