Compare commits
5 Commits
38e4199e94
...
script
| Author | SHA1 | Date | |
|---|---|---|---|
| ee24f8a4a9 | |||
| c18724e9a6 | |||
| b59f4084c0 | |||
| f6bd56d583 | |||
| f8f68df868 |
@@ -1,6 +1,7 @@
|
|||||||
{ inputs, config, ... }:
|
{ inputs, config, ... }:
|
||||||
let
|
let
|
||||||
sshKeys = import ../ssh_keys.nix;
|
sshKeys = import ../ssh_keys.nix;
|
||||||
|
peers = import ../modules/malobeo/peers.nix;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
sops.defaultSopsFile = ./secrets.yaml;
|
sops.defaultSopsFile = ./secrets.yaml;
|
||||||
@@ -87,6 +88,35 @@ in
|
|||||||
ethernetDrivers = ["r8169"];
|
ethernetDrivers = ["r8169"];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
boot.initrd = {
|
||||||
|
availableKernelModules = [ "wireguard" ];
|
||||||
|
systemd = {
|
||||||
|
enable = true;
|
||||||
|
network = {
|
||||||
|
enable = true;
|
||||||
|
netdevs."30-wg-initrd" = {
|
||||||
|
netdevConfig = {
|
||||||
|
Kind = "wireguard";
|
||||||
|
Name = "wg-initrd";
|
||||||
|
};
|
||||||
|
wireguardConfig = { PrivateKeyFile = "/etc/secrets/30-wg-initrd.key"; };
|
||||||
|
wireguardPeers = [{
|
||||||
|
AllowedIPs = peers.fanny-initrd.allowedIPs;
|
||||||
|
PublicKey = peers.fanny-initrd.publicKey;
|
||||||
|
Endpoint = "${peers.vpn.publicIp}:${builtins.toString(peers.vpn.listenPort)}";
|
||||||
|
PersistentKeepalive = 25;
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
networks."30-wg-initrd" = {
|
||||||
|
name = "wg-initrd";
|
||||||
|
addresses = [{ Address = peers.fanny-initrd.address; }];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
boot.initrd.secrets."/etc/secrets/30-wg-initrd.key" = "/etc/wireguard/wg.private";
|
||||||
|
|
||||||
services.malobeo.vpn = {
|
services.malobeo.vpn = {
|
||||||
enable = true;
|
enable = true;
|
||||||
name = "fanny";
|
name = "fanny";
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ in
|
|||||||
path = with pkgs; [ zfs ];
|
path = with pkgs; [ zfs ];
|
||||||
serviceConfig.Type = "oneshot";
|
serviceConfig.Type = "oneshot";
|
||||||
script = ''
|
script = ''
|
||||||
echo "systemctl default" >> /var/empty/.profile
|
echo "zfs load-key -a; killall zfs; systemctl default" >> /var/empty/.profile
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,6 +44,14 @@
|
|||||||
publicKey = "3U59F6T1s/1LaZBIa6wB0qsVuO6pRR9jfYZJIH2piAU=";
|
publicKey = "3U59F6T1s/1LaZBIa6wB0qsVuO6pRR9jfYZJIH2piAU=";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
"fanny-initrd" = {
|
||||||
|
role = "client";
|
||||||
|
address = "10.100.0.102";
|
||||||
|
allowedIPs = [ "10.100.0.102/32" ];
|
||||||
|
#TODO: UPDATE
|
||||||
|
publicKey = "h1A2yt7OQ5EJIilC8tQg203u27o6J6/c+Kd/pZ4UWAY=";
|
||||||
|
};
|
||||||
|
|
||||||
"backup0" = {
|
"backup0" = {
|
||||||
role = "client";
|
role = "client";
|
||||||
address = "10.100.0.20";
|
address = "10.100.0.20";
|
||||||
|
|||||||
@@ -31,10 +31,13 @@ cd "$pwpath"
|
|||||||
# Generate SSH keys
|
# Generate SSH keys
|
||||||
ssh-keygen -f $hostkey -t ed25519 -N "" -C "root@$host"
|
ssh-keygen -f $hostkey -t ed25519 -N "" -C "root@$host"
|
||||||
ssh-keygen -f $initrdkey -t ed25519 -N "" -C "root@$host-initrd"
|
ssh-keygen -f $initrdkey -t ed25519 -N "" -C "root@$host-initrd"
|
||||||
|
wg genkey > wg.private
|
||||||
|
publickey=$(cat wg.private | wg pubkey)
|
||||||
|
|
||||||
#encrypt the private keys
|
#encrypt the private keys
|
||||||
sops -e -i ./$hostkey
|
sops -e -i ./$hostkey
|
||||||
sops -e -i ./$initrdkey
|
sops -e -i ./$initrdkey
|
||||||
|
sops -e -i ./wg.private
|
||||||
|
|
||||||
#generate encryption key
|
#generate encryption key
|
||||||
tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 20 > disk.key
|
tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 20 > disk.key
|
||||||
@@ -45,6 +48,9 @@ echo
|
|||||||
echo "Hier ist der age public key für sops etc:"
|
echo "Hier ist der age public key für sops etc:"
|
||||||
echo "$(ssh-to-age -i ./"$hostkey".pub)"
|
echo "$(ssh-to-age -i ./"$hostkey".pub)"
|
||||||
echo
|
echo
|
||||||
|
echo "Hier ist der wireguard pubkey für das gerät"
|
||||||
|
echo "$publickey"
|
||||||
|
echo
|
||||||
echo "Hier ist eine reproduzierbare mac-addresse:"
|
echo "Hier ist eine reproduzierbare mac-addresse:"
|
||||||
echo "$hostname"|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/'
|
echo "$hostname"|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/'
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ trap cleanup EXIT
|
|||||||
|
|
||||||
# Create the directory where sshd expects to find the host keys
|
# Create the directory where sshd expects to find the host keys
|
||||||
install -d -m755 "$temp/etc/ssh/"
|
install -d -m755 "$temp/etc/ssh/"
|
||||||
|
install -d -m755 "$temp/etc/wireguard/"
|
||||||
|
|
||||||
|
##TODO:: wg genkey + pubkey --> /etc/wireguard/wg.private
|
||||||
diskKey=$(sops -d $pwpath/disk.key)
|
diskKey=$(sops -d $pwpath/disk.key)
|
||||||
echo "$diskKey" > /tmp/secret.key
|
echo "$diskKey" > /tmp/secret.key
|
||||||
|
|
||||||
@@ -48,6 +50,7 @@ sops -d "$pwpath/$hostkey" > "$temp/etc/ssh/$hostname"
|
|||||||
|
|
||||||
sops -d "$pwpath/$initrdkey" > "$temp/etc/ssh/initrd"
|
sops -d "$pwpath/$initrdkey" > "$temp/etc/ssh/initrd"
|
||||||
|
|
||||||
|
sops -d "$pwpath/wg.private" > "$temp/etc/wireguard/wg.private"
|
||||||
# # Set the correct permissions so sshd will accept the key
|
# # Set the correct permissions so sshd will accept the key
|
||||||
chmod 600 "$temp/etc/ssh/$hostname"
|
chmod 600 "$temp/etc/ssh/$hostname"
|
||||||
chmod 600 "$temp/etc/ssh/initrd"
|
chmod 600 "$temp/etc/ssh/initrd"
|
||||||
|
|||||||
@@ -24,14 +24,16 @@ diskkey=$(sops -d machines/$hostname/secrets/disk.key)
|
|||||||
echo
|
echo
|
||||||
if [ $# = 1 ]
|
if [ $# = 1 ]
|
||||||
then
|
then
|
||||||
echo "$diskkey" | ssh $sshoptions root@$hostname-initrd "systemd-tty-ask-password-agent" #root
|
ssh $sshoptions root@$hostname-initrd "zpool import -a"
|
||||||
|
echo "$diskkey" | ssh $sshoptions root@$hostname-initrd "zfs load-key storage/encrypted" #root
|
||||||
echo "$diskkey" | ssh $sshoptions root@$hostname-initrd "systemd-tty-ask-password-agent" #data
|
echo "$diskkey" | ssh $sshoptions root@$hostname-initrd "systemd-tty-ask-password-agent" #data
|
||||||
|
|
||||||
elif [ $# = 2 ]
|
elif [ $# = 2 ]
|
||||||
then
|
then
|
||||||
ip=$2
|
ip=$2
|
||||||
echo "$diskkey" | ssh $sshoptions root@$ip "systemd-tty-ask-password-agent" #root
|
ssh $sshoptions root@$ip "zpool import -a"
|
||||||
echo "$diskkey" | ssh $sshoptions root@$ip "systemd-tty-ask-password-agent" #data
|
echo "$diskkey" | ssh $sshoptions root@$ip "zfs load-key storage/encrypted"
|
||||||
|
echo "$diskkey" | ssh $sshoptions root@$ip "systemd-tty-ask-password-agent"
|
||||||
|
|
||||||
else
|
else
|
||||||
echo
|
echo
|
||||||
|
|||||||
Reference in New Issue
Block a user