Tool for complete hardening of Linux boot chain with UEFI Secure Boot. Inspired by Hanno Heinrichs and Florent Hochwelker blog post.
Even if your hard disk is encrypted with full disk encryption, your bootloader config or initramdrive may be spoofed while you left your computer unattended. And this way your encryption key may be silently extracted when you unlock your system next time.
This kit establishes following signature verification chain: UEFI Secure Boot -> Custom GRUB2 Image with your embedded verification keys -> Signed kernel, initramrs, grub config.
Here is step by step guide:
- x64 UEFI-enabled Linux installation with GRUB2 bootloader
- GRUB2 config without
blscfgdirectives (they will fail boot since all files will have to be signed). Where applicable it is disabled automatically upon installation viaGRUB_ENABLE_BLSCFG="false"variable in/etc/default/grub - GRUB2 tools and modules (grub2-efi-x64-modules and grub2-tools on RPM-based distros, Debian-based provides them by default)
- sbsigntools (sbsigntool) 0.6+ (https://git.kernel.org/pub/scm/linux/kernel/git/jejb/sbsigntools.git/). If it is absent in your distro or too old, you have two options:
- Use static build. HEAD commit of this gist can be verified with my PGP public key. See install instructions in gist comment.
- Build it yourself. You'll need:
- @development-tools (build-essential)
- openssl-devel (libssl-dev)
- libuuid-devel (uuid-dev)
- binutils-devel (binutils-dev)
- efitools 1.9.2+ (https://git.kernel.org/pub/scm/linux/kernel/git/jejb/efitools.git). If it is absent in your distro or too old, you have two options:
- Use static build. HEAD commit of this gist can be verified with my PGP public key. See install instructions in gist comment.
- Build it yourself. You'll need:
- @development-tools (build-essential)
- openssl-devel (libssl-dev)
- gnu-efi-devel (gnu-efi)
- perl-File-Slurp (libfile-slurp-perl)
- help2man
If you are building efitools on Fedora you'll need this build script to workaroud library paths issue.
make backup
Usually, it can be done via BIOS Setup Menu.
When done, verify it. efi-readvar output should look like this:
# efi-readvar
Variable PK has no entries
Variable KEK has no entries
Variable db has no entries
Variable dbx has no entries
Variable MokList has no entries
sudo make
Root access is required for proper embedded boot config generation. You will be asked for GRUB password during build process.
sudo make install
All new installed kernels, ramdrives and grub config has to be signed on update. Automation of this process may differ on various distros, but basicly all you have to do is generate detached signature with gpg like this:
FILE=/boot/vmlinuz-5.0.13-300.fc30.x86_64
gpg2 --quiet --no-permission-warning \
--homedir /var/lib/secureboot/gpg-home \
--detach-sign \
--default-key "bootsigner@localhost" < "$FILE" > "$FILE.sig"For some distros we already have such installable automation.
sudo make fedora30-install
sudo make debian9-install
sudo make ubuntu-install
sudo make centos7-install
Actually, you may just run single command with final target for your system and make will figure out which actions are pending. But step-by-step process is more explicit and easier to troubleshoot.
Ensure Secure Boot is enabled in your BIOS settings and administrator password is set. Set 'SignedBoot' UEFI boot entry as your first boot option.