Verify Managed DB VPC attach, role setup, and RLS on a live us-iad cluster #64

Closed
opened 2026-11-24 07:44:49 -05:00 by bobby · 1 comment
Owner

Part of #44

Question

Do the database decisions from #53 hold on the real platform? Spin up a throwaway Linode Managed PostgreSQL cluster (Shared 1 GB, 1 node, PostgreSQL 18) attached to a throwaway VPC in us-iad. Check the following, then destroy everything.

  1. VPC attach in us-iad: the cluster provisions with private_network { vpc_id, subnet_id, public_access = false } via linode_database_postgresql_v2, and a Linode in the same VPC subnet can connect over the private hostname with sslmode=verify-full using the ca_cert output. If us-iad refuses, try us-iad-2, then us-east (Newark), and record which works. The Owner may also confirm the beta rollout status with Akamai.
  2. password_encryption: set engine_config_pg_password_encryption = "scram-sha-256" and confirm it with SHOW password_encryption.
  3. Role setup as akmadmin (not a superuser): create a hapi database and two roles. hapi_migrator owns the database and a domain schema; hapi_app gets DML only through ALTER DEFAULT PRIVILEGES. Confirm that hapi_app can't run DDL.
  4. RLS: as hapi_migrator, create a table with ENABLE + FORCE ROW LEVEL SECURITY and a policy keyed on current_setting('hapi.principal_id'). As hapi_app, check that SET LOCAL hapi.principal_id = ... limits the visible rows, and that leaving it unset returns no rows (no error leak).
  5. max_connections: record the actual value.
  6. No-bypass checks: confirm that hapi_app can't SET ROLE hapi_migrator or ALTER TABLE ... NO FORCE ROW LEVEL SECURITY. Confirm that a SET LOCAL inside a transaction doesn't leak into the next transaction on the same pooled connection.
  7. Audit for break-glass: can log_statement (or pgaudit) be enabled through engine_config, and where do those logs surface?

When everything passes, close How does hAPI connect to its managed database? (#53) and merge the ADR-0004 draft (branch draft/adr-0004-database-access) with status accepted.

Resolved when each check has a recorded pass/fail with evidence. On a failure, record the fallback it triggers: another region (ADR-0003 region change), or app-only enforcement instead of RLS.

Part of #44 ## Question Do the database decisions from #53 hold on the real platform? Spin up a **throwaway** Linode Managed PostgreSQL cluster (Shared 1 GB, 1 node, PostgreSQL 18) attached to a throwaway VPC in **`us-iad`**. Check the following, then destroy everything. 1. **VPC attach in `us-iad`**: the cluster provisions with `private_network { vpc_id, subnet_id, public_access = false }` via `linode_database_postgresql_v2`, and a Linode in the same VPC subnet can connect over the private hostname with `sslmode=verify-full` using the `ca_cert` output. If `us-iad` refuses, try `us-iad-2`, then `us-east` (Newark), and record which works. The Owner may also confirm the beta rollout status with Akamai. 2. **`password_encryption`**: set `engine_config_pg_password_encryption = "scram-sha-256"` and confirm it with `SHOW password_encryption`. 3. **Role setup as `akmadmin`** (not a superuser): create a `hapi` database and two roles. `hapi_migrator` owns the database and a domain schema; `hapi_app` gets DML only through `ALTER DEFAULT PRIVILEGES`. Confirm that `hapi_app` can't run DDL. 4. **RLS**: as `hapi_migrator`, create a table with `ENABLE` + `FORCE ROW LEVEL SECURITY` and a policy keyed on `current_setting('hapi.principal_id')`. As `hapi_app`, check that `SET LOCAL hapi.principal_id = ...` limits the visible rows, and that leaving it unset returns no rows (no error leak). 5. **`max_connections`**: record the actual value. 6. **No-bypass checks**: confirm that `hapi_app` can't `SET ROLE hapi_migrator` or `ALTER TABLE ... NO FORCE ROW LEVEL SECURITY`. Confirm that a `SET LOCAL` inside a transaction doesn't leak into the next transaction on the same pooled connection. 7. **Audit for break-glass**: can `log_statement` (or pgaudit) be enabled through `engine_config`, and where do those logs surface? When everything passes, close **How does hAPI connect to its managed database?** (#53) and merge the ADR-0004 draft (branch `draft/adr-0004-database-access`) with status `accepted`. Resolved when each check has a recorded pass/fail with evidence. On a failure, record the fallback it triggers: another region (ADR-0003 region change), or app-only enforcement instead of RLS.
bobby added the wayfinder:task label 2026-11-24 07:44:49 -05:00
bobby added a new dependency 2026-11-24 07:51:34 -05:00
bobby self-assigned this 2026-11-24 07:53:56 -05:00
Author
Owner

Resolution

Run 2026-11-24 with Terraform (linode/linode v4.10) against a throwaway VPC, a PG 18 cluster and a Debian probe VM in us-iad, then all destroyed (5 resources). The state, keys and passwords were deleted locally. Evidence: checks.sh, main.tf, results 1 GB, results 2 GB, resize probe log.

# Check Result
1 VPC attach in us-iad ✅ Works in us-iad, so no region fallback is needed. The private hostname resolves to a VPC IP (10.64.0.x) and only from inside the VPC. TLS 1.3 with verify-full against ca_cert works.
1b No public route ✅ With public_access = false, the public name still resolves (IPv6 and IPv4), but connections from outside the allowlist time out. That includes a public IPv6 Linode in the same region. The allowlist is the enforcing control.
2 password_encryption ✅ scram-sha-256 when set via engine_config_pg_password_encryption.
3 Bootstrap as akmadmin ✅ with notes. akmadmin is rolsuper=f, createrole, createdb, bypassrls=t. Because createrole_self_grant = inherit,set, it can SET ROLE to any role it creates, so CREATE DATABASE hapi OWNER hapi_migrator works directly. Database-level REVOKE/GRANT must run as hapi_migrator (the owner); run as akmadmin they silently do nothing. pg_authid isn't readable. hapi_app can't run DDL in the domain schemas or in public.
4 RLS ✅ hapi_app with no principal sees 0 rows. SET LOCAL / set_config(..., true) scope correctly, and nothing leaks into the next transaction: afterwards the setting reads '', so the policy must wrap it in nullif(..., ''). WITH CHECK blocks cross-owner inserts, and cross-owner updates affect 0 rows. ⚠️ FORCE puts the owner hapi_migrator under RLS too. With no principal it sees 0 rows and can't insert. It can run ALTER TABLE ... NO FORCE ROW LEVEL SECURITY inside a transaction (tested, rolled back).
5 max_connections ⚠️ 25 on Shared 1 GB, 50 on Shared 2 GB, minus 3 reserved for superusers, not "100 per GB". About 1 extra platform client backend is always present.
6 No-bypass ✅ hapi_app is denied SET ROLE hapi_migrator, NO FORCE, DISABLE RLS and DROP POLICY. ⚠️ Anyone holding hapi_app credentials can set any hapi.principal_id and read that Person's rows. RLS doesn't protect against leaked app credentials.
7 Audit ❌ ALTER ROLE ... SET log_statement / log_min_duration_statement is denied, and no logging or pgaudit settings exist in engine_config or the API. There's no statement audit on the platform, so break-glass auditing has to happen outside the database.

Other facts later tickets depend on

  • Provisioning time: about 5 minutes, but the private DNS name took about 60 seconds more to resolve after Terraform reported the cluster ready. Restore runbooks and tooling should wait for DNS.
  • Resizing a single node: an in-place resize (1 GB → 2 GB) stalled at 0% "resizing" for over 19 minutes, though the DB stayed fully available the whole time (223 of 223 probes). We destroyed and recreated instead. "Scaling up is just a plan change" is not reliable. Expect a support ticket or a restore-to-new-cluster.
  • Server certificate: the SANs include *.g2a.akamaidb.net plus public and private IPs and names, so verify-full also passes when connecting by IP.
  • Terraform: private_network is an attribute (private_network = { ... }), not a block. The account uses Linode Interfaces: instances need linode_interfaces blocks, and every interface needs an explicit firewall_id (or -1). This matters for ADR-0003's node provisioning.
  • PostgreSQL 19 is now offered (engine postgresql/19). The cluster reports PG 18.7.

Follow-up amendments for How does hAPI connect to its managed database? are posted on that ticket.

## Resolution Run 2026-11-24 with Terraform (linode/linode v4.10) against a throwaway VPC, a PG 18 cluster and a Debian probe VM in **`us-iad`**, then **all destroyed** (5 resources). The state, keys and passwords were deleted locally. Evidence: [checks.sh](https://git.bobbypalko.com/bobby/hapi/src/branch/task/verify-db-64/docs/research/verify-db-64/checks.sh), [main.tf](https://git.bobbypalko.com/bobby/hapi/src/branch/task/verify-db-64/docs/research/verify-db-64/main.tf), [results 1 GB](https://git.bobbypalko.com/bobby/hapi/src/branch/task/verify-db-64/docs/research/verify-db-64/results.txt), [results 2 GB](https://git.bobbypalko.com/bobby/hapi/src/branch/task/verify-db-64/docs/research/verify-db-64/results-2gb.txt), [resize probe log](https://git.bobbypalko.com/bobby/hapi/src/branch/task/verify-db-64/docs/research/verify-db-64/resize-probe.log). | # | Check | Result | |---|---|---| | 1 | VPC attach in `us-iad` | ✅ **Works in `us-iad`**, so no region fallback is needed. The private hostname resolves to a VPC IP (`10.64.0.x`) and only from inside the VPC. TLS 1.3 with `verify-full` against `ca_cert` works. | | 1b | No public route | ✅ With `public_access = false`, the public name still resolves (IPv6 and IPv4), but connections from outside the allowlist time out. That includes a public IPv6 Linode in the same region. **The allowlist is the enforcing control.** | | 2 | `password_encryption` | ✅ `scram-sha-256` when set via `engine_config_pg_password_encryption`. | | 3 | Bootstrap as `akmadmin` | ✅ with notes. `akmadmin` is `rolsuper=f`, `createrole`, `createdb`, **`bypassrls=t`**. Because `createrole_self_grant = inherit,set`, it can `SET ROLE` to any role it creates, so `CREATE DATABASE hapi OWNER hapi_migrator` works directly. Database-level `REVOKE`/`GRANT` must run **as `hapi_migrator`** (the owner); run as `akmadmin` they silently do nothing. `pg_authid` isn't readable. `hapi_app` can't run DDL in the domain schemas or in `public`. | | 4 | RLS | ✅ `hapi_app` with no principal sees 0 rows. `SET LOCAL` / `set_config(..., true)` scope correctly, and nothing leaks into the next transaction: afterwards the setting reads `''`, so the policy **must** wrap it in `nullif(..., '')`. `WITH CHECK` blocks cross-owner inserts, and cross-owner updates affect 0 rows. ⚠️ **`FORCE` puts the owner `hapi_migrator` under RLS too.** With no principal it sees 0 rows and can't insert. It can run `ALTER TABLE ... NO FORCE ROW LEVEL SECURITY` inside a transaction (tested, rolled back). | | 5 | `max_connections` | ⚠️ **25 on Shared 1 GB, 50 on Shared 2 GB**, minus 3 reserved for superusers, not "100 per GB". About 1 extra platform client backend is always present. | | 6 | No-bypass | ✅ `hapi_app` is denied `SET ROLE hapi_migrator`, `NO FORCE`, `DISABLE RLS` and `DROP POLICY`. ⚠️ **Anyone holding `hapi_app` credentials can set any `hapi.principal_id` and read that Person's rows.** RLS doesn't protect against leaked app credentials. | | 7 | Audit | ❌ `ALTER ROLE ... SET log_statement` / `log_min_duration_statement` is denied, and no logging or pgaudit settings exist in `engine_config` or the API. **There's no statement audit on the platform**, so break-glass auditing has to happen outside the database. | **Other facts later tickets depend on** - **Provisioning time:** about 5 minutes, but the private DNS name took about **60 seconds more** to resolve after Terraform reported the cluster ready. Restore runbooks and tooling should wait for DNS. - **Resizing a single node:** an in-place resize (1 GB → 2 GB) stalled at 0% "resizing" for over 19 minutes, though the DB stayed fully available the whole time (223 of 223 probes). We destroyed and recreated instead. "Scaling up is just a plan change" is **not reliable**. Expect a support ticket or a restore-to-new-cluster. - **Server certificate:** the SANs include `*.g2a.akamaidb.net` plus public and private IPs and names, so `verify-full` also passes when connecting by IP. - **Terraform:** `private_network` is an **attribute** (`private_network = { ... }`), not a block. The account uses **Linode Interfaces**: instances need `linode_interfaces` blocks, and every interface needs an explicit `firewall_id` (or `-1`). This matters for ADR-0003's node provisioning. - **PostgreSQL 19** is now offered (engine `postgresql/19`). The cluster reports PG **18.7**. Follow-up amendments for **How does hAPI connect to its managed database?** are posted on that ticket.
bobby closed this issue 2026-11-24 08:34:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: bobby/hapi#64