k8s: deny ingress to every pod by default
This commit is contained in:
parent
c09ef6c358
commit
51ae57fb02
3 changed files with 241 additions and 27 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue