Watch
0
0
Fork
You've already forked hyperhive
0

semi-spread example: serve internal vhosts on the VPN addresses only, over IPv4 and IPv6

This commit is contained in:
atlas 2026-11-10 00:07:38 +01:00 • committed by mara
commit 7800f92425

View file

@ -1,6 +1,6 @@
# Names inside the VPN. Every swarm name that is not public resolves to the
# VPN address of the machine serving it, through a static table written on
# each host. Identical on every host.
# Names inside the VPN. Every swarm name, the public ones included, resolves to
# the VPN addresses (IPv4 and IPv6) of the machine serving it, through a static
# table written on each host. Identical on every host.
#
# Two readers need the table. Processes on the host read /etc/hosts
# (`networking.hosts`). Containers (agents, swarm services) ask the hive's
@ -49,17 +49,20 @@ let
};
elsewhere = removeAttrs servedBy [ self ];
# Each machine's names, once per address family: A and AAAA answers.
addressesOf = machine: [
mesh.${machine}.address
mesh.${machine}.address6
];
table = lib.concatMap (
machine: map (address: lib.nameValuePair address elsewhere.${machine}) (addressesOf machine)
) (builtins.attrNames elsewhere);
in
{
networking.hosts = lib.mapAttrs' (
machine: names: lib.nameValuePair mesh.${machine}.address names
) elsewhere;
networking.hosts = lib.listToAttrs table;
services.dnsmasq.settings.addn-hosts = "${builtins.toFile "swarm-vpn-hosts" (
lib.concatStringsSep "\n" (
lib.mapAttrsToList (
machine: names: "${mesh.${machine}.address} ${lib.concatStringsSep " " names}"
) elsewhere
)
lib.concatMapStrings (entry: "${entry.name} ${lib.concatStringsSep " " entry.value}\n") table
)}";
}