# ADR-001: Verified tenant ownership for payment orders
**Status:** Proposed
**Date:** 2026-09-15
**Deciders:** SIAX 0pt product and platform owners
## Context
The existing order configurator creates anonymous drafts, stores no verified
buyer or tenant on them, and later refers to an order by its ID. A valid
Zitadel principal proves who is calling but does not prove that this caller
owns that particular order. An order ID is an identifier, not an authorization
secret. The nullable `orders.org_id` UUID cannot directly hold the verified
tenant ID, which is a string. The repository has no automated SQL migration
runner, and legacy rows may remain unowned.
The payment flow must remain API-first and work consistently in UI, CLI and
MCP. It must not make anonymous drafts payable by treating a guessed or leaked
ID as ownership.
## Decision
Require a verified Zitadel principal before creating a payable order. Persist
`tenant_id` and buyer subject on each new order in a database migration.
Every read, status mutation and Checkout creation must use a tenant-scoped
query predicate; a cross-tenant order returns 404. The Stripe webhook uses
its verified signature plus recorded order ID and payment facts to advance
status, never a browser-supplied tenant claim. Legacy null-owned orders remain
unpayable until an audited, explicit migration or support workflow binds
them to a verified buyer. Keep the anonymous configurator as an estimate
without creating a payable order until sign-in.
## Options considered
| Option | Complexity | Scale | Consequence |
|---|---|---|---|
| Authenticate only, lookup by order ID | Low | High | Rejected: any signed-in user can access another order. |
| Bearer claim token for anonymous drafts | Medium | High | Requires capability issuance, hashing, secure browser storage and recovery. Not selected for initial production. |
| Verified tenant + buyer subject at order creation | Medium | High | Chosen: explicit ownership at source, shared API boundary. |
## Consequences
- UI must obtain a Zitadel session before order creation and send credentials
to the order and payment APIs; estimates stay anonymous.
- SQL migration must be applied and verified before the scoped code is deployed.
- Existing unowned rows are not silently assigned to a tenant.
- Idempotency keys must be scoped to the verified tenant.
- Admin operations require an explicit, audited role-bound path rather than
bypassing the buyer predicate.
## Action items
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.
**Kategori:** platform (K1) **Underkategori:** data-os **Status:** under utveckling (deployad frontend i drift, capability-lagret ej produktionsklart)
**Senast verifierad mot kod:** 2026-08-07 (commit `6531384`, main) · **Klassificeringsuppdatering:** 2026-08-10 (`siax.repo.json`) · **v2.0-standardmigrering (§5 tillagd, §6–§9 omnumrerade; §6 Deploy-fältet nedan uppdaterat mot `lib/health-checks.ts`):** 2026-08-11 — scoped till dessa avsnitt, ingen fullständig radrad-omverifiering av hela dokumentet gjord denna pass
> **Läsanvisning.** Detta dokument beskriver vad koden i repot **gör**, inte vad
> `README.md`, `CLAUDE.md` eller `docs/01–11` säger att den borde göra. Där de
> avviker står avvikelsen utskriven — se §8. Påståenden märkta *(live-verifierat
> 2026-08-07)* är kontrollerade mot den körande instansen på `https://0pt.app`.
> Allt annat är läst ur källkoden. Där något inte gick att belägga står **OKÄNT**.
---
## 1. Syfte
0pt är SIAX Clouds **Data OS**: plattformen som skaffar, strukturerar, härleder
och levererar företags-, kontakt- och fordonsdata för Norden/Europa, med
| **Capability-lager** | `src/` + `app/api/0pt/*` | TypeScript-tjänster för `0pt.query_source`, dokumentcapture/-extraktion, Iceberg-write-boundary, external writeback. **All state ligger i `Map`-objekt i minnet** (`src/services/*.ts`), inte i databas. |
ingen CLI-yta, ingen MCP-yta alls finns i detta repo ännu). API = 13/14 (allt
utom det renodlade job-kapabiliteten). Egen konsol ≈ 5/14, koncentrerat till
order-/katalog-/källflödet; kapabiliteter under `app/api/0pt/*` (lakehouse,
rate-policy, källfråga, sanktionsscreening, dokument-OCR) har ingen synlig UI
alls — matchar BACKLOG P1-8 ("`/api/0pt/*`-kapabiliteterna saknar UI").
---
## 6. Deploy
| Fält | Verifierat läge |
|---|---|
| **Nod** | Ingen SIAX-nod. *(live-verifierat 2026-08-07: `https://0pt.app/api/health` → `Server: Vercel`, `X-Vercel-Id: arn1::iad1::…`)* Frontenden körs alltså på **Vercel**, inte på flottan. |
| **Coolify-app** | Ingen verifierad — fortfarande **OKÄNT** om någon Coolify-app pekar på repot (2026-08-09: `git.siax.io/sax3l/0pt` genomsökt, ingen egen fleet-åtkomst att fråga Coolify API direkt denna pass). `Dockerfile` är skriven för Coolify (node:24-alpine, multistage, `HEALTHCHECK` mot `/api/health`, kör som `node`-användare). `siax.config.json` deklarerar nu `deploy.target: "coolify"` (ändrat från `"vercel"` 2026-08-09, PR i `fix/remove-vercel-deploy-target`) och ett nytt `.gitea/workflows/deploy.yml` finns, ported från n0d/st0re-mönstret — men appens UUID i den filen är en medveten platshållare som får jobbet att faila högljutt tills en riktig Coolify-app skapats och tokens/uuid fyllts i. Config-flippen ändrar alltså **avsikt**, inte trafik. |
| **Domän** | `0pt.app` (live). Docs nämner även `api.0pt.app`, `data.0pt.app`, `dash.0pt.app` via Caddy — **ej verifierade**. |
| **Bygg** | `next build` via pnpm@9. `next.config.mjs` sätter `typescript.ignoreBuildErrors: true` — bygget typkontrollerar alltså **inte**`app/`, `components/`, `lib/` eller `middleware.ts`. |
| **Engine-deploy** | `infra/docker-compose.yml` (postgres, redis, api, worker, nocodb, metabase, caddy) och `services/infra/docker-compose.data-stack.yml` (clickhouse, trino, flaresolverr, tor-proxy, superset, postgres). **Ingen av dem är verifierad som körande.** |
| **Hemligheter** | Rena miljövariabler (`.env.example` listar 20+). **Infisical är inte inkopplat** — ingen referens till Infisical/vault finns i repot. Vercel-projektets env är källan för webblagret. |
| **CI** | `.gitea/workflows/ci.yml`. `quality`-jobb: typecheck (blockerande, endast `src/` + `tests/`), vitest (blockerande, 17 testfiler), eslint (rådgivande), `next build` (blockerande). `security`-jobb: Trivy `--exit-code 0` (rådgivande). Kör på `ubuntu-latest`. |
> **Konflikt att fatta beslut om:** estate-projektet *GCP/Vercel-exit* säger att
> flottan ska bort från Vercel. 0pt:s enda körande instans ligger på Vercel. Se §9.
mandate is to replace paid SaaS with self-hosted fleet infrastructure
(Hetzner + Coolify), matching every other SIAX Cloud OS repo (`n0d`,
`st0re`, `aud0`, ...).
## Decision
`siax.config.json`'s `deploy.target` is `"coolify"`, not `"vercel"`. A
Dockerfile written for Coolify (multi-stage, non-root `node` user, `HEALTHCHECK`
against `/api/health`) and `.gitea/workflows/cd.yml` (POSTs a restart to a
Coolify app UUID on push to `main`) both exist and are committed.
## Consequences
- **This is a config-and-tooling change, not a traffic cutover.** As of this
record, no Coolify application has been provisioned for this repo —
`cd.yml`'s `COOLIFY_APP_ID` is a literal placeholder that fails the job
loudly on purpose (see the guard step) rather than posting to a bogus
endpoint. The live instance of `0pt.app` is still served by Vercel.
> **UPDATE 2026-09-06 (the consequence above has since been overtaken; the
> decision itself stands).** **CORRECTED 2026-09-06 — this is no longer true.** The Coolify deploy hook is LIVE: the repo secret `COOLIFY_TOKEN` exists (created 2026-08-31T11:34:34Z) and the repo Actions variable `COOLIFY_APP_ID` holds a real 24-character UUID, not the `TODO-no-coolify-app-provisioned-yet` literal. Both guard conditions in `.gitea/workflows/cd.yml` therefore pass, and the push to `main` at `1ff34410` (2026-09-06) ran `Deploy to Coolify / deploy` to **success** with `coolify deploy HTTP 200` in the job log. **Every merge into `main` now fires a real redeploy against cloud.siax.io.** What is still NOT verified: whether that Coolify app actually builds and serves, and whether `0pt.app` DNS points at it or still at Vercel — nobody has probed the running site.
>
> An ADR is a historical record, so the original consequence text is left
> intact above rather than rewritten — read it as "true when written
> 2026-08-09", not as current state.
- Flipping the config was deliberately decoupled from the actual cutover: it
states intent (BACKLOG P0-2 / P3-1 own the "provision the Coolify app, cut
DNS, decommission Vercel" work, gated on a dump-before-write blocker per
the standard's "safe to run now" classification).
- Until the cutover happens, docs describing Vercel as *where 0pt actually
runs today* are accurate; docs prescribing Vercel as *the plan going
forward* are stale (see BACKLOG P2-5 — `docs/02-architecture.md`'s
"Hosting" section is marked SUPERSEDED for exactly this reason).
BACKLOG P1-2. One file per decision, numbered sequentially, never renumbered
or deleted (superseded decisions get a new ADR that says so, per the
convention below).
| ADR | Title | Status |
|---|---|---|
| [0001](0001-deploy-target-coolify-not-vercel.md) | Deploy target is Coolify, not Vercel | Accepted (migration not yet executed) |
| [0002](0002-auth-zitadel-bearer-not-nextauth.md) | `/api/0pt/*` auth is fleet Zitadel Bearer, not NextAuth | Accepted and implemented |
| [0003](0003-lakehouse-format-iceberg-pointer.md) | Lakehouse format is Apache Iceberg (pointer to `n0d` ADR-0030) | Accepted (owned by `n0d`) |
## Deliberately not yet written here
Two decisions the original BACKLOG (P1-2) named explicitly are **not**
written as ADRs in this pass, on purpose:
- **Payments provider (Stripe vs. Revolut vs. Hyperswitch).** Gated on the
account owner's decision (BACKLOG P1-23) — writing an ADR that presents a
choice as "accepted" before it's actually been decided would misrepresent
the repo's own state, which is exactly what this whole documentation pass
is trying to stop doing.
- **The `services/scrapers/*` keep-vs-remove question.** Explicitly out of
scope for this pass — see `SECURITY.md` and the dated, attributed
provenance record already maintained for that decision elsewhere in this
repo's compliance docs. Not duplicated here.
## Convention
New ADR: `NNNN-short-kebab-title.md`, next sequential number, status one of
`Proposed` / `Accepted` / `Superseded by ADR-NNNN` / `Rejected`. Record the
date the decision was actually made (from `git log`/commit history where
possible), not just the date the ADR file was written, when they differ —
see 0001–0003 for the pattern.
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.