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
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ These choices fit the current `MetaProtocol`/`AccessPolicy`, `cmd_serve` listene
- `pkgs/id/src/publications.rs`
- `pkgs/id/src/commands/serve.rs`
- `pkgs/id/src/protocol.rs` and `pkgs/id/src/meta_client.rs`

## 2026-11-14 addendum (slice 3b implementation): operator identity is the local client identity

The 2026-11-04 decision said publication requests are authorized only when the authenticated caller is the serving node's own identity, with local commands connecting using that identity. The slice-3b acceptance walk showed that transport is impossible: an iroh endpoint refuses to connect to itself ("Connecting to ourself is not supported"), so a CLI presenting the node's own key can never reach its own serve process. Refinement, preserving the decision's security property (only key material on the serve host operates; remote writers never do): serve designates this machine's client identity -- the `CLIENT_KEY_FILE` keypair the access policy already trusts for local CLI/REPL work -- as its local operator, and the handler answers publication requests from the node itself (in-process) or from that designated identity. `--open-writes` and `--allow-node` identities are not operators. Recorded here and in the protocol/CLI code (PR #10410).
41 changes: 41 additions & 0 deletions pkgs/id/crates/id-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,47 @@ pub enum Command {
/// id serve --replace-defaults
/// ```
Serve(ServeArgs),
/// Publish a program (world) on the RUNNING `id serve` (#2147).
///
/// Drives the serve process's publication manager: the program
/// goes live without restarting the node, and the publication
/// persists across restarts. Exactly one placement is required:
/// `--listen ADDR` for a dedicated listener, or `--path PATH`
/// for a mount on the primary Explorer listener. A path mount
/// that shadows an Explorer route is refused unless
/// `--acknowledge-shadow` is passed. Operator-only: the command
/// connects with the serve node's own key, and fails when no
/// serve is running (it never edits local state directly).
Publish {
/// The world (program) name to publish.
world: String,
/// Publish on a dedicated listener at this address
/// (e.g. `127.0.0.1:8080`; port 0 = OS-assigned).
#[arg(long, conflicts_with = "path")]
listen: Option<String>,
/// Publish as a path mount on the primary Explorer
/// listener (e.g. `/prog`).
#[arg(long)]
path: Option<String>,
/// Acknowledge that a path mount shadows an Explorer
/// route ("I know I'm doing this").
#[arg(long)]
acknowledge_shadow: bool,
},
/// Remove a dynamic publication from the RUNNING `id serve`
/// (#2147): the listener closes or the Explorer route is
/// restored, without restarting the node.
Unpublish {
/// Unpublish the dedicated listener at this address.
#[arg(long, conflicts_with = "path")]
listen: Option<String>,
/// Unpublish the path mount at this path.
#[arg(long)]
path: Option<String>,
},
/// List the RUNNING `id serve`'s dynamic publications (#2147),
/// with live listener addresses.
Publications,
/// Start an interactive REPL for issuing commands.
///
/// The REPL provides a shell-like interface for executing multiple
Expand Down
59 changes: 59 additions & 0 deletions pkgs/id/crates/id-cli/src/cli/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,65 @@ fn test_cli_parse_list() {
}
}

#[test]
fn test_cli_parse_publish_listener() {
let cli = Cli::parse_from(["id", "publish", "arena", "--listen", "127.0.0.1:8080"]);
match cli.command {
Some(Command::Publish {
world,
listen,
path,
acknowledge_shadow,
}) => {
assert_eq!(world, "arena");
assert_eq!(listen.as_deref(), Some("127.0.0.1:8080"));
assert!(path.is_none());
assert!(!acknowledge_shadow);
}
_ => panic!("Expected Publish command"),
}
}

#[test]
fn test_cli_parse_publish_path_with_acknowledgement() {
let cli = Cli::parse_from([
"id",
"publish",
"arena",
"--path",
"/world",
"--acknowledge-shadow",
]);
match cli.command {
Some(Command::Publish {
world,
listen,
path,
acknowledge_shadow,
}) => {
assert_eq!(world, "arena");
assert!(listen.is_none());
assert_eq!(path.as_deref(), Some("/world"));
assert!(acknowledge_shadow);
}
_ => panic!("Expected Publish command"),
}
}

#[test]
fn test_cli_parse_unpublish_and_publications() {
let cli = Cli::parse_from(["id", "unpublish", "--path", "/world"]);
match cli.command {
Some(Command::Unpublish { listen, path }) => {
assert!(listen.is_none());
assert_eq!(path.as_deref(), Some("/world"));
}
_ => panic!("Expected Unpublish command"),
}
let cli = Cli::parse_from(["id", "publications"]);
assert!(matches!(cli.command, Some(Command::Publications)));
}

#[test]
fn test_cli_parse_list_remote() {
let node_id = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
Expand Down
29 changes: 28 additions & 1 deletion pkgs/id/crates/id-cli/src/commands/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,34 @@ use crate::{CLIENT_KEY_FILE, load_or_create_keypair};
pub async fn create_local_client_endpoint(
serve_info: &ServeInfo,
) -> Result<(Endpoint, EndpointAddr)> {
let client_key = load_or_create_keypair(CLIENT_KEY_FILE).await?;
create_local_endpoint_with_key(serve_info, CLIENT_KEY_FILE).await
}

/// Creates an endpoint that connects to a local serve as its
/// designated local operator (#2147 operator endpoint).
///
/// Publication control is operator-only: the serve handler answers
/// publish/unpublish/list requests only from the serving node
/// itself or the local operator identity serve designated -- this
/// machine's client identity. The local publication CLI therefore
/// presents the client keypair: an iroh endpoint cannot connect to
/// itself ("Connecting to ourself is not supported"), so the
/// node's own key cannot be the transport identity of a local
/// operator connection (learned in the slice-3b acceptance walk,
/// 2026-11-14). Holding either local key file is the operator
/// credential -- the design's trade-off, chosen over widening the
/// remote write policy to listener and route changes.
pub async fn create_local_operator_endpoint(
serve_info: &ServeInfo,
) -> Result<(Endpoint, EndpointAddr)> {
create_local_endpoint_with_key(serve_info, CLIENT_KEY_FILE).await
}

async fn create_local_endpoint_with_key(
serve_info: &ServeInfo,
key_file: &str,
) -> Result<(Endpoint, EndpointAddr)> {
let client_key = load_or_create_keypair(key_file).await?;
// The server's loopback addresses come from the lock file, so no relay and
// no address lookup (DNS, pkarr, mDNS) are needed. Using the full N0 preset
// here made every CLI command probe relays and publish this client's info
Expand Down
6 changes: 5 additions & 1 deletion pkgs/id/crates/id-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,21 @@ pub mod list;
#[cfg(feature = "sandbox")]
pub mod match_audit;
pub mod peers;
pub mod publish;
pub mod put;
pub mod repl;
pub mod send;
pub mod serve;
#[cfg(feature = "web")]
pub mod serve_publications;
pub mod tag;
pub mod text;
#[cfg(feature = "world")]
pub mod world;
pub mod writer_set;

pub use claim::cmd_claim;
pub use client::create_local_client_endpoint;
pub use client::{create_local_client_endpoint, create_local_operator_endpoint};
pub use doc::cmd_doc;
pub use find::{
PeekOptions, SearchOptions, cmd_find, cmd_find_matches, cmd_peek, cmd_search, cmd_show,
Expand All @@ -91,6 +94,7 @@ pub use list::{cmd_list, cmd_list_remote};
#[cfg(feature = "sandbox")]
pub use match_audit::cmd_match_audit;
pub use peers::{PeersOptions, cmd_peers};
pub use publish::{cmd_publications, cmd_publish, cmd_unpublish};
pub use put::{
cmd_put_hash, cmd_put_local_file, cmd_put_local_stdin, cmd_put_multi, cmd_put_one,
cmd_put_one_remote,
Expand Down
135 changes: 135 additions & 0 deletions pkgs/id/crates/id-cli/src/commands/publish.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
//! CLI publication commands (#2147 slice 3b): `id publish`,
//! `id unpublish`, `id publications`.
//!
//! These commands drive the publication manager of the RUNNING
//! `id serve` process, through the meta protocol's operator-only
//! publication requests. Two design rules (2026-11-04 decision on
//! #2147) shape everything here:
//!
//! - **Operator-only.** The connection presents this machine's
//! client keypair ([`create_local_operator_endpoint`]), which
//! serve designates as its local operator identity; the handler
//! refuses every other identity, however open the node's write
//! policy is. Holding a local key file is the credential.
//! - **Never a local fallback.** If no serve is running, the
//! command fails with an actionable error. It does NOT edit the
//! persisted registry itself and does NOT open the local stores:
//! a publication command that reports success without changing
//! the running server is exactly the failure the design forbids.

use anyhow::{Result, bail};

use crate::META_ALPN;
use crate::commands::client::create_local_operator_endpoint;
use crate::commands::serve::get_serve_info;
use crate::meta_client::{expect_ok, request_over};
use crate::protocol::{MetaRequest, MetaResponse, WirePlacement, WirePublication};

/// Publish `world` on the running serve: at `--listen ADDR` (a
/// dedicated listener) or `--path PATH` (a mount on the primary
/// Explorer listener). Exactly one placement is required.
pub async fn cmd_publish(
world: &str,
listen: Option<&str>,
path: Option<&str>,
acknowledge_shadow: bool,
) -> Result<()> {
let placement = placement_from_args(listen, path)?;
let described = describe_placement(&placement);
let publication = WirePublication {
world: world.to_owned(),
placement,
acknowledge_shadow,
};
match operator_request(MetaRequest::Publish { publication }).await? {
MetaResponse::Published { warning } => {
println!("published {world} at {described}");
if let Some(warning) = warning {
eprintln!("warning: {warning}");
}
Ok(())
}
other => bail!("unexpected response from serve: {other:?}"),
}
}

/// Remove the publication at `--listen ADDR` or `--path PATH` from
/// the running serve.
pub async fn cmd_unpublish(listen: Option<&str>, path: Option<&str>) -> Result<()> {
let placement = placement_from_args(listen, path)?;
let described = describe_placement(&placement);
match operator_request(MetaRequest::Unpublish { placement }).await? {
MetaResponse::Unpublished { success: true } => {
println!("unpublished {described}");
Ok(())
}
other => bail!("unexpected response from serve: {other:?}"),
}
}

/// List the running serve's live publications.
pub async fn cmd_publications() -> Result<()> {
match operator_request(MetaRequest::ListPublications).await? {
MetaResponse::Publications { items } => {
if items.is_empty() {
println!("no dynamic publications");
}
for item in &items {
let live = match &item.placement {
WirePlacement::Listener { .. } => match item.actual_addr {
Some(actual) => format!(" (live at {actual})"),
None => " (not live)".to_owned(),
},
WirePlacement::PathMount { .. } => String::new(),
};
println!(
"{} at {}{}",
item.world,
describe_placement(&item.placement),
live
);
}
Ok(())
}
other => bail!("unexpected response from serve: {other:?}"),
}
}

fn placement_from_args(listen: Option<&str>, path: Option<&str>) -> Result<WirePlacement> {
match (listen, path) {
(Some(addr), None) => Ok(WirePlacement::Listener {
addr: addr
.parse()
.map_err(|error| anyhow::anyhow!("invalid --listen address {addr:?}: {error}"))?,
}),
(None, Some(path)) => Ok(WirePlacement::PathMount {
path: path.to_owned(),
}),
_ => bail!("exactly one placement is required: --listen ADDR or --path PATH"),
}
}

fn describe_placement(placement: &WirePlacement) -> String {
match placement {
WirePlacement::Listener { addr } => format!("listener {addr}"),
WirePlacement::PathMount { path } => format!("path {path}"),
}
}

/// Send one publication request to the running serve, as the
/// operator. Fails (never falls back) when no serve is running.
async fn operator_request(req: MetaRequest) -> Result<MetaResponse> {
let Some(info) = get_serve_info().await else {
bail!(
"no `id serve` is running for this data directory — publication \
commands drive the running serve process and never edit local \
state directly; start one with `id serve --web` first"
);
};
let (endpoint, addr) = create_local_operator_endpoint(&info).await?;
let conn = id_core::connectivity::connect(&endpoint, addr, META_ALPN).await?;
let response = request_over(&conn, &req).await;
conn.close(0u32.into(), b"done");
endpoint.close().await;
expect_ok(response?)
}
Loading