Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cada14bb94 | ||
|
|
2aea5ebaef | ||
|
|
672c46de04 | ||
|
|
d746472e66 | ||
|
|
8b1edd38c1 | ||
|
|
3161f2888c |
No files matched your search
@@ -0,0 +1,2 @@
|
||||
.claude/
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
# hAPI
|
||||
|
||||
hAPI ("home API") is a personal, cloud-hosted API serving one household and its automations: finance, fitness, home maintenance, and smart home. Access is restricted to a small, known set of Principals.
|
||||
|
||||
## Language
|
||||
|
||||
### Access
|
||||
|
||||
**Principal**:
|
||||
Anything that authenticates to hAPI.
|
||||
_Avoid_: User, account, client
|
||||
|
||||
**Person**:
|
||||
A human Principal (the Owner, family, friends).
|
||||
_Avoid_: User, human user, member
|
||||
|
||||
**Bot**:
|
||||
A non-human Principal: a script, automation, or integration such as Home Assistant.
|
||||
_Avoid_: Service account, machine user, integration account
|
||||
|
||||
**Owner**:
|
||||
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
|
||||
|
||||
**Binding**:
|
||||
A Person's consent letting a specific Bot act on that Person's Personal data.
|
||||
_Avoid_: Delegation, impersonation, link
|
||||
|
||||
### Ownership
|
||||
|
||||
**Household**:
|
||||
The single group of Persons that hAPI serves. There is exactly one.
|
||||
_Avoid_: Family, tenant, organization, group
|
||||
|
||||
**Household member**:
|
||||
A Person who belongs to the Household. A Person can be a Principal without being a Household member (e.g. a friend).
|
||||
_Avoid_: Family member, resident
|
||||
|
||||
**Personal data**:
|
||||
A record owned by one Person, visible only to that Person (and to Bots bound to them).
|
||||
_Avoid_: Private data, user data
|
||||
|
||||
**Household data**:
|
||||
A record owned by the Household, visible to every Household member.
|
||||
_Avoid_: Shared data, common data
|
||||
|
||||
**Recorded by**:
|
||||
The Principal that created or last changed a record, distinct from who owns it.
|
||||
_Avoid_: Author, owner, creator
|
||||
@@ -0,0 +1,12 @@
|
||||
# Every record is owned by a Person or by the Household
|
||||
|
||||
hAPI serves exactly one Household, so there is no multi-tenancy. Every record is either **Personal data**, owned by one Person and visible only to them, or **Household data**, owned by the Household and visible to every Household member on equal terms. Each record type declares which kind it is: fitness is personal, home maintenance and smart home are household, and finance has both. We chose this over per-record sharing (which needs sharing lists and revocation) and over "everything household" (which gives no privacy for personal finances). Anything that needs to be shared is modelled as Household data.
|
||||
|
||||
## Consequences
|
||||
|
||||
- **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.
|
||||
- Ownership is fixed when a record is created, except that a Person may move their own Personal record to the Household (one way only).
|
||||
- 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.
|
||||
- Not in v1: roles within the Household, sharing outside the Household, and guest access to Household data.
|
||||
@@ -0,0 +1,18 @@
|
||||
# One public surface, gated only by hAPI's own auth; no tunnel to home
|
||||
|
||||
Persons must reach hAPI from anywhere without a VPN. The home network sits behind ISP CGNAT with a changing IP, so the cluster can never open a connection into the home, and the home IP can't be allowlisted. A CGNAT address is shared with other customers, so allowlisting it would also let them in. We therefore expose **one public surface**, the hAPI API over HTTPS on `:443`, used by Persons and Bots alike, with **hAPI's own authentication as the only gate**. Bots get no separate network path: no VPN, no separate port, no client certificates. Writing a cron job then takes nothing more than `curl` with a token. We chose this over a tunnel for Bots (Tailscale or WireGuard, with a client on every Bot) and over a client-cert-gated Bot port. Both were workable but added setup to every Bot. Client certs stay available as later hardening.
|
||||
|
||||
## Considered Options
|
||||
|
||||
- **A tunnel for every Bot (Tailscale + k8s operator, or plain WireGuard).** Works behind CGNAT because home dials out. Rejected: every Bot needs a client, and the Tailscale operator can't be used with Tailnet Lock, which leaves Tailscale's control plane trusted.
|
||||
- **Client-cert-gated Bot endpoints.** Gateway API enforces client certs per port, not per hostname, so this needs its own port. Home Assistant can present a client cert only over MQTT. Rejected as v1 friction.
|
||||
- **An identity-aware proxy or CDN in front (e.g. Cloudflare).** Rejected: we want no third party in the public request path, meaning no browser challenge pages and no outage when a vendor has one.
|
||||
|
||||
## Consequences
|
||||
|
||||
- **Traffic between the cluster and home only ever starts from home.** hAPI never calls into the house. The job bridge to Home Assistant must be one that HA connects out to (pulls or holds open).
|
||||
- **Every public endpoint is TLS-only and requires per-Principal auth.** No anonymous endpoints, including health: Uptime Kuma is a Bot with a health-only scope. `:80` is closed, so certificates use ACME DNS-01. A broker, if the bridge needs one, may be public under the same rule.
|
||||
- **Bot credentials carry the security a network gate would have.** Each is per-Bot, scoped, individually revocable, and stored hashed. A long-lived JWT that can't be revoked is not acceptable as a Bot credential.
|
||||
- **Owner administration has no HTTP route.** Creating Principals, issuing and revoking credentials, and Household grants are done through an admin CLI inside the hAPI pod, reached only through cluster management access. Persons' own actions, including granting Bindings, stay on the public API.
|
||||
- **Cluster and node management APIs (Kubernetes, Talos) are never public.** They're reachable only over a management-only Tailscale tailnet (node extension plus the Owner's devices) with Tailnet Lock on. This tailnet is not in the public request path, so a Tailscale outage never takes hAPI down. Break-glass: the Linode LISH console, or a temporary firewall rule for the Owner's current IP.
|
||||
- **Never public:** the database, metrics, detailed health, and any internal service.
|
||||
@@ -0,0 +1,18 @@
|
||||
# Talos on Linode with one control-plane node, Cilium, and OpenTofu
|
||||
|
||||
The hAPI cluster runs **Talos Linux** on Linode compute in `us-iad`: **one control-plane node and two workers**, all `g6-standard-2`, provisioned with **OpenTofu**. Its CNI is **Cilium**, with WireGuard encrypting traffic between nodes. We chose Talos because it is immutable and managed only through an authenticated API, with no shell or SSH. That fits a security-first, one-operator cluster better than RKE2 (CIS-hardened, but a general-purpose OS to patch), k3s (defaults favor convenience) or kubeadm (most learning, weakest defaults). A single control-plane node keeps cost and moving parts proportionate to a small load. Postgres is a managed service outside the cluster, so etcd holds no hAPI data, and the cluster can be rebuilt from code.
|
||||
|
||||
## Considered Options
|
||||
|
||||
- **Three control-plane nodes (HA etcd).** Rejected for v1 as oversized. With dedicated workers it costs about $48/mo more. Running workloads on the control plane instead would mix them with etcd. Moving to three is an additive Talos change.
|
||||
- **A NodeBalancer in front of the Kubernetes and Talos APIs**, as the Talos Linode guide describes. Rejected: ADR-0002 keeps those APIs off the internet. The cluster endpoint is the control-plane node's tailnet name instead.
|
||||
- **VPC-only nodes behind a NAT gateway.** Rejected for now: Tailscale would fall back to DERP relays, and the NAT gateway is newer. Nodes have public IPv4 with a firewall that denies all inbound traffic except Tailscale's UDP port.
|
||||
- **Terraform.** OpenTofu is chosen for its open licence and its client-side state encryption. The state holds Talos machine secrets.
|
||||
|
||||
## Consequences
|
||||
|
||||
- **Losing the control-plane node means rebuilding it from code.** Workloads keep serving in the meantime, but the cluster can't be changed until it is back.
|
||||
- **No SSH, ever.** All node access goes through `talosctl` over the management tailnet. Break-glass is the Linode LISH console.
|
||||
- **Every node joins the management tailnet** with a pre-signed auth key, so Tailnet Lock stays on.
|
||||
- **OpenTofu and Talos install only Cilium and the Linode CCM.** These are what nodes need to become Ready. Everything else arrives through delivery.
|
||||
- **Disks are encrypted at rest** with Talos LUKS on STATE and EPHEMERAL, in addition to Talos's default encryption of Secrets in etcd.
|
||||
@@ -1,302 +0,0 @@
|
||||
# Private connectivity between the home network and a Linode cluster
|
||||
|
||||
Research for Gitea issue #46 (part of map #44). Researched 2026-11-23.
|
||||
|
||||
## Question
|
||||
|
||||
What are the options for a private, authenticated link between the Owner's home
|
||||
network (Home Assistant, LAN Bots) and a self-managed Kubernetes cluster on
|
||||
Linode? Compare Tailscale (incl. the Kubernetes operator / subnet routers),
|
||||
Headscale, plain WireGuard site-to-site, and Linode VPC features: setup,
|
||||
security model, failure modes, how in-cluster Services are exposed over the
|
||||
link, and cost.
|
||||
|
||||
## TL;DR
|
||||
|
||||
- **Linode VPC can't do this.** It is a single-data-center private network
|
||||
with no VPN/on-prem attachment, no peering, and **no encryption**. Akamai
|
||||
has no managed site-to-site VPN product. VPC only matters for
|
||||
traffic inside the cluster. [VPC][akamai-vpc]
|
||||
- **Tailscale + the Kubernetes operator is the lowest-effort fit.** You can
|
||||
expose a Bot-facing Service to the tailnet with one annotation. Home Assistant
|
||||
joins via the community add-on, which can also act as a subnet router for
|
||||
other LAN Bots. Grants are deny-by-default, so you can limit LAN Bots
|
||||
to the Bot-facing Service only. The free Personal plan covers this load.
|
||||
- **Surprise: Tailnet Lock does not work with the operator.** Tailnet Lock is
|
||||
Tailscale's defense against a compromised coordination server, and the
|
||||
operator can't sign the proxy nodes it creates. The feature request is
|
||||
still open. So with the operator you have to trust Tailscale's control plane.
|
||||
[#13273][ts-13273]
|
||||
- **Headscale removes that third-party trust, but it isn't ready yet for the
|
||||
operator path.** Operator compatibility (OAuth clients on a v2 API) was
|
||||
merged in June 2026 for v0.30.0, but the latest release is still v0.29.7. You'd
|
||||
also have to host and secure the control server yourself.
|
||||
[#3334][hs-3334] [releases][hs-releases]
|
||||
- **Plain WireGuard has the smallest and most auditable surface**: a silent
|
||||
UDP port and static keys. But you do all key management, routing into the
|
||||
cluster, and HA by hand.
|
||||
|
||||
**Tentative recommendation** (a decision for the Owner, not made here):
|
||||
Tailscale with the operator, an L3 `tailscale` Service for the Bot-facing
|
||||
listener, tagged nodes, and a tight grants policy with `tests`. Keep the
|
||||
Bot-facing listener off the public Ingress entirely. If the Owner wants
|
||||
no third-party control plane, choose plain WireGuard (a single gateway now)
|
||||
or wait for Headscale v0.30.0.
|
||||
|
||||
## Options compared
|
||||
|
||||
| | Tailscale (SaaS) + operator | Headscale + Tailscale clients | Plain WireGuard | Linode VPC |
|
||||
|---|---|---|---|---|
|
||||
| Reaches home LAN? | Yes | Yes | Yes | **No** |
|
||||
| Encryption | WireGuard, keys never leave devices | Same | WireGuard | **None** (isolation only) |
|
||||
| Control plane | Tailscale-hosted | Self-hosted | None (static config) | n/a |
|
||||
| Inbound ports on cluster | None required (DERP relay fallback) | Control server must be reachable, and its DERP if embedded | One UDP port | n/a |
|
||||
| Expose k8s Service | Annotation / `loadBalancerClass: tailscale` / Ingress class | Same operator, **only once v0.30.0 ships** | DIY routing | n/a |
|
||||
| Access control | Grants/ACLs, deny-by-default, policy tests | ACLs/Grants supported | Cryptokey routing + your firewall rules | Cloud Firewall |
|
||||
| Cost | $0 (Personal: 6 users, 50 tagged resources) | $0 + hosting a server | $0 | $0 |
|
||||
|
||||
## Linode VPC and Cloud Firewall
|
||||
|
||||
- VPCs connect Linodes **within one data center**. They can't span data
|
||||
centers, and VPC peering isn't supported. [VPC][akamai-vpc]
|
||||
- "Traffic is isolated but not encrypted." There's no IPv6 on VPC interfaces.
|
||||
VPCs have no extra charge. [VPC][akamai-vpc]
|
||||
- The docs mention no VPN or on-prem attachment. I found no official Akamai
|
||||
site-to-site VPN product. The only guidance for on-prem links is community
|
||||
posts about running your own IPsec/strongSwan gateway on a Linode
|
||||
([community 21930][linode-c-21930]; low trust, used only to show that
|
||||
nothing first-party exists).
|
||||
- Cloud Firewall is stateful and free. It covers Linodes and NodeBalancers and
|
||||
allows max 25 rules per firewall. Rules apply to public and private traffic.
|
||||
For NodeBalancers, rules cover only the public IP, so backends need their own
|
||||
firewall. [Cloud Firewall][akamai-fw]
|
||||
|
||||
**Verdict:** VPC is useful for node-to-node traffic inside the cluster. It
|
||||
plays no part in the home link. Cloud Firewall is complementary: with WireGuard,
|
||||
it limits the UDP port to the home public IP (if that IP is stable).
|
||||
|
||||
## Tailscale (SaaS) with the Kubernetes operator
|
||||
|
||||
### Setup
|
||||
|
||||
- The operator is available on all plans. It covers ingress (tailnet → cluster
|
||||
workloads), egress (cluster → tailnet devices), API-server proxy, and
|
||||
subnet routers/exit nodes via a `Connector` resource.
|
||||
[operator][ts-operator]
|
||||
- Prerequisites: in the policy file, set `tagOwners` with
|
||||
`"tag:k8s-operator": ["autogroup:admin"]` and
|
||||
`"tag:k8s": ["tag:k8s-operator"]`. Create an OAuth client with read/write on
|
||||
Services, Devices Core, and Auth Keys, tagged `tag:k8s-operator`. The operator
|
||||
stores the credentials in the `operator-oauth` secret in the `tailscale`
|
||||
namespace. [quickstart][ts-quickstart]
|
||||
- If you want non-default proxy tags (e.g. `tag:hapi-bot`), `tag:k8s-operator`
|
||||
must own them, and the OAuth client must be allowed to use them. There's
|
||||
a known startup failure with multiple `defaultTags`
|
||||
([issue #15732][ts-15732]).
|
||||
|
||||
### Exposing in-cluster Services over the link
|
||||
|
||||
From [cluster ingress][ts-ingress]:
|
||||
|
||||
- **L3 (TCP/UDP):** annotate the Service with `tailscale.com/expose: "true"`, *or*
|
||||
set `type: LoadBalancer` + `loadBalancerClass: tailscale`. A proxy Pod DNATs
|
||||
its tailnet IP to the Service's ClusterIP.
|
||||
- **L7 (HTTP/S):** use `Ingress` with `ingressClassName: tailscale`. You get a
|
||||
MagicDNS name and a Let's Encrypt cert through Tailscale Serve.
|
||||
- These are **not public** by default. Public needs Funnel, which you should
|
||||
avoid for the Bot side.
|
||||
- HA: a `ProxyGroup` (`tailscale.com/proxy-group` annotation) runs multiple
|
||||
active proxies. Tailscale recommends it for production.
|
||||
|
||||
So a Bot-facing hAPI listener can be its own Service, reachable *only* via
|
||||
the tailnet. Persons hit the public Ingress, which never routes to it.
|
||||
|
||||
### Home side
|
||||
|
||||
- **Home Assistant:** the community add-on supports `advertise_routes`
|
||||
(subnet router), `accept_routes`, `advertise_tags`, `login_server` (custom
|
||||
control server, e.g. Headscale), and `userspace_networking`.
|
||||
[addon-tailscale docs][ha-addon]
|
||||
- **Other LAN Bots** that can't run Tailscale go through a subnet router (the
|
||||
HA add-on, or another always-on box). Devices behind a subnet router don't
|
||||
count toward the device limit. SNAT is on by default, so cluster-side traffic
|
||||
appears to come from the router, which loses per-Bot source IPs unless you set
|
||||
`--snat-subnet-routes=false` (Linux only, needs return routes for
|
||||
`100.64.0.0/10`). Route approval is separate from access: you need grants
|
||||
too. [subnet routers][ts-subnets]
|
||||
- Tailscale prefers installing the client directly on each device over
|
||||
subnet routing. [subnet routers][ts-subnets]
|
||||
|
||||
### Security model
|
||||
|
||||
- Data plane: WireGuard. Private keys never leave the device. DERP relays
|
||||
forward already-encrypted traffic they can't decrypt. Connections are usually
|
||||
direct, with peer relays and then DERP as fallback. [DERP][ts-derp]
|
||||
- Policy: deny-by-default grants (`src`/`dst`/`ip`). A `tests` section
|
||||
rejects policy updates that break assertions. Example intent: `src:
|
||||
["tag:home-bot"]`, `dst: ["tag:hapi-bot:443"]`. [policy syntax][ts-policy]
|
||||
- **Trust in the control plane:** Tailscale's coordination server distributes
|
||||
node keys, so a compromised control plane could inject nodes. Tailnet Lock
|
||||
closes that gap: nodes must be signed by trusted keys held on your devices.
|
||||
It's available on Personal. [Tailnet Lock][ts-lock]
|
||||
- **But the operator can't add its proxies to a locked tailnet** without manual
|
||||
signing of each proxy node key. Issue #13273 and PR #14404 are still open as
|
||||
of this research. [#13273][ts-13273] This trade-off is the main thing to
|
||||
weigh: operator convenience vs. control-plane-compromise resistance. One
|
||||
workaround: skip the operator and run a single `tailscaled` gateway
|
||||
(e.g. a Deployment with persisted state, or a node-level install) whose key
|
||||
is signed once, routing to the Bot-facing Service.
|
||||
|
||||
### Failure modes
|
||||
|
||||
- Tailscale control plane outage: existing connections generally keep working,
|
||||
but new nodes/key changes stall. (General property of the design. I didn't
|
||||
find a precise first-party statement for this, so check before relying on it.)
|
||||
- Proxy Pod restart blips the link unless you use `ProxyGroup` HA. [ingress][ts-ingress]
|
||||
- A subnet router going offline drops its routes, and there's no fallback to a
|
||||
less specific route. Run two routers for HA, without `--accept-routes` on
|
||||
them. [subnet routers][ts-subnets]
|
||||
- Let's Encrypt rate limits can bite L7 Ingress on frequent redeploys.
|
||||
[ingress][ts-ingress]
|
||||
|
||||
### Cost
|
||||
|
||||
Personal plan: $0, non-commercial, up to 6 users, unlimited user devices,
|
||||
**50 tagged resources** (then $1/mo each), 3 ACL groups. Operator proxies and
|
||||
tagged gateways count as tagged resources. That's ample here. [pricing][ts-pricing]
|
||||
|
||||
## Headscale
|
||||
|
||||
- An open-source, self-hosted implementation of the Tailscale control server.
|
||||
Its scope is deliberately narrow: **a single tailnet**, for self-hosters and
|
||||
hobbyists. [headscale][hs-home]
|
||||
- Supported: ACLs, Grants, Tailscale SSH, auto approvers, subnet routers, exit
|
||||
nodes, tags, OIDC (but OIDC groups can't be used in ACLs), embedded DERP, and
|
||||
Taildrop. Funnel/Serve and Tailnet Lock aren't listed as supported.
|
||||
[features][hs-features]
|
||||
- **Operator compatibility:** the operator chart has a `loginServer` value for a
|
||||
non-Tailscale control plane ([values.yaml][ts-values]). Headscale PR #3334
|
||||
("add OAuth clients and scopes to the v2 API") was merged on 2026-06-26 and
|
||||
closed issue #1202 ("OAuth Provider + Tailscale Kubernetes operator
|
||||
compatibility") under milestone v0.30.0. [#3334][hs-3334] [#1202][hs-1202]
|
||||
**The latest release is v0.29.7, so it hasn't shipped yet.** [releases][hs-releases]
|
||||
- The HA add-on supports `login_server`, so the home side works today.
|
||||
[ha-addon][ha-addon]
|
||||
- **Security trade-off:** you remove Tailscale Inc. from the trust base, but the
|
||||
control server becomes your crown jewel. It must be reachable by home and
|
||||
cluster nodes, so it's internet-exposed somewhere. Hosting it *inside* the
|
||||
cluster it protects creates a bootstrap/circular dependency. You also own
|
||||
its patching, backups, and DERP.
|
||||
- **Cost:** software is free. Hosting is a small Linode or a cluster
|
||||
workload, plus operations time.
|
||||
|
||||
## Plain WireGuard site-to-site
|
||||
|
||||
### Security model
|
||||
|
||||
- Cryptokey routing: each peer is a public key with a list of allowed IPs. Those
|
||||
act as the routing table for outbound traffic and the ACL for inbound, so
|
||||
firewall rules on source IP + interface are trustworthy. It uses Noise,
|
||||
Curve25519, ChaCha20-Poly1305, BLAKE2, and HKDF, and the codebase is
|
||||
small enough to audit. [wireguard.com][wg-home]
|
||||
- The server "does not even *respond at all*" to unauthenticated packets. It's
|
||||
silent to scanners, with a cookie mechanism under load. Handshakes occur
|
||||
every few minutes for rotating session keys. [protocol][wg-protocol]
|
||||
- Key distribution is out of scope: you exchange public keys out of band,
|
||||
like SSH keys. [wireguard.com][wg-home]
|
||||
|
||||
### Setup and exposing Services
|
||||
|
||||
- Home side: a WireGuard peer on an always-on LAN box (or router). It
|
||||
initiates toward the cluster's public UDP endpoint, with
|
||||
`PersistentKeepalive = 25` to hold the NAT mapping (off by default).
|
||||
[quickstart][wg-quick] The cluster doesn't need to know the home IP, because
|
||||
WireGuard roams to the last authenticated endpoint. [wireguard.com][wg-home]
|
||||
- Cluster side: you do all of it yourself. Options:
|
||||
- A WireGuard interface on one node (host-level), routing the tunnel subnet
|
||||
to the Bot-facing Service's ClusterIP or a dedicated internal IP.
|
||||
- A gateway Pod with `hostNetwork` or a UDP NodePort/LoadBalancer.
|
||||
Either way you handle iptables/nftables, return routes, and which node holds
|
||||
the endpoint.
|
||||
- Lock the UDP port down with Cloud Firewall (to the home public IP if it's
|
||||
stable). [Cloud Firewall][akamai-fw]
|
||||
|
||||
### Failure modes
|
||||
|
||||
- A single gateway node is a single point of failure, and HA needs your own
|
||||
failover (e.g. floating IP + keepalived). There's no built-in relay, so a home
|
||||
network with broken outbound UDP just fails. Losing a key means editing
|
||||
configs by hand on both sides.
|
||||
|
||||
### Cost
|
||||
|
||||
$0 (in-kernel software). You pay only in operator time.
|
||||
|
||||
## How this fits hAPI
|
||||
|
||||
- **Separation of Principals by network:** Persons → public Ingress. Bots →
|
||||
a distinct Bot-facing Service exposed only on the private link. Defense in
|
||||
depth: hAPI should still authenticate Bots at the application layer (the link
|
||||
is a network control, not Principal authentication).
|
||||
- With Tailscale/Headscale, tags give a stable identity per home device or
|
||||
subnet router. With SNAT on, hAPI sees only the router's address, so per-Bot
|
||||
identity must come from app-level credentials anyway.
|
||||
|
||||
## Open questions for the Owner
|
||||
|
||||
1. Is trusting Tailscale's hosted control plane acceptable, given Tailnet
|
||||
Lock is unavailable with the operator? If not: plain WireGuard now, or
|
||||
Headscale once v0.30.0 ships.
|
||||
2. Can each LAN Bot run a Tailscale client, or do most need a subnet router
|
||||
(which loses per-device source identity unless SNAT is disabled)?
|
||||
3. Is the home public IP stable (relevant to firewalling a WireGuard port)?
|
||||
|
||||
## Sources
|
||||
|
||||
- [akamai-vpc]: https://techdocs.akamai.com/cloud-computing/docs/vpc
|
||||
- [akamai-fw]: https://techdocs.akamai.com/cloud-computing/docs/cloud-firewall
|
||||
- [linode-c-21930]: https://www.linode.com/community/questions/21930/site-to-site-vpn (community, low trust)
|
||||
- [ts-operator]: https://tailscale.com/kb/1236/kubernetes-operator
|
||||
- [ts-quickstart]: https://tailscale.com/docs/kubernetes-operator/quickstart
|
||||
- [ts-ingress]: https://tailscale.com/kb/1439/kubernetes-operator-cluster-ingress
|
||||
- [ts-15732]: https://github.com/tailscale/tailscale/issues/15732
|
||||
- [ts-values]: https://github.com/tailscale/tailscale/blob/main/cmd/k8s-operator/deploy/chart/values.yaml
|
||||
- [ts-subnets]: https://tailscale.com/kb/1019/subnets
|
||||
- [ts-derp]: https://tailscale.com/kb/1232/derp-servers
|
||||
- [ts-policy]: https://tailscale.com/kb/1337/policy-syntax
|
||||
- [ts-lock]: https://tailscale.com/kb/1226/tailnet-lock
|
||||
- [ts-13273]: https://github.com/tailscale/tailscale/issues/13273
|
||||
- [ts-pricing]: https://tailscale.com/pricing
|
||||
- [ha-addon]: https://github.com/hassio-addons/addon-tailscale/blob/main/tailscale/DOCS.md
|
||||
- [hs-home]: https://headscale.net/stable/
|
||||
- [hs-features]: https://headscale.net/stable/about/features/
|
||||
- [hs-3334]: https://github.com/juanfont/headscale/pull/3334
|
||||
- [hs-1202]: https://github.com/juanfont/headscale/issues/1202
|
||||
- [hs-releases]: https://github.com/juanfont/headscale/releases
|
||||
- [wg-home]: https://www.wireguard.com/
|
||||
- [wg-protocol]: https://www.wireguard.com/protocol/
|
||||
- [wg-quick]: https://www.wireguard.com/quickstart/
|
||||
|
||||
[akamai-vpc]: https://techdocs.akamai.com/cloud-computing/docs/vpc
|
||||
[akamai-fw]: https://techdocs.akamai.com/cloud-computing/docs/cloud-firewall
|
||||
[linode-c-21930]: https://www.linode.com/community/questions/21930/site-to-site-vpn
|
||||
[ts-operator]: https://tailscale.com/kb/1236/kubernetes-operator
|
||||
[ts-quickstart]: https://tailscale.com/docs/kubernetes-operator/quickstart
|
||||
[ts-ingress]: https://tailscale.com/kb/1439/kubernetes-operator-cluster-ingress
|
||||
[ts-15732]: https://github.com/tailscale/tailscale/issues/15732
|
||||
[ts-values]: https://github.com/tailscale/tailscale/blob/main/cmd/k8s-operator/deploy/chart/values.yaml
|
||||
[ts-subnets]: https://tailscale.com/kb/1019/subnets
|
||||
[ts-derp]: https://tailscale.com/kb/1232/derp-servers
|
||||
[ts-policy]: https://tailscale.com/kb/1337/policy-syntax
|
||||
[ts-lock]: https://tailscale.com/kb/1226/tailnet-lock
|
||||
[ts-13273]: https://github.com/tailscale/tailscale/issues/13273
|
||||
[ts-pricing]: https://tailscale.com/pricing
|
||||
[ha-addon]: https://github.com/hassio-addons/addon-tailscale/blob/main/tailscale/DOCS.md
|
||||
[hs-home]: https://headscale.net/stable/
|
||||
[hs-features]: https://headscale.net/stable/about/features/
|
||||
[hs-3334]: https://github.com/juanfont/headscale/pull/3334
|
||||
[hs-1202]: https://github.com/juanfont/headscale/issues/1202
|
||||
[hs-releases]: https://github.com/juanfont/headscale/releases
|
||||
[wg-home]: https://www.wireguard.com/
|
||||
[wg-protocol]: https://www.wireguard.com/protocol/
|
||||
[wg-quick]: https://www.wireguard.com/quickstart/
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/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
|
||||
@@ -0,0 +1,75 @@
|
||||
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"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
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
|
||||
@@ -0,0 +1,121 @@
|
||||
== 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
|
||||
@@ -0,0 +1,109 @@
|
||||
== 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