Watch
0
0
Fork
You've already forked hyperhive
0

gateway reaches the controller over tls with its own client leaf when the tcp listener is on

This commit is contained in:
atlas 2026-11-15 16:10:59 +01:00 • committed by mara
commit 187ed82de0

View file

@ -41,6 +41,26 @@ let
deploy.hive-controller.hyperhiveRev = lib.fixedWidthString 40 "b" "";
};
# `allLocal` with the controller's TCP listener on, the one fixture that has
# the store, the controller and the gateway together: the two roles, the two
# issue grants and the vhost all render from this one option. The firewall is
# opened so the lookup that finds the port is shown to find it. Off is
# `allLocal` itself.
allLocalTcp = hiveWithController {
deploy.singleHostSwarm = true;
swarm.controller.tcp = {
enable = true;
domain = "controller.t.local";
};
deploy.swarm-controller.tcp.openFirewall = true;
};
# The listener asked for with nothing to name it by.
tcpNoDomain = hive {
deploy.swarm-controller.enable = true;
swarm.controller.tcp.enable = true;
};
bare = shared.bareWithController;
# `lib.hasInfix` matches by regex, which refuses a needle that refers to a
@ -3016,6 +3036,149 @@ let
mentions "privateListenAddresses holds"
&& !(mentions "while services.hyperhive.gateway.privateListenAddresses is empty");
}
{
# The off arm of the controller's TCP listener: a host that never set it
# renders what it rendered before it existed. The gateway still reaches
# the controller by socket, nothing TCP-shaped is rendered, and the
# store writes neither role nor grant. The `swarm-services-cert` unit is
# the presence control for the unit lookup, and the socket in
# `proxyPass` for the location lookup.
name = "a swarm without the controller's TCP listener renders the socket-only controller";
ok =
let
m = allLocal;
l = m.services.nginx.virtualHosts."t.local".locations;
socket = "http://unix:${m.services.hyperhive.deploy.swarm-controller.socketPath}:";
env = m.systemd.services.swarm-controller.environment;
policies = m.systemd.services.swarm-bao-controller-policy.script;
issuer = m.systemd.services.swarm-bao-services-issuer-policy.script;
in
l."/api/".proxyPass == socket
&& l."/webhook/forge/".proxyPass == socket
&& !(lib.hasInfix "proxy_ssl_certificate" l."/api/".extraConfig)
&& !(lib.hasInfix "proxy_ssl" l."/webhook/forge/".extraConfig)
&& !(m.systemd.services ? swarm-controller-tls)
&& !(m.systemd.services ? swarm-controller-gateway-client)
&& !(m.systemd.timers ? swarm-controller-tls)
&& !(m.systemd.timers ? swarm-controller-gateway-client)
&& m.systemd.services ? swarm-services-cert
&& !(lib.any (lib.hasPrefix "SWARM_CONTROLLER_TCP_") (lib.attrNames env))
&& !(lib.elem 9443 m.networking.firewall.allowedTCPPorts)
&& !(lib.hasInfix "swarm-controller-tls" policies)
&& !(lib.hasInfix "swarm-controller-gateway-client" policies)
&& !(lib.hasInfix "swarm-controller-gateway-client" issuer)
&& lib.hasInfix "issue/swarm-services" issuer
&& env.SWARM_CONTROLLER_PUBLIC_URL == "https://t.local"
&& m.services.hyperhive.deploy.swarm-controller.tcp.openFirewall == false
&& allLocalTcp.services.hyperhive.deploy.swarm-controller.tcp.openFirewall == true;
}
{
# The on arm. The gateway dials the listener by name over TLS, verified,
# with the client leaf, and keeps the operator gate on `/api/` and the
# webhook's absence of it; the controller is handed all five listener
# variables, naming the services root as the client CA and the gateway's
# one name as the client; the firewall port is open because the fixture
# asked.
name = "the controller's TCP listener is dialled over verified TLS with the gateway's client leaf";
ok =
let
m = allLocalTcp;
l = m.services.nginx.virtualHosts."t.local".locations;
upstream = "https://controller.t.local:9443";
tls = m.services.hyperhive.deploy.hive-controller.tls.stateDir;
env = m.systemd.services.swarm-controller.environment;
dialled =
loc:
lib.all (s: lib.hasInfix s loc.extraConfig) [
"proxy_ssl_verify on;"
"proxy_ssl_name controller.t.local;"
"proxy_ssl_certificate ${tls}/controller-client.pem;"
"proxy_ssl_certificate_key ${tls}/controller-client-key.pem;"
"proxy_set_header Host controller.t.local;"
];
in
l."/api/".proxyPass == upstream
&& l."/webhook/forge/".proxyPass == upstream
&& dialled l."/api/"
&& dialled l."/webhook/forge/"
&& l."/api/".recommendedProxySettings == false
&& l."/webhook/forge/".recommendedProxySettings == false
&& lib.hasInfix "auth_request /__hive_authelia;" l."/api/".extraConfig
&& !(lib.hasInfix "auth_request" l."/webhook/forge/".extraConfig)
&& env.SWARM_CONTROLLER_TCP_LISTEN == "0.0.0.0:9443"
&& env.SWARM_CONTROLLER_TCP_CERT == "/var/lib/swarm-controller-tls/cert.pem"
&& env.SWARM_CONTROLLER_TCP_KEY == "/var/lib/swarm-controller-tls/key.pem"
&& env.SWARM_CONTROLLER_TCP_CLIENT_CA == "${tls}/swarm-services-root.pem"
&& env.SWARM_CONTROLLER_TCP_CLIENT_NAME == "gateway-client.t.local"
&& lib.elem 9443 m.networking.firewall.allowedTCPPorts
&& env.SWARM_CONTROLLER_PUBLIC_URL == "https://t.local"
&& m.systemd.services.swarm-controller-tls.wantedBy == [ "multi-user.target" ]
&& lib.elem "swarm-controller-tls.service" m.systemd.services.swarm-controller.after;
}
{
# The two roles carry opposite flag pairs, which is the whole reason the
# swarm-services leaf cannot present itself to the listener: the client
# role issues `clientAuth` only and the server role `serverAuth` only.
# Each is read out of the one `bao write` that names it, so swapped flags
# fail here and a role that is missing fails on the first clause. The
# grants are split the same way: the controller may issue its server
# leaf and the gateway-side identity its client leaf, and neither may
# issue the other's.
name = "the store writes a server-only and a client-only role and grants each to one principal";
ok =
let
m = allLocalTcp;
script = m.systemd.services.swarm-bao-controller-policy.script;
write =
role: lib.findFirst (c: lib.hasInfix "/roles/${role} " c) "" (lib.splitString "bao write" script);
server = write "swarm-controller-tls";
client = write "swarm-controller-gateway-client";
issuer = m.systemd.services.swarm-bao-services-issuer-policy.script;
in
server != ""
&& client != ""
&& lib.hasInfix "allowed_domains=controller.t.local" server
&& lib.hasInfix "server_flag=true" server
&& lib.hasInfix "client_flag=false" server
&& lib.hasInfix "allowed_domains=gateway-client.t.local" client
&& lib.hasInfix "server_flag=false" client
&& lib.hasInfix "client_flag=true" client
&& lib.hasInfix "allow_any_name=false" client
&& lib.hasInfix "issue/swarm-controller-tls" script
&& !(lib.hasInfix "issue/swarm-controller-gateway-client" script)
&& lib.hasInfix "issue/swarm-controller-gateway-client" issuer
&& !(lib.hasInfix "issue/swarm-controller-tls" issuer)
&& lib.hasInfix "issue/swarm-services" issuer;
}
{
# The gateway's client leaf is checked for the `clientAuth` purpose
# before it is trusted as current, so a leaf issued under the wrong role
# is replaced rather than kept. The throwaway pair that stands in until
# the store answers is what keeps nginx's config loadable.
name = "the gateway's client leaf is issued with the services-issuer identity and placed for nginx";
ok =
let
u = allLocalTcp.systemd.services.swarm-controller-gateway-client;
in
lib.hasInfix "-purpose sslclient" u.script
&& lib.hasInfix "issue/swarm-controller-gateway-client" u.script
&& lib.hasInfix "chgrp nginx" u.script
&& lib.hasInfix "placeholder" u.script
&& lib.elem "nginx.service" u.before
&& u.environment ? BAO_ADDR
&& allLocalTcp.systemd.timers ? swarm-controller-gateway-client;
}
{
name = "the controller's TCP listener is refused at eval with no name to dial it by";
ok =
let
fired = lib.filter (a: !a.assertion) tcpNoDomain.assertions;
in
lib.any (a: lib.hasInfix "swarm.controller.tcp.domain" a.message) fired
&& !(lib.any (a: lib.hasInfix "swarm.controller.tcp.domain" a.message) (
lib.filter (a: !a.assertion) allLocalTcp.assertions
));
}
]
# Starting a unit that stays `active (exited)` is a no-op, so a timer aimed
# at one fires and fetches nothing.