k8s: the controller's listener is a ClusterIP service the host dials by name
The controller's api port was a hostPort on the node, which Pod Security baseline and restricted forbid. It is a ClusterIP Service now, behind a NetworkPolicy that admits only the node. The host's resolver (the hive's dnsmasq) forwards cluster.local to CoreDNS, and the gateway dials the Service by name through nginx's resolver. tcp.hostAddress goes.
This commit is contained in:
parent
ada980f35c
commit
8cd6ae3037
2 changed files with 355 additions and 103 deletions
|
|
@ -33,27 +33,9 @@ let
|
|||
|
||||
allLocal = shared.allLocal;
|
||||
|
||||
# The four auth responder packages pinned to four distinct derivations, as
|
||||
# in ./shared.nix: the all-local host needs them set.
|
||||
marker = name: pkgs.runCommand "auth-marker-${name}" { } "mkdir $out";
|
||||
|
||||
# The all-local host with the node on. It does not set
|
||||
# `services.hyperhive.k8s.enable`: the node turns the rendering on.
|
||||
nodeSettings = {
|
||||
deploy.singleHostSwarm = true;
|
||||
deploy.k8s.enable = true;
|
||||
deploy.victorialogs.authPackage = marker "logs";
|
||||
deploy.victorialogs.grafanaAuthPackage = marker "logs-grafana";
|
||||
deploy.victoriametrics.authPackage = marker "metrics";
|
||||
deploy.victoriametrics.agentAuthPackage = marker "metrics-agent";
|
||||
# The controller's TCP listener, which the controller in the cluster needs
|
||||
# and the one on the host serves as well.
|
||||
swarm.controller.tcp = {
|
||||
enable = true;
|
||||
domain = "controller.t.local";
|
||||
};
|
||||
};
|
||||
withNode = hiveWithController nodeSettings;
|
||||
# The all-local host with the node on, shared with the manifests' schema check.
|
||||
nodeSettings = shared.k8sNodeSettings;
|
||||
withNode = shared.k8sNode;
|
||||
|
||||
# The same host with the router, the speech-to-text service, the review
|
||||
# classifier, the claude login minter and the CI run poller in the cluster,
|
||||
|
|
@ -375,7 +357,8 @@ let
|
|||
# Nothing the host already runs differs but the store's side of the pods'
|
||||
# login: every unit, timer and container is still there, the only new
|
||||
# units are k3s's and the one that writes the pods' login, every unit but
|
||||
# the firewall (whose rules carry the pod network's interfaces) and the
|
||||
# the firewall (whose rules carry the pod network's interfaces), the
|
||||
# resolver (which hands the cluster's domain to its DNS) and the
|
||||
# granter's role unit (which enables the login's auth mount) starts the
|
||||
# same command, and the manifests are the same as without the node. The
|
||||
# fixture has the controller's TCP listener on, which `allLocal` has off:
|
||||
|
|
@ -424,6 +407,7 @@ let
|
|||
(
|
||||
lib.subtractLists [
|
||||
"firewall"
|
||||
"dnsmasq"
|
||||
"nginx"
|
||||
"opentelemetry-collector"
|
||||
"swarm-bao-controller-policy"
|
||||
|
|
@ -1429,6 +1413,7 @@ let
|
|||
&& lib.any (
|
||||
a: lib.hasInfix "tcp.listenAddress is" a.message && lib.hasInfix "\"10.0.0.5\"" a.message
|
||||
) runtimeRefusals
|
||||
&& lib.any (a: lib.hasInfix "gateway.dns.enable: the gateway dials" a.message) runtimeRefusals
|
||||
# The all-local host binds the default, which the refusal lets through.
|
||||
&& onCluster.services.hyperhive.deploy.swarm-controller.tcp.listenAddress == "0.0.0.0"
|
||||
&& lib.all (a: a.assertion) onCluster.assertions;
|
||||
|
|
@ -1543,12 +1528,51 @@ let
|
|||
== [
|
||||
"ConfigMap"
|
||||
"Deployment"
|
||||
"NetworkPolicy"
|
||||
"Service"
|
||||
"ServiceAccount"
|
||||
];
|
||||
}
|
||||
{
|
||||
# The host with no listener is the control: the controller has no Service
|
||||
# or policy there, and the policy admits nothing but the node.
|
||||
name = "the controller's listener is a ClusterIP Service that only the node reaches, with the cluster's DNS handed the cluster's domain by the host's resolver";
|
||||
ok =
|
||||
let
|
||||
cluster = render onCluster;
|
||||
svc = cluster."swarm-controller/service";
|
||||
policy = cluster."swarm-controller/networkpolicy";
|
||||
h = withNode.services.hyperhive;
|
||||
prune = withNode.systemd.services.swarm-controller-k8s-prune.script;
|
||||
in
|
||||
svc.kind == "Service"
|
||||
&& svc.spec.type == "ClusterIP"
|
||||
&& svc.spec.selector == policy.spec.podSelector.matchLabels
|
||||
&& !(svc.spec ? clusterIP)
|
||||
&&
|
||||
svc.spec.ports == [
|
||||
{
|
||||
name = "api";
|
||||
protocol = "TCP";
|
||||
port = 9443;
|
||||
targetPort = "api";
|
||||
}
|
||||
]
|
||||
&& policy.spec.policyTypes == [ "Ingress" ]
|
||||
&& !(policy.spec ? ingress)
|
||||
&& !(policy.spec ? egress)
|
||||
&& !(objects ? "swarm-controller/service")
|
||||
&& !(objects ? "swarm-controller/networkpolicy")
|
||||
&& h.swarm.controller.tcp.enable
|
||||
&& h.deploy.swarm-controller.tcp.serviceHost == "swarm-controller.hyperhive.svc.cluster.local"
|
||||
&& lib.elem "/cluster.local/10.201.0.10" withNode.services.dnsmasq.settings.server
|
||||
&& lib.elem "--cluster-dns=10.201.0.10" withNode.services.k3s.extraFlags
|
||||
&& !(lib.elem "/cluster.local/10.201.0.10" (allLocal.services.dnsmasq.settings.server or [ ]))
|
||||
&& lib.hasInfix "networkpolicy,service \\" prune;
|
||||
}
|
||||
{
|
||||
# The host with the controller on it dials the name, as it always did.
|
||||
name = "the gateway dials the controller pod's hostPort and verifies its certificate as the listener's name";
|
||||
name = "the gateway dials the controller's Service by name, resolved per request, and verifies its certificate as the listener's name";
|
||||
ok =
|
||||
let
|
||||
loc = c: path: c.services.nginx.virtualHosts."t.local".locations.${path};
|
||||
|
|
@ -1561,8 +1585,24 @@ let
|
|||
&& dials c path "proxy_ssl_verify on;"
|
||||
&& dials c path "proxy_ssl_certificate ";
|
||||
in
|
||||
(loc onCluster "/webhook/forge/").proxyPass == "https://10.42.0.1:9443"
|
||||
&& (loc onCluster "/api/").proxyPass == "https://10.42.0.1:9443"
|
||||
(loc onCluster "/webhook/forge/").proxyPass == "https://\$swarm_controller_upstream"
|
||||
&& (loc onCluster "/api/").proxyPass == "https://\$swarm_controller_upstream"
|
||||
&&
|
||||
lib.all
|
||||
(
|
||||
p:
|
||||
dials onCluster p "resolver 10.42.0.1 valid=10s ipv6=off;"
|
||||
&&
|
||||
dials onCluster p
|
||||
"set \$swarm_controller_upstream swarm-controller.hyperhive.svc.cluster.local:9443;"
|
||||
)
|
||||
[
|
||||
"/webhook/forge/"
|
||||
"/api/"
|
||||
]
|
||||
# The host with the controller on it names no variable and no resolver.
|
||||
&& !(dials withNode "/api/" "resolver")
|
||||
&& !(dials withNode "/api/" "swarm_controller_upstream")
|
||||
&& (loc withNode "/webhook/forge/").proxyPass == "https://controller.t.local:9443"
|
||||
&& (loc withNode "/api/").proxyPass == "https://controller.t.local:9443"
|
||||
&& verified onCluster "/webhook/forge/"
|
||||
|
|
@ -1570,7 +1610,7 @@ let
|
|||
&& verified withNode "/api/";
|
||||
}
|
||||
{
|
||||
name = "the controller's pod publishes its listener on the node, is probed on the health listener, and rolls with its rev file";
|
||||
name = "the controller's pod serves its listener on a named port with no hostPort, is probed on the health listener, and rolls with its rev file";
|
||||
ok =
|
||||
let
|
||||
cluster = render onCluster;
|
||||
|
|
@ -1588,9 +1628,9 @@ let
|
|||
c.readinessProbe.httpGet.path == "/readyz"
|
||||
&& c.livenessProbe.httpGet.path == "/healthz"
|
||||
&& (byName "health" c.ports).containerPort == 8080
|
||||
&& api.hostPort == 9443
|
||||
&& api.containerPort == 9443
|
||||
&& api.hostIP == "10.42.0.1"
|
||||
&& !(api ? hostPort)
|
||||
&& !(api ? hostIP)
|
||||
&& deployment.spec.replicas == 1
|
||||
&& deployment.spec.strategy.type == "Recreate"
|
||||
# The checksum is of the ConfigMap's content, and a changed rev changes it.
|
||||
|
|
|
|||
|
|
@ -35,6 +35,22 @@ let
|
|||
# The four auth responder packages pinned to four distinct derivations, so
|
||||
# a unit's ExecStart names which option it read. Nothing else reads them.
|
||||
marker = name: pkgs.runCommand "auth-marker-${name}" { } "mkdir $out";
|
||||
|
||||
# The all-local host with the k3s node on, and the controller's TCP listener
|
||||
# that a controller in the cluster needs and the one on the host serves as
|
||||
# well. It does not set `k8s.enable`: the node turns the rendering on.
|
||||
k8sNodeSettings = {
|
||||
deploy.singleHostSwarm = true;
|
||||
deploy.k8s.enable = true;
|
||||
deploy.victorialogs.authPackage = marker "logs";
|
||||
deploy.victorialogs.grafanaAuthPackage = marker "logs-grafana";
|
||||
deploy.victoriametrics.authPackage = marker "metrics";
|
||||
deploy.victoriametrics.agentAuthPackage = marker "metrics-agent";
|
||||
swarm.controller.tcp = {
|
||||
enable = true;
|
||||
domain = "controller.t.local";
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
agentBare = agent { };
|
||||
|
|
@ -55,6 +71,9 @@ in
|
|||
deploy.victoriametrics.agentAuthPackage = marker "metrics-agent";
|
||||
};
|
||||
|
||||
inherit k8sNodeSettings;
|
||||
k8sNode = hiveWithController k8sNodeSettings;
|
||||
|
||||
autheliaOnly = hive { deploy.authelia.enable = true; };
|
||||
|
||||
forgeHere = hive { deploy.forgejo.enable = true; };
|
||||
|
|
|
|||
Loading…
Reference in a new issue