Hi,
My objective was to create, with unstable 20.03 channel :
- a remote unlock (ssh / openssh)
- LUKS1 (for grub, waiting this patch published) on LVM encrypted
- /boot partition (partly) encrypted
- legacy boot GRUB, not UEFI (i’m on hetzner vps)
Before asking this question :
- I follow the multiple github issues to see where we are in term of initrd secrets and all other fun stuff by @emily @Yana @lopsided98 :
- nixos/grub: support initrd secrets by lopsided98 · Pull Request #85418 · NixOS/nixpkgs · GitHub
- nixos/tests/initrd-network-ssh: fix with real initrd secrets implementation by lopsided98 · Pull Request #91744 · NixOS/nixpkgs · GitHub
- nixos/initrd-ssh: switch from Dropbear to OpenSSH by emilazy · Pull Request #82603 · NixOS/nixpkgs · GitHub
- I follow multiple gist tutorials :
- I read the existing topic on this discourse
Here the actual working result on public gist : https://gist.github.com/reyman/65ed5de52bef3f2230825f68b0b831c6
The LVM and LUKS part of script :
diskdev=/dev/sda
bootpart=/dev/sda2
rootpart=/dev/sda3
sgdisk -o -g -n 1::+5M -t 1:ef02 -n 2::+500M -t 2:8300 -n 3:: -t 3:8300 $diskdev
echo "$password" cryptsetup luksFormat --type luks1 -h sha512 $rootpart
echo "$password" cryptsetup luksOpen $rootpart enc-pv
pvcreate /dev/mapper/enc-pv
vgcreate vg0 /dev/mapper/enc-pv
lvcreate -L 8G -n swap vg0
lvcreate -L 40G -n nixos vg0
lvcreate -l '100%FREE' -n home vg0
# format disk
mkfs.ext2 -L boot $bootpart
mkfs.ext4 -L root /dev/vg0/nixos
mkfs.ext4 -L home /dev/vg0/home
mkswap -L swap /dev/vg0/swap
swapon /dev/vg0/swap
mount /dev/vg0/nixos /mnt
mkdir /mnt/boot
mount $bootpart /mnt/boot # boot is encrypted by the mounting ?
The configuration.nix
part with grub / secrets / network
boot.loader.grub.devices = [ "/dev/sda" ];
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
boot.loader.grub.enableCryptodisk = true;
boot.loader.supportsInitrdSecrets = true;
boot.initrd.kernelModules = [ "dm-snapshot" ];
boot.initrd.availableKernelModules = ["virtio-pci"];
boot.initrd.network = {
enable = true;
ssh = {
enable = true;
port = 2222;
authorizedKeys = ["ssh-rsa xxx"];
hostKeys = [ "/host_ecdsa_key" ];
};
};
boot.initrd.luks.devices = [
{
name = "enc-pv";
preLVM = true;
device = "$luksuuid";
allowDiscards = true;
}
];
boot.initrd.secrets = {
"/host_ecdsa_key" = "/host_ecdsa_key";
};
But there are some points i don’t understand and someone could probably enlight me :
-
in many tutorial, with /boot encrypted, normaly we need to enter the passphrase twice, for Grub, then at stage 1, this is not the case with this config, password is only asked at stage 1. Why ??
-
in this step many tutorials mount
/boot/efi
and not/boot
, but in legacy boot, we use directly/boot
. Where is the magic ? Where did we say that/boot
files are encrypted in this case ? We mount something unencrypted (/dev/sda2
as/mnt/boot
) to something encrypted (/dev/sda3
as/mnt
), but/dev/sda2
continue to be unencrypted. -
So if it’s not the case, what’s the best way to encrypt
/boot
without or without creating a new encrypted partition ? -
and a more general question, i see in many tutorials some peoples using “keyfile” to automaticaly unlock encrypted partitions ? This is counter productive in term of security, isn’it ? What’s the interest ?
Thanks for your help on that,