The store gets a listener for the pods that asks for no client certificate, open on the pod network's interfaces only, and a jwt auth mount with one role per in-cluster service. The rendered pods run under a ServiceAccount with a projected token in place of their client certificate.
7.4 KiB
Service manifests
services.hyperhive.k8s renders Kubernetes manifests for the swarm services
that run in the cluster. nix/host-modules/k8s/render.nix builds them from
the systemd unit each service runs today. A host with
services.hyperhive.k8s.enable gets them as system.build.k8sManifests, a
directory with one YAML file per object, and the images their pods run as
system.build.k8sImages, which the cluster node loads. Rendering
changes no unit, and nothing in this module applies the manifests to a
cluster.
Options
services.hyperhive.k8s.enable(defaultfalse): render the manifests.services.hyperhive.k8s.namespace(defaulthyperhive): the namespace of every rendered object.
What gets rendered
A service gets manifests on the host whose configuration deploys it:
| service | workload | other objects |
|---|---|---|
swarm-controller |
Deployment | ServiceAccount, PersistentVolumeClaim swarm-controller-state, ConfigMap swarm-controller-etc |
swarm-notify-router |
Deployment | ServiceAccount |
swarm-ci-metrics |
CronJob | ServiceAccount, PersistentVolumeClaim swarm-ci-metrics-state |
namespace.yaml holds the Namespace. NATS with its auth responder,
swarm-review-classifier, swarm-claude-login and swarm-stt have no
manifests yet: their images don't exist yet.
One source: the unit
The renderer reads the service's evaluated unit, not a copy of its settings:
-
Environment: the unit's
environment, including what other modules merge into it, minusPATH. A systemd%dbecomes the credential directory it stands for. On a host with a hive collector, the OTLP endpoint variables point at it (Pod logs and metrics) instead. The renderer fails if the unit'spathholds anything beyond the NixOS default tools, because the image doesn't carry them. The other change is the store login, below. -
Files: the pod mounts each file the unit names at the same path, so the environment carries over unchanged:
- credentials at
/run/credentials/<service>.service/<id>, from the Secret<service>-credentials, one key perLoadCredentialid; - trust bundles (any
…/trust-bundle.pemthe environment names), from the ConfigMaphyperhive-ca-trust, keytrust-bundle.pem; RuntimeDirectoryas anemptyDir, andStateDirectoryon the service's PersistentVolumeClaim, withRUNTIME_DIRECTORYandSTATE_DIRECTORYset the way systemd sets them;/etcfiles the unit reads, from the service's own ConfigMap.
The renderer fails evaluation if an environment value names an absolute path the pod doesn't mount, or a credential the unit doesn't load. A new path in a unit then shows up as an error here, not as a pod that can't find a file.
- credentials at
-
Command:
ExecStartmust be the service's own binary. Its arguments become the container'sargs. -
Schedule: the CronJob runs every
OnUnitInactiveSecminutes of the unit's timer, never overlapping, withTimeoutStartSecas its deadline.
A change to a unit's environment therefore changes its manifest in the same commit.
Secrets
The YAML lands in the world-readable nix store, so it holds no credential.
It names the Secret <service>-credentials and the credential ids as keys.
It never names the host path the unit loads a credential from, and never its
contents. The hyperhive-ca-trust ConfigMap is only referenced as well,
because the hive CA exists only at runtime. Nothing here creates either
object.
Pods
- Image:
mkServiceImagefrom Service images, built from the samedeploy.<service>.packagethe unit runs. Store paths the environment names (the controller's branding assets, for example) go into the image too. Where the environment names none, the image is the flake'simage-<service>. The manifest carries the image name and tag but doesn't depend on the image: building the manifests builds no daemon.imagePullPolicyisNever, because the node imports the image tarball. - Security: the
serviceUseruid and gid from Service images, withfsGroupits gid so the pod reads its credentials (mode0440), read-only root filesystem with anemptyDiron/tmp, no privilege escalation, every capability dropped, the runtime's default seccomp profile, and no mounted API token. A service that logs in to the store gets a token of its own, below. - Probes: a service with an opt-in health listener gets its variable set to
0.0.0.0:8080, with liveness on/healthzand readiness on/readyz(see Readiness checks).swarm-controllerserves/readyzon its unix socket only, so it has no probes yet. - Shutdown:
terminationGracePeriodSecondsis 15, the 10-second drain a daemon allows itself after SIGTERM (DRAINinswarm-secret-client/src/shutdown.rs) plus headroom. - Rollout: each Deployment has one replica and the
Recreatestrategy, because each service runs once per swarm.
The store login
A service that has a role at the store's jwt-k8s auth mount
(services.hyperhive.deploy.bao.k8sPrincipals) logs in with its pod's
ServiceAccount token. A unit logs in with the client certificate in its
environment, so the pod differs from the unit in these places:
- ServiceAccount: one named like the service, in the rendered namespace,
with
automountServiceAccountToken: false, and the pod runs under it. - Token: a projected volume
bao-tokenwith oneserviceAccountTokensource for the audiencebao, expiring after 600 seconds (the shortest the API server grants) and mounted read-only at/var/run/secrets/hyperhive/bao. The kubelet rewrites the file before it expires, and the client reads it afresh at each login. The store's role for the service accepts this account and this audience only. - Environment: the pod sets neither
BAO_CLIENT_CERTnorBAO_CLIENT_KEY, and the credentials they named aren't in the pod's Secret.BAO_AUTH=jwt,BAO_JWT_FILE,BAO_JWT_ROLE(the service's name) andBAO_JWT_MOUNT(jwt-k8s) take their place, andBAO_ADDRnames the store's own name at the port of the listener that asks for no client certificate (deploy.bao.podListenerPort).BAO_CACERTstays.
The cluster node describes the store's side.
Not covered yet
- The pods reach the swarm's host-run services (store, queue, identity provider) by the same names as the units do. The node's CoreDNS answers those names with the hive bridge's address.
swarm-controller's socket lives in anemptyDir, so only the pod can reach it.
Validation
The flake check k8s-manifests-all-local renders the manifests for the
single-host swarm fixture and runs kubeconform -strict over them, offline,
against JSON schemas for Kubernetes 1.35 pinned by hash. A deliberately
malformed Deployment in the same check must fail, so a validator that loads no
schema can't pass. module-eval-k8s checks that each workload carries its
unit's environment and that no credential source path reaches the YAML.