Discord: self-serve server→org linking with /drb link (#213 item 1) #218
No Reviewers
Labels
Clear labels
area/ai-pipeline
area/auth
area/billing
area/correlation
area/discord
area/frontend
area/governance
area/growth
area/infra-deploy
area/legal
area/map
area/mqtt
area/node-ota
area/osint
area/recording-audio
area/sdr-radio
area/transcription
board
board:agenda
minutes:draft
minutes:final
role:ceo
role:cfo
role:cio
role:ciso
role:cmo
role:coo
role:cto
Scene/entity extraction, summarizer, AI providers, embeddings
AuthN/Z, roles, tenancy/org scoping, API keys, credentials
Plans, entitlements, AI spend accounting and caps
Incident correlation, linking, lifecycle, severity, corr_debug
Discord bot, radio bots, voice streams, bot tokens, webhooks
Web UI: Next.js app and the edge-node local dashboard
Board process, minutes, unattended runner, agent tooling
Go-to-market, outreach, cold email, discovery conversations
CI/CD, VM, registry, Firestore rules/indexes deploy, Terraform/Caddy
ToS, retention, licences/DAAs, CAN-SPAM, E&O, name suppression
Live map: pins, paths, tiles, legend, geocoding
Node-C2 MQTT, checkins, commands, node sweeper, dynsec
Node install, enrollment, OTA updater, image skew
External feeds: cameras, 511, ADS-B, AIS, outages, and their licences
Call capture, boundaries, PulseAudio, ring buffer, trimming, attribution
OP25 decode, SDR hardware/tuning, conventional, second SDR, mesh radio
STT, transcript correction, place verification, name accuracy
Board process: minutes and board-filed items
Needs board scoping at the next sitting; CEO removes the label once scoped
One exec pre-read, closed by CEO
CEO ruling; open until enacted
Filed by the CEO
Filed by the CFO
Filed by the CIO
Filed by the CISO
Filed by the CMO
Filed by the COO
Filed by the CTO
kind
behavior-bug
Wrong product behavior; the instrument reads it correctly
kind
measurement-bug
Corrupts the recording/instrument (debug data, evals, health checks), not behavior
priority
p0
Drop everything: prod broken, live exposure, or owner-ruled P0
priority
p1
Next up: blocks a gate, a customer, or core incident quality
priority
p2
Normal: real defect or planned work, schedule in turn
priority
p3
Low: minor, cosmetic, or someday
status
blocked
Waiting on an external party, spend, or another issue
status
in-progress
Branch or PR open against it
status
needs-decision
Waiting on an owner or board ruling before work
status
needs-info
Root cause or repro unknown; needs a reading first
type
bug
Something built is wrong: code, data, or a measurement
type
chore
Maintenance, refactor, tests, pinning, cleanup: no user-visible change
type
decision
A ruling to make or record: board minutes, owner calls, legal reviews
type
docs
Docs, runbooks, CLAUDE.md, skills, SOPs
type
feature
New capability or an extension of an existing one
type
security
Security, privacy, credential or tenant-isolation exposure
type
tracking
Tracker, checklist, initiative or punch-list spanning several changes
No labels
Milestone
No items
No Milestone
Projects
Clear projects
No projects
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: logan/server-26#218
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Slice B of server-26#213 — item 1: self-serve Discord server → org linking. Refs #213 (items 2–4 are sibling slices; this PR pairs with the #213 admin-page / node-join / systems-picker PRs, and only touches a shared file additively:
drb-frontend/lib/c2api.ts, plus a 4-line change indiscord_streams.resolve_guild_org).What changed
c2-core (new
routers/discord_link.py,internal/discord_guild_link.py)POST /discord/link-codes— org owner / platform admin mints a code (XXX-XXXX-XXX, 10 chars over a 31-symbol unambiguous alphabet, 10-min TTL, single use). Minting revokes the org's older unredeemed codes.POST /discord/guilds/{guild_id}/link/redeem— Discord bot only (service key). One Firestore transaction reads the code + guild docs before writing, so two servers racing for one code → exactly one wins, and a server linked to org A refuses org B's code (409) until A unlinks it.GET /discord/linked-guilds,DELETE /discord/linked-guilds/{id}— the caller's org's servers; unlink stops that server's radio channels._RateLimiter): mint 5/user/10 min; redeem 5/server and 10/Discord user per 10 min.write_auditon every mint (discord.link_code.create), link (discord.guild.link), refusal (discord.guild.link_refused, with reason), unlink (discord.guild.unlink). Redeemer stored as a Discord user id only — no usernames.resolve_guild_org: a server an org explicitly unlinked no longer falls back toDISCORD_UNLINKED_GUILD_ORG_ID(otherwise unlinking org B's server would hand it to the founding org). Linking a server away from the fallback org stops the streams it had playing for that org.Discord bot
/drb link code:(newcommands/drb.py) —default_permissions(manage_guild)and a runtime Manage Server check (server admins can re-grant default perms under Integrations).GatedTree(internal/guild_gate.py): in an unlinked server every command except/drb linkand/helpis answered with how to link; autocomplete returns nothing. Discord registers commands globally, so they still appear in the picker — per-guild sync would hide them but costs a sync per server per change; C2 refuses unlinked requests regardless, so the gate is UX, C2 is enforcement. C2 unreachable → command runs and reports that itself./helpgains a/drb linkentry.Frontend — Settings → Organization → Linked Discord servers card (matches the mockup's Servers panel): Generate link code → code + live countdown + copy
/drb link code:…; polls every 5 s while the code is live and shows "Linked " when it lands; table of linked servers with Unlink. Plan / incident-forum / roles / limits columns from the mockup are omitted — nothing backs them yet. Every button hits a real endpoint.DISCORD_UNLINKED_GUILD_ORG_ID— back-compatDefault stays
founding: every unlinked server keeps acting for the founding org and nothing is gated — today's deployment is unchanged by this merge.Set it to
""once every Discord server that should keep working has been linked (via/drb link, or adminPUT /discord/guilds/{id}/link). From then on an unlinked server sees only/drb linkand/help. The org settings card tells a platform admin which mode is live (unlinked_guilds_restricted).Verification (real runs)
~/venvs/drb-5c/bin/python -m pytest -qin drb-c2-core: 624 passed (16 new intests/test_discord_guild_link.py: single-use, two-server race, one-server/two-org race — both assert the race actually retried — expiry, revoked/malformed codes, wrong-org takeover, idempotent same-org relink, mint/redeem rate limits, member can't mint, fallback-org stop, scoped list, unlink never falls back).npx tsc --noEmit(Node 20.20.2): exit 0.drb-server-discord-bot; import-checked with discord.py 2.7.1 and droveGatedTree.interaction_checkagainst the real loaded command tree (unlinked:/drb link+/helpallowed,/joinblocked with the link text, autocomplete →[]; linked → allowed; C2 down → allowed; DMs → allowed). Not run against a live Discord gateway.Not in this PR
/tripand the account/linkare also gated in unlinked servers (the spec's "only /drb link and /help"). With the default fallback set this changes nothing.🤖 Generated with Claude Code
- c2-core: POST /discord/link-codes (org owner/admin) mints a single-use, 10-minute code; minting revokes the org's older codes. The bot redeems it via POST /discord/guilds/{id}/link/redeem (service key) inside one Firestore transaction, so two servers racing for one code cannot both win and a server linked to org A refuses org B's code. GET/DELETE /discord/linked-guilds lists/unlinks the caller's org's servers; unlink stops that server's streams. Rate-limited (mint per user, redeem per server and per Discord user); every mint/link/refusal/unlink audited. - resolve_guild_org: an explicitly unlinked server no longer falls back to DISCORD_UNLINKED_GUILD_ORG_ID. Linking away from the fallback org stops the streams it had running for that org. - Discord bot: /drb link code: (Manage Server, enforced at runtime too); GatedTree answers every other command in an unlinked server with how to link (autocomplete returns nothing). With the default fallback org set, nothing is gated — unchanged behaviour. - Frontend: "Linked Discord servers" card on Settings -> Organization — generate code with countdown + copy, polls for the new link, unlink. - 16 tests: single-use, two-server race, one-server/two-org race, expiry, revoked/malformed codes, wrong-org takeover, idempotent relink, rate limits, fallback stop, scoped list, unlink without fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>