Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(gl): surface the node's refusal instead of reporting a peer add t…
…hat did not happen

The announce route now answers 403 when an unproven caller tries to
repoint an existing peer. gl peer add discarded the local node's reply
with let _ and printed the success line unconditionally, so a refused add
reported as a completed one. The refusal is split into a small function so
the path is assertable, and it is tested for a 403 with a message, a
refusal with no body, and the accepted case. The local add stays best
effort: a transport failure warns rather than failing the command, which
is what the surrounding code already assumed.

The README described the staged rollout as accepting unsigned peers on
these routes, which is no longer the whole rule. With signed peer writes
off, an unsigned announce may still register an unseen peer and refresh a
row whose URL is unchanged, but changing an existing peer's http_url needs
a signature from that peer's own DID, and only a did:key can be registered
unsigned.
  • Loading branch information
beardthelion committed Aug 4, 2026
commit b6ebaa4b1e4a3f09ac694450122027a296caef13
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ POST /api/v1/peers/announce
POST /api/v1/sync/notify
```

When `GITLAWB_REQUIRE_SIGNED_PEER_WRITES=false`, unsigned legacy peers are accepted on those two routes, but signed requests are verified when signature headers are present. Once all live peers upgrade, operators can set:
When `GITLAWB_REQUIRE_SIGNED_PEER_WRITES=false`, unsigned legacy peers are accepted on those two routes, but signed requests are verified when signature headers are present. Staged rollout relaxes who may announce, not who owns a peer row. An unsigned announce may register a previously unseen peer, and it may refresh an existing row whose `http_url` is unchanged, but changing an existing peer's `http_url` requires an RFC 9421 signature from that peer's own DID and is refused with 403 otherwise. An unsigned announce can only register a `did:key`, since that is the only method whose verifying key can be resolved and therefore the only kind of row anyone could ever correct through the signed path; any other DID is refused with 400. Once all live peers upgrade, operators can set:

```bash
GITLAWB_REQUIRE_SIGNED_PEER_WRITES=true
Expand Down
76 changes: 73 additions & 3 deletions crates/gl/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ async fn cmd_list(node: String) -> Result<()> {
Ok(())
}

/// The warning text for a local peer-add reply, or `None` when the node
/// accepted it.
///
/// Split out so the refusal path is assertable. The node now answers 403 when
/// an unproven caller tries to repoint an existing peer's `http_url`, so a
/// reply that arrived and refused must not reach the success line.
fn local_add_refusal(status: reqwest::StatusCode, body: &Value) -> Option<String> {
if status.is_success() {
return None;
}
let msg = body["message"].as_str().unwrap_or("unknown error");
Some(format!(
"warning: local peer list not updated ({status}): {msg}"
))
}

async fn cmd_add(peer_url: String, node: String, dir: Option<PathBuf>) -> Result<()> {
let keypair = load_keypair_from_dir(dir.as_deref())?;
let my_did = keypair.did().to_string();
Expand Down Expand Up @@ -150,9 +166,24 @@ async fn cmd_add(peer_url: String, node: String, dir: Option<PathBuf>) -> Result
"did": their_did,
"http_url": their_url,
}))?;
// This requires the local node to be running; ignore errors here
let _ = local_client.post("/api/v1/peers/announce", &add_body).await;
println!(" Added to local peer list.");
// This requires the local node to be running, so a transport failure
// stays a warning rather than failing the command. A reply that
// ARRIVED and refused is different: the announce route answers 403
// when an unproven caller tries to repoint an existing peer, and
// printing the success line over that reports a completed add that
// never happened. Same status handling as the remote announce above,
// except best effort.
match local_client.post("/api/v1/peers/announce", &add_body).await {
Ok(resp) => {
let status = resp.status();
let result: Value = resp.json().await.unwrap_or(Value::Null);
match local_add_refusal(status, &result) {
Some(warning) => eprintln!("{warning}"),
None => println!(" Added to local peer list."),
}
}
Err(e) => eprintln!("warning: local peer list not updated: {e}"),
}
}

Ok(())
Expand Down Expand Up @@ -210,3 +241,42 @@ async fn cmd_resolve(did: String, node: String) -> Result<()> {
}
Ok(())
}

#[cfg(test)]
mod tests {
use super::local_add_refusal;
use reqwest::StatusCode;
use serde_json::json;

/// The node's 403 for repointing an existing peer must surface, not print
/// as a completed add. Without the status check the command prints "Added
/// to local peer list." over a refusal.
#[test]
fn a_refused_local_add_warns_with_the_node_reason() {
let warning = local_add_refusal(
StatusCode::FORBIDDEN,
&json!({ "error": "forbidden", "message": "peer http_url change requires a signature from that peer" }),
)
.expect("a refusal must not render as success");

assert!(warning.contains("403"), "must name the status: {warning}");
assert!(
warning.contains("requires a signature"),
"must carry the node's own reason: {warning}"
);
}

/// A refusal with no message body still warns rather than passing silently.
#[test]
fn a_refusal_without_a_message_still_warns() {
let warning = local_add_refusal(StatusCode::BAD_REQUEST, &serde_json::Value::Null)
.expect("a refusal must not render as success");
assert!(warning.contains("400"), "must name the status: {warning}");
}

/// The accepted case stays quiet, so the success line still prints.
#[test]
fn an_accepted_local_add_produces_no_warning() {
assert!(local_add_refusal(StatusCode::OK, &json!({ "peer_count": 3 })).is_none());
}
}