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
7a45c7f1b4
commit
8de33b7212
1 changed files with 355 additions and 103 deletions
|
|
@ -134,8 +134,8 @@ let
|
|||
# /readyz listener. `publicCredentials` maps the ids of the credentials that
|
||||
# hold a public CA file to their key in the CA ConfigMap, and `publicFiles`
|
||||
# the paths the unit names that hold one to theirs. `listener`, where a
|
||||
# service has one, is the TCP port the pod publishes on the node
|
||||
# (`hostAddress`) and the directory its init container writes the leaf to.
|
||||
# service has one, is the TCP port a Service publishes in the cluster and the
|
||||
# directory the pod's init container writes the leaf to.
|
||||
# `ephemeralState` gives a service an `emptyDir` in place of a claim for its
|
||||
# state directory: what it keeps there is re-derived at start. A pod starts on
|
||||
# whatever volume it gets.
|
||||
|
|
@ -168,11 +168,10 @@ let
|
|||
"hive-client-ca.pem" = hiveClientCaKey;
|
||||
};
|
||||
publicFiles = lib.optionalAttrs controllerTcp.enable { ${servicesRootPath} = servicesRootKey; };
|
||||
# The TCP listener, as a `hostPort` on the node's address: the gateway
|
||||
# on the host dials it there.
|
||||
# The TCP listener, behind a Service the gateway on the host dials by
|
||||
# name.
|
||||
listener = lib.optionalAttrs controllerTcp.enable {
|
||||
port = controllerTcp.port;
|
||||
hostAddress = controllerCfg.tcp.hostAddress;
|
||||
tlsDir = controllerCfg.tcp.tlsDir;
|
||||
};
|
||||
# The unit pushes to the swarm collector's route and mints its own bearer
|
||||
|
|
@ -423,6 +422,42 @@ let
|
|||
};
|
||||
};
|
||||
|
||||
# The listener's Service, and the policy that lets only the node reach it. The
|
||||
# cluster's policy engine (kube-router) admits traffic whose source is a local
|
||||
# address of the node to any pod (`--src-type LOCAL`, the rule it labels "from
|
||||
# local node"), and a policy that selects the pod for ingress and allows
|
||||
# nothing refuses every other source. The gateway on the host dials the
|
||||
# Service's name, so its connection reaches the pod from the node; a pod of
|
||||
# the cluster does not.
|
||||
listenerObjects = name: listener: {
|
||||
"${name}/service" = {
|
||||
apiVersion = "v1";
|
||||
kind = "Service";
|
||||
metadata = metaFor name;
|
||||
spec = {
|
||||
type = "ClusterIP";
|
||||
selector = labelsFor name;
|
||||
ports = [
|
||||
{
|
||||
name = "api";
|
||||
protocol = "TCP";
|
||||
port = listener.port;
|
||||
targetPort = "api";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
"${name}/networkpolicy" = {
|
||||
apiVersion = "networking.k8s.io/v1";
|
||||
kind = "NetworkPolicy";
|
||||
metadata = metaFor name;
|
||||
spec = {
|
||||
podSelector.matchLabels = labelsFor name;
|
||||
policyTypes = [ "Ingress" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# systemd duration "<n>min", the only form these units use.
|
||||
minutesOf =
|
||||
name: what: value:
|
||||
|
|
@ -776,8 +811,7 @@ let
|
|||
cpu = "0";
|
||||
};
|
||||
|
||||
# `hostPort` publishes the listener on the node's address. The cluster's
|
||||
# portmap plugin forwards it to the pod, so it reaches this one node.
|
||||
# The listener's Service targets this port by its name.
|
||||
ports =
|
||||
lib.optional (svc.healthEnv != null) {
|
||||
name = "health";
|
||||
|
|
@ -786,8 +820,6 @@ let
|
|||
++ lib.optional (listener != { }) {
|
||||
name = "api";
|
||||
containerPort = listener.port;
|
||||
hostPort = listener.port;
|
||||
hostIP = listener.hostAddress;
|
||||
};
|
||||
|
||||
container = {
|
||||
|
|
@ -994,6 +1026,7 @@ let
|
|||
// lib.optionalAttrs (svc ? egress) {
|
||||
"${name}/networkpolicy" = networkPolicyOf name svc.egress;
|
||||
}
|
||||
// lib.optionalAttrs (listener != { }) (listenerObjects name listener)
|
||||
// lib.optionalAttrs baoLogin {
|
||||
# Named after the service: the store's jwt role binds this account.
|
||||
"${name}/serviceaccount" = {
|
||||
|
|
@ -1031,6 +1064,8 @@ let
|
|||
fail name "the unit already sets ${svc.healthEnv}"
|
||||
else if svc ? egress && !(lib.all (r: hostPorts ? ${r}) svc.egress) then
|
||||
fail name "egress names a host service the renderer has no port for (${lib.concatStringsSep ", " (lib.attrNames hostPorts)})"
|
||||
else if svc ? egress && listener != { } then
|
||||
fail name "has an egress policy and a listener, which would share one NetworkPolicy"
|
||||
else if lib.head execWords != entrypoint then
|
||||
fail name "ExecStart is not ${entrypoint} with plain arguments"
|
||||
else if lib.any (w: lib.hasInfix "\"" w) execWords then
|
||||
|
|
|
|||
Loading…
Reference in a new issue