feat(payments): bind orders to verified tenant and buyer
CI (SIAX Cloud) / integration (push) Has been skipped
masterplan-lock / check (push) Successful in 4s
CI (SIAX Cloud) / security (push) Successful in 14s
masterplan-lock / check (pull_request) Successful in 4s
CI (SIAX Cloud) / security (pull_request) Successful in 14s
Security Scan (SIAX Cloud) / security (push) Successful in 30s
CI (SIAX Cloud) / quality (push) Successful in 35s
CI (SIAX Cloud) / integration (pull_request) Successful in 25s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m31s

This commit is contained in:
2026-09-15 19:53:58 +02:00
parent f976f36530
commit a1557b2a7d
19 changed files with 326 additions and 76 deletions
+9 -3
View File
@@ -50,9 +50,15 @@ without creating a payable order until sign-in.
## Action items
1. [ ] Build and verify the migration and deploy runner.
2. [ ] Bind create-order to verified tenant and buyer subject; scope idempotency.
3. [ ] Scope GET/PATCH/deposit/release to tenant at the SQL boundary.
1. [x] Build and smoke-verify `sql/011_orders_tenant_ownership.sql` on
throwaway pgvector/Postgres 16, including a second idempotent application.
A deploy migration runner and production application remain open.
2. [x] Bind create-order to verified tenant and buyer subject; scope idempotency.
3. [x] Scope buyer GET/PATCH/deposit/release to tenant at the SQL boundary.
4. [ ] Wire UI Zitadel login/session and CLI/MCP bearer auth; keep anonymous estimates.
5. [ ] Test cross-tenant 404, legacy unowned rejection, webhook, and staging
purchase/refund end-to-end before enabling live Stripe.
Implementation is pending PR review and merge. It is not evidence that the
production database has been migrated or that the browser purchase path is
ready: the current UI does not send a verified Zitadel credential.
+20 -16
View File
@@ -137,12 +137,12 @@ Risknivå = SIAX L0–L5-taxonomin, bedömd av mig utifrån vad handlern gör.
| Katalog / källor / fordon | `GET /api/{catalog,sources,vehicles}` | L1 | Nej |
| Sanktions-/PEP-screening | `GET /api/screen?q=` | L2 | Nej — proxar mot OpenSanctions |
| AI-parsning av fritext | `POST /api/ai/parse` | L2 | Nej |
| Skapa order | `POST /api/orders` | L2 | Nej |
| **Lista alla ordrar** | `GET /api/orders` | **L3** | Route-auth i source; org-scoping saknas |
| Läs/ändra order | `GET,PATCH /api/orders/{id}` | L3 | Route-auth i source; orderägande saknas |
| Skapa order | `POST /api/orders` | L2 | Verifierad buyer-principal i source; UI-SSO återstår |
| **Lista buyer-ordrar** | `GET /api/orders` | **L3** | Verifierad tenant och tenant-scoped SQL i source |
| Läs/ändra buyer-order | `GET,PATCH /api/orders/{id}` | L3 | Verifierad tenant och tenant-scoped SQL i source |
| **Adminmetrik (orderpipeline, belopp)** | `GET /api/admin/metrics` | **L3** | Route-auth i source; äldre liveobservation ej omverifierad |
| Deposition (Stripe checkout) | `POST /api/payments/{order_id}/deposit` | **L4** | Route-auth i source; orderägande saknas |
| **Frigör escrow-slutbetalning** | `POST /api/payments/{order_id}/release` | **L4** | Route-auth i source; `delivered` först efter betald webhook; orderägande saknas |
| Deposition (Stripe checkout) | `POST /api/payments/{order_id}/deposit` | **L4** | Verifierad tenant + ägd order i source; live-UI återstår |
| **Frigör escrow-slutbetalning** | `POST /api/payments/{order_id}/release` | **L4** | Ägd order; `delivered` först efter betald webhook; live-UI återstår |
| Stripe-webhook | `POST /api/webhooks/stripe` | L3 | Signaturkontroll via `STRIPE_WEBHOOK_SECRET` |
| Prenumerationer | `GET,POST /api/subscriptions` | L2 | Nej |
| Filuppladdning | `GET,POST /api/uploads` | L3 | Nej (`501` utan R2) |
@@ -353,12 +353,15 @@ Om/när Postgres provisioneras måste detta lösas separat — jfr estate-blocke
betalning som lyckad. Klient-PATCH kräver nu verifierad auth, följer
tillåtna statusövergångar och kan aldrig skriva `in_production`/`delivered`;
concurrent writes använder jämför-och-sätt. Slutbetalningsrouten kräver
också verifierad auth. **Fortfarande öppet före live-läge:** orderägarskap
och tenant-bindning vid checkout/acceptance behöver implementeras och
verifieras; en verifierad identitet ensam är inte per-order auktorisation.
Enskild order-GET och deposit-checkout kräver nu också route-auth; dessa
två vägar är inte längre anonyma i source. Ägarbindningens beslut och
beroenden dokumenteras i `ADR-001-order-ownership.md`.
också verifierad auth. Ny order-POST kräver nu en verifierad
Zitadel-principal; dennes tenant och subject lagras i
`orders.tenant_id`/`buyer_subject` via `sql/011`. Buyer GET/list/PATCH
och deposit/release använder tenant-predikat i SQL; legacy-ordrar utan
owner är osynliga och obetalbara. **Fortfarande öppet före live-läge:**
migrationen har bara smoke-testats på engångs-Postgres och måste appliceras
i målmiljön före deploy. Browser-UI saknar produktions-SSO/Bearer och
stagingköp/refund är ännu inte verifierat. Beslut och nästa steg finns i
`ADR-001-order-ownership.md`.
- `SECURITY.md` finns med rapporteringsväg (`security@siax.io`).
### KÄNDA LUCKOR
@@ -395,15 +398,16 @@ Matchern täcker bara `/api/0pt/:path*`. Orderkö/adminmetrik, enskild
order-GET, deposit- och release-checkout samt order-PATCH har nu explicita
route-auth-grindar i source. De äldre live-observationerna av anonymt 200
beskriver tidigare deploy, inte verifierat nuläge. Övriga icke-prefixade
API:er kräver egen inventering, och per-order tenantägande är fortfarande
öppet enligt ADR-001.
API:er kräver egen inventering. Buyer-order-API:t har nu tenant-predikat i
source, men migration, UI-SSO och liveverifiering återstår enligt ADR-001.
**S4 — Historisk escrow-bugg åtgärdad i source; tenantägande återstår.**
**S4 — Historisk escrow-bugg åtgärdad i source; liveköp återstår.**
`POST /api/payments/{order_id}/release` kräver nu route-auth och skapar
Checkout först efter `accepted`. En skapad session sätter inte `delivered`;
endast en signerad, betald och matchande Stripe-webhook får göra det.
Cross-tenant-skydd av den enskilda ordern saknas fortfarande, så livebetalning
får inte aktiveras innan ADR-001 är genomförd och verifierad.
Cross-tenant-skydd av buyer-ordern finns nu i SQL-predikat, men är inte
produktionsbevisat innan `sql/011` har applicerats, UI-SSO är kopplat och
stagingköp/refund är verifierat. Livebetalning får därför inte aktiveras.
**S5 — CL0UD-policyklienten är fail-open utan produktionsspärr.**
`src/clients/cl0ud-client.ts:45` — saknas `CL0UD_URL` returneras alltid
@@ -0,0 +1,43 @@
# 0pt order-ownership cutover
Status: source implementation in PR #66; **not applied to production**.
Canonical design: [ADR-001](./ADR-001-order-ownership.md).
## Dependency order
1. Confirm the target Postgres is the canonical 0pt order store. Capture a
recoverable database snapshot and identify current migration state.
`sql/001_init.sql` and `sql/006_orders_idempotency.sql` must already be
present; this repository has no general automated migration runner yet.
2. Apply `sql/011_orders_tenant_ownership.sql` transactionally to staging,
then production only after staging verification. The file is idempotent
and leaves legacy NULL-owned rows untouched. For an environment where
`DATABASE_URL` is securely injected, a manual controlled step is:
```bash
psql "$DATABASE_URL" -v ON_ERROR_STOP=1 --single-transaction -f sql/011_orders_tenant_ownership.sql
```
3. Verify `orders.tenant_id`, `orders.buyer_subject`, the ownership-pair
check constraint and `orders_tenant_created_idx`. Record migration
output and deployment SHA in the rollout evidence. Do not deploy the
tenant-scoped source before the schema is verified; an undefined column
will fail requests.
4. Wire a real Zitadel customer UI session and send the verified credential
to every order/payment API call. Existing dev HMAC login is not a payment
identity. Keep anonymous composition as an estimate only.
5. In staging, prove: no token -> 401; spoofed tenant header -> 401/403;
another tenant's order -> 404; legacy unowned order -> 404/unpayable;
matching signed paid Stripe event -> correct status; unpaid/mismatched
event -> no status change; repeat delivery -> idempotent. Test purchase,
cancellation and refund with real sandbox endpoints. Only then review
SIAX Technology AB live credentials and enable live Stripe.
## Rollback and legacy handling
Do not drop ownership columns to roll back the application. Roll back the
application deployment to its prior SHA if needed, retaining the additive
columns and snapshot. A paid Stripe event for a legacy unowned order receives
503 and requires an explicit, audited support decision; the webhook does not
guess a tenant or acknowledge it as fulfilled. Do not silently backfill
ownership from order config, browser storage, or a known order ID.