Watch
0
0
Fork
You've already forked hyperhive
0

k8s: stt's pod runs in a user namespace of its own

This commit is contained in:
atlas 2026-11-23 13:44:57 +01:00 • committed by mara
commit ada980f35c
3 changed files with 111 additions and 26 deletions

View file

@ -69,7 +69,12 @@ in
config = lib.mkIf cfg.enable {
services.hyperhive.k8s.rendered = {
inherit (rendered) caConfigMap caSources switches;
inherit (rendered)
caConfigMap
caSources
switches
userNamespaces
;
services = withoutContext rendered.services;
namespaceObject = withoutContext rendered.objects.namespace;
};

View file

@ -153,9 +153,10 @@ let
# containers, init containers, volumes, host aliases, pod settings, objects and
# and images. An `otlp` of `"none"` is a daemon that pushes no telemetry of its
# own.
# `egress`, where a service has it, names the host services its pod may reach
# (`hostPorts`). The pod then gets a NetworkPolicy that lets it reach those
# and cluster DNS and nothing else, and that admits no ingress.
# `egress`, where a service has it, names the host services (`hostPorts`) its
# pod may reach: it gets a NetworkPolicy that allows those and cluster DNS and
# admits no ingress. `hostUsers = false` runs the pod in a user namespace of
# its own, so its ids map to unprivileged ones on the node.
services = {
swarm-controller = {
inherit (controllerCfg) enable package unit;
@ -233,6 +234,9 @@ let
];
otlp = "hive";
ephemeralState = true;
# Stands in for the unit's `PrivateUsers`: the decoder reads audio that
# strangers sent.
hostUsers = false;
switch = {
inherit (deployCfg.stt) runtime;
hostUnit = "container@swarm-stt.service";
@ -912,6 +916,7 @@ let
};
}
// lib.optionalAttrs baoLogin { serviceAccountName = name; }
// lib.optionalAttrs (svc ? hostUsers && !svc.hostUsers) { hostUsers = false; }
// lib.optionalAttrs (listener != { } || extra.initContainers != [ ]) {
initContainers = lib.optional (listener != { }) leafContainer ++ extra.initContainers;
}
@ -1068,6 +1073,10 @@ in
switches = lib.mapAttrs (_: svc: svc.switch) (
lib.filterAttrs (_: svc: svc.enable && svc.switch != null) services
);
# The services whose pods run in a user namespace. Cheap to read, like `switches`.
userNamespaces = lib.attrNames (
lib.filterAttrs (_: svc: svc.enable && svc ? hostUsers && !svc.hostUsers) services
);
services = lib.mapAttrs (_: w: { inherit (w) objects; }) enabled;
inherit caConfigMap caSources;
}

View file

@ -30,10 +30,29 @@ let
apiReady = waitFor 600 "the cluster's API" "${kubectl} get --raw /readyz >/dev/null 2>&1";
caFiles = lib.filterAttrs (_: path: path != null) rendered.caSources;
# The services on the cluster whose pods run in a user namespace.
userNamespaced = lib.filter (name: onCluster ? ${name}) rendered.userNamespaces;
in
{
config = lib.mkIf (node.enable && cfg.enable) (
lib.mkMerge [
# A pod in a user namespace needs idmapped mounts for its volumes, which the
# kernel has for tmpfs from 6.3 on (the projected token and the Secrets
# are tmpfs).
(lib.mkIf (userNamespaced != [ ]) {
assertions = [
{
assertion = lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.3";
message = ''
The pods of ${lib.concatStringsSep ", " userNamespaced} run in a user
namespace (`hostUsers = false`), which needs a kernel of 6.3 or
later; this host's kernel is ${config.boot.kernelPackages.kernel.version}.
'';
}
];
})
(lib.mkIf (onCluster != { }) {
# The cluster applies each file of the manifests directory when it
# appears: a service's objects go in when its host unit has stopped,