systemd: Fix systemd-{cryptenroll,cryptsetup} TPM2 and FIDO2 support#179823
systemd: Fix systemd-{cryptenroll,cryptsetup} TPM2 and FIDO2 support#179823Kranzes wants to merge 2 commits intoNixOS:stagingfrom
Conversation
Update pkgs/os-specific/linux/systemd/default.nix Co-authored-by: Jörg Thalheim <[email protected]>
zhaofengli
left a comment
There was a problem hiding this comment.
I tried this with FIDO2, and the following changes are required:
- Since #167167, files in
${cfg.package}/libare only selectively copied. This meanslib/systemd/.systemd-cryptsetup-wrappeddoesn't exist and[email protected]simply crashes with255/EXCEPTION. - The above problem also means that
lib/cryptsetup/libcryptsetup-token-systemd-{tpm2,fido2}.sodo not exist in initrd, causing immediate fallback to password. - A missing dependency means that FIDO2 support is not actually added into
systemdStage1: #184510. libfido2needs to be added to the initrd as well, otherwise the unlocking process will simply crash withFIDO2 support is not installed.
I don't have enough compute to actually rebuild the world, so I used the following config to replicate the PR:
{ pkgs, lib, ... }:
let
cryptsetup' = pkgs.cryptsetup.overrideAttrs (old: {
patches = (old.patches or []) ++ [
./relative-token-path.patch
];
});
# https://github.com/NixOS/nixpkgs/pull/184510
libfido2' = pkgs.libfido2.overrideAttrs (old: {
propagatedBuildInputs = (old.propagatedBuildInputs or []) ++ [
pkgs.openssl
];
});
patchSystemd = systemd: (systemd.override {
cryptsetup = cryptsetup';
libfido2 = libfido2';
}).overrideAttrs (old: {
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [
pkgs.makeBinaryWrapper
];
postFixup = (old.postFixup or "") + ''
for f in lib/systemd/systemd-cryptsetup bin/systemd-cryptenroll; do
# This needs to be in LD_LIBRARY_PATH because rpath on a binary is not propagated to libraries using dlopen, in this case `libcryptsetup.so`
wrapProgram $out/$f --prefix LD_LIBRARY_PATH : ${placeholder "out"}/lib/cryptsetup
done
'';
});
systemdStage1' = patchSystemd pkgs.systemdStage1;
in {
boot.initrd.systemd = {
enable = true;
package = systemdStage1';
emergencyAccess = true;
initrdBin = with pkgs; [ gnugrep cryptsetup strace ]; # for debugging only
storePaths = [
# FIXME: Add to PR in a clean way
"${systemdStage1'}/lib/systemd/.systemd-cryptsetup-wrapped"
"${systemdStage1'}/lib/cryptsetup/libcryptsetup-token-systemd-tpm2.so"
"${systemdStage1'}/lib/cryptsetup/libcryptsetup-token-systemd-fido2.so"
libfido2'
];
};
}FIDO2 unlocking works with the above changes, and I haven't tested TPM2.
|
Is there anything that could be done to speed up merge of this PR? It's the only thing that keeps me from installing NixOS on my laptop, and I would be glad to help with anything |
What needs to be done are:
@zhaofengli Do you mind further helping with this PR? |
|
I'll test out TPM2 and see how we can make those changes cleanly over the weekend. |
|
I opened #189676 with the required changes and instructions to test. |
|
Superseded by #189676 |
Description of changes
With this change it is now possible to decrypt LUKs protected partitions with a FIDO2 or TPM2 token.
Reviving #171242
Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes