mirror of
https://github.com/block/buzz.git
synced 2026-11-25 10:42:26 +00:00
feat(push): make gateway origin configurable (#7261)
Make the push gateway origin configurable across the relay, gateway, mobile client, and deployment chart. This is a fresh deployment. The gateway has only run on personal development infrastructure, and push has no existing enabled users. Legacy migration, configured-to-unconfigured mobile transitions, and rolling upgrades from pre-launch gateway binaries are not supported. Populated pre-launch databases are rejected with an informative error before migrations run; their data is untouched. Mobile builds may omit the gateway URL, leaving push unavailable. Once push is enabled, subsequent builds must retain that configuration. ### Validation - All applicable CI checks pass at `5f546cfaf403f0386f146d213adfb4392f4ec29c`, including Rust, mobile/Swift, desktop/integration, security, image builds, and Helm checks. An unrelated agent cancellation test passed on retry. - PostgreSQL CI passed 384 tests, including the production-entry-point regression for refusing populated pre-launch databases before migrations, fresh initialization, and subsequent initialized deployments. - Focused local validation passed all 10 gateway PostgreSQL tests under the CI discovery filter and all 3 unconfigured-mobile tests. Repository-wide PostgreSQL discovery validation and the complete pre-push hooks passed. - Physical-device APNs/App Attest behavior and deployment to a live cluster were not verified in this work. --------- Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -279,7 +279,7 @@ The opaque string returned as `endpoint_grant` by `POST /v1/delegations` is the
|
||||
|
||||
All routes below accept only `POST`. Clients MUST send `Content-Type: application/json`; bodies are UTF-8 JSON and MUST be at most 8192 bytes, except `POST /v1/installations`, whose body MUST be at most 23896 bytes. That installation-only ceiling is derived from the maximum permitted base64-encoded 16384-byte App Attest object, the maximum 512-byte APNs endpoint encoded as hex, and 1024 bytes for the remaining closed envelope. A body over its applicable limit is rejected with HTTP `413` before JSON parsing. Every request object is closed: unknown members, duplicate members at any depth, missing or incorrectly typed members, trailing non-whitespace data, or a `v` other than integer `1` are `400 {"error":"invalid_request"}`. Integers are signed JSON integers in the ranges stated below. Unix times are integer seconds. UUIDs use the canonical lowercase hyphenated representation. Relay pubkeys are exactly 64 lowercase hexadecimal characters. APNs endpoints are non-empty, even-length lowercase hexadecimal strings encoding at most 512 bytes. Challenges are exactly 32 bytes encoded as unpadded URL-safe base64. `key_id`, `attestation`, and `assertion` use padded or unpadded standard base64 as accepted by Apple's App Attest API; decoded key ids are exactly 32 bytes, attestations are 1..16384 bytes, and assertions are 1..1024 bytes. An `endpoint_grant`, including its key-id prefix, MUST be at most 4096 bytes.
|
||||
|
||||
Handler responses are UTF-8 `application/json`. Closed error bodies are `{"error":"invalid_request"}`, `{"error":"invalid_attestation"}`, `{"error":"not_authorized"}`, `{"error":"invalid_auth"}`, `{"error":"invalid_grant"}`, `{"error":"rate_limited"}`, `{"error":"temporarily_unavailable"}`, `{"error":"configuration_fault"}`, or `{"error":"not_ready"}`. Authority, custody, and quota rejection MUST NOT reveal whether an installation, delegation, or endpoint exists. Delivery grant, authority, and replay failures collapse to `404 invalid_grant`; endpoint quota exhaustion uses `429 rate_limited`; storage failures use `503 temporarily_unavailable`.
|
||||
Handler responses are UTF-8 `application/json`. Closed error bodies are `{"error":"invalid_request"}`, `{"error":"invalid_attestation"}`, `{"error":"not_authorized"}`, `{"error":"invalid_auth"}`, `{"error":"invalid_grant"}`, `{"error":"installation_conflict"}`, `{"error":"rate_limited"}`, `{"error":"temporarily_unavailable"}`, `{"error":"configuration_fault"}`, or `{"error":"not_ready"}`. Authority, custody, and quota rejection MUST NOT reveal whether an installation, delegation, or endpoint exists. Delivery grant, authority, and replay failures collapse to `404 invalid_grant`; endpoint quota exhaustion uses `429 rate_limited`; storage failures use `503 temporarily_unavailable`.
|
||||
|
||||
### Exact App Attest transcript construction
|
||||
|
||||
@@ -329,7 +329,7 @@ The gateway verifies Apple's attestation chain, configured application identifie
|
||||
|
||||
The client MUST durably journal the exact attested enrollment request before its first send and retain it until delegation state is durable. If that exact request is replayed after the installation commit, the gateway MUST return the same success response after re-verifying the attestation, even though the challenge was already consumed. Idempotency requires exact equality of attested key, profile, endpoint fingerprint, epoch, and expiration, and the recovered public key MUST equal the committed key; any mismatch remains indistinguishable from other authority rejection. This recovery rule grants no authority beyond replaying the already authenticated request.
|
||||
|
||||
Invalid attestation is `401 invalid_attestation`; a consumed/expired challenge or a key/token owned by a live installation is `404 not_authorized`. A fresh verified enrollment may replace expired or revoked ownership so an app that missed its renewal window can recover.
|
||||
Invalid attestation is `401 invalid_attestation`; a consumed or expired challenge is `404 not_authorized`. After successful attestation verification, a key or token owned by a different live installation is `409 installation_conflict`; the conflicting request does not replace existing live authority. A fresh verified enrollment may replace expired or revoked ownership so an app that missed its renewal window can recover.
|
||||
|
||||
### Relay delegation and capability issuance
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# Buzz Push Gateway deployment
|
||||
|
||||
`buzz-push-gateway` is the standalone public APNs last hop intended for `push.buzz.xyz`. Build it with `Dockerfile.push-gateway`; do not run it in the relay image or give relays APNs credentials.
|
||||
`buzz-push-gateway` is a standalone APNs last hop. Build it with `Dockerfile.push-gateway`; do not run it in the relay image or give relays APNs credentials.
|
||||
|
||||
## Network and health
|
||||
|
||||
- Public listener: `BUZZ_PUSH_BIND_ADDR` (default `0.0.0.0:8080`). Route `https://push.buzz.xyz` to this port.
|
||||
- Public listener: `BUZZ_PUSH_BIND_ADDR` (default `0.0.0.0:8080`). Route the configured `BUZZ_PUSH_GATEWAY_ORIGIN` to this port.
|
||||
- Private health listener: `BUZZ_PUSH_HEALTH_ADDR` (default `0.0.0.0:8081`). Probe `/_liveness` and `/_readiness`; do not expose this port publicly. The chart has no pod-ingress allowance for 8081; Kubernetes node/kubelet-origin probe traffic is exempt from NetworkPolicy. Add a narrowly selected monitoring source only if the target CNI requires pod-origin health scraping.
|
||||
- Readiness fails when PostgreSQL authority is unavailable. Graceful shutdown stops accepting new requests before draining in-flight APNs calls.
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
| Variable | Purpose |
|
||||
|---|---|
|
||||
| `DATABASE_URL` | PostgreSQL authority/admission store. Runtime credentials need DML on the six gateway tables, not DDL. |
|
||||
| `BUZZ_PUSH_PUBLIC_DELIVERY_URL` | Exact externally signed URL, normally `https://push.buzz.xyz/v1/deliveries/apns`. |
|
||||
| `BUZZ_PUSH_GATEWAY_ORIGIN` | Exact externally reachable HTTPS origin. No credentials, port, path, query, or fragment. The gateway derives its transport routes from it; NIP-PL v1 App Attest audiences remain the registered `https://push.buzz.xyz/v1/...` constants. |
|
||||
| `BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS` | Maximum delegation capability lifetime (`1..=31536000`). |
|
||||
| `BUZZ_PUSH_MAX_INSTALLATION_LIFETIME_SECONDS` | Maximum encrypted-token installation lifetime (default 90 days, max one year). Clients must renew before expiry. |
|
||||
| `BUZZ_PUSH_APP_ATTEST_ROOT_CERT_PATH` | Read-only mounted Apple App Attest root certificate PEM. |
|
||||
@@ -24,7 +24,7 @@
|
||||
| `BUZZ_PUSH_GRANT_KEYS` | Capability AEAD keyring, `id:base64-32-bytes[,predecessor...]`; current key first. |
|
||||
| `BUZZ_PUSH_TOKEN_KEYS` | Independent token-custody AEAD keyring in the same format. Never reuse grant keys. |
|
||||
|
||||
The canonical `push.buzz.xyz` MVP serves the dogfood application identity
|
||||
The current MVP serves the dogfood application identity
|
||||
(`xyz.block.buzz.dogfood.mobile`). App Attest must cryptographically validate
|
||||
the configured application ID before enrollment. Assertions and delivery use
|
||||
the server-owned APNs topic, certificate-backed connection pool, and
|
||||
@@ -53,6 +53,25 @@ The gateway stores APNs tokens encrypted in PostgreSQL. Database backups therefo
|
||||
|
||||
## PostgreSQL and replicas
|
||||
|
||||
### First deployment, not a legacy upgrade
|
||||
|
||||
This gateway has never been deployed outside personal development infrastructure.
|
||||
This release supports a fresh dedicated database, not migration of existing
|
||||
development authority. Before running any schema migrations, `--migrate-only`
|
||||
refuses a non-empty database that has not completed gateway initialization
|
||||
(migration 0005). The error names the populated table and tells the operator to
|
||||
stop the development gateway and provision a fresh database. It does not delete
|
||||
or migrate that data. Normal deployments of an already initialized gateway may
|
||||
retain their data.
|
||||
|
||||
Do not run a rolling upgrade from a pre-launch development binary. Stop that
|
||||
deployment before initialization, use the fresh database, and do not roll back
|
||||
to a pre-launch binary against the new database. The rolling strategy is for
|
||||
compatible versions after initial deployment; no legacy writer compatibility or
|
||||
mobile configured-to-unconfigured migration is supported. Push has no existing
|
||||
enabled users. After enabling push, retain gateway configuration in updates to
|
||||
that app identity; omitting it is not a push shutdown mechanism.
|
||||
|
||||
The gateway's dedicated pool does not consume the relay-oriented `BUZZ_DB_LOCK_TIMEOUT_MS`, `BUZZ_DB_IDLE_TXN_TIMEOUT_MS`, or `BUZZ_DB_STATEMENT_TIMEOUT_MS` settings. Its session-timeout policy remains separate from the `buzz-db` writer policy and must be designed and rolled out independently.
|
||||
|
||||
All replicas must share one PostgreSQL database. Delivery authority, replay admission, and endpoint quota reservation are transactional there, so replica count does not multiply the abuse ceiling. The gateway owns a scoped migration history under `crates/buzz-push-gateway/migrations`; it creates only the six `push_gateway_*` authority tables plus SQLx's migration-history table and never runs relay migrations.
|
||||
@@ -122,10 +141,9 @@ Alerting rules ship as an opt-in prometheus-operator `PrometheusRule` (`promethe
|
||||
|
||||
Relay push is an explicit deployment opt-in through `BUZZ_PUSH_ENABLED=true`;
|
||||
the established strict boolean parser rejects unknown values and the default is
|
||||
false. When enabled, an absent `BUZZ_PUSH_GATEWAY_DELIVERY_URL` selects the exact
|
||||
canonical URL `https://push.buzz.xyz/v1/deliveries/apns`; operators can provide
|
||||
another exact HTTPS `/v1/deliveries/apns` URL as an advanced override. An
|
||||
explicitly empty URL while enabled is a startup error. Only an enabled relay
|
||||
false. When enabled, `BUZZ_PUSH_GATEWAY_DELIVERY_URL` is required and must be an
|
||||
exact HTTPS `/v1/deliveries/apns` URL. An absent or explicitly empty URL while
|
||||
enabled is a startup error. Only an enabled relay
|
||||
advertises its host-scoped NIP-PL descriptor, accepts leases, and starts the
|
||||
matcher and delivery worker. Relays retain lease matching, authorization, durable
|
||||
jobs/retries, and generation checks; they receive only opaque capabilities and
|
||||
@@ -157,7 +175,7 @@ capability—not a raw APNs token—into the encrypted relay lease.
|
||||
|
||||
## Internal dogfood evaluation and rollback
|
||||
|
||||
The MVP is ready to enable only when the canonical gateway's sole dogfood
|
||||
The MVP is ready to enable only when the configured gateway's sole dogfood
|
||||
profile is configured with its server-owned App Attest app ID, APNs topic,
|
||||
production certificate identity, and production APNs environment, and only the
|
||||
selected internal relay deployments set `BUZZ_PUSH_ENABLED=true`. Every iOS
|
||||
@@ -178,7 +196,7 @@ publish the next immutable `mobile-vX.Y.Z-rc.N` candidate from the exact current
|
||||
and wait for the signed `xyz.block.buzz.dogfood.mobile` artifact to appear in
|
||||
Mobile Releases/Comp Portal before installing it on a physical device. Verify
|
||||
APNs delivery, fetched and signature-verified notification content, and
|
||||
exact-message tap routing against the canonical gateway and a push-enabled
|
||||
exact-message tap routing against the configured gateway and a push-enabled
|
||||
internal relay before widening the internal evaluation.
|
||||
|
||||
Before that first candidate, the private dogfood builder's manual signing and
|
||||
@@ -229,7 +247,7 @@ the environment's GitOps values; the chart then renders
|
||||
`ghcr.io/block/buzz-push-gateway@sha256:...` and ignores the mutable tag.
|
||||
`values-production.yaml` remains an intentionally invalid production-input
|
||||
contract: deployment CI must inject the verified image digest, the provisioned
|
||||
dogfood Apple application identifier, and the actual PostgreSQL network. In an
|
||||
dogfood Apple application identifier, `gatewayOrigin`, and the actual PostgreSQL network. In an
|
||||
environment with an existing ingress or service mesh route, keep
|
||||
`httpRoute.enabled=false`. If this chart owns a Gateway API route, enable it and
|
||||
inject an environment-owned `parentRef`; schema validation rejects an enabled
|
||||
|
||||
Reference in New Issue
Block a user