Watch
0
0
Fork
You've already forked hyperhive
0

k8s: the queue's exporter is a ClusterIP service only the node reaches

The exporter's metrics port was a hostPort on the bridge's address, which Pod Security baseline and restricted forbid. It is a ClusterIP Service now, and the pod has a NetworkPolicy that admits the client port from any source and nothing else, so only the node reads the exporter, as the raw-table rules made it. The gateway's /metrics location dials the Service by name through nginx's resolver. The raw-table rules no longer name the exporter's port.
This commit is contained in:
atlas 2026-11-23 18:02:25 +01:00 • committed by maia
commit 7ef9444e42
3 changed files with 228 additions and 63 deletions

View file

@ -88,11 +88,12 @@ agents ask the same resolver, so they get the same names. A name is no route:
the hive's egress rules decide whether the host forwards their traffic to the
cluster's addresses, and a pod's NetworkPolicy refuses what it forwards.
A pod that serves the host, such as the controller's, has a NetworkPolicy that
selects it for ingress and allows nothing. kube-router, the policy engine, adds
a rule at the top of every pod's chain that admits traffic from any address of
the node (`-m addrtype --src-type LOCAL`, commented "from local node"), so the
host reaches the pod and no other pod does.
A pod that serves the host, such as the controller or the queue's exporter, has
a NetworkPolicy that selects it for ingress and allows no more than the port it
serves everyone, if it has one. kube-router, the policy engine, adds a rule at
the top of every pod's chain that admits traffic from any address of the node
(`-m addrtype --src-type LOCAL`, commented "from local node"), so the host
reaches the pod and no other pod does.
## Logging in to the secret store

View file

@ -228,10 +228,17 @@ holds the container back until the pod has gone.
read before the DNAT: a packet for the node's address and the client port is
dropped unless it arrives on the host's loopback, the hive bridge or a pod
interface, or unless `deploy.nats.openFirewall` is on. The container's port
has that reach. The exporter's port is a `hostPort` on the bridge's address,
for the gateway's `/metrics` location on the host. The rules drop it on every
interface but the host's loopback: the exporter answers with the name of
every client, and only the host's own processes may read it.
has that reach.
- **The exporter's port.** The exporter's port has no `hostPort`: a ClusterIP
Service, `swarm-nats-metrics`, fronts it, and the gateway's `/metrics`
location on the host dials the Service's name through nginx's `resolver` (the
hive's dnsmasq), as [the controller's](#the-controller) does, so
`gateway.dns.enable` has to be on. The exporter answers with the name of every
client, and only the node may read it. The pod's NetworkPolicy selects it for
ingress and allows the client port from any source and nothing else. The
cluster's policy engine always admits traffic from an address of the node, so
the gateway and the kubelet's probes reach the pod, and a pod of the cluster,
or a client of the bridge that the host forwards, doesn't reach the exporter.
- **The leaf.** `tls-issue` logs in to the store with the pod's token as the
role `swarm-nats` and issues the server's leaf from the same script as the
host's `swarm-bao-nats-tls`. The key lands in a volume in memory. The
@ -253,8 +260,8 @@ holds the container back until the pod has gone.
`swarm-bao-nats-callout-xkey` deliver into the container, so the configuration
turns them off. `swarm-bao-nats-tls` stays: it issues the host's own copy of
the leaf for the gateway's `/metrics` vhost, and with no container it has
nothing to restart. The gateway's location dials the exporter on the bridge's
address where it dialled loopback.
nothing to restart. The gateway's location dials the exporter's Service by
name where it dialled loopback.
- **State.** The server's store directory, `/var/lib/nats`, is the container's
own on the host, `/var/lib/nixos-containers/swarm-nats/var/lib/nats`: the
PersistentVolumeClaim `swarm-nats-store` binds a static local volume on it,
@ -382,9 +389,9 @@ it dials the pod by name and verifies the name, and the responder in the pod
admits it. A key written on the host before the switch is the pod's to read, a
key the pod writes is the host server's after the switch back, and a stream
written before a pod delete survives it: the replacement pod reads it from the
same directory. The exporter answers the host's own processes through the
published port, and the switch back removes the pod before the container
starts.
same directory. The exporter answers the host's own processes through its
Service and no pod or bridge client, and the switch back removes the pod before
the container starts.
The VM test `k8s-controller-switch` moves the controller. It asserts one copy at
each step by the switch's own timestamps and by a sampler, that the pod is Ready

View file

@ -19,7 +19,7 @@ You rarely switch it on yourself. `gateway.enable` defaults to off, and every mo
| `chat.<swarm>/_matrix/*` | tuwunel (unix socket `/run/hive-matrix/tuwunel.sock`) | `hive-matrix.nix`, `swarm.matrix.gatewayHost != null` |
| `chat.<swarm>/` | fluffychat-web static | `hive-matrix.nix`, `swarm.matrix.gatewayHost != null` |
| `chat.<swarm>/config.json` | inline JSON (FluffyChat boot config) | `hive-matrix.nix`, `swarm.matrix.gatewayHost != null` |
| `<queue domain>/metrics` | the queue exporter's `/metrics` on loopback, behind an authelia `auth_request`; every other path, `/` included, returns `403`, so `/varz` and `/connz` are never reachable | `swarm-nats.nix`, the queue's host |
| `<queue domain>/metrics` | the queue exporter's `/metrics` on loopback, or behind its Service where the queue runs in the cluster, behind an authelia `auth_request`; every other path, `/` included, returns `403`, so `/varz` and `/connz` are never reachable | `swarm-nats.nix`, the queue's host |
| `grafana.<swarm>`, `metrics.<swarm>`, `logs.<swarm>`, `otel.<swarm>`, `bao.<swarm>` | the matching swarm service | that service's module → [`2-handbook/swarm/services.md`](../../2-handbook/swarm/services.md) |
A service module declares its vhost as `services.hyperhive.gateway.vhosts.<name>`: the locations, `forceSSL` and any `extraConfig` it needs. The gateway renders it into `services.nginx.virtualHosts.<name>` and adds the `listen` set ([listen addresses](#listen-addresses)), the certificate for that name and the [security headers](#security-headers) (ahead of the vhost's own `extraConfig`), and drops `addSSL` from a vhost that sets `forceSSL`. The eval fails for a vhost that sets `listen`, `addSSL`, `onlySSL`, `enableACME`, `useACMEHost`, `sslCertificate` or `sslCertificateKey` itself, and for any vhost declared while `gateway.enable` is false. A name with a certificate from outside the gateway's leaves (the queue's) sets `certificate = { cert; key; }` instead. `hive-gateway/vhosts.nix` declares the gateway's own catch-all (`_`) the same way, `hive-c0re/vhosts.nix` the dashboard and the hive domain, and `glue-matrix-hive-discovery.nix` adds the matrix redirect to the hive domain where the homeserver runs, and discovery there when the hive domain is the pinned server name. The catch-all sets `securityHeaders = false` because it sends no response, and the gateway renders a vhost's `default` at `mkDefault` priority.