fix(ops): send apikey with push drain, read the web push public key from release/, record 2026-11-17 backlog evidence

The scheduled push drain got HTTP 401 because modern Supabase service keys need the apikey
header next to Bearer. NAS deploy scripts fall back to release/webpush-vapid-public.key
(public key only). Map, mobile SSOT and deployment runbooks are synced with the verified
operations run in docs/evidence/2026-11-17-backlog-operations.md.
This commit is contained in:
Yun Chan 2026-11-20 15:16:19 +09:00
parent 8d8aaf5794
commit 6791e29f27
16 changed files with 254 additions and 96 deletions

View file

@ -61,6 +61,16 @@ curl -fsSI http://127.0.0.1:3001/login | head -n 1
curl -fsSI http://127.0.0.1:3002/app/login | head -n 1
```
Windows에서 로컬 Docker 데몬 없이 SSH 빌드하는 현재 경로(2026-11-17 전체 빌드, 2026-11-18 선택 빌드 검증):
```powershell
$env:DOCKER_HOST = "ssh://yunchan-nas"
pwsh -NoProfile -File scripts/deploy-nas.ps1 -BuildOnly
ssh yunchan-nas "cd /volume1/docker/d3ro && docker compose up -d"
```
`-BuildOnly`는 기본적으로 API·Admin·Web 이미지를 원격 Docker에 만들고 tar/배포용 `.env` 패키징은 생략한다. 이미 완료된 이미지를 유지하며 하나만 다시 빌드할 때는 `-Services web`처럼 `api`/`admin`/`web`을 선택한다(2026-11-18). Web Push 공개키는 `NEXT_PUBLIC_VAPID_PUBLIC_KEY`/`WEBPUSH_VAPID_PUBLIC_KEY`가 비어 있으면 `release/webpush-vapid-public.key`에서 읽는다. 로컬 `JWT_SECRET` 없이도 빌드할 수 있으며 NAS의 기존 `.env`는 그대로 유지한다.
---
## 4. Rollback Procedure

View file

@ -40,7 +40,7 @@ In-app events use IPC/EventEmitter and Supabase Realtime. No push transport, no
### Web — Firebase-free, implemented in source
- Standard **Web Push** with **VAPID** keys. The browser Push API + service worker handles delivery; the server signs with a VAPID private key and POSTs to the subscription endpoint.
- The sidebar requests permission from an explicit user gesture, creates/checks in a stable active `platform='web'` device, and stores the serialized subscription in `push_tokens` through `register_push_registration`. Opt-out records a per-user disabled intent before bounded parallel server/local cleanup; an existing local subscription is re-registered through the server RPC before the UI may call it connected. Logout starts cleanup without waiting and always proceeds to sign-out.
- `NEXT_PUBLIC_VAPID_PUBLIC_KEY` is baked into the browser bundle and must match the Edge Function's `WEBPUSH_VAPID_PUBLIC_KEY`; a missing browser key leaves the control unavailable.
- `NEXT_PUBLIC_VAPID_PUBLIC_KEY` is baked into the browser bundle and must match the Edge Function's `WEBPUSH_VAPID_PUBLIC_KEY`; NAS deploy scripts fall back to the versioned public key `release/webpush-vapid-public.key`. A missing browser key leaves the control unavailable.
- No Firebase, no Google account. APNs not involved.
### iOS — Firebase-free, implemented in source
@ -74,9 +74,7 @@ If the goal is "no Firebase at all", the decision reduces to: replace Android tr
1. **Keep Supabase as the SSOT/outbox** (already true). Do not move token/outbox logic.
2. **[done] Implement `webpush` + `apns` transports** in `send-push` (`_shared/webpush.ts`, `_shared/apns.ts`).
3. **[source done] Register web/APNs clients through the device-bound RPCs.** Keep provider configuration and real delivery as runtime gates.
4. **For Android, offer two modes behind config:**
- `fcm` (default): minimal Firebase project, push-only usage.
- `unifiedpush` (opt-in): self-hosted ntfy distributor; documented UX and battery caveats.
4. **For Android, keep FCM** (2026-11-17 decision): use a minimal push-only Firebase project. Do not add a second UnifiedPush transport without a new product review.
5. **Do not adopt OneSignal/Pusher** as a "Firebase replacement" — it does not remove the dependency.
### Effort sketch
@ -98,7 +96,7 @@ If the goal is "no Firebase at all", the decision reduces to: replace Android tr
| Web Push transport | `_shared/webpush.ts` | VAPID ES256 JWT + RFC 8291 `aes128gcm` encryption; strict config/subscription validation; 200/404/410/413 mapping |
| APNs transport | `_shared/apns.ts` | Token-based `.p8` ES256 JWT (cached ~50 min); production/sandbox hosts; stale (`BadDeviceToken`/`Unregistered`) and 403 handling |
| Provider routing | `send-push/index.ts` | `fcm` / `webpush` / `apns` dispatched with per-delivery stale → `stale`, payload → `permanent_failure`, else retryable; unknown providers stay `push_provider_not_supported` |
| Cloudflare cron drain | `server/cloudflare-worker/src/push-drain.ts` + `scheduled()` + `wrangler.toml [triggers] crons` | POSTs `send-push?mode=drain&limit=…` with the service-role bearer every minute |
| Cloudflare cron drain | `server/cloudflare-worker/src/push-drain.ts` + `scheduled()` + `wrangler.toml [triggers] crons` | POSTs `send-push?mode=drain&limit=…` every minute with the current project secret as both Bearer and `apikey`; live scheduled success verified 2026-11-17 |
| Tests | `_shared/webpush.test.ts`, `_shared/apns.test.ts`, `push-drain.test.ts`, `push-contract.test.ts` | 10 new tests incl. an RFC 8291 decrypt round-trip; CI runs the edge suite and the worker drain test |
| Web client | `apps/web/public/sw.js`, `src/lib/{web-device,web-push,web-push-session}.ts`, `web-push-control.tsx` | Explicit opt-in/out, stable active device, device-bound RPCs, persistence rollback, disabled-intent reconciliation, bounded parallel cleanup, non-blocking logout; standalone image copies the service worker |
| Web contract tests | `apps/web/e2e/web-push.spec.ts` | 17 tests for installation identity, revoked-device refusal, permission/VAPID gate, register/unregister RPCs, rollback, stale-subscription reconciliation, bounded cleanup, and logout independence |
@ -111,14 +109,14 @@ An ephemeral VAPID pair, throwaway user, isolated Supabase project, and throwawa
### Required configuration
| Secret / var | Consumer | Purpose |
|---|---|---|
| `WEBPUSH_VAPID_PUBLIC_KEY` / `WEBPUSH_VAPID_PRIVATE_KEY` / `WEBPUSH_SUBJECT` | Supabase Edge Function | VAPID signing; subject must be `mailto:` or `https:` |
| `NEXT_PUBLIC_VAPID_PUBLIC_KEY` | Web image build | Public half of the same VAPID pair, baked into the client bundle; missing means unavailable/fail-closed |
| `APNS_KEY_ID` / `APNS_TEAM_ID` / `APNS_PRIVATE_KEY` / `APNS_TOPIC` / `APNS_ENVIRONMENT` | Supabase Edge Function | APNs token auth; topic is the bundle id (`com.d3ro.voice`) |
| `SUPABASE_URL` / `SUPABASE_SERVICE_ROLE_KEY` / `PUSH_DRAIN_BATCH_LIMIT` | Cloudflare Worker | Cron drain target + auth (service role key as `wrangler secret`) |
| `WEBPUSH_VAPID_PUBLIC_KEY` / `WEBPUSH_VAPID_PRIVATE_KEY` / `WEBPUSH_SUBJECT` | Supabase Edge Function | VAPID signing; production values configured 2026-11-17 |
| `NEXT_PUBLIC_VAPID_PUBLIC_KEY` | Web image build | Public half of the same pair. If the env is blank, NAS deploy scripts use `release/webpush-vapid-public.key` |
| `APNS_KEY_ID` / `APNS_TEAM_ID` / `APNS_PRIVATE_KEY` / `APNS_TOPIC` / `APNS_ENVIRONMENT` | Supabase Edge Function | APNs token auth; topic is the bundle id (`com.d3ro.voice`), still external |
| `SUPABASE_URL` / `SUPABASE_SERVICE_ROLE_KEY` / `PUSH_DRAIN_BATCH_LIMIT` | Cloudflare Worker | Cron drain target + current project secret; Bearer and `apikey` are both sent |
### Remaining work
- **Runtime proof:** configure matching web/server VAPID values and APNs credentials, build/deploy the web image and Edge/cron code, then prove authenticated browser/iOS registration, outbox drain, and real receipt. Source and automated contract tests alone do not satisfy this gate.
- **Android decision:** keep FCM or adopt UnifiedPush (see §2/§3).
- **Runtime proof:** rebuild/deploy the web image with the public VAPID key, then prove authenticated browser/iOS registration and real receipt. The production scheduled drain is already GREEN (`claimed=1 completed=1 pending=0`, 2026-11-17).
- **Android:** FCM remains the selected Play transport; production Firebase credentials are tracked in `EXT-FIREBASE-01`.
---