feat(relay): NIP-98 admin auth with Operator/Moderator roles and NIP-11 discovery - #3777
Open
wpfleger96 wants to merge 6 commits into
Open
feat(relay): NIP-98 admin auth with Operator/Moderator roles and NIP-11 discovery#3777wpfleger96 wants to merge 6 commits into
wpfleger96 wants to merge 6 commits into
Conversation
wpfleger96
force-pushed
the
wpfleger/admin-api-bearer-auth
branch
3 times, most recently
from
July 31, 2026 19:17
3fcbdc0 to
d014e40
Compare
kalvinnchau
previously approved these changes
Jul 31, 2026
kalvinnchau
left a comment
Contributor
There was a problem hiding this comment.
Re-reviewed at d014e40. The fail-closed config contract, constant-time bearer validation, host/origin ordering, insecure network-boundary mode, dashboard token lifecycle, authenticated attachment fetches, and CSP/static routing are coherent and covered. Deployment dependency is external: land bb-public#339 and wait for Argo rollout before deploying this relay image.
wpfleger96
force-pushed
the
wpfleger/admin-api-bearer-auth
branch
from
August 3, 2026 19:40
d014e40 to
e93d5be
Compare
wpfleger96
force-pushed
the
wpfleger/admin-api-bearer-auth
branch
2 times, most recently
from
August 3, 2026 20:22
9d54f68 to
1682a5e
Compare
…IP-98 auth Gate the relay admin moderation API (/api/admin/v1) behind explicit authentication configuration selected by BUZZ_ADMIN_AUTH: token (default), disabled, or nip98. In nip98 mode every request carries a signed kind-27235 NIP-98 event; the authenticated pubkey resolves to an OPERATOR or MODERATOR principal from RELAY_OPERATOR_PUBKEYS, the RELAY_OWNER_PUBKEY fallback, or the relay_operators table. Replaces the BUZZ_ADMIN_INSECURE_NO_AUTH bypass with a role model that is revocable without rotating a shared secret and fails closed at every boundary. Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Desktop had no way to discover the admin API endpoint and forced users to type its URL by hand. Advertise the canonical admin origin (scheme://host[:port], no path) in the NIP-11 relay-information document under an optional admin_api field, present iff the admin surface is configured (config.admin.is_some()). Extract the loopback scheme rule into a shared scheme_for_host helper so the advertised origin and the NIP-98 u-tag the relay verifies can never use different schemes; a test enforces the invariant. The helper now parses IPv6 authorities (bracketed [::1]:3000 and bare ::1) correctly instead of letting a colon-split mangle them. Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
RELAY_OPERATOR_PUBKEYS is the shared allowlist for both the NIP-98 admin console and the community-provisioning endpoints, but only provisioning needs RELAY_OPERATOR_API_ORIGIN. The boot hard-error forced admin-console operators to configure a provisioning surface they never use. Demote the boot error to a WARN naming the affected feature, and keep the provisioning endpoints fail-closed at request time: authorize_operator_request already rejects with a clean 500 when the origin is unset, before any replay or DB access. Document the decoupling and the NIP-11 admin_api advertisement in the env examples and the admin README. Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
wpfleger96
force-pushed
the
wpfleger/admin-api-bearer-auth
branch
from
August 11, 2026 00:19
5527704 to
1cdc816
Compare
A bare IPv6 admin host (BUZZ_ADMIN_HOST=::1) passed authority validation but then interpolated unbracketed into the NIP-11 admin_api advertisement and the NIP-98 u-tag canonical URL, yielding http://::1 — which no URL parser accepts (an IPv6 authority must be bracketed per RFC 3986). Desktop discovery rejected it and no client could match the malformed signed URL. Reject the shape at config parse with an error naming the required bracketed form, matching the documented exact-authority contract. This makes the unbracketed multi-colon branch in scheme_for_host dead, so drop it. Replace the auth.rs assertions that pinned http://::1 as expected output with parseability tests; keep the advertised-vs-verified scheme-consistency invariant. Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
…g parse
The bare-IPv6 bracket guard names the honest `::1` shape but skips
unclosed-bracket typos like `[::1` and `[::1:3000` — they start with
`[`, pass the guard, then interpolate into an unparseable
`http://[::1` NIP-11 advertisement and NIP-98 u-tag URL. Same defect
class as the bare-IPv6 case, just a typo shape.
Add a catch-all after the bracket guard: url::Url::parse("http://{host}")
must succeed, else reject with an error naming the host. This is a
validity gate only — the host is still stored verbatim, not normalized.
It kills every malformed authority in one guard, including shapes not
enumerated. url is already a buzz-relay dep.
Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
…parseable
The parse-only catch-all proved the whole `http://{host}` string is a
valid URL but not that {host} is exactly an authority. Query and fragment
delimiters are legal URL characters and were not in the forbidden set, so
`admin.example.com?x=1` and `[::1]#frag` passed startup: the suffix parsed
as query/fragment, then canonical_url appended the admin path after it
(`http://admin.example.com/?x=1/api/admin/v1/reports`), corrupting both the
NIP-11 advertisement and the NIP-98 u-tag URL — the same accepted-config/
unusable-URL class as the bare-IPv6 defect.
Validate the parsed sentinel structurally, mirroring parse_operator_api_origin:
host present, no credentials, path `/`, no query, no fragment. Any non-authority
character now lands in one of those and is rejected. Host still stored verbatim.
Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the
BUZZ_ADMIN_INSECURE_NO_AUTHinsecure-flag model with a two-tier principal model (Operator/Moderator) backed by a config-union-plus-DB roster and gated by NIP-98 HTTP auth, and adds NIP-11 auto-discovery so clients never have to type the admin URL by hand.Authentication (
BUZZ_ADMIN_AUTH)Replaces the deleted
BUZZ_ADMIN_INSECURE_NO_AUTH=truevariable withBUZZ_ADMIN_AUTHacceptingtoken(default),disabled, ornip98. Startup fails closed on missing or malformed configuration; any unrecognized value or conflicting combination aborts startup.Host/Originmatching is retained in all modes as defense-in-depth.Principal resolution (NIP-98 mode)
resolve_admin_principal()returnsAdminPrincipal { pubkey, role, source }:Operator/Config— pubkey is inRELAY_OPERATOR_PUBKEYSOperator/OwnerFallback— pubkey equalsRELAY_OWNER_PUBKEYandRELAY_OPERATOR_PUBKEYSis empty (config-evaluated, never from runtime DB rows)OperatororModerator/Db— row in therelay_operatorstable403Config always outranks DB, and
Nonenever falls through as a role. A malformedRELAY_OWNER_PUBKEYalongsidenip98is a startup error, since the owner key can be a break-glass root and silently discarding it would be a lockout.Token and disabled modes
Read routes work in all modes. Mutation and staffing routes require
nip98; token and disabled modes receive403fromrequire_mutation_principal.disabledmode logs aWARNon every boot and relies entirely on network-layer controls.Report resolution and feedback
POST /reports/{id}/resolveis an enforcement state machine with idempotency:dismiss/escalate): CAS open→terminal plus an audit row in one transaction.delete/kick/ban/timeout): claims the report (open→processing), runs the durable mutation, then finalizes toresolved. Crash-safe — re-drive resumes at the step marker and converges to exactly-one enforcement, fenced by a lease and a claim token on the outbox.PATCH /feedback/{id}updatesproduct_feedback.status(new/reviewed/archived); requiresnip98.Staffing endpoints
GET/PUT/DELETE /operators/{pubkey}are Operator-only.PUT/DELETEagainst a config-backed pubkey returns409 Conflict.GET /operatorsreturns the union of config and DB principals with per-entrysourceattribution.Probe endpoint
GET /probereports auth mode, role, source,canAct, andcanStafffor the desktop console.NIP-11 admin-API auto-discovery
The NIP-11 relay-information document gains an optional
admin_apifield carrying the canonical admin origin (scheme://host[:port], no path), present iff the admin surface is configured (BUZZ_ADMIN_HOSTset) and omitted entirely otherwise. The scheme follows the same loopback rule as NIP-98u-tag verification (httpforlocalhost/127.x/::1, elsehttps), extracted into a sharedscheme_for_hosthelper so the advertised origin and the origin the relay verifies against can never diverge. Clients read this to auto-discover the admin console instead of requiring manual URL entry.Loopback example:
{ "admin_api": "http://127.0.0.1:3000" }Operator API origin decoupling
RELAY_OPERATOR_API_ORIGINis no longer required at boot whenRELAY_OPERATOR_PUBKEYSis set. The allowlist is shared by the NIP-98 admin console (which needs no origin) and the community-provisioning endpoints (which do). Configuring the admin console no longer drags in an origin the operator does not use: the relay logs aWARNnaming the affected feature, and the provisioning endpoints (POST /operator/communities) fail closed at request time —authorize_operator_requestrejects with a clean500before any replay or DB access — untilRELAY_OPERATOR_API_ORIGINis set.Migrations
0029_relay_operators.sql—relay_operatorstable (deployment-global; registered in_operator_global_tables),actor_authorityonmoderation_actions,processingstatus plusactive_action_idonmoderation_reports,statusonproduct_feedback.0030_relay_admin_actions.sql—relay_admin_actionsenforcement-action table with arequest_ididempotency key and astep_markerfor crash recovery.0031_relay_admin_action_lease.sql— lease fencing for the action worker.0032_relay_admin_outbox_claim_token.sql— fenced claim token on the outbox worker.Documentation
docs/admin/README.mddocuments the full principal model, NIP-98 event requirements (query string, method tag, payload tag for body mutations), owner-fallback semantics, role/source table, capabilities by role, roster management, the startup error matrix, the NIP-11 auto-discovery field, and the origin decoupling..env.exampleanddeploy/compose/.env.exampledescribeRELAY_OPERATOR_API_ORIGINand the admin console/provisioning split.Related: block/buzz#4768 (desktop admin console consuming the
admin_apifield), squareup/bb-public#339 (Phase 4 rollout config)