Files
buzz/crates
Will Pfleger cb4a83a406 feat(relay): add percentage-based NIP-FI enforcement rollout in shadow mode (#9758)
Adds `BUZZ_NIP_FI_ENFORCE_PERCENT`, a permanent operator setting for
moving a relay from `shadow` to `enforce` in stages. While the relay
runs in `shadow`, it enforces NIP-FI for a stable, growing share of
communities (integer 0-100, default 0, read at startup). Operators raise
it in steps, watch denials, then switch to `BUZZ_NIP_FI_MODE=enforce`,
where the setting has no effect. Unset, behaviour is unchanged.

- **Cohort:** a community is in when `rollout_bucket(id) < percent`. The
bucket is SHA-256 over the UUID's 16 RFC 4122 big-endian bytes, first 8
bytes as a big-endian `u64`, mod 100. Cohorts are nested as the
percentage rises and stable across renames. Golden vectors freeze the
hash.
- **One helper:** `NipFiRelayConfig::policy_required(id, stored)`
returns `stored || in_rollout`, and only shadow mode widens it;
`NipFiRelayConfig::effective_mode(id, stored)` applies it to the relay
mode. They feed every field of the three `Policy` constructions
(`resolve`, `bind_for_upgrade`, and live-socket revalidation), so a
rollout community gets the same admission, upgrade, NIP-11
`requires_nip_fi`, binding check, `configured_mode` and deny-map guard
as a stored-Required one. `Policy::stored_required` is renamed
`policy_required` to match.
- **Stored policy stays raw:** the host cache, `CommunityAuthPolicy`,
stored-policy writes, the upgrade drain and the CAS/receipt fields don't
change. Operator `effective_required` reports the derived requirement
through `effective_mode`.
- **Validation:** a malformed or out-of-range value refuses startup in
every mode. Outside shadow the setting has no effect.
- **Precedence:** a community stored Required always enforces, at any
percentage, so lowering the percentage never stops it. A community
stored Optional that falls inside the cohort can't opt out: a stored
disable succeeds but enforcement stays on, and the only way to drop it
is to lower the percentage to its bucket or below, which also drops
every community in a higher bucket.
- **Logging:** the `nip-fi enforce deny` and `nip-fi enforce session
end` lines move to target `buzz_relay::nip_fi_enforce`, so a log filter
can keep real denials while suppressing shadow would-deny volume.
Startup logs one `NIP-FI config loaded` info line (target `buzz_relay`)
with `mode` and `enforce_percent`, so pods running different percentages
during a rollout show up in log search.
- **Docs:** `docs/operator-nip-fi-bindings.md` gains a "Staged enforce"
runbook step between Shadow and Enforce, with go/no-go signals, rollback
(lower the percentage) and its cost: each change is a full rollout, and
there is no per-community exemption. A required admission is refused
when the receiving pod holds an active deny for the key; revocation
closes open connections only in `enforce`, as for stored-Required
communities today. Denies live only in each pod's memory and spread
asynchronously, so a restarted pod, or an `enforce` pod during the
switch from `shadow`, can miss one; the key can then sign in until its
outstanding assertions expire (the issuer's
`maximum_assertion_age_seconds` plus `skew_seconds`, if the issuer stops
issuing), and finishing a rollout does not restore missed denies. The
runbook describes recovery, not continuity: re-push freshly signed
disconnect commands once the new pods are serving (resent old commands
can fail replay and command-age checks), or wait out the bound counted
from when the issuer stopped issuing. A revoked key can still be
admitted before recovery, and in `shadow` a later re-push does not close
a connection opened in that window. The Enforce step leaves the
percentage at 100, where it has no effect. Its rollback for admission
failures sets `shadow` and lowers the percentage to the last known-good
value; a mode-only rollback at 100 still requires every community. Never
roll back with `off`, which also turns off stored-Required enforcement.
A stored disable makes reconnects optional only when the effective
policy becomes optional. The upgrade runbook, community auth doc,
`ARCHITECTURE.md` and the multi-tenant conformance table say cohort
communities are required in `shadow` too. The NIP-FI spec drops its Buzz
implementation note and describes capability advertisement in generic
terms; its normative `MAY` is unchanged.

---------

Signed-off-by: Will Pfleger <wpfleger@block.xyz>
Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
2026-11-25 16:59:08 -05:00
..