Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d49485ef21 | ||
|
|
a132594b8b | ||
|
|
eb0022d94a | ||
|
|
3d8e3c7e6f | ||
|
|
86281226fc | ||
|
|
a8c7464e56 | ||
|
|
f82b8cbd82 |
No files matched your search
+57
-1
@@ -22,10 +22,22 @@ _Avoid_: Service account, machine user, integration account
|
|||||||
The single Person with administrative authority over hAPI and every other Principal. That authority covers Principals and the platform, not other Persons' Personal data.
|
The single Person with administrative authority over hAPI and every other Principal. That authority covers Principals and the platform, not other Persons' Personal data.
|
||||||
_Avoid_: Admin, root, superuser
|
_Avoid_: Admin, root, superuser
|
||||||
|
|
||||||
|
**Token**:
|
||||||
|
A Principal's secret credential for the API.
|
||||||
|
_Avoid_: API key, password
|
||||||
|
|
||||||
|
**Scope**:
|
||||||
|
A domain paired with read or write access: the unit of access that Household grants and Bindings carry.
|
||||||
|
_Avoid_: Permission, privilege
|
||||||
|
|
||||||
**Binding**:
|
**Binding**:
|
||||||
A Person's consent letting a specific Bot act on that Person's Personal data.
|
A Person's consent letting a specific Bot act on that Person's Personal data in one domain, up to a given Scope.
|
||||||
_Avoid_: Delegation, impersonation, link
|
_Avoid_: Delegation, impersonation, link
|
||||||
|
|
||||||
|
**Household grant**:
|
||||||
|
The Owner's permission for a specific Bot to act on one domain's Household data, up to a given Scope.
|
||||||
|
_Avoid_: Permission, role
|
||||||
|
|
||||||
### Ownership
|
### Ownership
|
||||||
|
|
||||||
**Household**:
|
**Household**:
|
||||||
@@ -47,3 +59,47 @@ _Avoid_: Shared data, common data
|
|||||||
**Recorded by**:
|
**Recorded by**:
|
||||||
The Principal that created or last changed a record, distinct from who owns it.
|
The Principal that created or last changed a record, distinct from who owns it.
|
||||||
_Avoid_: Author, owner, creator
|
_Avoid_: Author, owner, creator
|
||||||
|
|
||||||
|
### Smart home
|
||||||
|
|
||||||
|
**Job**:
|
||||||
|
A request, queued in hAPI, for Home Assistant to carry out an action in the house. Jobs are Household data. Domain code, Persons, and Bots can all create them.
|
||||||
|
_Avoid_: Task, command, message
|
||||||
|
|
||||||
|
### Finance
|
||||||
|
|
||||||
|
**Financial Account**:
|
||||||
|
A bank, credit card, or cash account whose money hAPI tracks. It is owned by a Person or by the Household, and its Transactions share that owner.
|
||||||
|
_Avoid_: Account (on its own), bank account, wallet
|
||||||
|
|
||||||
|
**Transaction**:
|
||||||
|
A single posted movement of money into or out of one Financial Account.
|
||||||
|
_Avoid_: Entry, charge, payment
|
||||||
|
|
||||||
|
**Category**:
|
||||||
|
A named bucket that Transactions are sorted into, of kind expense, income, or transfer. Household Categories can be used by the Household and by every Household member; Personal Categories only by their Person.
|
||||||
|
_Avoid_: Tag, label, envelope
|
||||||
|
|
||||||
|
**Budget**:
|
||||||
|
One owner's zero-based monthly plan: expected income assigned across Categories, then rebalanced during the month with Moves. The Household has one, and each Person may have one.
|
||||||
|
_Avoid_: Plan, envelope
|
||||||
|
|
||||||
|
**Target**:
|
||||||
|
A Budget's standing amount for one Category over a period (monthly, quarterly, or annual), spread into even monthly shares.
|
||||||
|
_Avoid_: Goal, limit
|
||||||
|
|
||||||
|
**Allocation**:
|
||||||
|
What a Budget assigns to one Category in one month: the Target's monthly share, adjusted by Moves.
|
||||||
|
_Avoid_: Budgeted amount, envelope
|
||||||
|
|
||||||
|
**Move**:
|
||||||
|
A shift of money from one Category's Allocation to another's within one month of a Budget. It never changes the month's total.
|
||||||
|
_Avoid_: Transfer (a kind of Category), reallocation
|
||||||
|
|
||||||
|
**Banked**:
|
||||||
|
Said of a Category whose Target period is longer than a month. Its unspent Allocations carry forward as a banked balance until the bill draws it down.
|
||||||
|
_Avoid_: Sinking fund, rollover, savings
|
||||||
|
|
||||||
|
**Payee mapping**:
|
||||||
|
An owner's remembered link from a payee to a Category, learned from manual categorization and applied to newly ingested Transactions.
|
||||||
|
_Avoid_: Rule, auto-categorization
|
||||||
@@ -7,6 +7,7 @@ hAPI serves exactly one Household, so there is no multi-tenancy. Every record is
|
|||||||
- **The Owner has no special read access to Personal data.** Owner authority covers Principals and the platform only. Bots reach Personal data only through a **Binding** that the bound Person grants and can revoke. The Owner cannot grant one on another Person's behalf.
|
- **The Owner has no special read access to Personal data.** Owner authority covers Principals and the platform only. Bots reach Personal data only through a **Binding** that the bound Person grants and can revoke. The Owner cannot grant one on another Person's behalf.
|
||||||
- Every record carries its owner plus **Recorded by**: the Principal that created it and the one that last changed it. Principals are deactivated, never hard-deleted, so Recorded by never dangles.
|
- Every record carries its owner plus **Recorded by**: the Principal that created it and the one that last changed it. Principals are deactivated, never hard-deleted, so Recorded by never dangles.
|
||||||
- Ownership is fixed when a record is created, except that a Person may move their own Personal record to the Household (one way only).
|
- Ownership is fixed when a record is created, except that a Person may move their own Personal record to the Household (one way only).
|
||||||
|
- **Finance exception:** Financial Accounts and their Transactions never move. To bring an account into the Household, the Personal Financial Account stops tracking at a date and a new Household one starts tracking from it, so spending history stays with the owner who spent it. Finance Categories can still be promoted.
|
||||||
- When a Person is removed, their Personal data is exported and then explicitly deleted. Household data they recorded stays with the Household.
|
- When a Person is removed, their Personal data is exported and then explicitly deleted. Household data they recorded stays with the Household.
|
||||||
- Persons who are not Household members (e.g. friends) see only their own Personal data.
|
- Persons who are not Household members (e.g. friends) see only their own Personal data.
|
||||||
- Not in v1: roles within the Household, sharing outside the Household, and guest access to Household data.
|
- Not in v1: roles within the Household, sharing outside the Household, and guest access to Household data.
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# Database access: VPC-only, two roles, Personal data isolated by row-level security
|
||||||
|
|
||||||
|
hAPI uses a **Linode Managed PostgreSQL 18** cluster (Shared 2 GB, 1 node) attached to the cluster's VPC with `public_access = false`, and its allowlist holds only the VPC subnet. Clients connect with `sslmode=verify-full` and scram-sha-256 passwords. Two roles share the `hapi` database. **`hapi_migrator`** owns every schema and table and runs `hapi migrate`. **`hapi_app`** has DML only; the running app and the admin CLI both connect as it. Personal-data tables have `ENABLE ROW LEVEL SECURITY` (not `FORCE`), with policies keyed on a per-transaction `SET LOCAL hapi.principal_id`, so a forgotten `WHERE` in a handler returns nothing instead of leaking another Person's data. `hapi_app` never owns a table and has no `BYPASSRLS`. That keeps ADR-0001's rule (not even the Owner reads others' Personal data) in the database for everything the app does. We accept that VPC for Managed Databases is still labelled beta, because ADR-0002 rules out a public database endpoint. It was verified working in `us-iad`.
|
||||||
|
|
||||||
|
**Amended by ADR-0005:** RLS also covers **Household data** tables. Their policies allow an active Household member or a Bot with a Household grant for that domain. Personal-data policies also allow a Bot that holds an active Binding from the record's owner. In both cases `USING` checks the read Scope and `WITH CHECK` checks the write Scope. `hapi.principal_id` is always the authenticated Principal, Person or Bot. The CI isolation check below covers every owned table, Personal or Household.
|
||||||
|
|
||||||
|
## Considered Options
|
||||||
|
|
||||||
|
- **Public endpoint with a node-IP allowlist.** Rejected: it contradicts ADR-0002 ("Never public: the database").
|
||||||
|
- **App-only filtering (no RLS).** Rejected: one missed filter becomes a data leak. Wrong-Principal tests stay mandatory on top of RLS.
|
||||||
|
- **`FORCE ROW LEVEL SECURITY`.** Rejected: it binds the owner `hapi_migrator` too, so every data migration and break-glass session would need `ALTER TABLE … NO FORCE`. The only thing it adds is protection against the migrator, which is the operator, and the operator is outside RLS's guarantee anyway.
|
||||||
|
- **Signed principal context, or one role per Person.** Rejected as protection against leaked `hapi_app` credentials. A signing key would live in the same pod as the password. Per-Person roles would all have to be grantable to `hapi_app`, so leaked credentials could switch to any of them.
|
||||||
|
- **A single role, or one role per domain schema.** One role lets the app run DDL and own tables, and owners bypass RLS. Per-domain roles add no isolation, because the monolith process would hold all of them anyway.
|
||||||
|
- **A `BYPASSRLS` role for admin tooling.** Rejected: the Owner has no read access to Personal data, so nothing in the request path or admin CLI needs one.
|
||||||
|
- **Managed or self-hosted PgBouncer.** Not needed at this load (see the connection budget below).
|
||||||
|
- **PostgreSQL 19.** Newly offered on the platform. We stay on 18, which all our verification ran on and which nothing in v1 outgrows. Revisit at the first major-upgrade window.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- **What RLS protects against:** app bugs only. Anyone holding `hapi_app` credentials can set any `hapi.principal_id`. Leaked credentials are contained by the network, because the VPC-only allowlist (verified as the enforcing control) limits use to the cluster and VPC. Whoever holds `akmadmin` (which has `BYPASSRLS`), `hapi_migrator` or the OpenTofu state can read everything. Owner non-access is enforced by policy and audit, not cryptography. Per-Person encryption is out of scope for v1.
|
||||||
|
- **Policies treat an unset principal as no principal.** After a transaction, the setting reads `''`, not NULL, so policies use `nullif(current_setting('hapi.principal_id', true), '')`.
|
||||||
|
- **CI enforces isolation:** every owner-mixin table must have `relrowsecurity` set and be owned by `hapi_migrator`, never `hapi_app`. Tests and local dev use the same bootstrap and connect as `hapi_app`.
|
||||||
|
- **`akmadmin` is never in the cluster.** An idempotent `hapi db bootstrap` admin CLI command creates the roles and the database. The Owner runs it in a pod and pastes in the `akmadmin` password at run time. It does the following:
|
||||||
|
1. Waits until the private hostname resolves (about 60 s after the cluster reports ready).
|
||||||
|
2. Creates `hapi_migrator` and `hapi_app`.
|
||||||
|
3. Runs `CREATE DATABASE hapi OWNER hapi_migrator`.
|
||||||
|
4. Runs `SET ROLE hapi_migrator` for the database-level `REVOKE`/`GRANT`s and `ALTER DEFAULT PRIVILEGES`. Run as `akmadmin`, these silently do nothing.
|
||||||
|
- **Cross-Person work runs per Person.** Purging a removed Person's data, or a job such as reminders, sets `hapi.principal_id` to each Person in turn.
|
||||||
|
- **Data repairs** normally ship as reviewed Alembic data migrations run as `hapi_migrator`, targeting rows by id or condition without printing them.
|
||||||
|
- **Break-glass goes through `hapi db breakglass --reason "…"`.** It opens `psql` as `hapi_migrator` from a pod and emits structured audit events to hAPI's centralized logs: start, end, reason, and every statement. Query results are never logged. The platform offers no statement logging or pgaudit, so this is the only audit trail.
|
||||||
|
- **Connection budget:** the plan allows 50 connections. That leaves about 46 usable after 3 reserved superuser slots and one platform backend. Each app pod holds at most 10 (`pool_size=5`, `max_overflow=5`), and the admin CLI holds 1–2. The rule is: (maximum concurrent app pods, including rollout surge) × 10, plus about 6 for migrate, CLI, break-glass and bootstrap, must be ≤ 46. That caps app pods at 4. Any future worker process counts against the same budget.
|
||||||
|
- **Plan changes are restores.** An in-place resize stalled during verification. Changing size or node count is done as a restore-to-new-cluster, with the same runbook as disaster recovery: fork, wait for DNS, `hapi db bootstrap`, repoint the app. Single-node maintenance windows (pinned to a quiet slot) cause short downtime, covered by 14-day point-in-time recovery.
|
||||||
|
- Passwords are rotated manually with a runbook. `password_encryption` is set explicitly to `scram-sha-256`.
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# Opaque per-Principal tokens; authorization by ownership, grants and row-level security
|
||||||
|
|
||||||
|
In v1, every Principal (Person or Bot) authenticates with a bearer **Token**. There is no identity provider and no interactive login, because there's no frontend: Persons use scripts, HTTP clients and Shortcuts, just as Bots do. A Token is opaque: `hapi_<public-id>_<secret>`, where the secret has 256 bits of entropy. hAPI stores only a SHA-256 of the secret and looks the Token up in Postgres on every request, so revoking a Token takes effect immediately, as ADR-0002 requires. Authorization keys off the **Principal**, never the credential. Persons are authorized purely by ownership (ADR-0001). Bots have no access until they're given a **Scope** (`<domain>:read` or `<domain>:write`, where write implies read, plus the special `health` scope). A Bot gets Scopes through **Household grants**, which the Owner gives through the admin CLI, and **Bindings**, which a Person gives through the API, one domain at a time. Enforcement sits in row-level security as well as in the app, so a forgotten check fails closed.
|
||||||
|
|
||||||
|
## Considered Options
|
||||||
|
|
||||||
|
- **OIDC with a self-hosted IdP** (Authelia, Kanidm, Pocket ID). Rejected for v1. It's another public-facing service to run and secure, every request would depend on it, and refresh flows are painful for curl cron jobs.
|
||||||
|
- **Passkeys served by hAPI.** These need a web origin and a login page, which amounts to a frontend. Deferred until a frontend exists (see Consequences).
|
||||||
|
- **Short-lived JWTs signed by hAPI, plus refresh tokens.** Rejected. Revocation lags by up to a token lifetime, there's a signing key to manage, and every client needs refresh logic. At our load, one indexed lookup per request costs nothing, and it uses the request's own pooled connection.
|
||||||
|
- **mTLS client certificates.** Already rejected in ADR-0002.
|
||||||
|
- **Per-resource or per-record-type Scopes** (e.g. `finance.transactions:write`). Rejected as premature. A domain Scope can later be split into finer ones without breaking anything.
|
||||||
|
- **Choosing whose Personal data a Bot means with a request header** (`Hapi-Acting-For`). Rejected because the same URI would then name different resources depending on the header.
|
||||||
|
- **Nested owner paths** (`/persons/{id}/workouts`, `/household/transactions`). Rejected. ADR-0001 lets a record move from Personal to Household, and nesting would change its URI when it does. Listing everything a Bot may see would also take one call per Person.
|
||||||
|
- **Owner powers on the public API** (e.g. revoking a Bot from a phone). Rejected. If the Owner's Token leaks, it should do no more harm than any other Person's.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- **Resources are flat and ownership is an attribute.** Each record has exactly one URI, `/v1/<domain>/<things>/{id}`, and keeps it when it moves to the Household. Every record exposes `owner` (a Person id or `household`) and `recorded_by`. Lists accept `?owner=me|household|<person-id>`, and without a filter they return everything the caller may see. When creating a record, `owner` is required for a Bot writing Personal data. For a Person it defaults to themselves on Personal types and to the Household on Household types.
|
||||||
|
- **`hapi.principal_id` is always the authenticated Principal.** Personal-data policies allow rows where the owner is the principal, **or** the owner has an active Binding to the principal for that domain. Household-data policies (amending ADR-0004) allow an active Household member **or** a Bot with a Household grant for that domain. `USING` checks the read Scope and `WITH CHECK` checks the write Scope. Routes also declare `require_scope(...)`, so a caller missing a Scope gets a clean `403` and the Scope appears in the OpenAPI export. Recorded by is simply the principal.
|
||||||
|
- **Responses:** any missing, malformed, unknown, expired or revoked Token gets the same `401` with `WWW-Authenticate: Bearer`. A missing Scope or Binding returns `403`. A record the caller can't see returns `404`. Tests cover wrong Person, wrong Bot, a revoked Binding and a read-only Scope attempting a write.
|
||||||
|
- **Token lifecycle:** Tokens expire after 365 days by default, with the lifetime configurable when issued. `--no-expiry` is allowed only for Bots, and the CLI lists such Tokens in a warning. A Principal may hold several live Tokens, so rotation goes issue, swap, revoke. `last_used_at` is written at most about once an hour, and `hapi token list` flags Tokens that are near expiry or unused for 90 days.
|
||||||
|
- **Issuing stays in the CLI** (ADR-0002). On the public API, a Person may list and revoke their own Tokens (but not mint them), grant, list, change and revoke their Bindings, and list Bots (id, name, description). The Owner cannot create a Binding on a Person's behalf.
|
||||||
|
- **Deactivation** revokes all of a Principal's Tokens and makes its Household grants and Bindings inert, whichever side of a Binding it was on. Household membership is a flag the Owner sets in the CLI. The Owner can't be deactivated; ownership is transferred through a CLI command that needs the current Owner's confirmation.
|
||||||
|
- **Auth is audited in the logs.** Every auth decision is logged as a structured event with the principal id, the credential's public id, the outcome and the reason. Changes to Tokens, grants and Bindings are logged as audit events. Secrets are never logged. There's no app-level rate limiting, since 256-bit secrets can't be brute-forced. Any per-IP limits belong at the Gateway.
|
||||||
|
- **The Token prefix is deliberate.** It lets secret scanners and push protection recognise a leaked Token.
|
||||||
|
- **A future frontend adds a credential kind and changes nothing else.** Credentials carry a `kind`, which is `api_token` in v1. A browser login (passkeys or OIDC) would add, say, a `session` kind that resolves to the same Person. Scopes, Bindings and RLS stay as they are. Cookie, CSRF and CORS handling arrive with that frontend.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Home Assistant polls hAPI for Jobs that name allowlisted HA scripts
|
||||||
|
|
||||||
|
hAPI needs Home Assistant to carry out actions in the house: things queued while a Person is away, or one-offs not worth configuring in HA. Traffic between the cluster and home only ever starts from home (ADR-0002), so HA has to come to hAPI. A **Job** is Household data (ADR-0001), created by domain code, Persons, or Bots through `/v1/smart_home/jobs`. **HA polls** `GET /v1/smart_home/jobs/next` every 15–30 s with its built-in `rest` sensor. An HA automation runs the Job and reports back through `rest_command` to `POST /v1/smart_home/jobs/{id}/result`. A Job never names an arbitrary HA action. It names an **HA script** (`hapi_*`) plus variables, and HA only runs `script.hapi_*`, so HA decides what hAPI can ever trigger. Jobs tolerate about 30 s of latency: anything interactive and real-time goes from the Person straight to HA's own app, not through hAPI. This bridge carries only Jobs and their results. HA sends other data to ordinary domain endpoints as a Bot.
|
||||||
|
|
||||||
|
## Considered Options
|
||||||
|
|
||||||
|
- **MQTT through a Mosquitto broker in the cluster.** HA's supported message bus gives sub-second delivery. Rejected for v1: it means running and exposing a broker, plus an auth bridge so the broker understands hAPI Tokens, plus a single publisher process inside hAPI. HA's client always uses a clean session, so durability would live in hAPI regardless. MQTT remains the upgrade path if real-time Jobs ever matter.
|
||||||
|
- **RabbitMQ / AMQP.** HA has no AMQP integration and explicitly doesn't support RabbitMQ's MQTT plugin.
|
||||||
|
- **A custom HA integration** (long-poll or SSE against hAPI). This has the cleanest semantics, but it's Python to keep working through every HA release. Since 2026.11 it also can't be installed through the Marketplace from a private Gitea repo.
|
||||||
|
- **hAPI calling HA's REST or WebSocket API.** Ruled out by ADR-0002, because traffic only starts from home.
|
||||||
|
- **Jobs naming arbitrary HA actions** (e.g. `lock.unlock`). Rejected: any holder of `smart_home:write` could do anything HA can do.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- **The bridge needs no new infrastructure or credentials.** HA is the `home-assistant` Bot with a Household grant of `smart_home:write`, and its Token lives in HA's `secrets.yaml`. There's no `jobs` Scope: `smart_home:write` both creates Jobs and consumes them, and ADR-0005 allows splitting the Scope later.
|
||||||
|
- **Delivery is at-least-once, FIFO by `not_before` (or creation time).** `next` hands out the oldest eligible Job and hides it for a 2-minute lease. After 3 deliveries with no result, the Job becomes `failed` (`no_result`), so one broken Job can't stall the queue. HA scripts must be idempotent: set states, don't toggle. After each result, HA calls `homeassistant.update_entity` on the sensor so a backlog drains without waiting for the next poll.
|
||||||
|
- **Job lifecycle:** `pending → succeeded | failed | expired | cancelled`. A Job may carry an optional `not_before`. `expires_at` defaults to 1 h after `not_before` (or after creation), and an expired Job is never delivered. A result is `{status, error?, response?}`, where `response` holds the script's response variables. The first result wins, and a later one gets `409`. Any Household member, or any Bot with `smart_home:write`, can cancel a `pending` Job. Finished Jobs are immutable and are kept for 90 days. Until scheduling exists, `hapi jobs purge` removes them.
|
||||||
|
- **hAPI checks only the shape of a Job, not what it does.** Script names must match `hapi_[a-z0-9_]+`, and variables are capped at 16 KB. hAPI keeps no catalogue of HA scripts. HA rejects unknown scripts, which comes back as a failed result.
|
||||||
|
- **HA-side configuration** is a reference package in this repo (`integrations/home-assistant/hapi_jobs.yaml`: rest sensor, automation, rest_command), copied into HA by hand. The `hapi_*` scripts themselves live in a separate HA configuration repo.
|
||||||
|
- **hAPI records HA's last poll**, so a stalled bridge can be detected. Turning that into an alert is part of observability.
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Flux pulls from git; CI builds images and commits their digest
|
||||||
|
|
||||||
|
Every green merge to protected `main` reaches production, with no release tags and no staging. **Gitea Actions** runs CI on a dedicated runner VM. On a PR it runs lint, pyright, import-linter, the testcontainers test suite, the image build, a smoke test, the OpenAPI export, and a Trivy scan that fails on fixable critical or high CVEs. On `main` it also pushes the image to **Gitea's container registry** and commits the new **digest** into `deploy/apps/hapi`. **Flux** in the cluster polls this repo every minute and applies what's committed. The cluster pulls; CI never pushes to it. CI holds no cluster credentials, and the cluster holds no git credentials (the repo is public, so Flux fetches anonymously over HTTPS). Kubernetes and Talos APIs stay reachable only from the management tailnet (ADR-0002), and no CI system ever joins it.
|
||||||
|
|
||||||
|
## Considered Options
|
||||||
|
|
||||||
|
- **CI push** (`kubectl apply` / `helm upgrade` from a workflow). Rejected: the runner would join the management tailnet with a kubeconfig, so a compromised workflow or dependency would become cluster-admin, and Tailnet Lock would have to trust another node.
|
||||||
|
- **Argo CD.** Rejected for its web UI, which would need keeping off the internet, and its weight. One operator with `flux`/`kubectl` over the tailnet doesn't need a UI.
|
||||||
|
- **Flux image automation** writing digest bumps back to git. Rejected: it needs a write deploy key inside the cluster, turning a cluster compromise into a source-code compromise. CI already decides which image runs, so giving CI the write key adds little.
|
||||||
|
- **A Flux webhook `Receiver`** for instant deploys. Rejected: it's a new public HTTP route without per-Principal auth (ADR-0002). A one-minute poll is fine.
|
||||||
|
- **A runner on the Gitea host or in the cluster.** Rejected: a job with Docker access on the Gitea host can read every repo and every Actions secret, and the cluster shouldn't run CI workloads.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- **Layout:** `deploy/clusters/prod` (Flux's entry point), `deploy/infrastructure` (`HelmRelease`s for upstream components), `deploy/apps/hapi` (the Kustomize base, including the migrate Job). Flux runs with `prune: true` and drift correction on. The Owner installs Flux once over the tailnet with `flux install` plus a `GitRepository`/`Kustomization`. From then on Flux manages itself from git.
|
||||||
|
- **Migrations run as a Job in their own Flux Kustomization** (`hapi-migrate`), using `hapi_migrator` credentials (ADR-0004). The Job name carries the image digest, so each release gets a new Job. The app Kustomization `dependsOn` it with `wait: true`, so a failed migration stops the rollout and the old pods keep serving. **Migrations must be backward-compatible** (expand, then contract in a later release) because old pods run against the new schema. **Migrations go forward only:** there are no down-migrations.
|
||||||
|
- **Rollout:** 2 replicas, `maxSurge: 1`, `maxUnavailable: 0`, no HPA, a PodDisruptionBudget with `minAvailable: 1`, and replicas spread across the two workers. That's at most 3 app pods, within ADR-0004's cap of 4.
|
||||||
|
- **Rollback is `git revert` of the digest bump.** A rollout that never becomes ready stalls, and the old pods keep serving. There's no automated rollback. Break-glass: `flux suspend`, then `kubectl rollout undo`, then bring git back in line.
|
||||||
|
- **Images are public**, because Gitea package visibility follows the owner. Images must never contain secrets. Deploys reference digests, never mutable tags. Builds are amd64 only.
|
||||||
|
- **The CI write credential is a deploy key with write access**, stored as an Actions secret and allowlisted past `main`'s branch protection. The build workflow's path filter skips bump commits, so a bump doesn't trigger another build.
|
||||||
|
- **Renovate runs nightly** on the same runner as its own bot user. It auto-merges only dev-only tooling. Anything that ships (runtime dependencies, base image, charts, Flux, Talos, OpenTofu providers) arrives as a PR the Owner merges.
|
||||||
|
- **Not delivered through Flux:** the runner VM, Cilium, and the Linode CCM live in OpenTofu under `infra/`, and the Owner runs `tofu apply` over the tailnet. Talos and Kubernetes upgrades are a manual `talosctl` runbook. CI never holds the Tofu state key.
|
||||||
|
- **Failures notify through ntfy:** a final `if: failure()` step in each workflow, and Flux's notification-controller for failed reconciles and rollouts. Topics and auth are designed with notifications.
|
||||||
|
- **Deferred:** having Flux verify commit signatures, and signing images (cosign) with admission-time verification. Both guard against a compromised Gitea and belong together in cluster hardening.
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# Secrets are SOPS-encrypted in the public repo; Owner roots live in Vaultwarden
|
||||||
|
|
||||||
|
Secrets the cluster needs are committed to this **public** repo, encrypted with **SOPS + age**, and Flux's kustomize-controller decrypts them as it applies them. Flux pulls with no git credentials and CI holds no cluster credentials (ADR-0007), so secrets must either ride in git encrypted or be placed by hand. Encrypting them in git keeps the cluster rebuildable from git plus one key, with no extra service to run. The roots of trust (the age key, the OpenTofu state key, the Linode and Object Storage tokens, talosconfig and kubeconfig) never enter the cluster or CI. They live in the Owner's self-hosted **Vaultwarden**.
|
||||||
|
|
||||||
|
## Considered Options
|
||||||
|
|
||||||
|
- **External Secrets Operator with a store** (Bitwarden Secrets Manager, 1Password, OpenBao). Rejected. It adds a third-party dependency or a service to run, and the cluster still needs its own credential for the store, so the bootstrap problem remains.
|
||||||
|
- **Sealed Secrets.** Rejected. The ciphertext still sits in git, and the controller's private key is generated in the cluster and has to be backed up, which makes disaster recovery worse than SOPS.
|
||||||
|
- **Secrets created by hand with `kubectl` over the tailnet.** Rejected. Nothing records what should exist, drift goes unnoticed, and rebuilding the cluster needs a manual step for each secret.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- **The ciphertext is public forever.** Key names and encrypted values can be read by anyone, along with every past version in history. If the age key is ever exposed, **every value it protected is rotated**. Replacing the key alone isn't enough.
|
||||||
|
- **Layout:** `.sops.yaml` encrypts only `data`/`stringData` in `deploy/**/*.sops.yaml`. The Flux Kustomizations that carry secrets set `decryption.provider: sops`.
|
||||||
|
- **The age key:** there is one, for prod, generated offline. Its durable copy is in Vaultwarden. During the Flux install runbook, the Owner creates `flux-system/sops-age` from it by hand. OpenTofu never sees it, so it stays out of Tofu state.
|
||||||
|
- **Secrets reach the app as files, never env vars.** They're mounted read-only under pydantic-settings' `secrets_dir`. Env vars leak through `/proc`, into child processes such as break-glass `psql`, and into debug output. Non-secret config such as the DB CA certificate is committed in plaintext as a ConfigMap.
|
||||||
|
- **DB credentials are split** (ADR-0004):
|
||||||
|
- `hapi-db-app` is mounted only into the app Deployment, which also hosts the admin CLI.
|
||||||
|
- `hapi-db-migrator` is mounted only into the migrate Job and a runbook admin pod used for `hapi db bootstrap` and `hapi db breakglass`.
|
||||||
|
- No workload ServiceAccount can read Secrets.
|
||||||
|
- **Git is the source of truth for DB passwords.** The Owner generates them and commits them encrypted. The idempotent `hapi db bootstrap` reads them from its mounted files and runs `CREATE`/`ALTER ROLE … PASSWORD`. The `akmadmin` password is still pasted in at run time and never stored in git or the cluster.
|
||||||
|
- **Each integration gets its own narrow credential:**
|
||||||
|
- The CCM gets a dedicated Linode token with only the scopes it needs. OpenTofu creates it, never reusing the Owner's Tofu token.
|
||||||
|
- Later credentials (DNS-01, ntfy, the backup target) are each a narrow token delivered through SOPS.
|
||||||
|
- **CI secrets** (the write deploy key, the Renovate bot token, a publish-only ntfy token for the CI topic) are repo-level Gitea Actions secrets. CI never decrypts SOPS.
|
||||||
|
- **Guardrails against plaintext:**
|
||||||
|
- gitleaks runs in pre-commit and as a required CI check.
|
||||||
|
- A second CI check fails on any `kind: Secret` manifest without SOPS metadata, or any `*.sops.yaml` that isn't encrypted.
|
||||||
|
- A plaintext secret that reaches `main` is rotated. Rewriting history doesn't help, because clones and caches already have it.
|
||||||
|
- **Rotation is manual and event-driven**, with no schedule. It happens on suspicion of exposure, when the age key is exposed, or when who has access changes.
|
||||||
|
- **For a DB password:** merge the new SOPS value, wait for Flux, run `hapi db bootstrap` (which runs `ALTER ROLE`), then `kubectl rollout restart`.
|
||||||
|
- **The cost:** new connections fail for a few seconds between the last two steps, which is accepted. There's no Reloader controller.
|
||||||
|
- **Owner roots:** kubeconfig and talosconfig sit on local disk only while in use. Vaultwarden is cloud-hosted with its own backups. An additional offline copy (paper or encrypted USB, kept away from home) holds the age key, the OpenTofu state passphrase and the Linode account recovery codes, and is updated whenever one of them rotates.
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# Probes on an internal port, authenticated three-state health, self-hosted Victoria stack
|
||||||
|
|
||||||
|
ADR-0002 allows no anonymous public endpoints, but kubelet probes can't carry a Token. So hAPI listens on two ports. **`:8000`** serves the API and is the only port the Gateway routes. **`:8081`** is internal: it is never routed, and a NetworkPolicy limits it to kubelet and the metrics scraper. It serves `/livez`, `/readyz` and `/metrics` without auth, from the **same process and event loop** as the API, so a wedged loop fails liveness. External health is **`GET /v1/health`** on the public API. It needs the `health` Scope, and it reports `ok`, `degraded` or `down` using only check names and `ok`/`fail`. Uptime Kuma, a Bot on its own public VM, polls it. Logs and metrics go to **VictoriaLogs and VictoriaMetrics**, self-hosted in the cluster. The Owner reads them through Grafana over a port-forward on the management tailnet. We chose this stack over Prometheus + Loki because it fits beside hAPI on two 4 GB workers, and over a SaaS because logs carry Principal ids and the breakglass audit trail (ADR-0004), which shouldn't leave the cluster.
|
||||||
|
|
||||||
|
## Considered Options
|
||||||
|
|
||||||
|
- **Probes on the public port, unauthenticated.** Rejected: it breaks ADR-0002's "no anonymous endpoints" rule. A probe path the Gateway happens not to route is also easier to expose by mistake than a port it never routes.
|
||||||
|
- **Readiness that checks the database.** Rejected: one blip of the managed database would mark every pod unready at once, and the NodeBalancer would serve nothing. A 503 with an RFC 9457 body is more honest. Database health goes into `/v1/health` and metrics instead.
|
||||||
|
- **Separate health endpoints per concern** (e.g. one for the HA bridge). Rejected in favour of one endpoint with critical and non-critical checks, which gives Kuma a "degraded" signal without a second route.
|
||||||
|
- **Prometheus + Loki (+ Alloy).** The industry standard. Rejected for v1 on footprint: it needs about 1.5–2 GB before tuning, on workers that also run hAPI, Flux and Cilium.
|
||||||
|
- **Grafana Cloud or another SaaS.** Rejected: it would put a vendor in the data path for Principal ids and audit events.
|
||||||
|
- **Built-in vmui / VictoriaLogs UI only.** Workable, but provisioned dashboards earn Grafana its place.
|
||||||
|
- **Write-once off-cluster storage for breakglass audit events.** Deferred: the Owner controls the cluster and is the one who runs breakglass. In v1, tamper-evidence comes from a Household ntfy alert on every breakglass start.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- **`/livez`** returns a constant. **`/readyz`** passes once startup is done (config loaded, pools created). On SIGTERM, `/readyz` fails first and the pod drains for about 5 s before it shuts down. Readiness also gates rollouts (ADR-0007): an image that never becomes Ready stalls the rollout.
|
||||||
|
- **`/v1/health`** checks `db` (a `SELECT 1` through the app pool) and `schema` (at the expected Alembic head). These are critical: if either fails, the status is `down` with HTTP 503. It also checks `ha_bridge` (no poll for 5 min, see ADR-0006) and `job_backlog` (oldest pending Job too old). These are non-critical: if one fails, the status is `degraded` with HTTP 200. Bodies carry no error text, hostnames, versions or latencies. Kuma points two monitors at it: *up* (HTTP status) and *healthy* (a JSON query asserting `status == "ok"`).
|
||||||
|
- **Collection:** vmagent scrapes the app, kubelet/cAdvisor, kube-state-metrics, node-exporter, Flux and Cilium. A Vector DaemonSet takes pod stdout and Talos service logs (`machine.logging`, JSON over TCP). An event exporter ships Kubernetes Events as logs. Everything lives in a `monitoring` namespace on Block Storage PVs and arrives as Flux `HelmRelease`s.
|
||||||
|
- **App metrics** come from `prometheus-client`: requests by route template, method and status; latency; DB pool usage; Job depth, age and failures; seconds since HA's last poll; auth failures by reason. **Labels never carry `principal_id` or Personal data.** Per-Principal detail stays in logs.
|
||||||
|
- **Retention:** logs and metrics are kept for 30 days, breakglass audit events for 1 year.
|
||||||
|
- **Locked down:** Grafana requires login, with analytics, update checks and Gravatar off. Datasource plugins are pinned in the image. Outbound traffic from `monitoring` is denied by default, except vmalert → ntfy and the Watchdog → Kuma push.
|
||||||
|
- **Every failure has one alerting owner.**
|
||||||
|
- Kuma: reachability and degraded status.
|
||||||
|
- Flux notification-controller: failed reconciles, migrate Jobs and rollouts.
|
||||||
|
- vmalert: PVs filling, crash loops, the DB pool near ADR-0004's budget, Jobs piling up or failing, a node NotReady.
|
||||||
|
- Watchdog: an always-firing alert pushes to a Kuma push monitor, so the monitoring stack dying is caught from outside. The push URL is a SOPS secret (ADR-0008).
|
||||||
|
- **Never public:** `:8081`, Grafana, VictoriaMetrics and VictoriaLogs. They're reachable only by `kubectl port-forward` over the management tailnet.
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Runs on the probe VM inside the VPC. Env: DBHOST, DBPORT, ROOTPW. CA at ./ca.crt
|
|
||||||
set -u
|
|
||||||
export PGSSLMODE=verify-full PGSSLROOTCERT=$PWD/ca.crt PGHOST=$DBHOST PGPORT=$DBPORT PGCONNECT_TIMEOUT=10
|
|
||||||
MIGPW=$(openssl rand -hex 16); APPPW=$(openssl rand -hex 16)
|
|
||||||
A=00000000-0000-0000-0000-00000000000a; B=00000000-0000-0000-0000-00000000000b
|
|
||||||
q() { local user=$1 pw=$2 db=$3; shift 3; PGPASSWORD=$pw psql -X -v ON_ERROR_STOP=0 -U "$user" -d "$db" "$@" 2>&1; }
|
|
||||||
|
|
||||||
echo "== 0. DNS + TLS"
|
|
||||||
getent hosts "$DBHOST"
|
|
||||||
q akmadmin "$ROOTPW" defaultdb -Atc "select 'tls='||ssl||' '||version from pg_stat_ssl where pid=pg_backend_pid()"
|
|
||||||
PGSSLMODE=verify-full PGPASSWORD=$ROOTPW psql -X -h "$(getent hosts "$DBHOST" | awk '{print $1}')" -U akmadmin -d defaultdb -Atc 'select 1' 2>&1 | sed 's/^/by-IP (expect cert mismatch): /'
|
|
||||||
|
|
||||||
echo "-- server cert names"
|
|
||||||
openssl s_client -starttls postgres -connect "$DBHOST:$DBPORT" </dev/null 2>/dev/null | openssl x509 -noout -subject -ext subjectAltName 2>&1
|
|
||||||
echo "== 1. platform settings / akmadmin attributes"
|
|
||||||
q akmadmin "$ROOTPW" defaultdb -Atc "select version()" -c "show password_encryption" -c "show max_connections" -c "show superuser_reserved_connections" -c "show reserved_connections" \
|
|
||||||
-c "select rolname, rolsuper, rolcreaterole, rolcreatedb, rolbypassrls from pg_roles where rolname = current_user" \
|
|
||||||
-c "show createrole_self_grant"
|
|
||||||
|
|
||||||
echo "== 2. bootstrap as akmadmin"
|
|
||||||
q akmadmin "$ROOTPW" defaultdb -c "create role hapi_migrator login password '$MIGPW'" -c "create role hapi_app login password '$APPPW'" \
|
|
||||||
-c "select rolname, rolpassword like 'SCRAM%' as scram from pg_authid where rolname like 'hapi_%'" \
|
|
||||||
-c "create database hapi owner hapi_migrator"
|
|
||||||
echo "-- retry create database after granting SET on hapi_migrator to akmadmin"
|
|
||||||
q akmadmin "$ROOTPW" defaultdb -c "grant hapi_migrator to akmadmin with set true, inherit false" -c "create database hapi owner hapi_migrator"
|
|
||||||
echo "-- db-level grants as owner hapi_migrator"
|
|
||||||
q hapi_migrator "$MIGPW" hapi -c "revoke all on database hapi from public" -c "grant connect on database hapi to hapi_app" -c "revoke create on schema public from public"
|
|
||||||
echo "-- audit: per-role log_statement"
|
|
||||||
q akmadmin "$ROOTPW" defaultdb -c "alter role hapi_migrator set log_statement = 'all'" -c "alter role hapi_migrator set log_min_duration_statement = 0"
|
|
||||||
echo "-- can akmadmin grant BYPASSRLS?"
|
|
||||||
q akmadmin "$ROOTPW" defaultdb -c "create role probe_bypass bypassrls" -c "drop role if exists probe_bypass"
|
|
||||||
|
|
||||||
echo "== 3. schema + RLS as hapi_migrator"
|
|
||||||
q hapi_migrator "$MIGPW" hapi -c "create schema finance" -c "grant usage on schema finance to hapi_app" \
|
|
||||||
-c "alter default privileges in schema finance grant select, insert, update, delete on tables to hapi_app" \
|
|
||||||
-c "create table finance.note (id uuid primary key default uuidv7(), owner_id uuid not null, body text)" \
|
|
||||||
-c "alter table finance.note enable row level security" -c "alter table finance.note force row level security" \
|
|
||||||
-c "create policy own on finance.note using (owner_id = nullif(current_setting('hapi.principal_id', true), '')::uuid) with check (owner_id = nullif(current_setting('hapi.principal_id', true), '')::uuid)"
|
|
||||||
echo "-- owner under FORCE, no principal set: insert (expect RLS violation)"
|
|
||||||
q hapi_migrator "$MIGPW" hapi -c "insert into finance.note(owner_id, body) values ('$A','a1')"
|
|
||||||
echo "-- owner seeds via per-row principal"
|
|
||||||
q hapi_migrator "$MIGPW" hapi -c "begin" -c "select set_config('hapi.principal_id','$A',true)" -c "insert into finance.note(owner_id, body) values ('$A','a1'),('$A','a2')" -c "commit" \
|
|
||||||
-c "begin" -c "select set_config('hapi.principal_id','$B',true)" -c "insert into finance.note(owner_id, body) values ('$B','b1')" -c "commit"
|
|
||||||
echo "-- owner, no principal: count (FORCE => 0)"
|
|
||||||
q hapi_migrator "$MIGPW" hapi -Atc "select count(*) from finance.note"
|
|
||||||
echo "-- owner temporarily NO FORCE (data-repair path)"
|
|
||||||
q hapi_migrator "$MIGPW" hapi -Atc "begin" -c "alter table finance.note no force row level security" -c "select count(*) from finance.note" -c "rollback"
|
|
||||||
|
|
||||||
echo "== 4. hapi_app"
|
|
||||||
echo "-- DDL attempts (expect permission denied x2)"
|
|
||||||
q hapi_app "$APPPW" hapi -c "create table finance.evil(x int)" -c "create table public.evil(x int)"
|
|
||||||
echo "-- no principal set: count (expect 0)"
|
|
||||||
q hapi_app "$APPPW" hapi -Atc "select count(*) from finance.note"
|
|
||||||
echo "-- SET LOCAL A in txn, then after commit on same connection (expect 2 then 0)"
|
|
||||||
q hapi_app "$APPPW" hapi -Atc "begin" -c "set local hapi.principal_id = '$A'" -c "select count(*) from finance.note" -c "commit" -c "select count(*) from finance.note" -c "select '['||current_setting('hapi.principal_id', true)||']'"
|
|
||||||
echo "-- set_config(..., true) as A (expect 2)"
|
|
||||||
q hapi_app "$APPPW" hapi -Atc "begin" -c "select set_config('hapi.principal_id','$A',true)" -c "select count(*) from finance.note" -c "commit"
|
|
||||||
echo "-- WITH CHECK: as A insert B-owned row (expect RLS violation)"
|
|
||||||
q hapi_app "$APPPW" hapi -c "begin" -c "set local hapi.principal_id = '$A'" -c "insert into finance.note(owner_id, body) values ('$B','x')" -c "rollback"
|
|
||||||
echo "-- as A update B rows (expect UPDATE 0)"
|
|
||||||
q hapi_app "$APPPW" hapi -c "begin" -c "set local hapi.principal_id = '$A'" -c "update finance.note set body='pwn' where owner_id='$B'" -c "rollback"
|
|
||||||
echo "-- escalation attempts (expect all denied)"
|
|
||||||
q hapi_app "$APPPW" hapi -c "set role hapi_migrator" -c "alter table finance.note no force row level security" -c "alter table finance.note disable row level security" -c "drop policy own on finance.note"
|
|
||||||
echo "-- spoof: leaked hapi_app creds can set any principal (expect 1 = B's row visible)"
|
|
||||||
q hapi_app "$APPPW" hapi -Atc "set hapi.principal_id = '$B'" -c "select count(*) from finance.note"
|
|
||||||
echo "-- connections in use"
|
|
||||||
q akmadmin "$ROOTPW" defaultdb -Atc "select backend_type, usename, count(*) from pg_stat_activity group by 1,2 order by 1,2"
|
|
||||||
echo DONE
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
terraform {
|
|
||||||
required_providers {
|
|
||||||
linode = { source = "linode/linode", version = "~> 4.10" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
provider "linode" {}
|
|
||||||
|
|
||||||
resource "linode_vpc" "v" {
|
|
||||||
label = "hapi-verify-64"
|
|
||||||
region = "us-iad"
|
|
||||||
}
|
|
||||||
resource "linode_vpc_subnet" "s" {
|
|
||||||
vpc_id = linode_vpc.v.id
|
|
||||||
label = "hapi-verify-64"
|
|
||||||
ipv4 = "10.64.0.0/24"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "linode_database_postgresql_v2" "db" {
|
|
||||||
label = "hapi-verify-64"
|
|
||||||
engine_id = "postgresql/18"
|
|
||||||
region = "us-iad"
|
|
||||||
type = "g6-standard-1"
|
|
||||||
cluster_size = 1
|
|
||||||
allow_list = ["10.64.0.0/24"]
|
|
||||||
engine_config_pg_password_encryption = "scram-sha-256"
|
|
||||||
private_network = {
|
|
||||||
vpc_id = linode_vpc.v.id
|
|
||||||
subnet_id = linode_vpc_subnet.s.id
|
|
||||||
public_access = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "linode_instance" "probe" {
|
|
||||||
label = "hapi-verify-64"
|
|
||||||
region = "us-iad"
|
|
||||||
type = "g6-nanode-1"
|
|
||||||
image = "linode/debian13"
|
|
||||||
authorized_keys = [chomp(file("${path.module}/id_ed25519.pub"))]
|
|
||||||
linode_interfaces {
|
|
||||||
firewall_id = linode_firewall.fw.id
|
|
||||||
public {
|
|
||||||
ipv4 {
|
|
||||||
addresses {
|
|
||||||
address = "auto"
|
|
||||||
primary = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default_route {
|
|
||||||
ipv4 = true
|
|
||||||
ipv6 = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
linode_interfaces {
|
|
||||||
firewall_id = linode_firewall.fw.id
|
|
||||||
vpc { subnet_id = linode_vpc_subnet.s.id }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
output "probe_ip" { value = linode_instance.probe.ip_address }
|
|
||||||
output "db_host" { value = linode_database_postgresql_v2.db.host_primary }
|
|
||||||
output "db_port" { value = linode_database_postgresql_v2.db.port }
|
|
||||||
|
|
||||||
resource "linode_firewall" "fw" {
|
|
||||||
label = "hapi-verify-64"
|
|
||||||
inbound_policy = "DROP"
|
|
||||||
outbound_policy = "ACCEPT"
|
|
||||||
inbound {
|
|
||||||
label = "ssh"
|
|
||||||
action = "ACCEPT"
|
|
||||||
protocol = "TCP"
|
|
||||||
ports = "22"
|
|
||||||
ipv4 = ["0.0.0.0/0"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,223 +0,0 @@
|
|||||||
13:05:53 up
|
|
||||||
13:05:58 up
|
|
||||||
13:06:03 up
|
|
||||||
13:06:08 up
|
|
||||||
13:06:13 up
|
|
||||||
13:06:18 up
|
|
||||||
13:06:23 up
|
|
||||||
13:06:28 up
|
|
||||||
13:06:33 up
|
|
||||||
13:06:38 up
|
|
||||||
13:06:44 up
|
|
||||||
13:06:49 up
|
|
||||||
13:06:54 up
|
|
||||||
13:06:59 up
|
|
||||||
13:07:04 up
|
|
||||||
13:07:09 up
|
|
||||||
13:07:14 up
|
|
||||||
13:07:19 up
|
|
||||||
13:07:24 up
|
|
||||||
13:07:29 up
|
|
||||||
13:07:34 up
|
|
||||||
13:07:39 up
|
|
||||||
13:07:45 up
|
|
||||||
13:07:50 up
|
|
||||||
13:07:55 up
|
|
||||||
13:08:00 up
|
|
||||||
13:08:05 up
|
|
||||||
13:08:10 up
|
|
||||||
13:08:15 up
|
|
||||||
13:08:20 up
|
|
||||||
13:08:25 up
|
|
||||||
13:08:30 up
|
|
||||||
13:08:35 up
|
|
||||||
13:08:40 up
|
|
||||||
13:08:46 up
|
|
||||||
13:08:51 up
|
|
||||||
13:08:56 up
|
|
||||||
13:09:01 up
|
|
||||||
13:09:06 up
|
|
||||||
13:09:11 up
|
|
||||||
13:09:16 up
|
|
||||||
13:09:21 up
|
|
||||||
13:09:26 up
|
|
||||||
13:09:31 up
|
|
||||||
13:09:36 up
|
|
||||||
13:09:41 up
|
|
||||||
13:09:46 up
|
|
||||||
13:09:52 up
|
|
||||||
13:09:57 up
|
|
||||||
13:10:02 up
|
|
||||||
13:10:07 up
|
|
||||||
13:10:12 up
|
|
||||||
13:10:17 up
|
|
||||||
13:10:22 up
|
|
||||||
13:10:27 up
|
|
||||||
13:10:32 up
|
|
||||||
13:10:37 up
|
|
||||||
13:10:43 up
|
|
||||||
13:10:48 up
|
|
||||||
13:10:53 up
|
|
||||||
13:10:58 up
|
|
||||||
13:11:03 up
|
|
||||||
13:11:08 up
|
|
||||||
13:11:13 up
|
|
||||||
13:11:18 up
|
|
||||||
13:11:23 up
|
|
||||||
13:11:28 up
|
|
||||||
13:11:33 up
|
|
||||||
13:11:38 up
|
|
||||||
13:11:43 up
|
|
||||||
13:11:49 up
|
|
||||||
13:11:54 up
|
|
||||||
13:11:59 up
|
|
||||||
13:12:04 up
|
|
||||||
13:12:09 up
|
|
||||||
13:12:14 up
|
|
||||||
13:12:19 up
|
|
||||||
13:12:24 up
|
|
||||||
13:12:29 up
|
|
||||||
13:12:34 up
|
|
||||||
13:12:39 up
|
|
||||||
13:12:44 up
|
|
||||||
13:12:49 up
|
|
||||||
13:12:55 up
|
|
||||||
13:13:00 up
|
|
||||||
13:13:05 up
|
|
||||||
13:13:10 up
|
|
||||||
13:13:15 up
|
|
||||||
13:13:20 up
|
|
||||||
13:13:25 up
|
|
||||||
13:13:30 up
|
|
||||||
13:13:35 up
|
|
||||||
13:13:40 up
|
|
||||||
13:13:45 up
|
|
||||||
13:13:51 up
|
|
||||||
13:13:56 up
|
|
||||||
13:14:01 up
|
|
||||||
13:14:06 up
|
|
||||||
13:14:11 up
|
|
||||||
13:14:16 up
|
|
||||||
13:14:21 up
|
|
||||||
13:14:26 up
|
|
||||||
13:14:31 up
|
|
||||||
13:14:36 up
|
|
||||||
13:14:41 up
|
|
||||||
13:14:46 up
|
|
||||||
13:14:52 up
|
|
||||||
13:14:57 up
|
|
||||||
13:15:02 up
|
|
||||||
13:15:07 up
|
|
||||||
13:15:12 up
|
|
||||||
13:15:17 up
|
|
||||||
13:15:22 up
|
|
||||||
13:15:27 up
|
|
||||||
13:15:32 up
|
|
||||||
13:15:37 up
|
|
||||||
13:15:43 up
|
|
||||||
13:15:48 up
|
|
||||||
13:15:53 up
|
|
||||||
13:15:58 up
|
|
||||||
13:16:03 up
|
|
||||||
13:16:08 up
|
|
||||||
13:16:13 up
|
|
||||||
13:16:18 up
|
|
||||||
13:16:23 up
|
|
||||||
13:16:28 up
|
|
||||||
13:16:34 up
|
|
||||||
13:16:39 up
|
|
||||||
13:16:44 up
|
|
||||||
13:16:49 up
|
|
||||||
13:16:54 up
|
|
||||||
13:16:59 up
|
|
||||||
13:17:04 up
|
|
||||||
13:17:09 up
|
|
||||||
13:17:14 up
|
|
||||||
13:17:19 up
|
|
||||||
13:17:24 up
|
|
||||||
13:17:29 up
|
|
||||||
13:17:35 up
|
|
||||||
13:17:40 up
|
|
||||||
13:17:45 up
|
|
||||||
13:17:50 up
|
|
||||||
13:17:55 up
|
|
||||||
13:18:00 up
|
|
||||||
13:18:05 up
|
|
||||||
13:18:10 up
|
|
||||||
13:18:15 up
|
|
||||||
13:18:20 up
|
|
||||||
13:18:25 up
|
|
||||||
13:18:30 up
|
|
||||||
13:18:36 up
|
|
||||||
13:18:41 up
|
|
||||||
13:18:46 up
|
|
||||||
13:18:51 up
|
|
||||||
13:18:56 up
|
|
||||||
13:19:01 up
|
|
||||||
13:19:06 up
|
|
||||||
13:19:11 up
|
|
||||||
13:19:16 up
|
|
||||||
13:19:21 up
|
|
||||||
13:19:26 up
|
|
||||||
13:19:32 up
|
|
||||||
13:19:37 up
|
|
||||||
13:19:42 up
|
|
||||||
13:19:47 up
|
|
||||||
13:19:52 up
|
|
||||||
13:19:57 up
|
|
||||||
13:20:02 up
|
|
||||||
13:20:07 up
|
|
||||||
13:20:12 up
|
|
||||||
13:20:17 up
|
|
||||||
13:20:22 up
|
|
||||||
13:20:27 up
|
|
||||||
13:20:33 up
|
|
||||||
13:20:38 up
|
|
||||||
13:20:43 up
|
|
||||||
13:20:48 up
|
|
||||||
13:20:53 up
|
|
||||||
13:20:58 up
|
|
||||||
13:21:03 up
|
|
||||||
13:21:08 up
|
|
||||||
13:21:13 up
|
|
||||||
13:21:18 up
|
|
||||||
13:21:23 up
|
|
||||||
13:21:28 up
|
|
||||||
13:21:34 up
|
|
||||||
13:21:39 up
|
|
||||||
13:21:44 up
|
|
||||||
13:21:49 up
|
|
||||||
13:21:54 up
|
|
||||||
13:21:59 up
|
|
||||||
13:22:04 up
|
|
||||||
13:22:09 up
|
|
||||||
13:22:14 up
|
|
||||||
13:22:19 up
|
|
||||||
13:22:24 up
|
|
||||||
13:22:29 up
|
|
||||||
13:22:35 up
|
|
||||||
13:22:40 up
|
|
||||||
13:22:45 up
|
|
||||||
13:22:50 up
|
|
||||||
13:22:55 up
|
|
||||||
13:23:00 up
|
|
||||||
13:23:05 up
|
|
||||||
13:23:10 up
|
|
||||||
13:23:15 up
|
|
||||||
13:23:20 up
|
|
||||||
13:23:26 up
|
|
||||||
13:23:31 up
|
|
||||||
13:23:36 up
|
|
||||||
13:23:41 up
|
|
||||||
13:23:46 up
|
|
||||||
13:23:51 up
|
|
||||||
13:23:56 up
|
|
||||||
13:24:01 up
|
|
||||||
13:24:06 up
|
|
||||||
13:24:11 up
|
|
||||||
13:24:16 up
|
|
||||||
13:24:21 up
|
|
||||||
13:24:27 up
|
|
||||||
13:24:32 up
|
|
||||||
13:24:37 up
|
|
||||||
13:24:42 up
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
== 0. DNS + TLS
|
|
||||||
tls=true TLSv1.3
|
|
||||||
by-IP (expect cert mismatch): 1
|
|
||||||
-- server cert names
|
|
||||||
subject=ST=service, O=a6555122-1463-44bd-bdcc-b8dd91653408, CN=a568915-1
|
|
||||||
X509v3 Subject Alternative Name:
|
|
||||||
IP Address:10.64.0.32, DNS:10.64.0.32, DNS:2600:3c05::2000:adff:fe30:f6eb, DNS:private-a568915-akamai-prod-1130531-default.g2a.akamaidb.net, IP Address:172.234.33.213, DNS:*.g2a.akamaidb.net, DNS:public-n-a568915-1.g2a.akamaidb.net, DNS:public-replica-a568915-akamai-prod-1130531-default.g2a.akamaidb.net, DNS:172.234.33.213, DNS:fda7:a938:5bfe:5fa6:0:5f7:bc5a:cb01, DNS:private-replica-a568915-akamai-prod-1130531-default.g2a.akamaidb.net, DNS:a568915-akamai-prod-1130531-default.g2a.akamaidb.net, IP Address:2600:3C05:0:0:2000:ADFF:FE30:F6EB, DNS:replica-a568915-akamai-prod-1130531-default.g2a.akamaidb.net, DNS:n-a568915-1.g2a.akamaidb.net, IP Address:FDA7:A938:5BFE:5FA6:0:5F7:BC5A:CB01, DNS:public-a568915-akamai-prod-1130531-default.g2a.akamaidb.net
|
|
||||||
== 1. platform settings / akmadmin attributes
|
|
||||||
PostgreSQL 18.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 15.3.1 20260722 (Red Hat 15.3.1-1), 64-bit
|
|
||||||
scram-sha-256
|
|
||||||
50
|
|
||||||
3
|
|
||||||
0
|
|
||||||
akmadmin|f|t|t|t
|
|
||||||
inherit,set
|
|
||||||
== 2. bootstrap as akmadmin
|
|
||||||
CREATE ROLE
|
|
||||||
CREATE ROLE
|
|
||||||
ERROR: permission denied for table pg_authid
|
|
||||||
CREATE DATABASE
|
|
||||||
-- retry create database after granting SET on hapi_migrator to akmadmin
|
|
||||||
GRANT ROLE
|
|
||||||
ERROR: database "hapi" already exists
|
|
||||||
-- db-level grants as owner hapi_migrator
|
|
||||||
REVOKE
|
|
||||||
GRANT
|
|
||||||
REVOKE
|
|
||||||
-- audit: per-role log_statement
|
|
||||||
ERROR: permission denied to set parameter "log_statement"
|
|
||||||
ERROR: permission denied to set parameter "log_min_duration_statement"
|
|
||||||
-- can akmadmin grant BYPASSRLS?
|
|
||||||
CREATE ROLE
|
|
||||||
DROP ROLE
|
|
||||||
== 3. schema + RLS as hapi_migrator
|
|
||||||
CREATE SCHEMA
|
|
||||||
GRANT
|
|
||||||
ALTER DEFAULT PRIVILEGES
|
|
||||||
CREATE TABLE
|
|
||||||
ALTER TABLE
|
|
||||||
ALTER TABLE
|
|
||||||
CREATE POLICY
|
|
||||||
-- owner under FORCE, no principal set: insert (expect RLS violation)
|
|
||||||
ERROR: new row violates row-level security policy for table "note"
|
|
||||||
-- owner seeds via per-row principal
|
|
||||||
BEGIN
|
|
||||||
set_config
|
|
||||||
--------------------------------------
|
|
||||||
00000000-0000-0000-0000-00000000000a
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
INSERT 0 2
|
|
||||||
COMMIT
|
|
||||||
BEGIN
|
|
||||||
set_config
|
|
||||||
--------------------------------------
|
|
||||||
00000000-0000-0000-0000-00000000000b
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
INSERT 0 1
|
|
||||||
COMMIT
|
|
||||||
-- owner, no principal: count (FORCE => 0)
|
|
||||||
0
|
|
||||||
-- owner temporarily NO FORCE (data-repair path)
|
|
||||||
BEGIN
|
|
||||||
ALTER TABLE
|
|
||||||
3
|
|
||||||
ROLLBACK
|
|
||||||
== 4. hapi_app
|
|
||||||
-- DDL attempts (expect permission denied x2)
|
|
||||||
ERROR: permission denied for schema finance
|
|
||||||
LINE 1: create table finance.evil(x int)
|
|
||||||
^
|
|
||||||
ERROR: permission denied for schema public
|
|
||||||
LINE 1: create table public.evil(x int)
|
|
||||||
^
|
|
||||||
-- no principal set: count (expect 0)
|
|
||||||
0
|
|
||||||
-- SET LOCAL A in txn, then after commit on same connection (expect 2 then 0)
|
|
||||||
BEGIN
|
|
||||||
SET
|
|
||||||
2
|
|
||||||
COMMIT
|
|
||||||
0
|
|
||||||
[]
|
|
||||||
-- set_config(..., true) as A (expect 2)
|
|
||||||
BEGIN
|
|
||||||
00000000-0000-0000-0000-00000000000a
|
|
||||||
2
|
|
||||||
COMMIT
|
|
||||||
-- WITH CHECK: as A insert B-owned row (expect RLS violation)
|
|
||||||
BEGIN
|
|
||||||
SET
|
|
||||||
ERROR: new row violates row-level security policy for table "note"
|
|
||||||
ROLLBACK
|
|
||||||
-- as A update B rows (expect UPDATE 0)
|
|
||||||
BEGIN
|
|
||||||
SET
|
|
||||||
UPDATE 0
|
|
||||||
ROLLBACK
|
|
||||||
-- escalation attempts (expect all denied)
|
|
||||||
ERROR: permission denied to set role "hapi_migrator"
|
|
||||||
ERROR: must be owner of table note
|
|
||||||
ERROR: must be owner of table note
|
|
||||||
ERROR: must be owner of relation note
|
|
||||||
-- spoof: leaked hapi_app creds can set any principal (expect 1 = B's row visible)
|
|
||||||
SET
|
|
||||||
1
|
|
||||||
-- connections in use
|
|
||||||
autovacuum launcher||1
|
|
||||||
background writer||1
|
|
||||||
checkpointer||1
|
|
||||||
client backend|akmadmin|1
|
|
||||||
client backend|postgres|1
|
|
||||||
io worker||3
|
|
||||||
logical replication launcher|postgres|1
|
|
||||||
pg_cron launcher|postgres|1
|
|
||||||
pg_failover_slots worker|postgres|1
|
|
||||||
TimescaleDB Background Worker Launcher|postgres|1
|
|
||||||
walsender|_aiven|1
|
|
||||||
walwriter||1
|
|
||||||
DONE
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
== 0. DNS + TLS
|
|
||||||
10.64.0.16 private-a568914-akamai-prod-1130531-default.g2a.akamaidb.net
|
|
||||||
tls=true TLSv1.3
|
|
||||||
by-IP (expect cert mismatch): 1
|
|
||||||
== 1. platform settings / akmadmin attributes
|
|
||||||
PostgreSQL 18.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 15.3.1 20260722 (Red Hat 15.3.1-1), 64-bit
|
|
||||||
scram-sha-256
|
|
||||||
25
|
|
||||||
3
|
|
||||||
0
|
|
||||||
akmadmin|f|t|t|t
|
|
||||||
inherit,set
|
|
||||||
== 2. bootstrap as akmadmin
|
|
||||||
CREATE ROLE
|
|
||||||
CREATE ROLE
|
|
||||||
ERROR: permission denied for table pg_authid
|
|
||||||
CREATE DATABASE
|
|
||||||
-- retry create database after granting SET on hapi_migrator to akmadmin
|
|
||||||
GRANT ROLE
|
|
||||||
ERROR: database "hapi" already exists
|
|
||||||
WARNING: no privileges could be revoked for "hapi"
|
|
||||||
REVOKE
|
|
||||||
WARNING: no privileges were granted for "hapi"
|
|
||||||
GRANT
|
|
||||||
WARNING: no privileges could be revoked for "public"
|
|
||||||
REVOKE
|
|
||||||
-- audit: per-role log_statement
|
|
||||||
ERROR: permission denied to set parameter "log_statement"
|
|
||||||
ERROR: permission denied to set parameter "log_min_duration_statement"
|
|
||||||
-- can akmadmin grant BYPASSRLS?
|
|
||||||
CREATE ROLE
|
|
||||||
DROP ROLE
|
|
||||||
== 3. schema + RLS as hapi_migrator
|
|
||||||
CREATE SCHEMA
|
|
||||||
GRANT
|
|
||||||
ALTER DEFAULT PRIVILEGES
|
|
||||||
CREATE TABLE
|
|
||||||
ALTER TABLE
|
|
||||||
ALTER TABLE
|
|
||||||
CREATE POLICY
|
|
||||||
-- owner under FORCE, no principal set: insert (expect RLS violation)
|
|
||||||
ERROR: new row violates row-level security policy for table "note"
|
|
||||||
-- owner seeds via per-row principal
|
|
||||||
BEGIN
|
|
||||||
set_config
|
|
||||||
--------------------------------------
|
|
||||||
00000000-0000-0000-0000-00000000000a
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
INSERT 0 2
|
|
||||||
COMMIT
|
|
||||||
BEGIN
|
|
||||||
set_config
|
|
||||||
--------------------------------------
|
|
||||||
00000000-0000-0000-0000-00000000000b
|
|
||||||
(1 row)
|
|
||||||
|
|
||||||
INSERT 0 1
|
|
||||||
COMMIT
|
|
||||||
-- owner, no principal: count (FORCE => 0)
|
|
||||||
0
|
|
||||||
-- owner temporarily NO FORCE (data-repair path)
|
|
||||||
BEGIN
|
|
||||||
ALTER TABLE
|
|
||||||
3
|
|
||||||
ROLLBACK
|
|
||||||
== 4. hapi_app
|
|
||||||
-- DDL attempts (expect permission denied x2)
|
|
||||||
ERROR: permission denied for schema finance
|
|
||||||
LINE 1: create table finance.evil(x int)
|
|
||||||
^
|
|
||||||
ERROR: permission denied for schema public
|
|
||||||
LINE 1: create table public.evil(x int)
|
|
||||||
^
|
|
||||||
-- no principal set: count (expect 0)
|
|
||||||
0
|
|
||||||
-- SET LOCAL A in txn, then after commit on same connection (expect 2 then 0)
|
|
||||||
BEGIN
|
|
||||||
SET
|
|
||||||
2
|
|
||||||
COMMIT
|
|
||||||
0
|
|
||||||
[]
|
|
||||||
-- set_config(..., true) as A (expect 2)
|
|
||||||
BEGIN
|
|
||||||
00000000-0000-0000-0000-00000000000a
|
|
||||||
2
|
|
||||||
COMMIT
|
|
||||||
-- WITH CHECK: as A insert B-owned row (expect RLS violation)
|
|
||||||
BEGIN
|
|
||||||
SET
|
|
||||||
ERROR: new row violates row-level security policy for table "note"
|
|
||||||
ROLLBACK
|
|
||||||
-- as A update B rows (expect UPDATE 0)
|
|
||||||
BEGIN
|
|
||||||
SET
|
|
||||||
UPDATE 0
|
|
||||||
ROLLBACK
|
|
||||||
-- escalation attempts (expect all denied)
|
|
||||||
ERROR: permission denied to set role "hapi_migrator"
|
|
||||||
ERROR: must be owner of table note
|
|
||||||
ERROR: must be owner of table note
|
|
||||||
ERROR: must be owner of relation note
|
|
||||||
-- spoof: leaked hapi_app creds can set any principal (expect 1 = B's row visible)
|
|
||||||
SET
|
|
||||||
1
|
|
||||||
-- connections in use
|
|
||||||
14
|
|
||||||
DONE
|
|
||||||
Reference in new issue
Block a user