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 maia
commit 67218f4052

View file

@ -820,7 +820,11 @@ let
"swarm-stt"
"swarm-victorialogs"
]
&& onCluster.services.k3s.manifests.hyperhive-namespace.content.kind == "Namespace"
&&
map (o: o.kind) onCluster.services.k3s.manifests.hyperhive-namespace.content == [
"Namespace"
"NetworkPolicy"
]
&&
lib.sort lib.lessThan (map (o: o.kind) onCluster.services.k3s.manifests.swarm-notify-router.content)
== [
@ -965,6 +969,39 @@ let
"swarm-ci-metrics"
];
}
{
# The policy is pinned by value: an empty selector is the property, since
# a `matchLabels` would leave every pod it does not name open, and a rule
# would admit someone. The pods the lists name have no ingress policy of
# their own and rely on it; the speech-to-text pod and the controller are
# the controls that the lookup finds a pod's own policy.
name = "the namespace has a default-deny ingress policy that selects every pod and admits nobody, and the pods without an ingress policy of their own rely on it";
ok =
let
policy = objects."default-deny-ingress/networkpolicy";
manifest = onCluster.services.k3s.manifests.hyperhive-namespace.content;
ownPolicy = name: objects ? "${name}/networkpolicy";
in
policy.kind == "NetworkPolicy"
&& policy.metadata.namespace == "hyperhive"
&&
policy.spec == {
podSelector = { };
policyTypes = [ "Ingress" ];
}
&& lib.elem policy manifest
&& lib.all (name: !(ownPolicy name)) [
"swarm-notify-router"
"swarm-review-classifier"
"swarm-claude-login"
"swarm-ci-metrics"
]
&& lib.all ownPolicy [
"swarm-stt"
"swarm-controller"
"swarm-nats"
];
}
{
# The policy is pinned by value: the ports are literals, not the options
# the render reads. The router's pod is the control that a service
@ -1040,12 +1077,13 @@ let
ports = [ (tcp 4222) ];
}
]
# Only the controller (its listener), the log store and its responders
# (listeners), the queue and this pod have a policy: the others have no
# egress and no listener.
# The namespace's default, the controller (its listener), the log store
# and its responders (listeners), the queue and this pod have a policy:
# the others have no egress and no listener, and rely on the default.
&&
lib.sort lib.lessThan (lib.filter (n: lib.hasSuffix "/networkpolicy" n) (lib.attrNames objects))
== [
"default-deny-ingress/networkpolicy"
"swarm-controller/networkpolicy"
"swarm-logs-auth/networkpolicy"
"swarm-nats/networkpolicy"