Skip to content

Threat Model: Data Plane

Created 2026-08-09
Last reviewed 2026-10-19
Next review due 2027-04-19 (6-month cadence, or on any change to the data stores, backups, or their access paths)
Reviewers Platform owner
Version 2.2
Surface owner Platform / Data

Scope: the stateful services on the OVH k3s server (Postgres on CloudNativePG, Redis, the NATS WebSocket backplane, Photon) and the R2 buckets they back up to or read from. Store-side view: who can reach each store, how it authenticates, where the data sits at rest and in backup, and whether a restore works. Human access to the admin UIs is in Authentication; the edge and NetworkPolicy view is in Network & Ingress.

For how it works, see Postgres Operations, Disaster Recovery, Cloudflare (R2), Secrets Management and Network Policies.

Data flow diagrams

Dev and prod share one cluster. Postgres, Redis, pgAdmin and Redis Insight for both envs run in the data namespace; NATS and Photon run once in platform and serve both envs; NATS gives each env its own account. All object storage is R2.

Path 1: backend to stores

flowchart LR
    P1[P1 · backend<br/>tomoda-env api + async] -->|F1 SQL, SCRAM over TLS verify-full| D1[(D1 · Postgres<br/>CNPG per env)]
    P1 -->|F2 RESP, password| D2[(D2 · Redis<br/>per env)]
    P1 -->|F3 pub/sub, per-env account, plaintext| P2[P2 · NATS nats-bus<br/>one account per env]
    P1 -->|F4 HTTP geocode| P3[P3 · Photon]
    P1 -->|F5 S3 API, app token| D4[(D4 · R2 assets-env)]
    E2([E2 · Operator]) -->|F6 oauth2-proxy| P5[P5 · pgAdmin / Redis Insight]
    P5 --> D1
    P5 --> D2
    subgraph data[trust boundary: data namespace, dev + prod]
        D1
        D2
        P5
    end
    subgraph platform[trust boundary: platform namespace]
        P2
        P3
    end

Path 2: backup, restore and bulk data

flowchart LR
    D1[(D1 · Postgres prod)] -->|F7 WAL + daily base, cluster token| D3[(D3 · R2 tomoda-db-backups)]
    P6[P6 · k3s etcd snapshots] -->|F8 every 6h, cluster token| D3
    D3 -->|F9 DR script, recovery cluster| D1
    D5[(D5 · R2 location-seed)] -->|F10 seed Job, cluster token| D1
    D6[(D6 · R2 photon-index, public)] -->|F11 HTTPS + MD5, same origin| P3[P3 · Photon]
    subgraph r2[trust boundary: Cloudflare R2]
        D3
        D5
        D6
    end

DFD elements

Ref Type Element Notes
E2 External entity Operator 4 allow-listed emails in k8s/envs/platform/oauth2-proxy/application.yaml
P1 Process Backend tomoda-api, tomoda-async in tomoda-dev / tomoda-prod
P2 Process NATS k8s/envs/platform/nats/manifests.yaml; nats-bus, accounts DEV and PROD, core NATS, no JetStream, no routes, 1 replica
P3 Process Photon k8s/envs/platform/photon/manifests.yaml; planet index, ClusterIP
P5 Process Admin UIs k8s/envs/*/pgadmin, k8s/envs/*/redis-insight
P6 Process k3s etcd snapshots scripts/ovh/k3s-server.yaml (etcd-s3, secrets-encryption: true)
D1 Data store Postgres k8s/envs/*/postgres/manifests/cluster.yaml; 1 instance, local-path PVC. Operator CNPG 1.30.1, which authenticates its calls to the instance manager's sensitive status-port endpoints (backup, pg_controldata, upgrade) with a pinned client certificate. Prod backs up through the Barman Cloud plugin sidecar (ObjectStore postgres-prod-backups); CNPG's in-tree barmanObjectStore is deprecated since CNPG 1.26 with removal scheduled for 1.31, and policy/cnpg_barman_plugin.rego rejects it
D2 Data store Redis k8s/envs/*/redis/values.yaml; sessions, rate limits, job queue
D3 Data store Backup bucket prod/ (CNPG), k3s-etcd/, ota/; 45-day lifecycle
D4 Data store Assets buckets User media, tomoda-assets-{dev,prod}
D5 Data store Seed bucket Seed sets and dated archives
D6 Data store Photon index bucket Public custom domain photon-index.tomoda.life

Assets and trust boundaries

Asset DFD Boundary crossed
User data at rest (PII, chat, places) D1 backend ns → data ns
Prod DB backups (full PII copy, live refresh tokens) D3 data ns → R2
etcd snapshots (all cluster objects, Secrets encrypted) D3 node → R2
Sessions, rate limits, queued jobs D2 backend ns → data ns
Realtime chat and notification payloads P2 backend ns → platform ns
User media D4 backend / client → R2
R2 cluster token, R2 app tokens, DB/Redis passwords, NATS account passwords all GCP SM → ESO → pods

STRIDE

Spoofing

DFD Threat Control Residual
F1 Rogue client logs in to Postgres pg_hba: hostssl all all 10.42.0.0/16 scram-sha-256, password_encryption: scram-sha-256 (k8s/envs/prod/postgres/manifests/cluster.yaml); NetworkPolicy postgres-prod-policy (network-policy.yaml) Low. Password from GCP SM tomoda-db-password-{env}
F1 Backend talks to a fake Postgres DB_SSLMODE=verify-full with the CNPG CA mirrored into the app ns (k8s/apps/tomoda/overlays/*/ca-sync.yaml, ca-reader-rbac.yaml); alias SAN in certificates.serverAltDNSNames Low
F2 Rogue client connects to Redis auth.enabled: true, password from tomoda-redis-password-{env}; NetworkPolicy admits only the env's backend pods and Redis Insight (k8s/envs/*/redis/values.yaml) Low
F3 Rogue NATS client One user per env account (tomoda-dev, tomoda-prod), passwords from the nats-bus-auth ExternalSecret; nats-ingress admits :4222 only from the api and async pods in tomoda-dev and tomoda-prod (k8s/envs/platform/nats/manifests.yaml) Low
F3 Rogue server joins as a NATS route No cluster block and no :6222; the server runs no routes Low
F6 Unauthenticated admin UI access oauth2-proxy forwardAuth middleware on every admin Ingress, email allow-list, CI guard policy/admin_ingress_auth.rego; pgAdmin adds its own login Low. Redis Insight has no login of its own

Tampering

DFD Threat Control Residual
D3 Prod backups deleted or overwritten 45-day lifecycle backstop, prevent_destroy on the bucket (infrastructure/cloudflare/r2.tf). Locks cover k3s-etcd/ (3d) and ota/ (14d) only Medium. prod/ is unlocked because barman rewrites backup.info and retried WAL keys. Any holder of the cluster token can delete prod backups. Findings 1, 4
D5 Seed archive altered Indefinite locks on seed-archive/20* and geo-covers/20* (r2.tf) Low. seed/<version>/ is writable by design (seed-publish.sh --force)
D4 User media altered Per-env app token (tomoda-r2-app-{env}-credentials), signed read URLs via the assets Worker Low. No lock, by design (users delete their media)
F11 Poisoned Photon index HTTPS from R2; MD5 fetched from the same origin (photon/manifests.yaml) Low. MD5 only detects corruption; write on the bucket is the cluster token. Finding 5
F3 Forged realtime message Per-env accounts: dev and prod have separate subject spaces Low. Within an account there is no subject ACL; any backend pod of that env can publish any client.<uuid> / session.<uuid> subject

Repudiation

DFD Threat Control Residual
F1 DB change not attributable One DB identity per env; app-layer audit log Low. Operator actions via pgAdmin are attributable only in the proxy log (see Authentication)
D3 Backup deletion unnoticed PostgresBackupStale, PostgresWALArchivingFailing, PostgresBaseBackupFailed alerts (k8s/envs/platform/manifests/postgres-alerts.yaml) Low. Alerts catch missing new backups, not deletion of old ones

Information disclosure

DFD Threat Control Residual
F1 DB traffic sniffed in-cluster TLS required by hostssl; backend verifies with verify-full Low. pgAdmin uses SSLMode: prefer (encrypted, unverified)
F3 Realtime payloads read off the bus Per-env accounts; caller-scoped nats-ingress Low. No TLS (NATS_TLS unset); traffic stays on the single-node pod network
D3 Backup bucket read Bucket is private; access only through R2 API tokens Medium. Same token is mounted in six places across dev and prod. Refresh tokens are stored as issued (see Authentication), so a backup read yields live credentials. Finding 1
D1, D2 Disk at rest None at the volume level. OVH template install, RAID1, no LUKS (docs/operations/bootstrap.md, scripts/ovh/bootstrap-node.sh); PVCs are local-path host directories. k3s secrets-encryption: true covers Secrets in etcd only Low-Medium. Exposure is the provider's physical and disk-disposal handling. Finding 2
D3, D4 R2 at rest R2 encrypts every object with AES-256-GCM (provider-managed keys). Barman adds no encryption: CNPG's encryption field asks for S3/KMS server-side encryption, which R2 does not support (Encryption at Rest) Low. A cluster-token holder reads backups in plaintext. Finding 7
Logs PII in logs Backend masks secrets and emails and redacts query tokens (tomoda repo backend/internal/logger/logger.go, backend/internal/wiring/router.go); Alloy redacts sensitive query params (tokens, codes, passwords, signatures, identifier, X-Amz-*) in Traefik lines before Loki (k8s/envs/platform/loki/values-alloy.yaml). Postgres never logs bind parameters (log_parameter_max_length and log_parameter_max_length_on_error are "0" in both envs, cluster.yaml) and logs only slow queries Low. Logs go to Loki (168h) and R2 tomoda-observability (14d). Traefik JSON access logs keep client IPs

Denial of service

Out of scope for the register except single-instance Postgres (finding 8). Notes: single instance for Postgres, Redis and NATS. Redis runs --maxmemory below its limit with noeviction, so it refuses writes instead of OOM-killing or dropping queued jobs. NATS caps max_payload (256 KiB), max_connections and write_deadline. A new Photon index causes a short outage (UPDATE_STRATEGY: SEQUENTIAL).

Elevation of privilege

DFD Threat Control Residual
D2 Any pod reaches Redis Bitnami chart NetworkPolicy with allowExternal: false; extraIngress admits :6379 only from the env's tomoda-api, tomoda-async and location-seed-load pods and its Redis Insight (k8s/envs/*/redis/values.yaml) Low
D1 Dev workloads reach prod Postgres postgres-prod-policy admits :5432 only from the prod api, async and seed-load pods, prod pgAdmin and its own instances; cnpg-system on all ports and monitoring on :9187 Low. Dev tooling in data is denied
P2 Any pod reaches NATS nats-ingress admits :4222 only from the api and async pods in tomoda-dev and tomoda-prod, and :7777 only from monitoring Low
P3 Any pod reaches Photon None; no NetworkPolicy Low. Index is public data
D3 R2 cluster token over-scoped Token scopes are set in the Cloudflare dashboard, not Terraform (r2.tf header). Documented scope: object R/W on db-backups, observability, ota-*, location-seed, photon-index (docs/security/iam.md) Medium. Mounted in data, kube-system, monitoring, platform (Xavia dev and prod), the seed Job's namespace and, during a drill, restore-drill. A compromise of any of them, including dev, reads or deletes prod backups and etcd snapshots. Scopes are not verifiable from code. Finding 1
D4 App token over-scoped tomoda-r2-app-{env}-credentials, documented as one bucket each Low. Dashboard-managed, same verification gap
F1 Backend over-privileged in the DB None; the backend logs in as the initdb owner (DB_USER: tomoda_prod_user) Medium. DDL/DROP on the app database. Finding 3
D3 Barman Cloud plugin controller over-privileged Chart RBAC (k8s/envs/platform/cnpg/application.yaml): the controller in cnpg-system reads Secrets cluster-wide and creates per-cluster Roles granting an instance pod its ObjectStore and credential Secrets. Operator to plugin gRPC uses mutual TLS from cert-manager Low. Same trust level as the CNPG operator, which also holds cluster-wide Secret access
F9 Restore clobbers prod DR script restores into a new cluster (postgres-prod-<date> in data, or restore-drill for a drill), never in place, and the new cluster archives to its own path (scripts/disaster-recovery.sh) Low

Backup restore testing

scripts/disaster-recovery.sh has a restore drill and a recovery path; Disaster Recovery is the runbook.

  • Drill. task dr:drill restores the live cluster's latest backup, or a point in time, into a single-instance cluster in the restore-drill namespace. It compares that cluster with prod over read-only sessions: health, promotion, extensions, the alias SAN on the server cert, row counts on six key tables and the latest created_at. It never scales, patches or backs up anything in prod; the drill cluster has no plugins entry and reads a copy of the ObjectStore, without retention, only as its recovery source. It checks node memory and disk first and refuses if they are short. Drills run quarterly and are recorded in the drill log; the latest passed.
  • TLS on cutover. The recovery cluster carries the live cluster's serverAltDNSNames plus the alias the backend dials. The cutover switches the backend's CA mirror (ca-sync.yaml) and the CA reader Role to the new cluster's CA, so verify-full passes.
  • Cutover in git. --mode cutover edits the alias Service, the CA mirror, the CA reader Role and the alert selectors in the working tree; Argo CD applies the merged change. The scale-down that stops writes runs only while auto-sync is paused for prod and tomoda-prod, and the script refuses otherwise.
  • Same controls as live. The recovery cluster gets a NetworkPolicy copied from the live cluster's, its pg_hba and parameters, and its own ObjectStore and plugin archiver writing prod/<name>/, apart from the source path. The operator types the new cluster's name before any change.
  • Exercised only in a real recovery. The CA mirror switch, the Argo CD pause and the git cutover. During a drill the R2 cluster token is also mounted in restore-drill (finding 1).

Findings and recommendations

Ordered by priority.

  1. One R2 token spans dev, prod and every bucket class (Medium, open). tomoda-r2-cluster-credentials has R/W on the backup bucket and is mounted in six consumers, including dev Xavia and the seed Job. Split it: a backup token (db-backups only, data and kube-system), an observability token, per-env OTA tokens, a read-only seed token, and Photon-index write held by CI only. Track the scopes in Terraform (cloudflare_api_token) so they can be reviewed.
  2. No disk encryption at rest on the OVH server (Low, accepted). PVCs, including the Postgres data directory, are plaintext on the RAID1 NVMe. Accepted: pre-launch single node; OVHcloud erases a server's drives after the service ends and before reuse (NIST SP 800-88 Purge, Clear where Purge is not possible), and we Purge the NVMe ourselves before releasing a server (Node Lifecycle); backups are off-node and encrypted in R2 with PITR and a passing restore drill. Revisit on a node reprovision or OS reinstall, when a node is added, or on a customer or contract requirement.
  3. Backend connects as the DB owner (Medium, open). Add a DML-only runtime role and keep the owner for migrations.
  4. Prod backups are deletable (Medium, accepted constraint). Barman can't write under a lock. Mitigate with finding 1, plus a nightly copy of completed base backups to a locked prefix.
  5. Photon index integrity is same-origin (Low, open). Publish a checksum from CI to a separate location, or restrict index write to CI (finding 1).
  6. Admin UI hygiene (Low, open). Redis Insight has no login of its own; pgAdmin uses SSLMode: prefer.
  7. Backups use provider-managed keys only (Low, open). A cluster-token holder reads WAL and base backups in plaintext. R2 supports customer-provided keys (SSE-C) and barman-cloud 3.20 does too, but the Barman Cloud plugin does not expose them yet (upstream plugin-barman-cloud issue #646, PR #1017). Prod backs up through the plugin (Postgres (CNPG)). Pending CNPG support: enable SSE-C with the key in Secret Manager and a new destinationPath.
  8. Single-instance Postgres (Medium, accepted). postgres-prod runs instances: 1 on the one node, so a node or disk loss means a restore from R2. Accepted: pre-launch single node (a standby would share the hardware); PITR from off-node backups and a passing restore drill cover data loss. Revisit on a node reprovision or OS reinstall, when a node is added, or on a customer or contract requirement.