When setting up Akmod for Nvidia, drivers, the RPMFusion instructions for setting up the key and adding it to my MOK include this line:
Because the Secure Boot key is available locally on your computer, (by default it’s in /etc/pki/akmods) you might need to consider encrypting your rootfs as appropriate in order to protect the key. Please consider this as a mandatory requirement, or consider to transfer the key to an external (and secure) location. or even use an hardware token
I already have LUKS setup, so my filesystem is encrypted. And this is what is suggested in responses to other questions, for example RPM fusion: What to do with the AKmods key stored in /etc/pki/akmods.
I find this answer unsatisfactory.
Here’s why. Starting from this comment: RPM fusion: What to do with the AKmods key stored in /etc/pki/akmods - #6 by computersavvy
Theoretically no one except root and akmods should be able to ever see the content of those files.
SecureBoot, as I understand it, will primarily protect me against an attacker with remote access. That is, even if an attacker gains root
access, SecureBoot + Lockdown should prevent the attacker from loading unsigned kernel modules, and if they use their root
access to modify the files (kernel, modules, etc.) in my /boot
partition, SecureBoot should detect that manipulation. I am basing this on this Reddit comment.
For that to work, an attacker, even one that has found a way to gain escalated privileges, must not be able to provide a legitimate signature for a kernel module.
If the Akmod key is sitting on my disk, then even if its permissions are set to “only root
+ akmod
” can read, an attacker who has achieved privilege escalation to manipulate my /boot
(which is also only writeable by root
) can presumably also read the Akmod key.
That seems like it would defeat the whole purpose of SecureBoot
LUKS doesn’t help here, because once my system has booted, the disk is decrypted, and Root can obviously read anything on the disk. The attack that “put the Akmod key in an encrypted partition” protects against would be something like:
- attacker gains physical access to the machine
- attacker uses a different system to bypass OS-level permissions in order to read the akmod key and install a signed malicious kernel module.
- attacker yields physical access and leaves the machine in my possession, and I continue to use it unaware of malware.
That just isn’t a threat I have any expectation of dealing with on my personal/consumer-level laptop. The threats I care about are either (1) malware/remote access achieves privilege esclation XOR (2) my laptop gets stolen.
In the case of (1) that’s where I want SecureBoot to prevent the malware from installing kernel/firmware level malware, and in the case of (2) that’s why I have LUKS, and SecureBoot isn’t doing anything anyway because the attacker can either just turn it off or move the drive to a machine that has SecureBoot disabled. (I have not been able to find instructions on enabling Measured Boot for Fedora, which I guess combines the two, and might protect more against a combined software/hardware attack, but again, a combined software/hardware attack is not something I really expect to deal with! Problem for another day.)
What can I do?
Let’s look at the options mentioned on Rpmfusion again:
Because the Secure Boot key is available locally on your computer, (by default it’s in /etc/pki/akmods) you might need to consider encrypting your rootfs as appropriate in order to protect the key. Please consider this as a mandatory requirement, or consider to transfer the key to an external (and secure) location. or even use an hardware token
We’ve already encrypted our rootfs, and also I’ve argued that doing so is useless at accomplishing the thing that I want SecureBoot to do for me.
Moving the key to an external location is not practical. Having to plug in an external hard drive or usb stick in order to perform system updates is a level of inconvenience I’m not willing to accept. Additionally, I don’t know how I would configure the akmod builder to use an externally stored key, except maybe by mounting the external drive over top of /etc/pki/akmods
before performing any operation that might trigger an akmod rebuild.
The only other option mentioned is “use an hardware token”. I have a yubikey I use for some web logins, though I haven’t ever experimented with using it for key storage for SSH or GPG keys, and I have no idea how I would configure akmod to sign kernel modules using my yubikey instead of a key stored in /etc/pki/akmods
.
The other option I can think of is to set up local encryption for just the /etc/pki/akmods
folder. I can’t use fscrypt
because I’m on btrfs
and as best I can tell that’s not supported by btrfs
yet, but eCryptfs is apparently deprecated/unsupported, so I don’t want to use that. I also don’t want to repartition just for this. Maybe I can create an ext4
image inside of a file and secure that with some other crypt setup? That just seems very complicated though and the more I have to do to mount /etc/pki/akmods
the more it seems like it would be easier to just put the mount for /etc/pki/akmods
on a flash drive…
Is there not a better way to deal with this? I really just want the private key in /etc/pki/akmods
to be encrypted with a symmetric key like my GPG key is, and have the akmod module builder just ask me for the password whenever it rebuilds kernel modules through dnf update
or akmods --force
.