Watch
0
0
Fork
You've already forked hyperhive
0

k8s: deny ingress to every pod by default

This commit is contained in:
atlas 2026-11-27 15:10:15 +01:00 • committed by mara
commit 51ae57fb02
3 changed files with 241 additions and 27 deletions

View file

@ -57,7 +57,8 @@ in
internal = true;
description = ''
What ./runtime.nix applies: each enabled service's
objects, the namespace object, and the CA ConfigMap's name
objects, the namespace's own objects (the namespace and its
default-deny ingress policy), and the CA ConfigMap's name
and host files.
'';
};
@ -72,7 +73,10 @@ in
userNamespaces
;
services = withoutContext rendered.services;
namespaceObject = withoutContext rendered.objects.namespace;
namespaceObjects = withoutContext [
rendered.objects.namespace
rendered.objects."default-deny-ingress/networkpolicy"
];
};
# The images those pods run, for a node to load: ./node.nix.

View file

@ -1190,6 +1190,28 @@ in
};
};
}
# Every pod of the namespace is selected for ingress and no rule admits
# anyone, so a pod is reachable from the node alone until a policy of its own
# admits more. The cluster's policy engine takes the union of the policies
# that select a pod and always admits the node's own addresses, so the
# kubelet's probes and the host's gateway still reach every pod. A port a pod
# opens later is closed to the other pods and to the hive bridge without a
# line here.
// {
"default-deny-ingress/networkpolicy" = {
apiVersion = "networking.k8s.io/v1";
kind = "NetworkPolicy";
metadata = {
name = "default-deny-ingress";
inherit (k8sCfg) namespace;
labels."app.kubernetes.io/part-of" = "hyperhive";
};
spec = {
podSelector = { };
policyTypes = [ "Ingress" ];
};
};
}
// lib.concatMapAttrs (_: w: w.objects) enabled;
# The image each enabled service's pod runs: what the main node imports,

View file

@ -59,7 +59,7 @@ in
# configuration drops before it activates the new configuration, and
# the files are linked in by the activation.
services.k3s.manifests = {
hyperhive-namespace.content = rendered.namespaceObject;
hyperhive-namespace.content = rendered.namespaceObjects;
}
// lib.genAttrs onCluster (name: {
content = lib.attrValues rendered.services.${name}.objects;