tang: declare client pins and server allow lists in one table #1354
No files matched your search
Generated
+3
-3
@@ -1025,11 +1025,11 @@
|
||||
"treefmt-nix": "treefmt-nix_9"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1786323062,
|
||||
"narHash": "sha256-PBHsGzhjFtqGQYrmX7lxMIqhvrWv4ZNQTgmbY92JSUc=",
|
||||
"lastModified": 1790458770,
|
||||
"narHash": "sha256-ztM5btz1eg3vPyYoyDbj6EG1Slpj0yIhLEuY7w2IKCc=",
|
||||
"owner": "JakeHillion",
|
||||
"repo": "ogygia-nix",
|
||||
"rev": "ba81ff2e56073deb1502190f8f0342d1f35348d1",
|
||||
"rev": "e256add195f32ab8c5ff4314b570a0ba756b3f7a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
Additional installation step for Clevis/Tang:
|
||||
|
||||
$ echo -n $DISK_ENCRYPTION_PASSWORD | clevis encrypt sss "$(cat /etc/nixos/hosts/boron.cx.neb.jakehillion.me/clevis_config.json)" >/mnt/data/disk_encryption.jwe
|
||||
$ echo -n $DISK_ENCRYPTION_PASSWORD | clevis encrypt sss "$(nix eval --json '/etc/nixos#nixosConfigurations."boron.cx.neb.jakehillion.me".config.ogygia.clevis.spec')" >/mnt/data/disk_encryption.jwe
|
||||
$ sudo chown root:root /mnt/data/disk_encryption.jwe
|
||||
$ sudo chmod 0400 /mnt/data/disk_encryption.jwe
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
Additional installation step for Clevis/Tang:
|
||||
|
||||
$ echo -n $DISK_ENCRYPTION_PASSWORD | clevis encrypt sss "$(cat /etc/nixos/hosts/phoenix.st.neb.jakehillion.me/clevis_config.json)" >/mnt/data/disk_encryption.jwe
|
||||
$ echo -n $DISK_ENCRYPTION_PASSWORD | clevis encrypt sss "$(nix eval --json '/etc/nixos#nixosConfigurations."phoenix.st.neb.jakehillion.me".config.ogygia.clevis.spec')" >/mnt/data/disk_encryption.jwe
|
||||
$ sudo chown root:root /mnt/data/disk_encryption.jwe
|
||||
$ sudo chmod 0400 /mnt/data/disk_encryption.jwe
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
let
|
||||
cfg = config.custom.services.tang;
|
||||
|
||||
servedGroups = lib.lists.filter
|
||||
(g: lib.attrsets.hasAttr config.networking.fqdn g.pins)
|
||||
(lib.attrsets.attrValues config.custom.tang.fleet.groups);
|
||||
in
|
||||
{
|
||||
options.custom.services.tang = {
|
||||
@@ -13,14 +17,7 @@ in
|
||||
|
||||
services.tang = {
|
||||
enable = true;
|
||||
ipAddressAllow = [
|
||||
"10.64.50.0/24"
|
||||
"37.27.136.99/32"
|
||||
"127.0.0.0/8"
|
||||
"138.201.252.214/32"
|
||||
"140.238.103.110/32"
|
||||
"185.240.111.53/32"
|
||||
];
|
||||
ipAddressAllow = [ "127.0.0.0/8" ] ++ lib.lists.unique (lib.lists.concatMap (g: g.sources) servedGroups);
|
||||
};
|
||||
|
||||
networking.firewall.allowedTCPPorts = [ 7654 ];
|
||||
|
||||
+146
-29
@@ -2,6 +2,15 @@
|
||||
|
||||
let
|
||||
cfg = config.custom.tang;
|
||||
|
||||
fqdn = config.networking.fqdn;
|
||||
domain = config.ogygia.domain;
|
||||
|
||||
group = lib.lists.findSingle
|
||||
(g: lib.lists.elem fqdn g.clients)
|
||||
(throw "${fqdn} enables tang but is not a client of any group in custom.tang.fleet.groups")
|
||||
(throw "${fqdn} is a client of multiple groups in custom.tang.fleet.groups")
|
||||
(lib.attrsets.attrValues cfg.fleet.groups);
|
||||
in
|
||||
{
|
||||
options.custom.tang = {
|
||||
@@ -20,39 +29,147 @@ in
|
||||
type = with lib.types; listOf str;
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
boot.initrd = {
|
||||
availableKernelModules = [ cfg.networkingModule ];
|
||||
|
||||
# Configure systemd-networkd directly in initrd. We don't go via
|
||||
# boot.initrd.network.enable because that auto-translates the full
|
||||
# stage 2 networking.interfaces.* into boot.initrd.systemd.network,
|
||||
# which doesn't tolerate stage 2 route schemas (e.g. cyclone's
|
||||
# cellular VLAN).
|
||||
systemd.network = {
|
||||
enable = true;
|
||||
# Fallback DHCP on the tang interface. Hosts that set a static
|
||||
# `ip=...` kernel parameter get a higher-priority 91-*.network from
|
||||
# systemd-network-generator that wins over this 99-*.
|
||||
networks."99-tang-dhcp" = {
|
||||
matchConfig.Driver = cfg.networkingModule;
|
||||
networkConfig.DHCP = "yes";
|
||||
};
|
||||
fleet = {
|
||||
servers = lib.mkOption {
|
||||
description = ''
|
||||
Tang servers by FQDN: the thumbprint of each server's signing key
|
||||
(from `tang-show-keys 7654`) and the URLs it is reachable at, keyed
|
||||
by how it is reached.
|
||||
'';
|
||||
readOnly = true;
|
||||
};
|
||||
|
||||
clevis = {
|
||||
enable = true;
|
||||
useTang = true;
|
||||
|
||||
devices = builtins.listToAttrs (builtins.map
|
||||
(dev: {
|
||||
name = dev;
|
||||
value = { secretFile = cfg.secretFile; };
|
||||
})
|
||||
cfg.devices);
|
||||
groups = lib.mkOption {
|
||||
description = ''
|
||||
Groups of clients that bind to the same servers. `pins` maps a
|
||||
server FQDN to which of its URLs the clients use, `sources` are the
|
||||
addresses those servers see the clients connect from.
|
||||
'';
|
||||
readOnly = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
{
|
||||
custom.tang.fleet = {
|
||||
servers = {
|
||||
"cyclone.gw.${domain}" = {
|
||||
thp = "L-njyA01teJse7gxbkBJMc6DuLKrwlvqfrbvKj528m4";
|
||||
lan = "http://10.64.50.1:7654";
|
||||
wan = "http://185.240.111.53:7654";
|
||||
};
|
||||
"warlock.cx.${domain}" = {
|
||||
thp = "m4sWMYoNuEv1Z5PuWeZ3tUkfFSJCyaeL4WxYWQY6piU";
|
||||
lan = "http://10.64.50.21:7654";
|
||||
};
|
||||
"stinger.pop.${domain}" = {
|
||||
thp = "mk6z2KAxuW1zee0S7D7qOFchgyiyei9XvJaF9pJkqK0";
|
||||
lan = "http://10.64.50.29:7654";
|
||||
};
|
||||
"boron.cx.${domain}" = {
|
||||
thp = "UzoraC1HFiCmhtz6f43N-6sqY77YDHXNi7Eow9RA9D0";
|
||||
wan = "http://138.201.252.214:7654";
|
||||
};
|
||||
"li.pop.${domain}" = {
|
||||
thp = "_rbDZVBx35wwUu36P7C-DlQJhQQt4zO8g6r5prT0RWs";
|
||||
wan = "http://80.229.251.26:7654";
|
||||
};
|
||||
};
|
||||
|
||||
groups = {
|
||||
# Hosts behind cyclone. They only unlock while they can reach the
|
||||
# home servers over the LAN, never from the Internet.
|
||||
home = {
|
||||
pins = {
|
||||
"cyclone.gw.${domain}" = "lan";
|
||||
"warlock.cx.${domain}" = "lan";
|
||||
"stinger.pop.${domain}" = "lan";
|
||||
};
|
||||
clients = [
|
||||
"maverick.cx.${domain}"
|
||||
"merlin.rig.${domain}"
|
||||
"phoenix.st.${domain}"
|
||||
"rooster.cx.${domain}"
|
||||
"stinger.pop.${domain}"
|
||||
"sundown.st.${domain}"
|
||||
"warlock.cx.${domain}"
|
||||
"wolfman.io.${domain}"
|
||||
];
|
||||
sources = [ "10.64.50.0/24" ];
|
||||
};
|
||||
|
||||
internet = {
|
||||
pins = {
|
||||
"cyclone.gw.${domain}" = "wan";
|
||||
"boron.cx.${domain}" = "wan";
|
||||
"li.pop.${domain}" = "wan";
|
||||
};
|
||||
clients = [
|
||||
"boron.cx.${domain}"
|
||||
"cyclone.gw.${domain}"
|
||||
"iceman.cx.${domain}"
|
||||
"slider.pop.${domain}"
|
||||
"viper.pop.${domain}"
|
||||
];
|
||||
sources = [
|
||||
"37.27.136.99/32" # iceman
|
||||
"138.201.252.214/32" # boron
|
||||
"140.238.103.110/32" # slider
|
||||
"185.240.111.53/32" # cyclone
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
(lib.mkIf cfg.enable {
|
||||
boot.initrd = {
|
||||
availableKernelModules = [ cfg.networkingModule ];
|
||||
|
||||
# Configure systemd-networkd directly in initrd. We don't go via
|
||||
# boot.initrd.network.enable because that auto-translates the full
|
||||
# stage 2 networking.interfaces.* into boot.initrd.systemd.network,
|
||||
# which doesn't tolerate stage 2 route schemas (e.g. cyclone's
|
||||
# cellular VLAN).
|
||||
systemd.network = {
|
||||
enable = true;
|
||||
# Fallback DHCP on the tang interface. Hosts that set a static
|
||||
# `ip=...` kernel parameter get a higher-priority 91-*.network from
|
||||
# systemd-network-generator that wins over this 99-*.
|
||||
networks."99-tang-dhcp" = {
|
||||
matchConfig.Driver = cfg.networkingModule;
|
||||
networkConfig.DHCP = "yes";
|
||||
};
|
||||
};
|
||||
|
||||
clevis = {
|
||||
enable = true;
|
||||
useTang = true;
|
||||
|
||||
devices = builtins.listToAttrs (builtins.map
|
||||
(dev: {
|
||||
name = dev;
|
||||
value = { secretFile = cfg.secretFile; };
|
||||
})
|
||||
cfg.devices);
|
||||
};
|
||||
};
|
||||
|
||||
ogygia.clevis = {
|
||||
enable = true;
|
||||
secretFile = cfg.secretFile;
|
||||
spec = {
|
||||
t = 1;
|
||||
pins.tang = lib.attrsets.mapAttrsToList
|
||||
(server: via: {
|
||||
url = cfg.fleet.servers.${server}.${via};
|
||||
inherit (cfg.fleet.servers.${server}) thp;
|
||||
})
|
||||
(lib.attrsets.removeAttrs group.pins [ fqdn ]);
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"t": 1,
|
||||
"pins": {
|
||||
"tang": [
|
||||
{
|
||||
"url": "http://80.229.251.26:7654"
|
||||
},
|
||||
{
|
||||
"url": "http://138.201.252.214:7654"
|
||||
},
|
||||
{
|
||||
"url": "http://185.240.111.53:7654"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"t": 1,
|
||||
"pins": {
|
||||
"tang": [
|
||||
{ "url": "http://10.64.50.1:7654" },
|
||||
{ "url": "http://10.64.50.21:7654" },
|
||||
{ "url": "http://10.64.50.29:7654" }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#!/usr/bin/env -S nix shell nixpkgs#bash nixpkgs#clevis --command bash
|
||||
set -e
|
||||
|
||||
TMPFILE=$(sudo mktemp)
|
||||
|
||||
sudo cat /data/disk_encryption.jwe | clevis decrypt | clevis encrypt sss "$(cat /etc/nixos/scripts/clevis/global_config.json)" | sudo tee $TMPFILE >/dev/null
|
||||
|
||||
echo "!!!!!!!!!!!!!!!!!!!!!"
|
||||
echo "WARNING: clevis gives the wrong exit code, so we don't know if the file was decrypted successfully - check carefully before continuing!"
|
||||
echo "!!!!!!!!!!!!!!!!!!!!!"
|
||||
|
||||
read -p "Do you want to overwrite this file?" yn
|
||||
case $yn in
|
||||
[Yy]* ) ;;
|
||||
[Nn]* ) exit;;
|
||||
* ) echo "Invalid answer"; exit;;
|
||||
esac
|
||||
|
||||
sudo install -m0400 $TMPFILE /data/disk_encryption.jwe
|
||||
@@ -1,19 +0,0 @@
|
||||
#!/usr/bin/env -S nix shell nixpkgs#bash nixpkgs#clevis --command bash
|
||||
set -e
|
||||
|
||||
TMPFILE=$(sudo mktemp)
|
||||
|
||||
sudo cat /data/disk_encryption.jwe | clevis decrypt | clevis encrypt sss "$(cat /etc/nixos/scripts/clevis/home_config.json)" | sudo tee $TMPFILE >/dev/null
|
||||
|
||||
echo "!!!!!!!!!!!!!!!!!!!!!"
|
||||
echo "WARNING: clevis gives the wrong exit code, so we don't know if the file was decrypted successfully - check carefully before continuing!"
|
||||
echo "!!!!!!!!!!!!!!!!!!!!!"
|
||||
|
||||
read -p "Do you want to overwrite this file?" yn
|
||||
case $yn in
|
||||
[Yy]* ) ;;
|
||||
[Nn]* ) exit;;
|
||||
* ) echo "Invalid answer"; exit;;
|
||||
esac
|
||||
|
||||
sudo install -m0400 $TMPFILE /data/disk_encryption.jwe
|
||||
Reference in new issue
Block a user