semi-spread example: serve internal vhosts on the VPN addresses only, over IPv4 and IPv6
This commit is contained in:
parent
538da5a13a
commit
7800f92425
1 changed files with 356 additions and 89 deletions
|
|
@ -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
|
||||
)}";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue