Everybody wants encryption today; encryption of network traffic, mainly.
But what about the encryption of data-at-rest? I mean, what if someone got physical access to your storage?
Of course you can protect specific folders with your tools of choice, but there’s always a chance that some file got saved outside your security fence by a zealous program, or just forgotten by you on the desktop… here comes the Full Disk Encryption (shortly, FDE) to the rescue!
Maybe you are already using it without being aware of that… if BitLocker on Windows and FileVault on Mac OS X sound familiar, you are on track.
The penguin within
But, what about our beloved Linux machines?
In the Linux world, FDE is mainly achieved through LUKS; this software is capable of encrypting your disks with AES–XTS using both passphrases and key files, usually stored in an USB drive and plugged on-demand.
I won’t tell you how to setup LUKS in your machine because you should better refer to the installation manual of your distro.
If you plan to use it with a workstation, you’ll be set already manually inserting the password or the USB drive on every boot.
And my VMs?
But, what if you want to use LUKS in a virtual environment, in a hosted VM?
I won’t talk about acrobatic USB-passthrough, focusing instead on the passphrase method.
Of course, you can manually type it in your preferred hypervisor VM-console; but because having a very long and random passphrase is of utmost importance, writing a 40 characters long on every server reboot can be extremely tedious and can easily bring to bad habits, like short passphrases, avoiding necessary update-reboot cycles or dumping the LUKS thing at all.
Meeting the serial (killer?)
The best way of input long keys would be having it stored in encrypted keyrings with the possibility to copy-and-paste them into the VM prompt as needed, but the graphical consoles AFAIK don’t support input methods like that, and of course we cannot use SSH&co. because there isn’t any service running in the VM before boot.
There’s another way to access the VM at “physical” level, at least with hypervisors like KVM and XEN: the glorious and vintage serial console!
Maybe you have already heard of it for router configuration; shortly, it was the leading way of talking to an operating system out-of-band before the video output we use today.
Any Linux distribution provide this capability; to enable it in a CentOS 7 guest, you just need to modify your
/etc/default/grub to make it looks like this:
GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL="console serial" GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1" GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0,115200" GRUB_CMDLINE_LINUX="rd.lvm.lv=DONT_CHANGE_IT!/root rd.luks.uuid=DONT_CHANGE_IT! rd.lvm.lv=DONT_CHANGE_IT!/s wap rhgb" GRUB_DISABLE_RECOVERY="true"
and rebuild your initrd with
grub2-mkconfig -o /boot/grub2/grub.cfg.
Take a snapshot before doing any modification to your
grub.cfg, you have been warned!
Now reboot your system and everything should work as before, except for…
Yes, now there is an active serial interface that can be used to access your VM from the hypervisor, in a completely textually way.
Really, you can stop typing that super-long random string one-character-at-time right now!
The thing is, how to access it from the virtualization host?
- If you are using libvirt-virsh framework, you are lucky: just type
virsh console VMnameand you are set! The exit-escape is
- If you are on XenServer with XAPI, use the
xl console VMnameconsole (same escape). Dump that
xe consolecommand, it won’t help you if you are targeting an HVM guest; it is very likely that you are on HVM, you should now if you still are on PV-mode. The
xlcommand solution is undocumented in the XenServer doc, and it’s the actual reason why I wrote this post.
Oh, XL is also the new default toolstack for XEN management!
Now you should be set and smooth, go and enjoy your very-long and very-random LUKS passphrases!