buzz icon indicating copy to clipboard operation
buzz copied to clipboard

NIP-29 member/admin lists silently omit the relay's own pubkey, making channels permanently unjoinable

Open jamiedewar opened this issue 3 months ago • 3 comments

Summary

If BUZZ_RELAY_PRIVATE_KEY is set to the key of an identity that is also a community member, that member is silently excluded from every kind:39002 (members) and kind:39001 (admins) event the relay emits — even though the row exists and is correct in channel_members.

Clients that derive "am I in this channel?" from kind:39002 therefore render a Join button for a user who is already a member (in our case the community owner). Clicking Join can never succeed (second bug, below), so the channel is permanently unjoinable from the UI with no error shown.

Environment

  • buzz relay 0.2.0, ghcr.io/block/buzz:main, revision 5e0efb0bb95182f588390b55cc5affa09114c87e
  • Postgres 17, self-hosted deploy/compose
  • BUZZ_REQUIRE_RELAY_MEMBERSHIP=true, NIP-42 auth required

Impact

Community owner could not join or appear in any channel. Every kind:39001 admin list was empty despite an active owner row existing for each channel.

Reproduction

  1. Set BUZZ_RELAY_PRIVATE_KEY to the private key of identity X.
  2. Create a community where X is also owner in channel_members.
  3. Trigger emit_group_discovery_events (add a member, or delete the kind:39000 and start with BUZZ_RECONCILE_CHANNELS=true).
  4. Inspect the emitted kind:39002 / kind:39001.

Expected: X present with role owner. Actual: X absent from 39002; 39001 empty.

Evidence that the exclusion is identity-specific

I inserted a throwaway member into channel_members with role owner and a joined_at earlier than X's row, then regenerated:

39001 → [["d",…],["p","deadbeef…deadbeef","owner"]]
39002 → [["d",…],["p","deadbeef…deadbeef","","owner"],
                 ["p","<other member>","","member"],
                 ["p","<bot>","","bot"]]

The throwaway owner appears, and appears first. X still does not. This rules out:

  • an owner-role filter — the throwaway is owner and appears; kind:39002 has no role filter at all, yet X is missing from it too
  • an off-by-one / skip-first-row bug — the throwaway sorts first by joined_at and appears

The only distinguishing property of X is that it is the relay's signing key.

Also ruled out: the DB itself (running the exact get_members query from buzz-db/src/channel.rs:689 returns X with role owner), a stale membership cache, row-level security, a duplicate schema/database, a dirty working tree, and an image/source mismatch (the image's org.opencontainers.image.created is ~90s after the commit it claims).

I could not locate the code performing the exclusion. emit_group_discovery_events (buzz-relay/src/handlers/side_effects.rs:1045) contains no such filter — relay_pubkey_hex (line 1053) is only passed through as the signing author, and the kind:39002 loop (line 1141) iterates all members unconditionally. replace_addressable_event persists serde_json::to_value(&event.tags) verbatim. So the behaviour is empirically reproducible but the mechanism is unidentified; a pointer from someone who knows the code would be very welcome.

Resolution on our side

Generating a dedicated relay keypair distinct from any human identity, then regenerating group state, fixed it completely — X now appears as owner in every list.

Suggested fixes

  1. Validate at startup: fail, or at minimum warn loudly, when relay_keypair.public_key() == relay_owner_pubkey. Today this can't happen structurally: bootstrap_owner runs at main.rs:321, roughly 100 lines before the keypair is parsed at main.rs:419. The misconfiguration is easy to make and fails silently and confusingly.
  2. Document that BUZZ_RELAY_PRIVATE_KEY must never be a human's key.

Second, compounding bug: kind:9021 join on an existing member is a silent no-op

handle_join_request (side_effects.rs:1930):

if state.is_member_cached(tenant.community(), channel_id, &actor_bytes).await? {
    info!(channel = %channel_id, "kind:9021 join — already a member, skipping");
    return Ok(());
}

This returns before emit_group_discovery_events (line 1988). The event was already stored, so the client still receives ["OK", <id>, true, ""]. Side-effect errors are only logged, never surfaced (ingest.rs:2829).

Consequence: whenever a member list is stale or wrong for any reason, Join becomes a dead button — no state change, no re-emit, no error, indefinitely. Our owner clicked it 7 times; all 7 requests are in the DB, all silently no-oped.

This is compounded by reconcile_channel_events (side_effects.rs:3054), which only re-emits when a kind:39000 is entirely absent (if existing.is_empty(), line 3090). A channel with a valid 39000 but a stale 39002 is never repaired — and reconcile only runs under BUZZ_RECONCILE_CHANNELS at all.

Suggested fix: on the already-a-member path, re-emit the discovery events (or at least kind:39002) before returning. It's idempotent and makes Join self-healing. Optionally, have reconcile compare 39002 p tags against channel_members instead of only checking whether a 39000 exists.

jamiedewar avatar Aug 04 '26 21:08 jamiedewar

Confirmed independently in my self-hosted deployment. This was also the root cause of #3796.

After separating BUZZ_RELAY_PRIVATE_KEY from the human/community owner identity, soft-deleting the stale 39000/39001/39002 discovery events, and running buzz-admin reconcile-channels, all five regenerated administrator and membership lists contained the owner correctly.

Buzz Desktop now retains every channel after a complete restart, identifies me as owner, allows normal participation, and preserves new messages. I posted the complete before/after evidence and repair procedure in #3796.

Thank you, @jamiedewar—your report supplied the decisive missing explanation and resolved an issue we had been persistently troubleshooting.

irlcdn avatar Aug 05 '26 03:08 irlcdn

Independent reproduction on a different deployment path, plus one extra detail about the fix that cost us an hour.

Still present on current main

  • Image: ghcr.io/block/buzz:sha-02f640b (newest main at time of writing), amd64
  • Postgres 17, Redis 7, MinIO — deployed from the Railway template, not deploy/compose

Worth flagging: the Railway one-click template sets BUZZ_RELAY_PRIVATE_KEY to the deploying user's own identity key by default. So this isn't only reachable by hand-configuring a relay — the template ships the misconfiguration, and the operator has no reason to suspect it.

Confirmed the collision with:

select distinct encode(pubkey,'hex') from events where kind in (39000,39001,39002);
-- 2ea357fd…  ← identical to RELAY_OWNER_PUBKEY and to the owner's channel_members row

A different user-visible symptom

We didn't see a stuck Join button. We saw every private channel silently disappear from the sidebar, while open channels stayed visible.

The path: Desktop resolves a user's channels via {"kinds":[39002], "#p":[my_pubkey]} (desktop/src-tauri/src/commands/channels.rs), finds nothing because the owner is omitted, sets isMember: false, and AppShell.tsx's channels.filter((channel) => channel.isMember) drops them. Open channels render without membership, so the failure looks selective — it reads as data loss affecting only the channels you created, which is a very misleading trail. Rows in channels and channel_members were intact throughout, nothing archived or deleted, and the client's own buzz-channels.v1 cache held all five.

Also confirming your finding that this is identity-specific rather than role-based, from the other direction: we flipped the owner's channel_members.role to admin and then to member and regenerated each time. Still excluded. Bots in the same channels are tagged normally.

Counts before → after rotating to a dedicated relay keypair (p tags per kind:39002):

channel before after
welcome-everyone (owner is the only member) 0 1
general 1 2
Media room 1 2
Welcome 3 4
Cntinue dev 3 4

Every channel gained exactly one entry: the owner.

Extra detail: rotating the key leaves both event sets live

Your resolution works, but there's a step that isn't obvious. Addressable events are keyed by (kind, pubkey, d-tag), so regenerating under a new signing key does not replace the old events — it creates a parallel set. We briefly had two live kind:39002 per channel, one correct and one stale, and clients could still act on the stale one.

The old set has to be retired explicitly:

update events set deleted_at = now()
 where kind in (39000,39001,39002) and deleted_at is null
   and pubkey = decode('<old relay pubkey hex>','hex');

Also note buzz-admin reconcile-channels skips any channel that already has a live kind:39000, so the live 39000 rows need soft-deleting first or it reports "already had events" and does nothing.

Supporting the startup-validation suggestion

Your suggested fix 1 would have saved us a full day of misdiagnosis — we suspected client cache, then relay/client version skew, and even upgraded the relay before finding this issue. A startup check comparing relay_keypair.public_key() against RELAY_OWNER_PUBKEY (or against any channel_members row) would turn a silent, badly-signposted failure into one line in the boot log.

JVPartanen avatar Aug 08 '26 07:08 JVPartanen

Rechecked against main at c213d90d5c450e2e579505da4a4145f528ecbcf2. There is an important distinction between the signing-path fix and the proposed startup policy (source inspection only; I have not reproduced this against a running relay).

  • The current 39002 writer now explicitly uses allow_self_tagging(). Its comment explains the missing mechanism: nostr's default builder strips p tags matching the signer. It also documents a legitimate relay-member topology: moderation DMs. This addresses the stripping mechanism in that writer, not necessarily already-stored discovery events or every other writer.
  • The generic discovery signer, still used for 39001, lacks that opt-in. Draft #5395 already changes this exact path and the admin tool, as well as reconciliation, so a separate fix would overlap. Redundant-join repair is already proposed in #4277/#3847; completeness probing in #4039. #4300 is now closed, unmerged.
  • The startup-order premise has changed: key loading now precedes owner bootstrap. I found no owner-versus-derived-signer equality check in current startup/config code, nor one in the inspected PRs.

The still-unclaimed policy decision is specifically whether RELAY_OWNER_PUBKEY == derived_public_key(BUZZ_RELAY_PRIVATE_KEY) should be prohibited—not whether the relay may ever be a channel member. Could maintainers choose fail startup, warn and continue, or permit equality once signing paths preserve the roster, and specify whether the rule applies universally or only to membership-enforced deployments (including any dev exception)? A blanket check against any channel member would conflict with the moderation-DM path above.

Once that contract is settled, a focused startup/config regression can cover equal/distinct identities and the agreed scope without duplicating discovery repair work.

maxitoon avatar Sep 22 '26 20:09 maxitoon