Repository navigation
Commit 40bc07a
feat(relay): mint invites that never expire (#9690)
## Summary
Community owners and admins can mint invite links that never expire. A
mint request with `"never_expires": true` stores the invite with a NULL
`expires_at`, and the response returns `expires_at: null`. The link
stays claimable until it's revoked or used up. Requests without it still
get the default finite expiry, finite links keep the 30-day cap, and
`never_expires` together with `ttl_secs` is a 400. Migration 0112 drops
`NOT NULL` from `relay_invites.expires_at`. It only changes metadata.
On relays that require membership, both `POST /api/invites` and the
operator route refuse a never-expiring link with a 403 unless the
request also sends `"confirm_never_expires": true`. The operator route
also returns the code `never_expires_not_allowed`. Sending
`confirm_never_expires` without `never_expires` is a 400. The Buzz app
(block/buzz-app#4120) matches the exact refusal text to offer its
confirmation, so that text must stay stable.
An invite now stops working once its creator is no longer an owner or
admin, the same way a ban affects that person's invites. This applies to
finite and never-expiring links alike. Demotion, removal and ownership
transfer revoke the person's invites in the same transaction, under the
invite admission lock, and getting the role back doesn't revive them. A
claim also revokes an older invite whose creator has lost the role.
Retention now deletes revoked invites once they're older than its
cutoff, not only expired ones, so revoked never-expiring links don't
pile up. Migration 0112 adds a partial index on `revoked_at` for this.
Mint, list and revoke go through the shared per-pubkey API rate limit
(`human_api_calls_per_min`, 60-second window) before the replay and
membership checks. An exhausted quota returns 429 `rate-limited: quota
exceeded; retry in Ns`. The limiter fails closed, so these routes return
503 while Redis is unavailable. Claim keeps its own limiter. Revoking an
unknown invite returns 404 without waiting on the admission lock.
There's no kill switch: a leaked never-expiring link has to be revoked
on its own.
### Related issue
Builds on #9680 (listing and revoking invites). Client:
block/buzz-app#4120.
### Deploy order and rollback
- Deploy only after #9680 is deployed to every serving relay. #9680
makes every reader of an invite's expiry accept a missing value, and
this PR adds the only writer of one.
- The rollback floor is #9680. Once a never-expiring link exists, never
roll back below it: older relays can't decode a NULL `expires_at`, so
claims of that link fail.
- A #9680 relay that is already running keeps working after migration
0112. One that starts or restarts with auto-migrate on refuses the
database, because it doesn't know 0112 (sqlx `VersionMissing`). Run it
with `BUZZ_AUTO_MIGRATE=false` and apply migrations separately, as
`docs/database.md` describes.
- Self-hosted relay operators get this together with #9680 in one
release, since no tagged relay release contains #9680 yet. For them,
that release is the rollback floor.
### Schema change (`docs/database.md` checklist)
- Phase: expand plus writer. #9680 shipped the readers that accept a
NULL expiry. Migration 0112 relaxes the column and adds an index, and
this PR adds the writers.
- No trigger, function, procedure, rule or foreign key is added, and no
migration rewrites rows.
- Locks: 0112 starts with `SET LOCAL lock_timeout = '5s'` and
`statement_timeout = '30s'`, like 0075. `DROP NOT NULL` changes only
metadata. The partial index `relay_invites_revoked_at_idx` covers
revoked rows only and is built inline in the same transaction, under
those limits. There is no prebuild step.
- Every schema location matches:
`schema/tables/public/relay_invites.sql`, the desired-vs-migrated column
and index parity test (which now covers `relay_invites`), and the
embedded-migrator test, which checks both 0112 statements.
`assert_admission_column` checks the nullable column after a pgschema
reconcile.
- The deployed relay against the new schema:
`migration_schema_optional_expiry_keeps_populated_invites_and_admits_permanent_ones`
migrates a populated database through 0112, checks that no row changes,
and checks that existing finite, revoked and exhausted invites behave as
before. #9680's `readers_accept_an_invite_without_expiry` covers its
readers on a NULL expiry.
### Testing
- CI run 46800668669 at 247b2b0 (merge 04b19be onto 86511a9):
PostgreSQL Tests passed 1902/1902, including the new revocation, reap,
confirmation and upgrade tests. Unit Tests, Rust Lint and Relay E2E are
green. Relay E2E includes
`test_never_expiring_invite_claims_then_revokes`, which runs on a relay
that doesn't require membership.
- An agent review at 927c87b also ran fmt, the buzz-db unit and
`observability_source` tests and the PostgreSQL lane for every touched
module locally, plus a test-merge onto main. The changes since then were
checked by reading the code and by CI.
- Still to do: an agent exercise against a local relay, then a human
test (AGENTS.md, "Before opening a PR"). On a relay that requires
membership:
1. `POST /api/invites` with `{"never_expires":true}` returns 403 with
the refusal text.
2. Adding `"confirm_never_expires": true` returns 200 with `expires_at:
null`.
3. `GET /api/invites` lists the link as active with no expiry.
4. A claim from a new key joins.
5. After the link's creator is demoted to member, the next claim gets
403, and promoting them back doesn't revive the link.
6. A fresh link revoked by its code returns 200, and a later claim gets
403.
7. In Buzz, choosing Never expires shows the confirmation, and Create
permanent link mints the link.
- The author adds `buzz-review-completed` once the human test is done.
---------
Signed-off-by: Will Pfleger <wpfleger@block.xyz>
Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>1 parent 9043b51 commit 40bc07a
20 files changed
Lines changed: 1517 additions & 221 deletions
File tree
- crates
- buzz-db/src
- runtime
- store
- relay_invite
- buzz-relay/src/api
- invites/postgres_tests
- operator
- postgres_tests
- buzz-test-client/tests
- migrations
- schema/tables/public
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1200 | 1200 | | |
1201 | 1201 | | |
1202 | 1202 | | |
1203 | | - | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
1204 | 1213 | | |
1205 | 1214 | | |
1206 | 1215 | | |
| |||
3955 | 3964 | | |
3956 | 3965 | | |
3957 | 3966 | | |
| 3967 | + | |
3958 | 3968 | | |
3959 | 3969 | | |
3960 | 3970 | | |
| |||
5071 | 5081 | | |
5072 | 5082 | | |
5073 | 5083 | | |
| 5084 | + | |
| 5085 | + | |
| 5086 | + | |
| 5087 | + | |
| 5088 | + | |
| 5089 | + | |
| 5090 | + | |
| 5091 | + | |
| 5092 | + | |
| 5093 | + | |
| 5094 | + | |
| 5095 | + | |
| 5096 | + | |
| 5097 | + | |
| 5098 | + | |
| 5099 | + | |
| 5100 | + | |
| 5101 | + | |
| 5102 | + | |
| 5103 | + | |
| 5104 | + | |
| 5105 | + | |
| 5106 | + | |
| 5107 | + | |
| 5108 | + | |
| 5109 | + | |
| 5110 | + | |
| 5111 | + | |
| 5112 | + | |
| 5113 | + | |
| 5114 | + | |
| 5115 | + | |
5074 | 5116 | | |
5075 | 5117 | | |
5076 | 5118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| |||
859 | 859 | | |
860 | 860 | | |
861 | 861 | | |
862 | | - | |
| 862 | + | |
| 863 | + | |
863 | 864 | | |
864 | 865 | | |
865 | | - | |
866 | | - | |
| 866 | + | |
| 867 | + | |
867 | 868 | | |
868 | 869 | | |
869 | 870 | | |
| |||
0 commit comments