Watch
0
0
Fork
You've already forked hyperhive
0

k8s: pods log in to the secret store with their ServiceAccount token

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.
This commit is contained in:
atlas 2026-11-21 14:03:28 +01:00 • committed by maia
commit 2a6b0ee00a

View file

@ -41,6 +41,11 @@ let
builtins.bitAnd pa.base keep == builtins.bitAnd pb.base keep;
cidrType = lib.types.strMatching "([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}";
# k3s's own defaults, named so the flags below and the ServiceAccount
# issuer and key paths read from one place.
dataDir = "/var/lib/rancher/k3s";
clusterDomain = "cluster.local";
in
{
options.services.hyperhive.deploy.k8s = {
@ -86,6 +91,45 @@ in
constraints as {option}`services.hyperhive.deploy.k8s.podCidr` apply.
'';
};
cniInterfaces = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [
"cni0"
"flannel.1"
];
readOnly = true;
internal = true;
description = ''
The pod network's interfaces. The firewall trusts them, and a
listener meant for pods only is opened on these and no other.
'';
};
serviceAccountIssuer = lib.mkOption {
type = lib.types.str;
readOnly = true;
internal = true;
default = "https://kubernetes.default.svc.${clusterDomain}";
description = ''
The `iss` claim of the ServiceAccount tokens the cluster issues, the
issuer k3s gives its API server for the cluster domain it runs with.
'';
};
serviceAccountKeyFiles = lib.mkOption {
type = lib.types.listOf lib.types.str;
readOnly = true;
internal = true;
default = [
"${dataDir}/server/tls/service.key"
"${dataDir}/server/tls/service.current.key"
];
description = ''
The files k3s keeps its ServiceAccount keys in: the key that verifies
tokens and the one that signs them, which differ after a rotation.
'';
};
};
config = lib.mkIf cfg.enable {
@ -136,6 +180,8 @@ in
"--secrets-encryption"
"--cluster-cidr=${cfg.podCidr}"
"--service-cidr=${cfg.serviceCidr}"
"--data-dir=${dataDir}"
"--cluster-domain=${clusterDomain}"
];
# k3s's own images come first: with no registry the node pulls nothing,
# not even CoreDNS.
@ -145,9 +191,6 @@ in
++ (config.system.build.k8sImages or [ ]);
};
networking.firewall.trustedInterfaces = [
"cni0"
"flannel.1"
];
networking.firewall.trustedInterfaces = cfg.cniInterfaces;
};
}