How does hAPI connect to its managed database? #53
Notifications
Due Date
No due date set.
Depends on
Reference: bobby/hapi#53
Reference in new issue
Block a user
Part of #44
Question
How is the Linode managed Postgres provisioned and reached from the cluster: private networking vs allowlisted public endpoint, TLS, role/credential model (app role, migration role, per-schema roles), and connection pooling? Also decide the DB plan (node count and size). Per ADR-0003 the cluster is in
us-iadand sits in a VPC, so check whether Managed DB VPC attach (beta) is available there and whetherlinode_database_postgresql_v2exposes it.Decisions (provisional, pending #64)
Decided in a grilling session on 2026-11-24. This ticket stays open, blocked by Verify Managed DB VPC attach, role setup, and RLS on a live us-iad cluster (#64). Close it when those checks pass. If a check fails, reopen the affected point (region, or RLS) here.
Plan and provisioning
linode_database_postgresql_v2) in the cluster's VPC.engine_config_pg_password_encryption = "scram-sha-256"set explicitly, because Akamai's sources disagree on the default.Network
public_access = false, withallow_listholding only the cluster's VPC subnet CIDR. We accept the beta risk. Ifus-iadlacks support, tryus-iad-2, thenus-east(Newark). The fallback is a public endpoint plus a node-IP allowlist, as an explicit ADR-0002 amendment.sslmode=verify-full, with the CA from Tofu'sca_cert. The app fails fast without it. Local dev uses plain Compose.Roles and credentials
hapidatabase (notdefaultdb) with two roles:hapi_migratorowns the database, schemas and tables, and runshapi migrate.hapi_apphas DML only viaALTER DEFAULT PRIVILEGES. The app and the admin CLI both connect ashapi_app.akmadminis never in the cluster. An idempotenthapi db bootstrapadmin CLI command, run by the Owner in a pod with theakmadminpassword pasted in at run time, creates the database and roles. It is rerun after any restore (a restore forks a new cluster).Personal-data isolation
ENABLE+FORCE), with policies keyed onSET LOCAL hapi.principal_idper transaction and covering Bindings. Household data uses app-level checks only.BYPASSRLSrole. Onlyhapi_migrator(as table owner) is exempt. Cross-Person work, such as purging a removed Person or running reminders, runs once per Person with that Person's id set.hapi_migrator.psqlashapi_migratorfrom a pod, following a runbook and recorded on the incident.hapi_app. CI fails if any owner-mixin table lacks forced RLS.Pooling
pool_size=5,max_overflow=5,pool_pre_ping, shortpool_recycle), budgeted against the plan's ~200max_connections. No PgBouncer in v1: there's no Terraform resource for Akamai's pools and VPC support for them is undocumented.ADR: ADR-0004 was drafted on a
draft/adr-0004-database-accessbranch, now deleted. The accepted version, amended per the resolution below, is ADR-0004 onmain.Platform facts gathered for this ticket: VPC attach is still "open beta" with no GA entry.
us-iadlists both VPCs and Managed Databases. Terraformprivate_networkupdates in place. The "private IP not supported" note refers to legacy private IPv4. Connections are capped at 100 per GB of RAM.Live verification results: points to re-decide
Verify Managed DB VPC attach, role setup, and RLS on a live us-iad cluster (#64) is resolved (results). VPC attach in
us-iad, TLS, scram, the role split, and RLS forhapi_appall hold. Before this ticket closes, the following provisional decisions need revisiting in a grilling session:FORCEvs "hapi_migratoris exempt".FORCE ROW LEVEL SECURITYalso binds the table owner, so the decisions as written contradict each other. Options:ENABLEonly. The migrator is exempt as owner, and the CI check testsrelrowsecurity.FORCE. Data migrations and break-glass explicitlyALTER TABLE ... NO FORCEinside their transaction, or set a principal per row.hapi_appcredentials, because any session can sethapi.principal_id. It protects only against app bugs. Fix the ADR-0004 wording. Decide whether that's acceptable or whether something stronger is needed (e.g. signed principal context, or per-requestSET ROLEto a per-Person role).hapi db bootstrap: database-level grants must run ashapi_migrator.akmadmincanSET ROLEto the roles it creates and hasBYPASSRLS, which fits the operator caveat. After a restore, wait for DNS (~60 s after "ready").Resolution
The provisional decisions above stand. The live check (Verify Managed DB VPC attach, role setup, and RLS on a live us-iad cluster, #64) confirmed VPC attach in
us-iad,verify-full, scram, the two-role bootstrap and RLS. The 7 re-decide points were settled in a grilling session on 2026-11-24:ENABLERLS only, noFORCE.hapi_migratoris exempt as owner. CI checks that every owner-mixin table hasrelrowsecurityset and is owned byhapi_migrator, neverhapi_app. Policies usenullif(current_setting('hapi.principal_id', true), '').hapi_appcredentials can set any principal. The containment is the VPC-only allowlist, which limits use to the cluster and VPC. We accept this: a signed principal context or per-Person roles add nothing real.hapi db breakglass --reason. It runspsqlashapi_migratorand logs start, end, reason and every statement (never results) to centralized logs. An ntfy alert to the Household is a candidate for the notifications work.pool_size=5+max_overflow=5. The rule: (app pods including surge) × 10 + ~6 ≤ 46 usable, so at most 4 app pods. Delivery enforces the replica and surge limits, and future workers share the budget. Traffic is expected to be very low.hapi db bootstrapwaits for private DNS, creates the roles andCREATE DATABASE hapi OWNER hapi_migrator, then runsSET ROLE hapi_migratorfor the database-level grants.akmadmin'sBYPASSRLSfalls under the operator caveat.ADR: ADR-0004, accepted on
main. It supersedes thedraft/adr-0004-database-accessbranch.