k8s: stt's pod gets a network policy: dns and four host ports out, nothing in
This commit is contained in:
parent
4ea3b0e10d
commit
02cc38d89e
1 changed files with 262 additions and 22 deletions
|
|
@ -110,7 +110,11 @@ let
|
|||
objects = render allLocal;
|
||||
# The queue's pod reads the settings of the system it runs from, which differ
|
||||
# in the path of the server's key: what a switch must leave alone is the rest.
|
||||
notQueue = lib.filterAttrs (n: _: !(lib.hasPrefix "swarm-nats/" n));
|
||||
# The speech-to-text policy names the queue's pod only where the queue runs in
|
||||
# the cluster, so it follows the queue; its own case reads it.
|
||||
notQueue = lib.filterAttrs (
|
||||
n: _: !(lib.hasPrefix "swarm-nats/" n) && n != "swarm-stt/networkpolicy"
|
||||
);
|
||||
|
||||
units = {
|
||||
swarm-controller = allLocal.systemd.services.swarm-controller;
|
||||
|
|
@ -888,6 +892,7 @@ let
|
|||
&&
|
||||
lib.sort lib.lessThan (map (o: o.kind) onCluster.services.k3s.manifests.swarm-stt.content) == [
|
||||
"Deployment"
|
||||
"NetworkPolicy"
|
||||
"ServiceAccount"
|
||||
]
|
||||
&&
|
||||
|
|
@ -1034,6 +1039,81 @@ let
|
|||
"swarm-ci-metrics"
|
||||
];
|
||||
}
|
||||
{
|
||||
# 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
|
||||
# without `egress` has no policy, and the host without the queue in the
|
||||
# cluster the control that the queue's pod rule follows the queue.
|
||||
name = "the speech-to-text pod's NetworkPolicy admits no ingress and allows DNS and four host ports, and a pod without egress has none";
|
||||
ok =
|
||||
let
|
||||
bridge = "${withNode.services.hyperhive.network.bridgeIp}/32";
|
||||
policyOf = o: o."swarm-stt/networkpolicy";
|
||||
policy = policyOf objects;
|
||||
clusterPolicy = policyOf (render onCluster);
|
||||
tcp = port: {
|
||||
protocol = "TCP";
|
||||
inherit port;
|
||||
};
|
||||
dns = {
|
||||
to = [
|
||||
{
|
||||
namespaceSelector.matchLabels."kubernetes.io/metadata.name" = "kube-system";
|
||||
podSelector.matchLabels.k8s-app = "kube-dns";
|
||||
}
|
||||
];
|
||||
ports = [
|
||||
{
|
||||
protocol = "UDP";
|
||||
port = 53;
|
||||
}
|
||||
(tcp 53)
|
||||
];
|
||||
};
|
||||
host = {
|
||||
to = [ { ipBlock.cidr = bridge; } ];
|
||||
ports = map tcp [
|
||||
8208
|
||||
443
|
||||
4222
|
||||
4318
|
||||
];
|
||||
};
|
||||
in
|
||||
policy.kind == "NetworkPolicy"
|
||||
&& policy.metadata.namespace == "hyperhive"
|
||||
&& policy.metadata.labels."app.kubernetes.io/name" == "swarm-stt"
|
||||
&& policy.spec.podSelector.matchLabels == objects."swarm-stt/deployment".spec.selector.matchLabels
|
||||
&&
|
||||
policy.spec.policyTypes == [
|
||||
"Ingress"
|
||||
"Egress"
|
||||
]
|
||||
&& !(policy.spec ? ingress)
|
||||
&&
|
||||
policy.spec.egress == [
|
||||
dns
|
||||
host
|
||||
]
|
||||
&&
|
||||
clusterPolicy.spec.egress == [
|
||||
dns
|
||||
host
|
||||
{
|
||||
to = [
|
||||
{
|
||||
podSelector.matchLabels = objects."swarm-stt/deployment".spec.selector.matchLabels // {
|
||||
"app.kubernetes.io/name" = "swarm-nats";
|
||||
};
|
||||
}
|
||||
];
|
||||
ports = [ (tcp 4222) ];
|
||||
}
|
||||
]
|
||||
&& !(lib.any (n: lib.hasSuffix "/networkpolicy" n) (
|
||||
lib.attrNames (removeAttrs objects [ "swarm-stt/networkpolicy" ])
|
||||
));
|
||||
}
|
||||
{
|
||||
# Other spellings of a ceiling: bytes, megabytes, a fractional core, no
|
||||
# memory limit. A setting render cannot read fails the evaluation, the
|
||||
|
|
|
|||
Loading…
Reference in a new issue