k8s: the queue's client port is a loadbalancer service
The queue's client port was a hostPort on 0.0.0.0, which Pod Security baseline and restricted forbid. It is a LoadBalancer Service now, which k3s's service load balancer binds on every address of the node with a hostPort of its own in kube-system, so hives on other hosts keep their URL. No node port is allocated. The stt policy allows the load balancer's pods in place of the queue's, and the prune unit waits for them to go before the host unit starts. The egress published-port rule and the raw-table rules apply to the load balancer's hostPort as to the pod's.
This commit is contained in:
parent
c2d57df7f5
commit
796fd6201f
1 changed files with 200 additions and 75 deletions
|
|
@ -1115,8 +1115,10 @@ let
|
|||
{
|
||||
to = [
|
||||
{
|
||||
podSelector.matchLabels = objects."swarm-stt/deployment".spec.selector.matchLabels // {
|
||||
"app.kubernetes.io/name" = "swarm-nats";
|
||||
namespaceSelector.matchLabels."kubernetes.io/metadata.name" = "kube-system";
|
||||
podSelector.matchLabels = {
|
||||
"svccontroller.k3s.cattle.io/svcname" = "swarm-nats";
|
||||
"svccontroller.k3s.cattle.io/svcnamespace" = "hyperhive";
|
||||
};
|
||||
}
|
||||
];
|
||||
|
|
@ -1782,15 +1784,13 @@ let
|
|||
"-c"
|
||||
"/var/lib/nats-callout/nats.conf"
|
||||
]
|
||||
# The client port is published on every address of the node. The
|
||||
# exporter's port is named for its Service and has no `hostPort`.
|
||||
# Both ports are named for their Services, and neither has a `hostPort`:
|
||||
# the load balancer publishes the client port on the node.
|
||||
&&
|
||||
(named "nats").ports == [
|
||||
{
|
||||
name = "client";
|
||||
containerPort = 4222;
|
||||
hostPort = 4222;
|
||||
hostIP = "0.0.0.0";
|
||||
}
|
||||
]
|
||||
&&
|
||||
|
|
@ -2025,6 +2025,47 @@ let
|
|||
&& has "-t raw -A nixos-fw-nats -p tcp --dport 4222 -m addrtype --dst-type LOCAL -j DROP" onCluster.networking.firewall.extraCommands
|
||||
&& has "-t raw -F nixos-fw-nats" onCluster.networking.firewall.extraStopCommands;
|
||||
}
|
||||
{
|
||||
# The host with the queue on it renders the same Service, the control that
|
||||
# a `deploy.nats.runtime` changes none of it.
|
||||
name = "the queue's client port is a LoadBalancer Service with no node port, and the pod has no hostPort";
|
||||
ok =
|
||||
let
|
||||
cluster = render onCluster;
|
||||
svc = cluster."swarm-nats/loadbalancer";
|
||||
pod = cluster."swarm-nats/deployment".spec.template;
|
||||
ports = lib.concatMap (c: c.ports or [ ]) pod.spec.containers;
|
||||
in
|
||||
svc.kind == "Service"
|
||||
&& svc.metadata.name == "swarm-nats"
|
||||
&& svc.metadata.labels."app.kubernetes.io/name" == "swarm-nats"
|
||||
&& svc.spec.type == "LoadBalancer"
|
||||
&& svc.spec.allocateLoadBalancerNodePorts == false
|
||||
&& svc.spec.selector == pod.metadata.labels
|
||||
&&
|
||||
svc.spec.ports == [
|
||||
{
|
||||
name = "client";
|
||||
protocol = "TCP";
|
||||
port = 4222;
|
||||
targetPort = "client";
|
||||
}
|
||||
]
|
||||
&& !(svc.spec ? loadBalancerClass)
|
||||
&& !(svc.spec ? externalTrafficPolicy)
|
||||
&& !(lib.any (p: p ? hostPort || p ? hostIP) ports)
|
||||
&&
|
||||
lib.sort lib.lessThan (map (p: p.name) ports) == [
|
||||
"client"
|
||||
"health"
|
||||
"metrics"
|
||||
]
|
||||
&& (render withNode)."swarm-nats/loadbalancer" == svc
|
||||
# Waiting for the load balancer's pods to go is part of every prune, and
|
||||
# names the service's own Service and namespace.
|
||||
&& lib.hasInfix "--selector svccontroller.k3s.cattle.io/svcname=swarm-nats,svccontroller.k3s.cattle.io/svcnamespace=hyperhive" withNode.systemd.services.swarm-nats-k8s-prune.script
|
||||
&& !(lib.hasInfix "svcname=swarm-nats," withNode.systemd.services.swarm-controller-k8s-prune.script);
|
||||
}
|
||||
{
|
||||
# The host with the queue on it is the control: it publishes no port, and
|
||||
# its chain has no rule of the kind.
|
||||
|
|
|
|||
Loading…
Reference in a new issue