require k8s: swarm services with a pod run in the cluster only
This commit is contained in:
parent
6be1b59ffc
commit
052b559196
1 changed files with 1044 additions and 3125 deletions
|
|
@ -89,7 +89,7 @@ let
|
|||
|
||||
policyScript = allLocal.systemd.services.swarm-bao-nats-tls-policy.script;
|
||||
leafUnit = allLocal.systemd.services.swarm-bao-nats-tls;
|
||||
natsContainer = allLocal.containers.swarm-nats.config;
|
||||
natsContainer = allLocal.services.hyperhive.deploy.nats.system;
|
||||
natsTls = natsContainer.services.nats.settings.tls;
|
||||
|
||||
# Every `(nats|tls)://…` in a string.
|
||||
|
|
@ -118,21 +118,28 @@ let
|
|||
containerUnits = lib.concatLists (
|
||||
lib.mapAttrsToList (c: cc: fromUnits c cc.config.systemd.services) machine.containers
|
||||
);
|
||||
# The daemons that run as pods are read from the units their pods are
|
||||
# rendered from.
|
||||
d = machine.services.hyperhive.deploy;
|
||||
podUnits = lib.concatLists (
|
||||
map (n: lib.optionals d.${n}.enable (fromUnits "pod" { ${n} = d.${n}.unit; })) [
|
||||
"notify-router"
|
||||
"stt"
|
||||
"review-classifier"
|
||||
"claude-login"
|
||||
"ci-metrics"
|
||||
]
|
||||
);
|
||||
# The responder runs beside the queue only, so a hive without one has
|
||||
# none to read.
|
||||
responder =
|
||||
map
|
||||
(u: {
|
||||
name = "swarm-nats/swarm-nats-auth/--nats-url";
|
||||
value = u;
|
||||
})
|
||||
(
|
||||
lib.optionals (machine.containers ? swarm-nats) (
|
||||
urlsIn machine.containers.swarm-nats.config.systemd.services.swarm-nats-auth.serviceConfig.ExecStart
|
||||
)
|
||||
);
|
||||
responder = map (u: {
|
||||
name = "swarm-nats/swarm-nats-auth/--nats-url";
|
||||
value = u;
|
||||
}) (lib.optionals d.nats.enable (urlsIn d.nats.unit.serviceConfig.ExecStart));
|
||||
in
|
||||
lib.listToAttrs (fromUnits "host" machine.systemd.services ++ containerUnits ++ responder);
|
||||
lib.listToAttrs (
|
||||
fromUnits "host" machine.systemd.services ++ containerUnits ++ podUnits ++ responder
|
||||
);
|
||||
|
||||
scanned = clientUrls allLocal;
|
||||
|
||||
|
|
@ -206,12 +213,10 @@ let
|
|||
{
|
||||
# Mint to consume: the leaf the unit writes is the one the server reads,
|
||||
# and the login leaf glue-bao-tls signs is the one the unit presents.
|
||||
name = "the server serves the leaf the host unit issues, and the unit logs in as swarm-nats";
|
||||
name = "the server serves the leaf the pod issues, and the host unit that writes the gateway's copy logs in as swarm-nats";
|
||||
ok =
|
||||
natsTls.cert_file == "/var/lib/swarm-nats-tls/cert.pem"
|
||||
&& natsTls.key_file == "/run/credentials/nats.service/tls-key"
|
||||
&& lib.elem "tls-key:/var/lib/swarm-nats-tls/key.pem" natsContainer.systemd.services.nats.serviceConfig.LoadCredential
|
||||
&& allLocal.containers.swarm-nats.bindMounts ? "/var/lib/swarm-nats-tls"
|
||||
&& natsTls.key_file == "/var/lib/swarm-nats-tls/key.pem"
|
||||
&& lib.hasInfix "d=/var/lib/swarm-nats-tls" leafUnit.script
|
||||
&& lib.hasInfix "pki/issue/swarm-nats" leafUnit.script
|
||||
&& leafUnit.environment.BAO_CLIENT_CERT == "/var/lib/swarm-bao-pki/nats.pem"
|
||||
|
|
@ -221,14 +226,14 @@ let
|
|||
{
|
||||
# The leaf rotation restarts the server; the responder, stopped when
|
||||
# the server failed, is cleared and started after it.
|
||||
name = "the leaf rotation starts the responder after restarting the server";
|
||||
name = "the host's leaf unit restarts no server: the queue runs in the pod";
|
||||
ok =
|
||||
let
|
||||
s = leafUnit.script;
|
||||
in
|
||||
lib.hasInfix "restart nats.service" s
|
||||
&& lib.hasInfix "reset-failed swarm-nats-auth.service" s
|
||||
&& lib.hasInfix "start --no-block swarm-nats-auth.service" s;
|
||||
lib.hasInfix "pki/issue/swarm-nats" s
|
||||
&& !(lib.hasInfix "restart nats.service" s)
|
||||
&& !(lib.hasInfix "swarm-nats-auth.service" s);
|
||||
}
|
||||
{
|
||||
# The hive's own reader is not the queue's identity, and no path is
|
||||
|
|
@ -397,7 +402,7 @@ let
|
|||
]
|
||||
&& locs."/".return == "403"
|
||||
&& locs."/".proxyPass == null
|
||||
&& locs."= /metrics".proxyPass == "http://127.0.0.1:${toString h.deploy.nats.metricsPort}/metrics"
|
||||
&& locs."= /metrics".proxyPass == "http://\$swarm_nats_metrics_upstream/metrics"
|
||||
&& checksOf locs."= /metrics" == [ "auth_request /__nats_metrics_authz;" ]
|
||||
&& !(lib.hasInfix "error_page" locs."= /metrics".extraConfig)
|
||||
&& authz.proxyPass == "https://auth.t.local/api/authz/auth-request"
|
||||
|
|
|
|||
Loading…
Reference in a new issue