Wayfinder: hAPI v1 spec #44

Closed
opened 2026-11-23 16:04:54 -05:00 by bobby · 1 comment
Owner

Destination

A v1 spec for hAPI: locked platform decisions (recorded as ADRs) covering cluster, database, network exposure, auth, job bridge to Home Assistant, delivery, secrets, and observability, plus MVP-depth specs for the four starting domains (finance, fitness, maintenance, smart home). Detailed enough to break directly into ready-for-agent / ready-for-human implementation issues.

Notes

  • Planning only. Tickets produce decisions, not deliverables. wayfinder:task tickets may touch real infrastructure only when a decision is blocked on hands-on evidence; building the real cluster is the first implementation epic after this map closes.
  • Domain docs: use the vocabulary in GLOSSARY.md (Principal / Person / Bot / Owner); record hard-to-reverse decisions as ADRs in docs/adr/. Grilling sessions should also call domain-modeling.
  • Standing decisions (settled while charting):
    • hAPI is a FastAPI modular monolith: one deployable, one module per domain plus shared platform code, one Postgres database with a schema per domain.
    • Cluster infra code lives in this repo (e.g. infra/ for the cluster, deploy/ for hAPI's manifests), kept cleanly separable for a later split.
    • Environments: production plus local dev only.
    • Self-managed Kubernetes on Linode (not LKE) for the learning experience; Linode managed database. Keep resources reasonable for small load.
    • Uptime Kuma, ntfy, Home Assistant, and Gitea exist outside the cluster; hAPI only integrates with them.
    • Observability in v1 = health checks (for Kuma) + centralized logs + basic metrics.
  • Security is imperative: data is personal; assume hostile internet.

Tickets

  • Private connectivity between the home network and a Linode cluster (#46)
  • How can Home Assistant consume jobs from an external system? (#47)
  • Self-managed Kubernetes on Linode: distributions and integration points (#48)
  • Linode Managed PostgreSQL: networking, security, and backups (#49)
  • Who owns data: a Person, the household, or both? (#50)
  • Which libraries and conventions form the FastAPI app skeleton? (#51)
  • How is hAPI reachable on the network? (#45)
  • Which Kubernetes distribution and cluster topology? (#52)
  • How does hAPI connect to its managed database? (#53)
  • How do Principals authenticate, and what may each do? (#54)
  • Which bridge carries jobs to Home Assistant? (#55)
  • How do code changes reach the cluster? (#56)
  • How are secrets stored and delivered? (#57)
  • How are health, logs, and metrics exposed and collected? (#58)
  • What is the Finance MVP? (#59)
  • What is the Fitness MVP? (#60)
  • What is the Home maintenance MVP? (#61)
  • What is the Smart home MVP? (#62)
  • Which Gateway, certificates, and DNS front the public surface? (#63)
  • Verify Managed DB VPC attach, role setup, and RLS on a live us-iad cluster (#64)
  • Which sources can feed posted Transactions from our banks and cards? (#65)
  • Check whether SimpleFIN covers Capital One and Fulton with purchase dates (#66)
  • Which importer Bots ship in v1, and where do they run? (#67)
  • How do scheduled and background jobs run? (#68)
  • How does hAPI send notifications through ntfy? (#69)
  • How are backups taken, and how do we recover from disaster? (#70)
  • Which cluster hardening ships in v1? (#71)

Decisions so far

  • Self-managed Kubernetes on Linode: distributions and integration points: all of kubeadm/k3s/RKE2/Talos work with Linode CCM, CSI, VPC, Cloud Firewall via linode/linode TF. Suggested direction: Talos + Cilium (Gateway API, WireGuard node encryption) + OpenTofu. ingress-nginx archived 2026-03; use Gateway API. VPC traffic is unencrypted; cloud-firewall-controller is LKE-only; Talos needs direct-disk boot. findings
  • How can Home Assistant consume jobs from an external system?: HA has no AMQP and explicitly doesn't support RabbitMQ's MQTT plugin (use Mosquitto). HA-initiated: MQTT (always clean session, so no offline queueing) or REST polling; hAPI-initiated over the private link: HA REST/WebSocket API (simplest, no broker). No built-in job acks; durability must live in hAPI (Postgres job table + idempotency). findings
  • Private connectivity between the home network and a Linode cluster: Linode VPC can't reach home (single-DC, no VPN/peering). Tentative pick: Tailscale + k8s operator exposing Bot-facing Services privately; HA joins via add-on (can subnet-route LAN Bots). Trade-off: operator is incompatible with Tailnet Lock, so Tailscale's control plane is trusted; alternatives plain WireGuard or Headscale (operator support lands v0.30). findings
  • Linode Managed PostgreSQL: networking, security, and backups: private access via VPC works but is still beta; otherwise public endpoint + allowlist. TLS mandatory, PG 15–18, 1–3 nodes, 14-day PITR (no off-platform export → own pg_dump). Watch-outs: LKE auto-allowlisting, md5 default, root password in TF state. findings
  • Who owns data: a Person, the household, or both?: both, fixed per record type. There is one Household; each record is Personal data (one Person) or Household data (all Household members, equal access, no roles). No per-record sharing; the Owner has no read access to others' Personal data; Bots use Owner-given Household grants or Person-granted, revocable Bindings; every record carries Recorded by. ADR-0001
  • Which libraries and conventions form the FastAPI app skeleton?: Python 3.14 + uv, Ruff + pyright strict, just/pre-commit/Renovate; async SQLAlchemy 2 + Pydantic v2, Alembic single history via explicit hapi migrate; platform/ + per-domain packages bounded by import-linter; /v1, RFC 9457 errors, UUIDv7 ids, cursor pagination, structlog JSON; pytest on real Postgres with mandatory wrong-Principal tests; slim non-root image, one uvicorn per pod. resolution
  • How is hAPI reachable on the network?: one public surface (HTTPS :443) for Persons and Bots, gated only by hAPI's own auth. No tunnel to home (CGNAT: traffic only ever starts from home), no IAP/CDN. Every public endpoint is TLS-only and requires per-Principal auth, so Kuma is a Bot and :80 is closed (DNS-01). Owner admin is CLI-only in the pod. The k8s/Talos APIs are reachable only over a management-only Tailscale tailnet with Tailnet Lock. ADR-0002
  • Which Kubernetes distribution and cluster topology?: Talos in us-iad. 1 control-plane node + 2 workers (g6-standard-2) in a spread placement group. Cilium with WireGuard, tunnel mode. Nodes have public IPv4 for outbound traffic, a deny-all firewall except Tailscale UDP 41641 and the VPC, and :443 arrives through a CCM NodeBalancer with VPC backends. No API NodeBalancer: the cluster endpoint is reachable over the management tailnet only. Talos LUKS on STATE and EPHEMERAL. OpenTofu with encrypted state in Object Storage. Tofu installs only Cilium and the CCM; everything else comes through delivery. ADR-0003
  • Verify Managed DB VPC attach, role setup, and RLS on a live us-iad cluster: VPC attach works in us-iad (private DNS resolves in the VPC only; the allowlist is what blocks outside access), along with scram, verify-full, the two-role bootstrap, and RLS for hapi_app. Surprises: FORCE binds the owner too; leaked hapi_app creds can spoof any principal; max_connections is 50 on 2 GB (25 on 1 GB); no statement audit is available; an in-place resize stalled (no downtime); Terraform needs Linode Interfaces with an explicit firewall_id; PG 19 is offered. Re-decide points are posted on How does hAPI connect to its managed database?. evidence
  • How does hAPI connect to its managed database?: Managed PG 18, Shared 2 GB, 1 node, VPC-only (the allowlist holds only the VPC subnet), verify-full, scram. Two roles: hapi_migrator owns everything and hapi_app is DML-only; akmadmin stays out of the cluster and runs only through hapi db bootstrap. RLS (ENABLE, not FORCE) on Personal data guards against app bugs, not leaked app credentials (the network contains those). Break-glass goes through a logged hapi db breakglass wrapper. Pool 5+5 per pod, at most 4 app pods within 46 usable connections. Plan changes are restores-to-new-cluster. ADR-0004
  • How do Principals authenticate, and what may each do?: every Principal uses an opaque bearer Token (hapi_<id>_<secret>, stored hashed, looked up on each request, so revocation is instant, 365-day default expiry). No IdP and no interactive login in v1. Persons are authorized by ownership; Bots by Scopes (<domain>:read|write, health) from Owner-given Household grants or Person-given per-domain Bindings. Flat resources with owner as an attribute. RLS now covers Household data too and enforces Bindings and read/write Scopes. The Owner is an ordinary Person on the API. ADR-0005
  • Which bridge carries jobs to Home Assistant?: HA polls GET /v1/smart_home/jobs/next (built-in rest sensor, 15–30 s) and reports results via rest_command. There is no broker and no new public surface; MQTT is the upgrade path. A Job is Household data naming an allowlisted HA script (hapi_*) plus variables. Delivery is at-least-once FIFO with a 2-minute lease and 3 attempts. Jobs can carry not_before, and expires_at defaults to 1 h. HA is a Bot with smart_home:write (no jobs Scope). The scripts live in a separate HA config repo. ADR-0006
  • How do code changes reach the cluster?: Flux pulls this public repo anonymously (1-min poll, prune, no git credentials in the cluster). Gitea Actions runs on a dedicated runner VM: PRs get lint, types, tests, image build, smoke test, and a Trivy scan. On main, CI also pushes to Gitea's registry and commits the digest bump. Every green merge to main deploys. Migrations are a digest-named Job that the app dependsOn (expand/contract, forward-only). 2 replicas with surge 1. Rollback = git revert. Renovate auto-merges only dev tooling. Tofu and Talos changes stay manual over the tailnet. ADR-0007
  • How are secrets stored and delivered?: SOPS + age in this public repo, decrypted by Flux. One offline-generated age key lives in Vaultwarden, and the Owner installs it by hand (never in Tofu state). Secrets are mounted as files, never env vars. hapi-db-app and hapi-db-migrator are split, and bootstrap makes the roles match the passwords in git. Each integration gets one narrow token (the CCM's comes from Tofu). CI secrets are Gitea Actions secrets. gitleaks plus a SOPS check run in CI. Rotation is manual and event-driven. Owner roots are in Vaultwarden, with an offline copy. ADR-0008
  • How are health, logs, and metrics exposed and collected?: kubelet probes and /metrics sit on an internal :8081 that the Gateway never routes, in the API's event loop (/readyz doesn't check the DB). Kuma (a Bot on its own public VM) polls GET /v1/health (health Scope), which reports ok/degraded/down with only check names. VictoriaMetrics + VictoriaLogs self-hosted in-cluster, with Vector, Talos logs and k8s Events. Grafana only via port-forward over the tailnet, with egress denied. Logs are kept 30 d, breakglass audit 1 y. Alert owners: Kuma, Flux, vmalert, plus a Watchdog → Kuma push. ADR-0009
  • Which sources can feed posted Transactions from our banks and cards?: none of the five banks has a personal API (Capital One's is partner-only; the MCP servers found are third-party). Recommended joint importer: SimpleFIN Bridge ($15/yr, read-only, pending skipped, one revocable access URL, optional transacted_at purchase date). Fallback and history: OFX/QFX exports (stable ids, posted date only); avoid CSV (no ids). Apple Card = Wallet/card.apple.com export (FinanceKit needs an App Store app). Unverified: SimpleFIN coverage of Capital One/Fulton and whether it fills purchase dates. findings
  • What is the Finance MVP?: a ledger + zero-based Budget per owner (Household Budget over Household Accounts, a Person's over their Personal Accounts). Financial Accounts own their Transactions and never change owner (hand-over = tracked_until / new Account tracked_from). Household Categories can be used on members' Personal Transactions. Standing Targets (monthly/quarterly/annual), Moves, Banked Categories carry forward, unassigned reported but not enforced, rebalance hint. Idempotent transactions/ingest from importer Bots (posted only, occurred_on = purchase date), manual > learned Payee mappings. Deferred: splits, net worth + transfer-leg linking, ML, pending, finer Scopes (v2). resolution
  • What is the Fitness MVP?: hand-logged Workouts + body Measurements, Personal per Person; greenfield, no import. Shared Household/Personal Exercises (Category pattern: merge same-kind, promote, kind frozen once used) of kind strength/bodyweight/timed/cardio; a Workout (performed_on date) holds entries of Sets (reps, load_g, RPE, warmup) or one cardio effort; a run is a one-entry Workout. Fixed-enum Measurements. SI integers. Whole-Workout POST, idempotent on optional external_id; plain REST edits/hard deletes; per-Exercise history + bests computed on read. Fitness v2: templates/goals, wearable import, reminders. resolution
  • What is the Home maintenance MVP?: domain renamed Maintenance (upkeep of the Household's physical property, vehicles included), all Household data. Assets (roof, furnace, car; optional make/model/serial, installed, warranty) with an optional meter and Readings. Tasks always recur: floating interval after the last Service, or fixed restricted RRULE, plus an optional usage interval, due on whichever comes first; computed on read; snooze/archive. Services record any work done (optionally fulfilling a Task; one-off past work stands alone; no future to-dos). external_id on Services/Readings. v2: attachments, Finance cost link, HA runtime-Reading Bot. resolution
  • Check whether SimpleFIN covers Capital One and Fulton with purchase dates: SimpleFIN covers Capital One + Fulton (Diamond CU, Chase, Apple Card listed in search, not connected). No purchase date: transacted_at always equals posted (treat it as date-only). History is about 45–90 days, anchored at connection; use ≤45-day start-date windows; no pending rows. Ids TRN-… are stable across pulls (100/100, 47/47), so they're safe as per-Account idempotency keys. The Access URL is in Vaultwarden "SimpleFIN Access URL". resolution
  • What is the Smart home MVP?: Jobs only; HA stays the source of truth for house state (no state store, no hAPI automations: v2; HA data for other domains goes to their endpoints). Generic script+variables Jobs, no typed controls or catalogue; state read-back via a query Job's response. Optional external_id per creator. List/get/cancel, no PATCH. POST /jobs/{id}/result is the one way to finish a Job: HA or any Household member closing it by hand (Recorded by shows who), not restricted to the leasing Bot. No domain code creates Jobs in v1. resolution
  • Which Gateway, certificates, and DNS front the public surface?: hapi.bobbypalko.com, IPv4 only, on a Tofu-reserved IP. The NodeBalancer runs in TCP mode with Proxy Protocol v2, behind a 443-only firewall. Envoy Gateway (2 replicas) terminates TLS 1.3 and enforces edge limits (1 MiB bodies, ~20 req/s per IP, connection caps, timeouts); Cilium's Gateway lacks these. cert-manager uses Let's Encrypt over DNS-01, with the challenge CNAMEd into a delegated acme.bobbypalko.com zone whose restricted-user token can't touch the main zone. CAA pins dns-01 and our accounturi, and the account key is kept in SOPS. Still to verify during the build: token capping and subzone delegation (fallback: acme-dns). ADR-0010
  • Which importer Bots ship in v1, and where do they run?: v1 ships one SimpleFIN Bot for the Household Accounts only, with no backfill and no file importer (the Owner's Personal Accounts and Apple Card come in v2). It's an in-cluster CronJob (bots/simplefin/, every 6 h, 14-day window) that calls the internal hAPI Service with a finance:write Household grant. Its Token, Access URL and account mapping live in one SOPS secret. A clean run pings Kuma (13 h window), and its egress is default-deny. Finance amended: occurred_on is the best-known date, editable within 31 days before posted_on; new dated_by; a date_review flag on posted-date rows from days 1–5. ADR-0011, resolution
  • How do scheduled and background jobs run?: Kubernetes CronJobs running hapi <subcommand> from the app image. No worker, queue or outbox. hapi jobs sweep every 15 min (expire + 90-day purge); notification checks are hapi notify <check> CronJobs. Household work runs as a built-in tokenless scheduler Bot, and Personal work runs per Person, read-only. Event-triggered work is caught by the next check. Checks write durable Notifications (dedupe ledger, retry, future inbox). Pool 1 per CronJob (ADR-0004 budget amended); one generic vmalert staleness rule; Household timezone drives spec.timeZone. ADR-0012
  • How does hAPI send notifications through ntfy?: two lanes: platform alerts (CI, Flux, vmalert, Kuma) publish straight to Owner-only ops/ops-urgent topics; hAPI Notifications are records to one Person or the Household. ntfy at notify.bobbypalko.com, deny-all, one publish-only user per sender, read-only user per Person. v1 checks: tasks (due soon/overdue), jobs (failed/expired), budget (hourly, a Household Category goes red), tokens (30/7 d); no Personal-domain checks. Checks only write; hapi notify deliver every 2 min publishes. Breakglass fails closed if it can't notify. No preferences, read state or API in v1; titles carry no amounts. ADR-0013
  • How are backups taken, and how do we recover from disaster?: a daily hapi db backup CronJob (03:00, read-only BYPASSRLS hapi_backup role) streams pg_dump → pg_restore --list check → age to a dedicated recipient whose private key never enters the cluster → a Linode bucket with Object Lock in compliance mode (35 d). An off-account puller with a read_only key (rclone copy --immutable; the Owner's PC for now, a NAS later) keeps 90 dailies, 3 years of monthlies, 1 year of breakglass audit/, and the Tofu state. No etcd snapshots: the cluster is rebuilt from code; Gitea is out of scope. Kuma push monitors at 26 h for the job and 8 d for the puller (26 h once on the NAS). hapi db restore runs in a pod with the key pasted in at run time. A full drill before go-live, then a restore every 6 months as a Maintenance Task. ADR-0014
  • Which cluster hardening ships in v1?: built-ins only. Default-deny CiliumNetworkPolicies in every namespace we own (kube-system stays open); PSA restricted, with the node agents moved into a privileged monitoring-node namespace; two ValidatingAdmissionPolicies (images from Gitea's registry or pinned by digest; read-only root filesystem and no SA token in hapi/bots); K8s audit logs at Metadata level, kept 1 y, with an ops alert on exec or a human reading a Secret. Upgrades: versions pinned, Renovate PRs, security patches within 14 d, a runbook, and a monthly Maintenance Task on a "hAPI cluster" Asset (Maintenance now covers digital systems). Commit and image signing deferred (their keys would sit with Gitea). Runtime detection, Trivy Operator, host firewall and least-privilege kubeconfigs: v2. ADR-0015

Not yet specified

(nothing left in the fog: every in-scope area is a ticket)

Out of scope

  • Frontend (separate repo, may never be built).
  • Mobile apps.
  • Public signups and third-party OAuth access.
  • Changes to Home Assistant configuration beyond what the job bridge needs.
  • Deploying Uptime Kuma, ntfy, Home Assistant, or Gitea.
  • A staging environment (v1).
  • Distributed tracing.
  • Sharing data outside the Household, and guest access to Household data for non-members (per Who owns data: a Person, the household, or both?; unlikely even later).
  • Roles within the Household (v2; v1 Household members have equal access).
  • Recurring Smart home Jobs in hAPI: HA automations own recurring house behaviour; Jobs are one-shot with not_before (per What is the Smart home MVP?).
  • Interactive login (passkeys, OIDC) in v1: Persons use Tokens. Expected to arrive with a future browser frontend as a new credential kind (per How do Principals authenticate, and what may each do?).
  • Multi-currency in Finance: USD only, not expected ever (per What is the Finance MVP?).
  • Fitness v2: wearable (Garmin/Apple Watch) import, historical import, templates/programs/goals, richer records, daily aggregates, and fitness reminders (per What is the Fitness MVP?). Nutrition as a domain.
## Destination A **v1 spec** for hAPI: locked platform decisions (recorded as ADRs) covering cluster, database, network exposure, auth, job bridge to Home Assistant, delivery, secrets, and observability, plus **MVP-depth** specs for the four starting domains (finance, fitness, maintenance, smart home). Detailed enough to break directly into `ready-for-agent` / `ready-for-human` implementation issues. ## Notes - **Planning only.** Tickets produce decisions, not deliverables. `wayfinder:task` tickets may touch real infrastructure only when a decision is blocked on hands-on evidence; building the real cluster is the first implementation epic after this map closes. - **Domain docs:** use the vocabulary in `GLOSSARY.md` (Principal / Person / Bot / Owner); record hard-to-reverse decisions as ADRs in `docs/adr/`. Grilling sessions should also call `domain-modeling`. - **Standing decisions (settled while charting):** - hAPI is a **FastAPI modular monolith**: one deployable, one module per domain plus shared platform code, one Postgres database with a schema per domain. - **Cluster infra code lives in this repo** (e.g. `infra/` for the cluster, `deploy/` for hAPI's manifests), kept cleanly separable for a later split. - **Environments:** production plus local dev only. - Self-managed Kubernetes on **Linode** (not LKE) for the learning experience; **Linode managed database**. Keep resources reasonable for small load. - Uptime Kuma, ntfy, Home Assistant, and Gitea exist outside the cluster; hAPI only integrates with them. - Observability in v1 = health checks (for Kuma) + centralized logs + basic metrics. - **Security is imperative**: data is personal; assume hostile internet. ## Tickets - [x] Private connectivity between the home network and a Linode cluster (#46) - [x] How can Home Assistant consume jobs from an external system? (#47) - [x] Self-managed Kubernetes on Linode: distributions and integration points (#48) - [x] Linode Managed PostgreSQL: networking, security, and backups (#49) - [x] Who owns data: a Person, the household, or both? (#50) - [x] Which libraries and conventions form the FastAPI app skeleton? (#51) - [x] How is hAPI reachable on the network? (#45) - [x] Which Kubernetes distribution and cluster topology? (#52) - [x] How does hAPI connect to its managed database? (#53) - [x] How do Principals authenticate, and what may each do? (#54) - [x] Which bridge carries jobs to Home Assistant? (#55) - [x] How do code changes reach the cluster? (#56) - [x] How are secrets stored and delivered? (#57) - [x] How are health, logs, and metrics exposed and collected? (#58) - [x] What is the Finance MVP? (#59) - [x] What is the Fitness MVP? (#60) - [x] What is the Home maintenance MVP? (#61) - [x] What is the Smart home MVP? (#62) - [x] Which Gateway, certificates, and DNS front the public surface? (#63) - [x] Verify Managed DB VPC attach, role setup, and RLS on a live us-iad cluster (#64) - [x] Which sources can feed posted Transactions from our banks and cards? (#65) - [x] Check whether SimpleFIN covers Capital One and Fulton with purchase dates (#66) - [x] Which importer Bots ship in v1, and where do they run? (#67) - [x] How do scheduled and background jobs run? (#68) - [x] How does hAPI send notifications through ntfy? (#69) - [x] How are backups taken, and how do we recover from disaster? (#70) - [x] Which cluster hardening ships in v1? (#71) ## Decisions so far <!-- one line per closed ticket: [title](link): gist --> - [Self-managed Kubernetes on Linode: distributions and integration points](https://git.bobbypalko.com/bobby/hapi/issues/48): all of kubeadm/k3s/RKE2/Talos work with Linode CCM, CSI, VPC, Cloud Firewall via `linode/linode` TF. Suggested direction: **Talos + Cilium** (Gateway API, WireGuard node encryption) + OpenTofu. ingress-nginx archived 2026-03; use Gateway API. VPC traffic is unencrypted; `cloud-firewall-controller` is LKE-only; Talos needs `direct-disk` boot. [findings](https://git.bobbypalko.com/bobby/hapi/src/branch/research/self-managed-k8s-linode/docs/research/self-managed-k8s-linode.md) - [How can Home Assistant consume jobs from an external system?](https://git.bobbypalko.com/bobby/hapi/issues/47): HA has **no AMQP** and explicitly doesn't support RabbitMQ's MQTT plugin (use Mosquitto). HA-initiated: MQTT (always clean session, so no offline queueing) or REST polling; hAPI-initiated over the private link: HA REST/WebSocket API (simplest, no broker). No built-in job acks; durability must live in hAPI (Postgres job table + idempotency). [findings](https://git.bobbypalko.com/bobby/hapi/src/branch/research/ha-job-consumption/docs/research/ha-job-consumption.md) - [Private connectivity between the home network and a Linode cluster](https://git.bobbypalko.com/bobby/hapi/issues/46): Linode VPC can't reach home (single-DC, no VPN/peering). Tentative pick: **Tailscale + k8s operator** exposing Bot-facing Services privately; HA joins via add-on (can subnet-route LAN Bots). Trade-off: operator is incompatible with Tailnet Lock, so Tailscale's control plane is trusted; alternatives plain WireGuard or Headscale (operator support lands v0.30). [findings](https://git.bobbypalko.com/bobby/hapi/src/branch/research/private-home-cluster-link/docs/research/private-home-cluster-link.md) - [Linode Managed PostgreSQL: networking, security, and backups](https://git.bobbypalko.com/bobby/hapi/issues/49): private access via VPC works but is still **beta**; otherwise public endpoint + allowlist. TLS mandatory, PG 15–18, 1–3 nodes, 14-day PITR (no off-platform export → own pg_dump). Watch-outs: LKE auto-allowlisting, md5 default, root password in TF state. [findings](https://git.bobbypalko.com/bobby/hapi/src/branch/research/linode-managed-postgres/docs/research/linode-managed-postgres.md) - [Who owns data: a Person, the household, or both?](https://git.bobbypalko.com/bobby/hapi/issues/50): **both, fixed per record type**. There is one Household; each record is Personal data (one Person) or Household data (all Household members, equal access, no roles). No per-record sharing; the Owner has no read access to others' Personal data; Bots use Owner-given Household grants or Person-granted, revocable **Bindings**; every record carries Recorded by. [ADR-0001](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0001-data-ownership-model.md) - [Which libraries and conventions form the FastAPI app skeleton?](https://git.bobbypalko.com/bobby/hapi/issues/51): Python 3.14 + **uv**, Ruff + pyright strict, just/pre-commit/Renovate; **async SQLAlchemy 2** + Pydantic v2, Alembic single history via explicit `hapi migrate`; `platform/` + per-domain packages bounded by import-linter; `/v1`, RFC 9457 errors, UUIDv7 ids, cursor pagination, structlog JSON; pytest on real Postgres with mandatory wrong-Principal tests; slim non-root image, one uvicorn per pod. [resolution](https://git.bobbypalko.com/bobby/hapi/issues/51#issuecomment-196) - [How is hAPI reachable on the network?](https://git.bobbypalko.com/bobby/hapi/issues/45): **one public surface** (HTTPS :443) for Persons and Bots, gated only by hAPI's own auth. No tunnel to home (CGNAT: traffic only ever starts from home), no IAP/CDN. Every public endpoint is TLS-only and requires per-Principal auth, so Kuma is a Bot and :80 is closed (DNS-01). Owner admin is CLI-only in the pod. The k8s/Talos APIs are reachable only over a management-only Tailscale tailnet with Tailnet Lock. [ADR-0002](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0002-network-exposure.md) - [Which Kubernetes distribution and cluster topology?](https://git.bobbypalko.com/bobby/hapi/issues/52): **Talos** in `us-iad`. **1 control-plane node + 2 workers** (`g6-standard-2`) in a spread placement group. **Cilium** with WireGuard, tunnel mode. Nodes have public IPv4 for outbound traffic, a deny-all firewall except Tailscale UDP 41641 and the VPC, and :443 arrives through a CCM NodeBalancer with VPC backends. No API NodeBalancer: the cluster endpoint is reachable over the management tailnet only. Talos LUKS on STATE and EPHEMERAL. **OpenTofu** with encrypted state in Object Storage. Tofu installs only Cilium and the CCM; everything else comes through delivery. [ADR-0003](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0003-talos-single-control-plane.md) - [Verify Managed DB VPC attach, role setup, and RLS on a live us-iad cluster](https://git.bobbypalko.com/bobby/hapi/issues/64): **VPC attach works in `us-iad`** (private DNS resolves in the VPC only; the allowlist is what blocks outside access), along with scram, `verify-full`, the two-role bootstrap, and RLS for `hapi_app`. Surprises: `FORCE` binds the owner too; leaked `hapi_app` creds can spoof any principal; **`max_connections` is 50 on 2 GB** (25 on 1 GB); no statement audit is available; an in-place resize stalled (no downtime); Terraform needs Linode Interfaces with an explicit `firewall_id`; PG 19 is offered. Re-decide points are posted on *How does hAPI connect to its managed database?*. [evidence](https://git.bobbypalko.com/bobby/hapi/src/branch/task/verify-db-64/docs/research/verify-db-64) - [How does hAPI connect to its managed database?](https://git.bobbypalko.com/bobby/hapi/issues/53): **Managed PG 18, Shared 2 GB, 1 node**, VPC-only (the allowlist holds only the VPC subnet), `verify-full`, scram. Two roles: `hapi_migrator` owns everything and `hapi_app` is DML-only; `akmadmin` stays out of the cluster and runs only through `hapi db bootstrap`. RLS (`ENABLE`, not `FORCE`) on Personal data guards against app bugs, not leaked app credentials (the network contains those). Break-glass goes through a logged `hapi db breakglass` wrapper. Pool 5+5 per pod, at most **4 app pods** within 46 usable connections. Plan changes are restores-to-new-cluster. [ADR-0004](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0004-database-access.md) - [How do Principals authenticate, and what may each do?](https://git.bobbypalko.com/bobby/hapi/issues/54): every Principal uses an **opaque bearer Token** (`hapi_<id>_<secret>`, stored hashed, looked up on each request, so revocation is instant, 365-day default expiry). No IdP and no interactive login in v1. Persons are authorized by ownership; Bots by **Scopes** (`<domain>:read|write`, `health`) from Owner-given **Household grants** or Person-given per-domain Bindings. **Flat resources** with `owner` as an attribute. **RLS now covers Household data too** and enforces Bindings and read/write Scopes. The Owner is an ordinary Person on the API. [ADR-0005](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0005-authentication-and-authorization.md) - [Which bridge carries jobs to Home Assistant?](https://git.bobbypalko.com/bobby/hapi/issues/55): **HA polls** `GET /v1/smart_home/jobs/next` (built-in `rest` sensor, 15–30 s) and reports results via `rest_command`. There is no broker and no new public surface; MQTT is the upgrade path. A **Job** is Household data naming an allowlisted HA script (`hapi_*`) plus variables. Delivery is at-least-once FIFO with a 2-minute lease and 3 attempts. Jobs can carry `not_before`, and `expires_at` defaults to 1 h. HA is a Bot with `smart_home:write` (no `jobs` Scope). The scripts live in a separate HA config repo. [ADR-0006](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0006-home-assistant-job-polling.md) - [How do code changes reach the cluster?](https://git.bobbypalko.com/bobby/hapi/issues/56): **Flux pulls** this public repo anonymously (1-min poll, prune, no git credentials in the cluster). **Gitea Actions** runs on a dedicated runner VM: PRs get lint, types, tests, image build, smoke test, and a Trivy scan. On `main`, CI also pushes to **Gitea's registry** and commits the **digest** bump. Every green merge to `main` deploys. Migrations are a digest-named Job that the app `dependsOn` (expand/contract, forward-only). 2 replicas with surge 1. Rollback = `git revert`. Renovate auto-merges only dev tooling. Tofu and Talos changes stay manual over the tailnet. [ADR-0007](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0007-flux-pull-delivery.md) - [How are secrets stored and delivered?](https://git.bobbypalko.com/bobby/hapi/issues/57): **SOPS + age** in this public repo, decrypted by Flux. One offline-generated age key lives in Vaultwarden, and the Owner installs it by hand (never in Tofu state). Secrets are mounted as files, never env vars. `hapi-db-app` and `hapi-db-migrator` are split, and bootstrap makes the roles match the passwords in git. Each integration gets one narrow token (the CCM's comes from Tofu). CI secrets are Gitea Actions secrets. gitleaks plus a SOPS check run in CI. Rotation is manual and event-driven. Owner roots are in Vaultwarden, with an offline copy. [ADR-0008](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0008-sops-secrets-in-git.md) - [How are health, logs, and metrics exposed and collected?](https://git.bobbypalko.com/bobby/hapi/issues/58): kubelet probes and `/metrics` sit on an **internal `:8081`** that the Gateway never routes, in the API's event loop (`/readyz` doesn't check the DB). Kuma (a Bot on its own public VM) polls **`GET /v1/health`** (`health` Scope), which reports `ok`/`degraded`/`down` with only check names. **VictoriaMetrics + VictoriaLogs** self-hosted in-cluster, with Vector, Talos logs and k8s Events. Grafana only via port-forward over the tailnet, with egress denied. Logs are kept 30 d, breakglass audit 1 y. Alert owners: Kuma, Flux, vmalert, plus a Watchdog → Kuma push. [ADR-0009](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0009-observability.md) - [Which sources can feed posted Transactions from our banks and cards?](https://git.bobbypalko.com/bobby/hapi/issues/65): none of the five banks has a personal API (Capital One's is partner-only; the MCP servers found are third-party). Recommended joint importer: **SimpleFIN Bridge** ($15/yr, read-only, pending skipped, one revocable access URL, optional `transacted_at` purchase date). Fallback and history: **OFX/QFX** exports (stable ids, posted date only); avoid CSV (no ids). Apple Card = Wallet/card.apple.com export (FinanceKit needs an App Store app). Unverified: SimpleFIN coverage of Capital One/Fulton and whether it fills purchase dates. [findings](https://git.bobbypalko.com/bobby/hapi/src/branch/research/bank-transaction-sources/docs/research/bank-transaction-sources.md) - [What is the Finance MVP?](https://git.bobbypalko.com/bobby/hapi/issues/59): a **ledger + zero-based Budget per owner** (Household Budget over Household Accounts, a Person's over their Personal Accounts). Financial Accounts own their Transactions and **never change owner** (hand-over = `tracked_until` / new Account `tracked_from`). Household Categories can be used on members' Personal Transactions. Standing Targets (monthly/quarterly/annual), Moves, **Banked** Categories carry forward, unassigned reported but not enforced, rebalance hint. Idempotent `transactions/ingest` from importer Bots (posted only, `occurred_on` = purchase date), manual > learned Payee mappings. Deferred: splits, net worth + transfer-leg linking, ML, pending, finer Scopes (v2). [resolution](https://git.bobbypalko.com/bobby/hapi/issues/59#issuecomment-281) - [What is the Fitness MVP?](https://git.bobbypalko.com/bobby/hapi/issues/60): **hand-logged Workouts + body Measurements**, Personal per Person; greenfield, no import. Shared **Household/Personal Exercises** (Category pattern: merge same-kind, promote, kind frozen once used) of kind strength/bodyweight/timed/cardio; a Workout (`performed_on` date) holds entries of Sets (reps, `load_g`, RPE, warmup) or one cardio effort; a run is a one-entry Workout. Fixed-enum Measurements. SI integers. Whole-Workout POST, idempotent on optional `external_id`; plain REST edits/hard deletes; per-Exercise history + bests computed on read. Fitness v2: templates/goals, wearable import, reminders. [resolution](https://git.bobbypalko.com/bobby/hapi/issues/60#issuecomment-295) - [What is the Home maintenance MVP?](https://git.bobbypalko.com/bobby/hapi/issues/61): domain renamed **Maintenance** (upkeep of the Household's physical property, **vehicles included**), all Household data. **Assets** (roof, furnace, car; optional make/model/serial, installed, warranty) with an optional meter and **Readings**. **Tasks** always recur: **floating** interval after the last Service, or **fixed** restricted RRULE, plus an optional usage interval, due on whichever comes first; computed on read; snooze/archive. **Services** record any work done (optionally fulfilling a Task; one-off past work stands alone; no future to-dos). `external_id` on Services/Readings. v2: attachments, Finance cost link, HA runtime-Reading Bot. [resolution](https://git.bobbypalko.com/bobby/hapi/issues/61#issuecomment-298) - [Check whether SimpleFIN covers Capital One and Fulton with purchase dates](https://git.bobbypalko.com/bobby/hapi/issues/66): SimpleFIN **covers Capital One + Fulton** (Diamond CU, Chase, Apple Card listed in search, not connected). **No purchase date**: `transacted_at` always equals posted (treat it as date-only). History is about 45–90 days, anchored at connection; use ≤45-day `start-date` windows; no pending rows. Ids `TRN-…` are **stable across pulls** (100/100, 47/47), so they're safe as per-Account idempotency keys. The Access URL is in Vaultwarden "SimpleFIN Access URL". [resolution](https://git.bobbypalko.com/bobby/hapi/issues/66#issuecomment-315) - [What is the Smart home MVP?](https://git.bobbypalko.com/bobby/hapi/issues/62): **Jobs only**; HA stays the source of truth for house state (no state store, no hAPI automations: v2; HA data for other domains goes to their endpoints). Generic `script`+`variables` Jobs, no typed controls or catalogue; state read-back via a query Job's `response`. Optional `external_id` per creator. List/get/cancel, no PATCH. `POST /jobs/{id}/result` is the one way to finish a Job: HA or any Household member closing it by hand (Recorded by shows who), not restricted to the leasing Bot. No domain code creates Jobs in v1. [resolution](https://git.bobbypalko.com/bobby/hapi/issues/62#issuecomment-301) - [Which Gateway, certificates, and DNS front the public surface?](https://git.bobbypalko.com/bobby/hapi/issues/63): `hapi.bobbypalko.com`, IPv4 only, on a Tofu-reserved IP. The NodeBalancer runs in TCP mode with Proxy Protocol v2, behind a 443-only firewall. **Envoy Gateway** (2 replicas) terminates TLS 1.3 and enforces edge limits (1 MiB bodies, ~20 req/s per IP, connection caps, timeouts); Cilium's Gateway lacks these. cert-manager uses Let's Encrypt over DNS-01, with the challenge CNAMEd into a **delegated `acme.bobbypalko.com` zone** whose restricted-user token can't touch the main zone. CAA pins `dns-01` and our `accounturi`, and the account key is kept in SOPS. Still to verify during the build: token capping and subzone delegation (fallback: acme-dns). [ADR-0010](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0010-envoy-gateway-public-edge.md) - [Which importer Bots ship in v1, and where do they run?](https://git.bobbypalko.com/bobby/hapi/issues/67): v1 ships **one SimpleFIN Bot for the Household Accounts only**, with no backfill and no file importer (the Owner's Personal Accounts and Apple Card come in v2). It's an **in-cluster CronJob** (`bots/simplefin/`, every 6 h, 14-day window) that calls the internal hAPI Service with a `finance:write` Household grant. Its Token, Access URL and account mapping live in one SOPS secret. A clean run pings Kuma (13 h window), and its egress is default-deny. Finance amended: `occurred_on` is the best-known date, editable within 31 days before `posted_on`; new `dated_by`; a `date_review` flag on posted-date rows from days 1–5. [ADR-0011](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0011-in-cluster-importer-bots.md), [resolution](https://git.bobbypalko.com/bobby/hapi/issues/67#issuecomment-320) - [How do scheduled and background jobs run?](https://git.bobbypalko.com/bobby/hapi/issues/68): **Kubernetes CronJobs running `hapi <subcommand>`** from the app image. No worker, queue or outbox. `hapi jobs sweep` every 15 min (expire + 90-day purge); notification checks are `hapi notify <check>` CronJobs. Household work runs as a built-in **tokenless `scheduler` Bot**, and Personal work runs per Person, read-only. Event-triggered work is caught by the next check. Checks write **durable Notifications** (dedupe ledger, retry, future inbox). Pool 1 per CronJob (ADR-0004 budget amended); one generic vmalert staleness rule; Household timezone drives `spec.timeZone`. [ADR-0012](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0012-housekeeping-cronjobs.md) - [How does hAPI send notifications through ntfy?](https://git.bobbypalko.com/bobby/hapi/issues/69): **two lanes**: platform alerts (CI, Flux, vmalert, Kuma) publish straight to Owner-only `ops`/`ops-urgent` topics; hAPI **Notifications** are records to one Person or the Household. ntfy at notify.bobbypalko.com, deny-all, one publish-only user per sender, read-only user per Person. v1 checks: `tasks` (due soon/overdue), `jobs` (failed/expired), `budget` (hourly, a Household Category goes red), `tokens` (30/7 d); no Personal-domain checks. Checks only write; `hapi notify deliver` every 2 min publishes. Breakglass fails closed if it can't notify. No preferences, read state or API in v1; titles carry no amounts. [ADR-0013](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0013-ntfy-notifications.md) - [How are backups taken, and how do we recover from disaster?](https://git.bobbypalko.com/bobby/hapi/issues/70): a daily **`hapi db backup` CronJob** (03:00, read-only `BYPASSRLS` `hapi_backup` role) streams `pg_dump` → `pg_restore --list` check → **age** to a dedicated recipient whose private key never enters the cluster → a Linode bucket with **Object Lock in compliance mode** (35 d). An **off-account puller** with a `read_only` key (`rclone copy --immutable`; **the Owner's PC for now, a NAS later**) keeps 90 dailies, 3 years of monthlies, 1 year of breakglass `audit/`, and the Tofu state. No etcd snapshots: the cluster is rebuilt from code; Gitea is out of scope. Kuma push monitors at 26 h for the job and **8 d for the puller (26 h once on the NAS)**. `hapi db restore` runs in a pod with the key pasted in at run time. A full drill before go-live, then a restore every 6 months as a Maintenance Task. [ADR-0014](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0014-backups-and-disaster-recovery.md) - [Which cluster hardening ships in v1?](https://git.bobbypalko.com/bobby/hapi/issues/71): built-ins only. **Default-deny CiliumNetworkPolicies** in every namespace we own (`kube-system` stays open); **PSA `restricted`**, with the node agents moved into a `privileged` `monitoring-node` namespace; two **ValidatingAdmissionPolicies** (images from Gitea's registry or pinned by digest; read-only root filesystem and no SA token in `hapi`/`bots`); **K8s audit logs** at Metadata level, kept 1 y, with an `ops` alert on exec or a human reading a Secret. Upgrades: versions pinned, Renovate PRs, security patches within 14 d, a runbook, and a monthly Maintenance Task on a "hAPI cluster" Asset (Maintenance now covers digital systems). **Commit and image signing deferred** (their keys would sit with Gitea). Runtime detection, Trivy Operator, host firewall and least-privilege kubeconfigs: v2. [ADR-0015](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0015-cluster-hardening-baseline.md) ## Not yet specified _(nothing left in the fog: every in-scope area is a ticket)_ ## Out of scope - Frontend (separate repo, may never be built). - Mobile apps. - Public signups and third-party OAuth access. - Changes to Home Assistant configuration beyond what the job bridge needs. - Deploying Uptime Kuma, ntfy, Home Assistant, or Gitea. - A staging environment (v1). - Distributed tracing. - Sharing data outside the Household, and guest access to Household data for non-members (per [Who owns data: a Person, the household, or both?](https://git.bobbypalko.com/bobby/hapi/issues/50); unlikely even later). - Roles within the Household (v2; v1 Household members have equal access). - Recurring Smart home Jobs in hAPI: HA automations own recurring house behaviour; Jobs are one-shot with `not_before` (per [What is the Smart home MVP?](https://git.bobbypalko.com/bobby/hapi/issues/62)). - Interactive login (passkeys, OIDC) in v1: Persons use Tokens. Expected to arrive with a future browser frontend as a new credential kind (per [How do Principals authenticate, and what may each do?](https://git.bobbypalko.com/bobby/hapi/issues/54)). - Multi-currency in Finance: USD only, not expected ever (per [What is the Finance MVP?](https://git.bobbypalko.com/bobby/hapi/issues/59)). - Fitness v2: wearable (Garmin/Apple Watch) import, historical import, templates/programs/goals, richer records, daily aggregates, and fitness reminders (per [What is the Fitness MVP?](https://git.bobbypalko.com/bobby/hapi/issues/60)). Nutrition as a domain.
bobby added the wayfinder:map label 2026-11-23 16:04:54 -05:00
Author
Owner

Destination reached: the hAPI v1 spec is #72 (#72). It consolidates ADR-0001–0015 and the domain resolutions on #51, #59, #60, #61, #62 and #67. Next: slice #72 into implementation issues.

Destination reached: the hAPI v1 spec is #72 (https://git.bobbypalko.com/bobby/hapi/issues/72). It consolidates ADR-0001–0015 and the domain resolutions on #51, #59, #60, #61, #62 and #67. Next: slice #72 into implementation issues.
bobby closed this issue 2026-11-27 16:16:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: bobby/hapi#44