mirror of
https://github.com/block/buzz.git
synced 2026-11-27 19:52:31 +00:00
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>
87 lines
4.4 KiB
Markdown
87 lines
4.4 KiB
Markdown
# Manage a community's NIP-FI requirement
|
|
|
|
Use `buzz-admin nip-fi-policy` to enable, disable or inspect a community's
|
|
stored requirement through the deployment operator API. The command needs the
|
|
configured `RELAY_OPERATOR_API_ORIGIN` and an allowlisted operator signing key
|
|
in a protected file. It sends one signed request and never retries automatically.
|
|
|
|
Before rolling, close `BUZZ_NIP_FI_UPGRADES_ENABLED` on every old relay and
|
|
keep `BUZZ_NIP_FI_CHANGES=false` on new relays. Pause callers and upgrade them
|
|
for the [supported API](operator-nip-fi-policy-client.md) before deploying this
|
|
relay version. Apply the schema and roll compatible management writers across
|
|
the whole fleet. Then explicitly
|
|
enable that gate, which controls both enable and disable. Enable additionally
|
|
requires the deployment-selected issuer to be trusted and already bound to the
|
|
community. The active community must have exactly one owner; the authenticated
|
|
actor mediated by the operator must be that owner. See the
|
|
[policy contract](community-auth-upgrades.md) and [binding guide](operator-nip-fi-bindings.md).
|
|
|
|
Read current preconditions first:
|
|
|
|
```sh
|
|
buzz-admin nip-fi-policy --origin https://operator.example.org --key-file operator.key \
|
|
status --community-id c9acf9a6-37d5-4af1-8df9-92a165637b01 --host team.communities.example.org
|
|
```
|
|
|
|
Save a new request file with a fresh operation UUID and the exact
|
|
`expected_policy_generation` and `expected_requires_nip_fi` from that response:
|
|
|
|
```json
|
|
{
|
|
"operation_id": "c2ffcc20-9505-48fd-b6c7-446aa833bcd1",
|
|
"community_id": "c9acf9a6-37d5-4af1-8df9-92a165637b01",
|
|
"expected_host": "team.communities.example.org",
|
|
"actor_pubkey": "<owner's registered lowercase hex public key>",
|
|
"expected_owner_pubkey": "<same current owner's public key>",
|
|
"expected_issuer": "https://identity.example.org",
|
|
"requires_nip_fi": true,
|
|
"expected_policy_generation": 0,
|
|
"expected_requires_nip_fi": false
|
|
}
|
|
```
|
|
|
|
```sh
|
|
buzz-admin nip-fi-policy --origin https://operator.example.org --key-file operator.key \
|
|
enable --request policy.json
|
|
buzz-admin nip-fi-policy --origin https://operator.example.org --key-file operator.key \
|
|
status --operation-id c2ffcc20-9505-48fd-b6c7-446aa833bcd1
|
|
```
|
|
|
|
To disable, save a **new** file/UUID with `requires_nip_fi:false`, omit
|
|
`expected_issuer`, and copy freshly read preconditions. Run `disable --request`
|
|
with that file. The subcommand checks the saved action before reading the key
|
|
or sending anything. A same-state operation also advances the generation,
|
|
creating a barrier against earlier uncommitted requests.
|
|
|
|
After `policy_conflict`, re-read current policy and use a new UUID for the revised
|
|
intent. After a timeout or lost response, keep the complete original file and UUID:
|
|
read its status or retry that exact file. A committed replay never reapplies policy.
|
|
|
|
| Exit | Result |
|
|
|---|---|
|
|
| 0 | Current-state read, or applied stored disable |
|
|
| 10 | Enable accepted; connection closure remains unverified (`pending`) |
|
|
| 11 | Historical acceptance superseded by a later generation |
|
|
| 12 | Receipt target or required trust unavailable |
|
|
| 5 | Invalid input, API refusal or uncertain transport/response |
|
|
|
|
Inspect `mode` and `effective_required` separately from the stored flag.
|
|
`enforce` keeps FI required after disable; `off` suspends FI after enable.
|
|
`shadow` follows the stored flag, and also requires FI for communities inside
|
|
the `BUZZ_NIP_FI_ENFORCE_PERCENT` cohort; a stored disable does not take a
|
|
community out of the cohort, only lowering the percentage does. An enable
|
|
receipt remains pending even after local sweeps, since it cannot certify
|
|
fleet-wide connection closure. Required host caches can over-restrict for their
|
|
remaining one-second lease after disable. When the effective policy becomes
|
|
optional, a racing sweep may close one last non-FI socket; it can reconnect
|
|
under optional policy. A community inside the cohort, or any community under
|
|
global `enforce`, stays required: its non-FI sockets keep closing on
|
|
revalidation, and reconnects still need FI. FI-admitted sockets retain their
|
|
finite deadline. Re-enable repeats the optional-lease drain and existing
|
|
periodic revalidation.
|
|
|
|
The old `nip-fi-upgrade` command and endpoint are removed. Requests to that
|
|
route now return 404. Recover historical receipts with `nip-fi-policy status
|
|
--operation-id`; their original null CAS preconditions remain visible. Never
|
|
reuse a historical operation UUID for a new intent.
|